Exemplo n.º 1
0
def GenerateJavadoc(options, src_dir, output_dir):
    working_dir = os.path.join(options.input_dir, 'android', 'api')
    overview_file = os.path.abspath(options.overview_file)

    android_sdk_jar = options.android_sdk_jar
    if not android_sdk_jar:
        android_sdk_jar = os.path.join(SDK_DIR, 'platforms', 'android-27',
                                       'android.jar')

    build_utils.DeleteDirectory(output_dir)
    build_utils.MakeDirectory(output_dir)
    javadoc_cmd = [
        os.path.abspath(JAVADOC_PATH),
        '-d',
        output_dir,
        '-quiet',
        '-overview',
        overview_file,
        '-doclet',
        'com.google.doclava.Doclava',
        '-docletpath',
        '%s:%s' % (os.path.join(DOCLAVA_DIR, 'jsilver.jar'),
                   os.path.join(DOCLAVA_DIR, 'doclava.jar')),
        '-title',
        'Cronet API',
        '-federate',
        'Android',
        'https://developer.android.com/',
        '-federationapi',
        'Android',
        os.path.join(DOCLAVA_DIR, 'current.txt'),
        '-classpath',
        '%s:%s' % (os.path.abspath(android_sdk_jar),
                   os.path.abspath(options.support_annotations_jar)),
    ]
    for subdir, _, files in os.walk(src_dir):
        for filename in files:
            if filename.endswith(".java"):
                javadoc_cmd += [os.path.join(subdir, filename)]
    try:

        def stderr_filter(stderr):
            return stderr.replace(JAVADOC_WARNING, '')

        build_utils.CheckOutput(javadoc_cmd,
                                cwd=working_dir,
                                stderr_filter=stderr_filter)
    except build_utils.CalledProcessError:
        build_utils.DeleteDirectory(output_dir)
        raise

    # Create an index.html file at the root as this is the accepted format.
    # Do this by copying reference/index.html and adjusting the path.
    with open(os.path.join(output_dir, 'reference', 'index.html'), 'r') as \
        old_index, open(os.path.join(output_dir, 'index.html'), 'w') as new_index:
        for line in old_index:
            new_index.write(
                line.replace('classes.html',
                             os.path.join('reference', 'classes.html')))
Exemplo n.º 2
0
def main(argv):
    options = ParseArgs()

    build_utils.DeleteDirectory(options.res_v14_compatibility_dir)
    build_utils.MakeDirectory(options.res_v14_compatibility_dir)

    for name in os.listdir(options.res_dir):
        if not os.path.isdir(os.path.join(options.res_dir, name)):
            continue

        dir_pieces = name.split('-')
        resource_type = dir_pieces[0]
        qualifiers = dir_pieces[1:]

        # Android pre-v17 API doesn't support RTL. Skip.
        if 'ldrtl' in qualifiers:
            continue

        # We also need to copy the original v17 resource to *-v17 directory
        # because the generated v14 resource will hide the original resource.
        input_dir = os.path.join(options.res_dir, name)
        output_v14_dir = os.path.join(options.res_v14_compatibility_dir, name)
        output_v17_dir = os.path.join(options.res_v14_compatibility_dir,
                                      name + '-v17')

        # We only convert resources under layout*/, xml*/,
        # and style resources under values*/.
        # TODO(kkimlabs): don't process xml directly once all layouts have
        # been moved out of XML directory. see http://crbug.com/238458
        if resource_type in ('layout', 'xml', 'values'):
            GenerateV14XmlResourcesInDir(input_dir, output_v14_dir,
                                         output_v17_dir)

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 3
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    options = _ParseArgs(args)

    debug_temp_resources_dir = os.environ.get(_ENV_DEBUG_VARIABLE)
    if debug_temp_resources_dir:
        debug_temp_resources_dir = os.path.join(
            debug_temp_resources_dir, os.path.basename(options.apk_path))
        build_utils.DeleteDirectory(debug_temp_resources_dir)
        build_utils.MakeDirectory(debug_temp_resources_dir)

    with resource_utils.BuildContext(debug_temp_resources_dir) as build:
        dep_subdirs = resource_utils.ExtractDeps(options.dependencies_res_zips,
                                                 build.deps_dir)

        _PackageApk(options, dep_subdirs, build.temp_dir, build.gen_dir,
                    build.r_txt_path)

        r_txt_path = _WriteFinalRTxtFile(options, build.r_txt_path)

        # If --shared-resources-whitelist is used, the all resources listed in
        # the corresponding R.txt file will be non-final, and an onResourcesLoaded()
        # will be generated to adjust them at runtime.
        #
        # Otherwise, if --shared-resources is used, the all resources will be
        # non-final, and an onResourcesLoaded() method will be generated too.
        #
        # Otherwise, all resources will be final, and no method will be generated.
        #
        rjava_build_options = resource_utils.RJavaBuildOptions()
        if options.shared_resources_whitelist:
            rjava_build_options.ExportSomeResources(
                options.shared_resources_whitelist)
            rjava_build_options.GenerateOnResourcesLoaded()
        elif options.shared_resources or options.app_as_shared_lib:
            rjava_build_options.ExportAllResources()
            rjava_build_options.GenerateOnResourcesLoaded()

        resource_utils.CreateRJavaFiles(build.srcjar_dir, None, r_txt_path,
                                        options.extra_res_packages,
                                        options.extra_r_text_files,
                                        rjava_build_options)

        if options.srcjar_out:
            build_utils.ZipDir(options.srcjar_out, build.srcjar_dir)

        if options.check_resources_pkg_id is not None:
            expected_id = options.check_resources_pkg_id
            package_id = _ExtractPackageIdFromApk(options.apk_path,
                                                  options.aapt_path)
            if package_id != expected_id:
                raise Exception('Invalid package ID 0x%x (expected 0x%x)' %
                                (package_id, expected_id))

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 options.apk_path,
                                 inputs=options.dependencies_res_zips +
                                 options.extra_r_text_files,
                                 add_pydeps=False)
Exemplo n.º 4
0
def main(argv):
    options = ParseArgs()

    build_utils.DeleteDirectory(options.res_v14_compatibility_dir)
    build_utils.MakeDirectory(options.res_v14_compatibility_dir)

    for name in os.listdir(options.res_dir):
        if not os.path.isdir(os.path.join(options.res_dir, name)):
            continue

        dir_pieces = name.split('-')
        resource_type = dir_pieces[0]
        qualifiers = dir_pieces[1:]

        api_level_qualifier_index = -1
        api_level_qualifier = ''
        for index, qualifier in enumerate(qualifiers):
            if re.match('v[0-9]+$', qualifier):
                api_level_qualifier_index = index
                api_level_qualifier = qualifier
                break

        # Android pre-v17 API doesn't support RTL. Skip.
        if 'ldrtl' in qualifiers:
            continue

        input_dir = os.path.abspath(os.path.join(options.res_dir, name))

        if options.verify_only:
            if not api_level_qualifier or int(api_level_qualifier[1:]) < 17:
                VerifyV14ResourcesInDir(input_dir, resource_type)
            else:
                AssertNoDeprecatedAttributesInDir(input_dir, resource_type)
        else:
            # We also need to copy the original v17 resource to *-v17 directory
            # because the generated v14 resource will hide the original resource.
            output_v14_dir = os.path.join(options.res_v14_compatibility_dir,
                                          name)
            output_v17_dir = os.path.join(options.res_v14_compatibility_dir,
                                          name + '-v17')

            # We only convert layout resources under layout*/, xml*/,
            # and style resources under values*/.
            if resource_type in ('layout', 'xml'):
                if not api_level_qualifier:
                    GenerateV14LayoutResourcesInDir(input_dir, output_v14_dir,
                                                    output_v17_dir)
            elif resource_type == 'values':
                if api_level_qualifier == 'v17':
                    output_qualifiers = qualifiers[:]
                    del output_qualifiers[api_level_qualifier_index]
                    output_v14_dir = os.path.join(
                        options.res_v14_compatibility_dir,
                        '-'.join([resource_type] + output_qualifiers))
                    GenerateV14StyleResourcesInDir(input_dir, output_v14_dir)
                elif not api_level_qualifier:
                    ErrorIfStyleResourceExistsInDir(input_dir)

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 5
0
def main(argv):
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option("--protoc", help="Path to protoc binary.")
    parser.add_option("--proto-path", help="Path to proto directory.")
    parser.add_option("--java-out-dir",
                      help="Path to output directory for java files.")
    parser.add_option("--srcjar", help="Path to output srcjar.")
    parser.add_option("--stamp", help="File to touch on success.")
    parser.add_option("--nano",
                      help="Use to generate nano protos.",
                      action='store_true')
    options, args = parser.parse_args(argv)

    build_utils.CheckOptions(options, parser, ['protoc', 'proto_path'])
    if not options.java_out_dir and not options.srcjar:
        print 'One of --java-out-dir or --srcjar must be specified.'
        return 1

    with build_utils.TempDir() as temp_dir:
        if options.nano:
            # Specify arguments to the generator.
            generator_args = [
                'optional_field_style=reftypes', 'store_unknown_fields=true'
            ]
            out_arg = '--javanano_out=' + ','.join(
                generator_args) + ':' + temp_dir
        else:
            out_arg = '--java_out=' + temp_dir

            # Check if all proto files (which are listed in the args) are opting to
            # use the lite runtime, otherwise we'd have to include the much heavier
            # regular proto runtime in Chrome.
            # TODO(jkrcal): Replace this check by '--java_lite_out=' for the out_arg
            # above once this works on the master branch of the protobuf library,
            # expected in version 4.0 (see https://crbug.com/800281).
            for proto_file in args:
                if not 'LITE_RUNTIME' in open(proto_file).read():
                    raise Exception(
                        'Chrome only supports lite protos. Please add "optimize_for = '
                        'LITE_RUNTIME" to your proto file to enable the lite runtime.'
                    )
        # Generate Java files using protoc.
        build_utils.CheckOutput(
            [options.protoc, '--proto_path', options.proto_path, out_arg] +
            args)

        if options.java_out_dir:
            build_utils.DeleteDirectory(options.java_out_dir)
            shutil.copytree(temp_dir, options.java_out_dir)
        else:
            build_utils.ZipDir(options.srcjar, temp_dir)

    if options.depfile:
        assert options.srcjar
        deps = args + [options.protoc]
        build_utils.WriteDepfile(options.depfile, options.srcjar, deps)

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 6
0
def _ExtractAllChromeLocalesLists():
  with build_utils.TempDir() as tmp_path:
    if _DEBUG_LOCALES_WORK_DIR:
      tmp_path = _DEBUG_LOCALES_WORK_DIR
      build_utils.DeleteDirectory(tmp_path)
      build_utils.MakeDirectory(tmp_path)

    out_path = _PrepareTinyGnWorkspace(tmp_path, 'out')

    # NOTE: The file suffixes used here should be kept in sync with
    # build/config/locales.gni
    gn_executable = _FindGnExecutable()
    subprocess.check_output(
        [gn_executable, 'gen', out_path, '--root=' + tmp_path])

    global _INTERNAL_CHROME_LOCALES
    _INTERNAL_CHROME_LOCALES = _ReadJsonList(
        os.path.join(out_path, 'foo.locales'))

    global _INTERNAL_ANDROID_OMITTED_LOCALES
    _INTERNAL_ANDROID_OMITTED_LOCALES = _ReadJsonList(
        os.path.join(out_path, 'foo.android_omitted_locales'))

    global _INTERNAL_IOS_UNSUPPORTED_LOCALES
    _INTERNAL_IOS_UNSUPPORTED_LOCALES = _ReadJsonList(
        os.path.join(out_path, 'foo.ios_unsupported_locales'))
Exemplo n.º 7
0
def main(argv):
  parser = optparse.OptionParser()
  build_utils.AddDepfileOption(parser)
  parser.add_option("--protoc", help="Path to protoc binary.")
  parser.add_option("--proto-path", help="Path to proto directory.")
  parser.add_option("--java-out-dir",
      help="Path to output directory for java files.")
  parser.add_option("--srcjar", help="Path to output srcjar.")
  parser.add_option("--stamp", help="File to touch on success.")
  parser.add_option("--nano",
      help="Use to generate nano protos.", action='store_true')
  parser.add_option("--protoc-javalite-plugin-dir",
      help="Path to protoc java lite plugin directory.")
  options, args = parser.parse_args(argv)

  build_utils.CheckOptions(options, parser, ['protoc', 'proto_path'])
  if not options.java_out_dir and not options.srcjar:
    print 'One of --java-out-dir or --srcjar must be specified.'
    return 1

  if not options.nano and not options.protoc_javalite_plugin_dir:
    print 'One of --nano or --protoc-javalite-plugin-dir must be specified.'
    return 1

  with build_utils.TempDir() as temp_dir:
    if options.nano:
      # Specify arguments to the generator.
      generator_args = ['optional_field_style=reftypes',
                        'store_unknown_fields=true']
      out_arg = '--javanano_out=' + ','.join(generator_args) + ':' + temp_dir
    else:
      out_arg = '--javalite_out=' + temp_dir

    custom_env = os.environ.copy()
    if options.protoc_javalite_plugin_dir:
      # if we are generating lite protos, then the lite plugin needs to be in the path when protoc
      # is called. See https://github.com/protocolbuffers/protobuf/blob/master/java/lite.md
      custom_env['PATH'] = '{}:{}'.format(
          os.path.abspath(options.protoc_javalite_plugin_dir), custom_env['PATH'])

    # Generate Java files using protoc.
    build_utils.CheckOutput(
        [options.protoc, '--proto_path', options.proto_path, out_arg]
        + args, env=custom_env)

    if options.java_out_dir:
      build_utils.DeleteDirectory(options.java_out_dir)
      shutil.copytree(temp_dir, options.java_out_dir)
    else:
      build_utils.ZipDir(options.srcjar, temp_dir)

  if options.depfile:
    assert options.srcjar
    deps = args + [options.protoc]
    build_utils.WriteDepfile(options.depfile, options.srcjar, deps,
                             add_pydeps=False)

  if options.stamp:
    build_utils.Touch(options.stamp)
Exemplo n.º 8
0
def DoCompress(dest_path, sources):
    build_utils.DeleteDirectory(dest_path)
    build_utils.MakeDirectory(dest_path)

    for source in sources:
        shutil.copy(source, dest_path)
        file_to_compress = os.path.join(dest_path, os.path.basename(source))
        subprocess.check_call(['lzma', '-f', file_to_compress])
Exemplo n.º 9
0
 def Compile():
     # Delete the classes directory. This ensures that all .class files in the
     # output are actually from the input .java files. For example, if a .java
     # file is deleted or an inner class is removed, the classes directory should
     # not contain the corresponding old .class file after running this action.
     build_utils.DeleteDirectory(output_dir)
     build_utils.MakeDirectory(output_dir)
     build_utils.CheckOutput(javac_cmd, print_stdout=options.chromium_code)
Exemplo n.º 10
0
def DoJavac(options):
    output_dir = options.output_dir

    src_dirs = build_utils.ParseGypList(options.src_dirs)
    java_files = build_utils.FindInDirectories(src_dirs, '*.java')
    if options.javac_includes:
        javac_includes = build_utils.ParseGypList(options.javac_includes)
        filtered_java_files = []
        for f in java_files:
            for include in javac_includes:
                if fnmatch.fnmatch(f, include):
                    filtered_java_files.append(f)
                    break
        java_files = filtered_java_files

    # Compiling guava with certain orderings of input files causes a compiler
    # crash... Sorted order works, so use that.
    # See https://code.google.com/p/guava-libraries/issues/detail?id=950
    java_files.sort()
    classpath = build_utils.ParseGypList(options.classpath)

    jar_inputs = []
    for path in classpath:
        if os.path.exists(path + '.TOC'):
            jar_inputs.append(path + '.TOC')
        else:
            jar_inputs.append(path)

    javac_cmd = [
        'javac',
        '-g',
        '-source',
        '1.5',
        '-target',
        '1.5',
        '-classpath',
        ':'.join(classpath),
        '-d',
        output_dir,
        '-Xlint:unchecked',
        '-Xlint:deprecation',
    ] + java_files

    md5_stamp = '%s/javac.md5' % options.output_dir
    md5_checker = md5_check.Md5Checker(stamp=md5_stamp,
                                       inputs=java_files + jar_inputs,
                                       command=javac_cmd)
    if md5_checker.IsStale():
        # Delete the classes directory. This ensures that all .class files in the
        # output are actually from the input .java files. For example, if a .java
        # file is deleted or an inner class is removed, the classes directory should
        # not contain the corresponding old .class file after running this action.
        build_utils.DeleteDirectory(output_dir)
        build_utils.MakeDirectory(output_dir)
        suppress_output = not options.chromium_code
        build_utils.CheckCallDie(javac_cmd, suppress_output=suppress_output)
        md5_checker.Write()
Exemplo n.º 11
0
def main(argv):
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--protoc',
                        required=True,
                        help='Path to protoc binary.')
    parser.add_argument('--proto-path',
                        required=True,
                        help='Path to proto directory.')
    parser.add_argument('--java-out-dir',
                        help='Path to output directory for java files.')
    parser.add_argument('--srcjar', help='Path to output srcjar.')
    parser.add_argument('--stamp', help='File to touch on success.')
    parser.add_argument(
        '--import-dir',
        action='append',
        default=[],
        help='Extra import directory for protos, can be repeated.')
    parser.add_argument('protos', nargs='+', help='proto source files')
    options = parser.parse_args(argv)

    if not options.java_out_dir and not options.srcjar:
        raise Exception('One of --java-out-dir or --srcjar must be specified.')

    _EnforceJavaPackage(options.protos)

    with build_utils.TempDir() as temp_dir:
        out_arg = '--java_out=lite:' + temp_dir

        proto_path_args = ['--proto_path', options.proto_path]
        for path in options.import_dir:
            proto_path_args += ["--proto_path", path]

        # Generate Java files using protoc.
        build_utils.CheckOutput(
            [options.protoc] + proto_path_args + [out_arg] + options.protos,
            # protoc generates superfluous warnings about LITE_RUNTIME deprecation
            # even though we are using the new non-deprecated method.
            stderr_filter=lambda output: build_utils.FilterLines(
                output, '|'.join(
                    [r'optimize_for = LITE_RUNTIME', r'java/lite\.md'])))

        if options.java_out_dir:
            build_utils.DeleteDirectory(options.java_out_dir)
            shutil.copytree(temp_dir, options.java_out_dir)
        else:
            build_utils.ZipDir(options.srcjar, temp_dir)

    if options.depfile:
        assert options.srcjar
        deps = options.protos + [options.protoc]
        build_utils.WriteDepfile(options.depfile, options.srcjar, deps)

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 12
0
def GenerateJavadoc(options, args):
    source_dir = options.source_dir
    output_dir = options.output_dir

    build_utils.DeleteDirectory(output_dir)
    build_utils.MakeDirectory(output_dir)
    javadoc_cmd = [
        'javadoc', '-sourcepath', source_dir, '-d',
        os.path.abspath(output_dir)
    ] + args
    build_utils.CheckOutput(javadoc_cmd)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--android-template',
                        required=True,
                        help='Path to the main template directory.')
    parser.add_argument('--core-library-dir',
                        required=True,
                        help='Path to xwalk_core_library/.')
    parser.add_argument('--extra-files',
                        help='Extra files to add to the template.')
    parser.add_argument('--output-dir',
                        required=True,
                        help='Directory where the app template files will be '
                        'stored.')
    parser.add_argument('--shared-library-dir',
                        required=True,
                        help='Path to xwalk_shared_library/.')
    parser.add_argument('--stamp',
                        required=True,
                        help='Path to touch on success.')
    parser.add_argument('--xwalk-runtime-jar',
                        required=True,
                        help='Path to the Crosswalk runtime JAR.')

    args = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))

    build_utils.DeleteDirectory(args.output_dir)
    build_utils.MakeDirectory(args.output_dir)

    shutil.copytree(
        args.android_template,
        os.path.join(args.output_dir, 'template'),
        # Make sure app/android/app_template's BUILD.gn is
        # not included.
        ignore=shutil.ignore_patterns('*.gn'))
    shutil.copytree(args.core_library_dir,
                    os.path.join(args.output_dir, 'xwalk_core_library'))
    shutil.copytree(args.shared_library_dir,
                    os.path.join(args.output_dir, 'xwalk_shared_library'))

    # For now at least, we have to continue calling the runtime JAR
    # xwalk_app_runtime_java.jar to avoid breaking app-tools.
    template_libs_dir = os.path.join(args.output_dir, 'template', 'libs')
    build_utils.MakeDirectory(template_libs_dir)
    shutil.copy2(args.xwalk_runtime_jar,
                 os.path.join(template_libs_dir, 'xwalk_app_runtime_java.jar'))

    for extra_file in build_utils.ParseGypList(args.extra_files):
        # For now we just assume all files are supposed to go to the root of the
        # output directory.
        shutil.copy2(extra_file, args.output_dir)

    build_utils.Touch(args.stamp)
Exemplo n.º 14
0
def ProcessResources(options):
    with open(options.rules_path) as f:
        rules = JarJarRules(f.read())

    build_utils.DeleteDirectory(options.output_dir)
    for input_dir in options.input_dir:
        shutil.copytree(input_dir, options.output_dir)

    for root, _dirnames, filenames in os.walk(options.output_dir):
        layout_files = LayoutFilesFilter(root, filenames)
        for layout_file in layout_files:
            ProcessLayoutFile(os.path.join(root, layout_file), rules)
def main():
    options = ParseArgs()

    res_v14_dir = options.res_v14_compatibility_dir

    build_utils.DeleteDirectory(res_v14_dir)
    build_utils.MakeDirectory(res_v14_dir)

    GenerateV14Resources(options.res_dir, res_v14_dir, options.verify_only)

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 16
0
def main(args):
    args = build_utils.ExpandFileArgs(args)

    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)

    parser.add_option('--dest', help='Directory to copy files to.')
    parser.add_option('--files',
                      action='append',
                      help='List of files to copy.')
    parser.add_option(
        '--clear',
        action='store_true',
        help='If set, the destination directory will be deleted '
        'before copying files to it. This is highly recommended to '
        'ensure that no stale files are left in the directory.')
    parser.add_option('--stamp', help='Path to touch on success.')
    parser.add_option('--renaming-sources',
                      action='append',
                      help='List of files need to be renamed while being '
                      'copied to dest directory')
    parser.add_option('--renaming-destinations',
                      action='append',
                      help='List of destination file name without path, the '
                      'number of elements must match rename-sources.')

    options, _ = parser.parse_args(args)

    if options.clear:
        build_utils.DeleteDirectory(options.dest)
        build_utils.MakeDirectory(options.dest)

    deps = []

    if options.files:
        DoCopy(options, deps)

    if options.renaming_sources:
        DoRenaming(options, deps)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 options.stamp,
                                 deps,
                                 add_pydeps=False)

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 17
0
def main(args):
    args = build_utils.ExpandFileArgs(args)

    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)

    parser.add_option('--dest', help='Directory to copy files to.')
    parser.add_option('--files',
                      action='append',
                      help='List of files to copy.')
    parser.add_option(
        '--clear',
        action='store_true',
        help='If set, the destination directory will be deleted '
        'before copying files to it. This is highly recommended to '
        'ensure that no stale files are left in the directory.')
    parser.add_option('--stamp', help='Path to touch on success.')

    options, _ = parser.parse_args(args)

    if options.clear:
        build_utils.DeleteDirectory(options.dest)
        build_utils.MakeDirectory(options.dest)

    files = []
    for file_arg in options.files:
        files += build_utils.ParseGypList(file_arg)

    deps = []

    for f in files:
        if os.path.isdir(f):
            if not options.clear:
                print('To avoid stale files you must use --clear when copying '
                      'directories')
                sys.exit(-1)
            shutil.copytree(f, os.path.join(options.dest, os.path.basename(f)))
            deps.extend(_get_all_files(f))
        else:
            shutil.copy(f, options.dest)
            deps.append(f)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 deps + build_utils.GetPythonDependencies())

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 18
0
def main():
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--output-dir', help='Directory to put javadoc')
    parser.add_option('--input-dir', help='Root of cronet source')
    parser.add_option('--input-src-jar', help='Cronet api source jar')
    parser.add_option('--overview-file', help='Path of the overview page')
    parser.add_option('--readme-file', help='Path of the README.md')
    parser.add_option('--zip-file', help='Path to ZIP archive of javadocs.')
    parser.add_option('--android-sdk-jar', help='Path to android.jar')
    parser.add_option('--support-annotations-jar',
                      help='Path to support-annotations-$VERSION.jar')

    options, _ = parser.parse_args()
    # A temporary directory to put the output of cronet api source jar files.
    unzipped_jar_path = tempfile.mkdtemp(dir=options.output_dir)
    if os.path.exists(options.input_src_jar):
        jar_cmd = ['jar', 'xf', os.path.abspath(options.input_src_jar)]
        build_utils.CheckOutput(jar_cmd, cwd=unzipped_jar_path)
    else:
        raise Exception('Jar file does not exist: %s' % options.input_src_jar)

    net_docs.ProcessDocs([options.readme_file],
                         options.input_dir,
                         options.output_dir,
                         extensions=[CronetExtension()])

    output_dir = os.path.abspath(os.path.join(options.output_dir, 'javadoc'))
    GenerateJavadoc(options, os.path.abspath(unzipped_jar_path), output_dir)

    if options.zip_file:
        assert options.zip_file.endswith('.zip')
        shutil.make_archive(options.zip_file[:-4], 'zip', output_dir)
    if options.depfile:
        assert options.zip_file
        deps = []
        for root, _, filenames in os.walk(options.input_dir):
            # Ignore .pyc files here, it might be re-generated during build.
            deps.extend(
                os.path.join(root, f) for f in filenames
                if not f.endswith('.pyc'))
        build_utils.WriteDepfile(options.depfile, options.zip_file, deps)
    # Clean up temporary output directory.
    build_utils.DeleteDirectory(unzipped_jar_path)
Exemplo n.º 19
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--dest-path',
                        required=True,
                        help='Destination directory for compressed files.')
    parser.add_argument('--sources',
                        required=True,
                        help='The list of files to be compressed.')

    options = parser.parse_args()
    options.sources = build_utils.ParseGypList(options.sources)

    with build_utils.TempDir() as temp_dir:
        for source in options.sources:
            shutil.copy2(source, temp_dir)
            file_to_compress = os.path.join(temp_dir, os.path.basename(source))
            build_utils.CheckOutput(['lzma', '-f', file_to_compress],
                                    print_stderr=True)
        build_utils.DeleteDirectory(options.dest_path)
        shutil.copytree(temp_dir, options.dest_path)
Exemplo n.º 20
0
def main(argv):
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option("--protoc", help="Path to protoc binary.")
    parser.add_option("--proto-path", help="Path to proto directory.")
    parser.add_option("--java-out-dir",
                      help="Path to output directory for java files.")
    parser.add_option("--srcjar", help="Path to output srcjar.")
    parser.add_option("--stamp", help="File to touch on success.")
    options, args = parser.parse_args(argv)

    build_utils.CheckOptions(options, parser, ['protoc', 'proto_path'])
    if not options.java_out_dir and not options.srcjar:
        print 'One of --java-out-dir or --srcjar must be specified.'
        return 1

    with build_utils.TempDir() as temp_dir:
        # Specify arguments to the generator.
        generator_args = [
            'optional_field_style=reftypes', 'store_unknown_fields=true'
        ]
        out_arg = '--javanano_out=' + ','.join(generator_args) + ':' + temp_dir
        # Generate Java files using protoc.
        build_utils.CheckOutput(
            [options.protoc, '--proto_path', options.proto_path, out_arg] +
            args)

        if options.java_out_dir:
            build_utils.DeleteDirectory(options.java_out_dir)
            shutil.copytree(temp_dir, options.java_out_dir)
        else:
            build_utils.ZipDir(options.srcjar, temp_dir)

    if options.depfile:
        assert options.srcjar
        deps = args + [options.protoc]
        build_utils.WriteDepfile(options.depfile, options.srcjar, deps)

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 21
0
def main(args):
    args = build_utils.ExpandFileArgs(args)

    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)

    parser.add_option('--dest', help='Directory to copy files to.')
    parser.add_option('--files',
                      action='append',
                      help='List of files to copy.')
    parser.add_option(
        '--clear',
        action='store_true',
        help='If set, the destination directory will be deleted '
        'before copying files to it. This is highly recommended to '
        'ensure that no stale files are left in the directory.')
    parser.add_option('--stamp', help='Path to touch on success.')

    options, _ = parser.parse_args(args)

    if options.clear:
        build_utils.DeleteDirectory(options.dest)
        build_utils.MakeDirectory(options.dest)

    files = []
    for file_arg in options.files:
        files += build_utils.ParseGypList(file_arg)

    for f in files:
        shutil.copy(f, options.dest)

    if options.depfile:
        build_utils.WriteDepfile(
            options.depfile,
            options.files + build_utils.GetPythonDependencies())

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 22
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    options = _ParseArgs(args)

    debug_temp_resources_dir = os.environ.get(_ENV_DEBUG_VARIABLE)
    if debug_temp_resources_dir:
        debug_temp_resources_dir = os.path.join(
            debug_temp_resources_dir, os.path.basename(options.arsc_path))
        build_utils.DeleteDirectory(debug_temp_resources_dir)
        build_utils.MakeDirectory(debug_temp_resources_dir)

    with resource_utils.BuildContext(debug_temp_resources_dir) as build:
        _PackageApk(options, build)

        # If --shared-resources-whitelist is used, the all resources listed in
        # the corresponding R.txt file will be non-final, and an onResourcesLoaded()
        # will be generated to adjust them at runtime.
        #
        # Otherwise, if --shared-resources is used, the all resources will be
        # non-final, and an onResourcesLoaded() method will be generated too.
        #
        # Otherwise, all resources will be final, and no method will be generated.
        #
        rjava_build_options = resource_utils.RJavaBuildOptions()
        if options.shared_resources_whitelist:
            rjava_build_options.ExportSomeResources(
                options.shared_resources_whitelist)
            rjava_build_options.GenerateOnResourcesLoaded()
        elif options.shared_resources or options.app_as_shared_lib:
            rjava_build_options.ExportAllResources()
            rjava_build_options.GenerateOnResourcesLoaded()

        custom_root_package_name = None
        grandparent_custom_package_name = None

        if options.arsc_package_name:
            # This is for test apks with an apk under test. If we have an apk under
            # test we don't want to name the resources for both the test apk and the
            # under test apk "base". This special case lets us name the test apk's
            # resources "test".
            custom_root_package_name = 'test'
        elif options.package_name:
            # If there exists a custom package name such as vr for a feature module,
            # pass the name and base for the parent_custom_root_package_name.
            custom_root_package_name = options.package_name
            grandparent_custom_package_name = 'base'
        else:
            # No grandparent_custom_package_name for base module
            custom_root_package_name = 'base'

        resource_utils.CreateRJavaFiles(
            build.srcjar_dir, None, build.r_txt_path,
            options.extra_res_packages, options.extra_r_text_files,
            rjava_build_options, options.srcjar_out, custom_root_package_name,
            grandparent_custom_package_name)

        build_utils.ZipDir(build.srcjar_path, build.srcjar_dir)

        # Sanity check that the created resources have the expected package ID.
        expected_id = _PackageIdFromOptions(options)
        if expected_id is None:
            expected_id = '0x00' if options.shared_resources else '0x7f'
        expected_id = int(expected_id, 16)
        _, package_id = resource_utils.ExtractArscPackage(
            options.aapt2_path,
            build.arsc_path if options.arsc_path else build.proto_path)
        if package_id != expected_id:
            raise Exception('Invalid package ID 0x%x (expected 0x%x)' %
                            (package_id, expected_id))

        _WriteOutputs(options, build)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 options.srcjar_out,
                                 inputs=options.dependencies_res_zips +
                                 options.extra_r_text_files,
                                 add_pydeps=False)
Exemplo n.º 23
0
def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('--abi', help='Android ABI being used in the build.')
    parser.add_argument('--binary-files',
                        help='Binary files to store in res/raw.')
    parser.add_argument('--js-bindings',
                        required=True,
                        help='.js files to copy to res/raw.')
    parser.add_argument('--main-jar',
                        required=True,
                        help='Path to the main JAR to copy to libs/.')
    parser.add_argument('--native-libraries',
                        help='List of libraries to copy to libs/<abi>.')
    parser.add_argument('--output-dir',
                        required=True,
                        help='Directory where the project will be created.')
    parser.add_argument('--resource-strings',
                        default='',
                        help='List of zipped .grd files.')
    parser.add_argument('--resource-zip-sources',
                        default='',
                        help='Source directories corresponding to each zipped '
                        'resource file from --resource-zips.')
    parser.add_argument('--resource-zips',
                        default='',
                        help='Zipped, processed resource files.')
    parser.add_argument('--stamp',
                        required=True,
                        help='Path to touch on success.')
    parser.add_argument('--template-dir',
                        required=True,
                        help='Directory with an empty app template.')

    options = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))

    options.resource_strings = build_utils.ParseGypList(
        options.resource_strings)
    options.resource_zips = build_utils.ParseGypList(options.resource_zips)
    options.resource_zip_sources = build_utils.ParseGypList(
        options.resource_zip_sources)

    # With GN, just create a list with None as elements, we derive the source
    # directories based on the zipped resources' paths.
    if len(options.resource_zip_sources) == 0:
        options.resource_zip_sources = [None] * len(options.resource_zips)
    if len(options.resource_zips) != len(options.resource_zip_sources):
        print('--resource-zips and --resource-zip-sources must have the same '
              'number of arguments.')
        return 1

    resources = []
    for resource_zip, resource_src in zip(options.resource_zips,
                                          options.resource_zip_sources):
        if resource_zip.endswith('_grd.resources.zip'):
            # In GN, we just use --resource-zips, and the string files are
            # part of the list.
            # We need to put them into options.resource_strings for separate
            # processing, and do so by filtering the files by their names.
            options.resource_strings.append(resource_zip)
        else:
            resources.append(MakeResourceTuple(resource_zip, resource_src))

    # Copy Eclipse project files of library project.
    build_utils.DeleteDirectory(options.output_dir)
    shutil.copytree(options.template_dir, options.output_dir)

    # Copy binaries and resources.
    CopyResources(options.output_dir, resources, options.resource_strings)
    CopyMainJar(options.output_dir, options.main_jar)

    if options.binary_files:
        CopyBinaryData(options.output_dir,
                       build_utils.ParseGypList(options.binary_files))

    if options.native_libraries:
        CopyNativeLibraries(options.output_dir, options.abi,
                            build_utils.ParseGypList(options.native_libraries))

    # Copy JS API binding files.
    CopyJSBindingFiles(build_utils.ParseGypList(options.js_bindings),
                       options.output_dir)

    # Create an empty src/.
    build_utils.MakeDirectory(os.path.join(options.output_dir, 'src'))
    build_utils.Touch(os.path.join(options.output_dir, 'src', '.empty'))

    build_utils.Touch(options.stamp)
Exemplo n.º 24
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    options = _ParseArgs(args)

    # Order of these must match order specified in GN so that the correct one
    # appears first in the depfile.
    possible_output_paths = [
        options.apk_path,
        options.apk_path + '.info',
        options.r_text_out,
        options.srcjar_out,
        options.proguard_file,
        options.proguard_file_main_dex,
        options.unoptimized_resources_path,
    ]
    output_paths = [x for x in possible_output_paths if x]

    # List python deps in input_strings rather than input_paths since the contents
    # of them does not change what gets written to the depsfile.
    input_strings = options.extra_res_packages + [
        options.shared_resources,
        options.resource_blacklist_regex,
        options.resource_blacklist_exceptions,
        str(options.debuggable),
        str(options.png_to_webp),
        str(options.support_zh_hk),
        str(options.no_xml_namespaces),
        str(options.optimize_resources),
    ]

    input_strings.extend(_CreateLinkApkArgs(options))

    debug_temp_resources_dir = os.environ.get(_ENV_DEBUG_VARIABLE)
    if debug_temp_resources_dir:
        debug_temp_resources_dir = os.path.join(
            debug_temp_resources_dir, os.path.basename(options.apk_path))
        build_utils.DeleteDirectory(debug_temp_resources_dir)
        build_utils.MakeDirectory(debug_temp_resources_dir)

    possible_input_paths = [
        options.aapt_path,
        options.aapt2_path,
        options.android_manifest,
        options.shared_resources_whitelist,
        options.resources_config_path,
    ]
    possible_input_paths += options.include_resources
    input_paths = [x for x in possible_input_paths if x]
    input_paths.extend(options.dependencies_res_zips)
    input_paths.extend(options.extra_r_text_files)

    if options.webp_binary:
        input_paths.append(options.webp_binary)

    build_utils.CallAndWriteDepfileIfStale(
        lambda: _OnStaleMd5(options, debug_temp_resources_dir),
        options,
        input_paths=input_paths,
        input_strings=input_strings,
        output_paths=output_paths,
        force=bool(debug_temp_resources_dir),
        depfile_deps=options.dependencies_res_zips +
        options.extra_r_text_files,
        add_pydeps=False)
Exemplo n.º 25
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option(
        '--clear-dir',
        action='store_true',
        help='If set, the destination directory will be deleted '
        'before copying files to it. This is highly recommended to '
        'ensure that no stale files are left in the directory.')

    parser.add_option('--configuration-name',
                      default='Release',
                      help='Gyp configuration name (i.e. Debug, Release)')
    parser.add_option(
        '--enable-packing',
        choices=['0', '1'],
        help=('Pack relocations if 1 and configuration name is \'Release\','
              ' otherwise plain file copy'))
    parser.add_option(
        '--has-relocations-with-addends',
        choices=['0', '1'],
        help=(
            'Pack into \'.android.rela.dyn\' if 1, else \'.android.rel.dyn\''))
    parser.add_option('--exclude-packing-list',
                      default='',
                      help='Names of any libraries explicitly not packed')
    parser.add_option('--android-pack-relocations',
                      help='Path to the ARM relocations packer binary')
    parser.add_option('--android-objcopy',
                      help='Path to the toolchain\'s objcopy binary')
    parser.add_option('--stripped-libraries-dir',
                      help='Directory for stripped libraries')
    parser.add_option('--packed-libraries-dir',
                      help='Directory for packed libraries')
    parser.add_option('--libraries', action='append', help='List of libraries')
    parser.add_option('--stamp', help='Path to touch on success')

    options, _ = parser.parse_args(args)
    enable_packing = (options.enable_packing == '1'
                      and options.configuration_name == 'Release')
    has_relocations_with_addends = (
        options.has_relocations_with_addends == '1')
    exclude_packing_set = set(shlex.split(options.exclude_packing_list))

    libraries = []
    for libs_arg in options.libraries:
        libraries += build_utils.ParseGypList(libs_arg)

    if options.clear_dir:
        build_utils.DeleteDirectory(options.packed_libraries_dir)

    build_utils.MakeDirectory(options.packed_libraries_dir)

    for library in libraries:
        library_path = os.path.join(options.stripped_libraries_dir, library)
        output_path = os.path.join(options.packed_libraries_dir,
                                   os.path.basename(library))

        if enable_packing and library not in exclude_packing_set:
            PackArmLibraryRelocations(options.android_pack_relocations,
                                      options.android_objcopy,
                                      has_relocations_with_addends,
                                      library_path, output_path)
        else:
            CopyArmLibraryUnchanged(library_path, output_path)

    if options.depfile:
        build_utils.WriteDepfile(
            options.depfile, libraries + build_utils.GetPythonDependencies())

    if options.stamp:
        build_utils.Touch(options.stamp)

    return 0
def main():
    options = ParseArgs()
    android_jar = os.path.join(options.android_sdk, 'android.jar')
    aapt = os.path.join(options.android_sdk_tools, 'aapt')

    build_utils.DeleteDirectory(options.R_dir)
    build_utils.MakeDirectory(options.R_dir)

    with build_utils.TempDir() as temp_dir:
        deps_dir = os.path.join(temp_dir, 'deps')
        build_utils.MakeDirectory(deps_dir)
        v14_dir = os.path.join(temp_dir, 'v14')
        build_utils.MakeDirectory(v14_dir)

        input_resource_dirs = build_utils.ParseGypList(options.resource_dirs)

        for resource_dir in input_resource_dirs:
            generate_v14_compatible_resources.GenerateV14Resources(
                resource_dir, v14_dir, options.v14_verify_only)

        # Generate R.java. This R.java contains non-final constants and is used only
        # while compiling the library jar (e.g. chromium_content.jar). When building
        # an apk, a new R.java file with the correct resource -> ID mappings will be
        # generated by merging the resources from all libraries and the main apk
        # project.
        package_command = [
            aapt, 'package', '-m', '-M', options.android_manifest,
            '--auto-add-overlay', '-I', android_jar, '--output-text-symbols',
            options.R_dir, '-J', options.R_dir
        ]

        for d in input_resource_dirs:
            package_command += ['-S', d]

        dep_zips = build_utils.ParseGypList(options.dependencies_res_zips)
        for z in dep_zips:
            subdir = os.path.join(deps_dir, os.path.basename(z))
            if os.path.exists(subdir):
                raise Exception('Resource zip name conflict: ' +
                                os.path.basename(z))
            build_utils.ExtractAll(z, path=subdir)
            package_command += ['-S', subdir]

        if options.non_constant_id:
            package_command.append('--non-constant-id')
        if options.custom_package:
            package_command += ['--custom-package', options.custom_package]
        if options.proguard_file:
            package_command += ['-G', options.proguard_file]
        build_utils.CheckOutput(package_command, print_stderr=False)

        if options.extra_res_packages:
            CreateExtraRJavaFiles(
                options.R_dir,
                build_utils.ParseGypList(options.extra_res_packages),
                build_utils.ParseGypList(options.extra_r_text_files))

        # This is the list of directories with resources to put in the final .zip
        # file. The order of these is important so that crunched/v14 resources
        # override the normal ones.
        zip_resource_dirs = input_resource_dirs + [v14_dir]

        base_crunch_dir = os.path.join(temp_dir, 'crunch')

        # Crunch image resources. This shrinks png files and is necessary for
        # 9-patch images to display correctly. 'aapt crunch' accepts only a single
        # directory at a time and deletes everything in the output directory.
        for idx, d in enumerate(input_resource_dirs):
            crunch_dir = os.path.join(base_crunch_dir, str(idx))
            build_utils.MakeDirectory(crunch_dir)
            zip_resource_dirs.append(crunch_dir)
            aapt_cmd = [aapt, 'crunch', '-C', crunch_dir, '-S', d]
            build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail)

        # Python zipfile does not provide a way to replace a file (it just writes
        # another file with the same name). So, first collect all the files to put
        # in the zip (with proper overriding), and then zip them.
        files_to_zip = dict()
        for d in zip_resource_dirs:
            for root, _, files in os.walk(d):
                for f in files:
                    archive_path = os.path.join(os.path.relpath(root, d), f)
                    path = os.path.join(root, f)
                    files_to_zip[archive_path] = path
        with zipfile.ZipFile(options.resource_zip_out, 'w') as outzip:
            for archive_path, path in files_to_zip.iteritems():
                outzip.write(path, archive_path)

        if options.stamp:
            build_utils.Touch(options.stamp)
Exemplo n.º 27
0
def main():
    args = build_utils.ExpandFileArgs(sys.argv[1:])

    options = ParseArgs(args)
    android_jar = os.path.join(options.android_sdk, 'android.jar')
    aapt = os.path.join(options.android_sdk_tools, 'aapt')

    input_files = []

    with build_utils.TempDir() as temp_dir:
        deps_dir = os.path.join(temp_dir, 'deps')
        build_utils.MakeDirectory(deps_dir)
        v14_dir = os.path.join(temp_dir, 'v14')
        build_utils.MakeDirectory(v14_dir)

        gen_dir = os.path.join(temp_dir, 'gen')
        build_utils.MakeDirectory(gen_dir)

        input_resource_dirs = build_utils.ParseGypList(options.resource_dirs)

        for resource_dir in input_resource_dirs:
            generate_v14_compatible_resources.GenerateV14Resources(
                resource_dir, v14_dir, options.v14_verify_only)

        dep_zips = build_utils.ParseGypList(options.dependencies_res_zips)
        input_files += dep_zips
        dep_subdirs = []
        for z in dep_zips:
            subdir = os.path.join(deps_dir, os.path.basename(z))
            if os.path.exists(subdir):
                raise Exception('Resource zip name conflict: ' +
                                os.path.basename(z))
            build_utils.ExtractAll(z, path=subdir)
            dep_subdirs.append(subdir)

        # Generate R.java. This R.java contains non-final constants and is used only
        # while compiling the library jar (e.g. chromium_content.jar). When building
        # an apk, a new R.java file with the correct resource -> ID mappings will be
        # generated by merging the resources from all libraries and the main apk
        # project.
        package_command = [
            aapt, 'package', '-m', '-M', options.android_manifest,
            '--auto-add-overlay', '-I', android_jar, '--output-text-symbols',
            gen_dir, '-J', gen_dir
        ]

        for d in input_resource_dirs:
            package_command += ['-S', d]

        for d in dep_subdirs:
            package_command += ['-S', d]

        if options.non_constant_id:
            package_command.append('--non-constant-id')
        if options.custom_package:
            package_command += ['--custom-package', options.custom_package]
        if options.proguard_file:
            package_command += ['-G', options.proguard_file]
        build_utils.CheckOutput(package_command, print_stderr=False)

        if options.extra_res_packages:
            CreateExtraRJavaFiles(
                gen_dir, build_utils.ParseGypList(options.extra_res_packages),
                build_utils.ParseGypList(options.extra_r_text_files))

        # This is the list of directories with resources to put in the final .zip
        # file. The order of these is important so that crunched/v14 resources
        # override the normal ones.
        zip_resource_dirs = input_resource_dirs + [v14_dir]

        base_crunch_dir = os.path.join(temp_dir, 'crunch')

        # Crunch image resources. This shrinks png files and is necessary for
        # 9-patch images to display correctly. 'aapt crunch' accepts only a single
        # directory at a time and deletes everything in the output directory.
        for idx, d in enumerate(input_resource_dirs):
            crunch_dir = os.path.join(base_crunch_dir, str(idx))
            build_utils.MakeDirectory(crunch_dir)
            zip_resource_dirs.append(crunch_dir)
            aapt_cmd = [aapt, 'crunch', '-C', crunch_dir, '-S', d]
            build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail)

        ZipResources(zip_resource_dirs, options.resource_zip_out)

        if options.all_resources_zip_out:
            ZipResources(zip_resource_dirs + dep_subdirs,
                         options.all_resources_zip_out)

        if options.R_dir:
            build_utils.DeleteDirectory(options.R_dir)
            shutil.copytree(gen_dir, options.R_dir)
        else:
            build_utils.ZipDir(options.srcjar_out, gen_dir)

    if options.depfile:
        input_files += build_utils.GetPythonDependencies()
        build_utils.WriteDepfile(options.depfile, input_files)

    if options.stamp:
        build_utils.Touch(options.stamp)
Exemplo n.º 28
0
def main(args):
    build_utils.InitLogging('RESOURCE_DEBUG')
    args = build_utils.ExpandFileArgs(args)
    options = _ParseArgs(args)

    if options.expected_file:
        actual_data = _CreateNormalizedManifestForVerification(options)
        diff_utils.CheckExpectations(actual_data, options)
        if options.only_verify_expectations:
            return

    path = options.arsc_path or options.proto_path
    debug_temp_resources_dir = os.environ.get('TEMP_RESOURCES_DIR')
    if debug_temp_resources_dir:
        path = os.path.join(debug_temp_resources_dir, os.path.basename(path))
    else:
        # Use a deterministic temp directory since .pb files embed the absolute
        # path of resources: crbug.com/939984
        path = path + '.tmpdir'
    build_utils.DeleteDirectory(path)

    with resource_utils.BuildContext(
            temp_dir=path, keep_files=bool(debug_temp_resources_dir)) as build:

        manifest_package_name = _PackageApk(options, build)

        # If --shared-resources-allowlist is used, all the resources listed in the
        # corresponding R.txt file will be non-final, and an onResourcesLoaded()
        # will be generated to adjust them at runtime.
        #
        # Otherwise, if --shared-resources is used, the all resources will be
        # non-final, and an onResourcesLoaded() method will be generated too.
        #
        # Otherwise, all resources will be final, and no method will be generated.
        #
        rjava_build_options = resource_utils.RJavaBuildOptions()
        if options.shared_resources_allowlist:
            rjava_build_options.ExportSomeResources(
                options.shared_resources_allowlist)
            rjava_build_options.GenerateOnResourcesLoaded()
            if options.shared_resources:
                # The final resources will only be used in WebLayer, so hardcode the
                # package ID to be what WebLayer expects.
                rjava_build_options.SetFinalPackageId(
                    protoresources.SHARED_LIBRARY_HARDCODED_ID)
        elif options.shared_resources or options.app_as_shared_lib:
            rjava_build_options.ExportAllResources()
            rjava_build_options.GenerateOnResourcesLoaded()

        custom_root_package_name = options.r_java_root_package_name
        grandparent_custom_package_name = None

        # Always generate an R.java file for the package listed in
        # AndroidManifest.xml because this is where Android framework looks to find
        # onResourcesLoaded() for shared library apks. While not actually necessary
        # for application apks, it also doesn't hurt.
        apk_package_name = manifest_package_name

        if options.package_name and not options.arsc_package_name:
            # Feature modules have their own custom root package name and should
            # inherit from the appropriate base module package. This behaviour should
            # not be present for test apks with an apk under test. Thus,
            # arsc_package_name is used as it is only defined for test apks with an
            # apk under test.
            custom_root_package_name = options.package_name
            grandparent_custom_package_name = options.r_java_root_package_name
            # Feature modules have the same manifest package as the base module but
            # they should not create an R.java for said manifest package because it
            # will be created in the base module.
            apk_package_name = None

        logging.debug('Creating R.srcjar')
        resource_utils.CreateRJavaFiles(
            build.srcjar_dir, apk_package_name, build.r_txt_path,
            options.extra_res_packages, rjava_build_options,
            options.srcjar_out, custom_root_package_name,
            grandparent_custom_package_name, options.extra_main_r_text_files)
        build_utils.ZipDir(build.srcjar_path, build.srcjar_dir)

        # Sanity check that the created resources have the expected package ID.
        logging.debug('Performing sanity check')
        if options.package_id:
            expected_id = options.package_id
        elif options.shared_resources:
            expected_id = 0
        else:
            expected_id = 127  # == '0x7f'.
        _, package_id = resource_utils.ExtractArscPackage(
            options.aapt2_path,
            build.arsc_path if options.arsc_path else build.proto_path)
        if package_id != expected_id:
            raise Exception('Invalid package ID 0x%x (expected 0x%x)' %
                            (package_id, expected_id))

        logging.debug('Copying outputs')
        _WriteOutputs(options, build)

    if options.depfile:
        depfile_deps = (options.dependencies_res_zips +
                        options.dependencies_res_zip_overlays +
                        options.extra_main_r_text_files +
                        options.include_resources)
        build_utils.WriteDepfile(options.depfile, options.srcjar_out,
                                 depfile_deps)
Exemplo n.º 29
0
def main(args):
    build_utils.InitLogging('RESOURCE_DEBUG')
    args = build_utils.ExpandFileArgs(args)
    options = _ParseArgs(args)

    path = options.arsc_path or options.proto_path
    debug_temp_resources_dir = os.environ.get('TEMP_RESOURCES_DIR')
    if debug_temp_resources_dir:
        path = os.path.join(debug_temp_resources_dir, os.path.basename(path))
    else:
        # Use a deterministic temp directory since .pb files embed the absolute
        # path of resources: crbug.com/939984
        path = path + '.tmpdir'
    build_utils.DeleteDirectory(path)
    build_utils.MakeDirectory(path)

    with resource_utils.BuildContext(
            temp_dir=path, keep_files=bool(debug_temp_resources_dir)) as build:
        manifest_package_name = _PackageApk(options, build)

        # If --shared-resources-whitelist is used, the all resources listed in
        # the corresponding R.txt file will be non-final, and an onResourcesLoaded()
        # will be generated to adjust them at runtime.
        #
        # Otherwise, if --shared-resources is used, the all resources will be
        # non-final, and an onResourcesLoaded() method will be generated too.
        #
        # Otherwise, all resources will be final, and no method will be generated.
        #
        rjava_build_options = resource_utils.RJavaBuildOptions()
        if options.shared_resources_whitelist:
            rjava_build_options.ExportSomeResources(
                options.shared_resources_whitelist)
            rjava_build_options.GenerateOnResourcesLoaded()
        elif options.shared_resources or options.app_as_shared_lib:
            rjava_build_options.ExportAllResources()
            rjava_build_options.GenerateOnResourcesLoaded()

        custom_root_package_name = options.r_java_root_package_name
        grandparent_custom_package_name = None

        if options.package_name and not options.arsc_package_name:
            # Feature modules have their own custom root package name and should
            # inherit from the appropriate base module package. This behaviour should
            # not be present for test apks with an apk under test. Thus,
            # arsc_package_name is used as it is only defined for test apks with an
            # apk under test.
            custom_root_package_name = options.package_name
            grandparent_custom_package_name = options.r_java_root_package_name

        if options.shared_resources or options.app_as_shared_lib:
            package_for_library = manifest_package_name
        else:
            package_for_library = None

        logging.debug('Creating R.srcjar')
        resource_utils.CreateRJavaFiles(
            build.srcjar_dir, package_for_library, build.r_txt_path,
            options.extra_res_packages, options.extra_r_text_files,
            rjava_build_options, options.srcjar_out, custom_root_package_name,
            grandparent_custom_package_name, options.extra_main_r_text_files)
        build_utils.ZipDir(build.srcjar_path, build.srcjar_dir)

        # Sanity check that the created resources have the expected package ID.
        logging.debug('Performing sanity check')
        if options.package_id:
            expected_id = options.package_id
        elif options.shared_resources:
            expected_id = 0
        else:
            expected_id = 127  # == '0x7f'.
        _, package_id = resource_utils.ExtractArscPackage(
            options.aapt2_path,
            build.arsc_path if options.arsc_path else build.proto_path)
        if package_id != expected_id:
            raise Exception('Invalid package ID 0x%x (expected 0x%x)' %
                            (package_id, expected_id))

        logging.debug('Copying outputs')
        _WriteOutputs(options, build)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 options.srcjar_out,
                                 inputs=options.dependencies_res_zips +
                                 options.extra_r_text_files,
                                 add_pydeps=False)
Exemplo n.º 30
0
def main(argv):
  colorama.init()

  argv = build_utils.ExpandFileArgs(argv)

  parser = optparse.OptionParser()
  build_utils.AddDepfileOption(parser)

  parser.add_option(
      '--src-gendirs',
      help='Directories containing generated java files.')
  parser.add_option(
      '--java-srcjars',
      action='append',
      default=[],
      help='List of srcjars to include in compilation.')
  parser.add_option(
      '--bootclasspath',
      action='append',
      default=[],
      help='Boot classpath for javac. If this is specified multiple times, '
      'they will all be appended to construct the classpath.')
  parser.add_option(
      '--classpath',
      action='append',
      help='Classpath for javac. If this is specified multiple times, they '
      'will all be appended to construct the classpath.')
  parser.add_option(
      '--javac-includes',
      help='A list of file patterns. If provided, only java files that match'
      'one of the patterns will be compiled.')
  parser.add_option(
      '--jar-excluded-classes',
      default='',
      help='List of .class file patterns to exclude from the jar.')

  parser.add_option(
      '--chromium-code',
      type='int',
      help='Whether code being compiled should be built with stricter '
      'warnings for chromium code.')

  parser.add_option(
      '--use-errorprone-path',
      help='Use the Errorprone compiler at this path.')

  parser.add_option(
      '--classes-dir',
      help='Directory for compiled .class files.')
  parser.add_option('--jar-path', help='Jar output path.')
  parser.add_option(
      '--main-class',
      help='The class containing the main method.')
  parser.add_option(
      '--manifest-entry',
      action='append',
      help='Key:value pairs to add to the .jar manifest.')

  parser.add_option('--stamp', help='Path to touch on success.')

  options, args = parser.parse_args(argv)

  if options.main_class and not options.jar_path:
    parser.error('--main-class requires --jar-path')

  bootclasspath = []
  for arg in options.bootclasspath:
    bootclasspath += build_utils.ParseGypList(arg)

  classpath = []
  for arg in options.classpath:
    classpath += build_utils.ParseGypList(arg)

  java_srcjars = []
  for arg in options.java_srcjars:
    java_srcjars += build_utils.ParseGypList(arg)

  java_files = args
  if options.src_gendirs:
    src_gendirs = build_utils.ParseGypList(options.src_gendirs)
    java_files += build_utils.FindInDirectories(src_gendirs, '*.java')

  input_files = bootclasspath + classpath + java_srcjars + java_files
  with build_utils.TempDir() as temp_dir:
    classes_dir = os.path.join(temp_dir, 'classes')
    os.makedirs(classes_dir)
    if java_srcjars:
      java_dir = os.path.join(temp_dir, 'java')
      os.makedirs(java_dir)
      for srcjar in java_srcjars:
        build_utils.ExtractAll(srcjar, path=java_dir, pattern='*.java')
      java_files += build_utils.FindInDirectory(java_dir, '*.java')

    if options.javac_includes:
      javac_includes = build_utils.ParseGypList(options.javac_includes)
      filtered_java_files = []
      for f in java_files:
        for include in javac_includes:
          if fnmatch.fnmatch(f, include):
            filtered_java_files.append(f)
            break
      java_files = filtered_java_files

    if len(java_files) != 0:
      DoJavac(
          bootclasspath,
          classpath,
          classes_dir,
          options.chromium_code,
          options.use_errorprone_path,
          java_files)

    if options.jar_path:
      if options.main_class or options.manifest_entry:
        if options.manifest_entry:
          entries = map(lambda e: e.split(":"), options.manifest_entry)
        else:
          entries = []
        manifest_file = os.path.join(temp_dir, 'manifest')
        CreateManifest(manifest_file, classpath, options.main_class, entries)
      else:
        manifest_file = None
      jar.JarDirectory(classes_dir,
                       build_utils.ParseGypList(options.jar_excluded_classes),
                       options.jar_path,
                       manifest_file=manifest_file)

    if options.classes_dir:
      # Delete the old classes directory. This ensures that all .class files in
      # the output are actually from the input .java files. For example, if a
      # .java file is deleted or an inner class is removed, the classes
      # directory should not contain the corresponding old .class file after
      # running this action.
      build_utils.DeleteDirectory(options.classes_dir)
      shutil.copytree(classes_dir, options.classes_dir)

  if options.depfile:
    build_utils.WriteDepfile(
        options.depfile,
        input_files + build_utils.GetPythonDependencies())

  if options.stamp:
    build_utils.Touch(options.stamp)