예제 #1
0
파일: dex.py 프로젝트: chhxia/chromium
def main():
  args = build_utils.ExpandFileArgs(sys.argv[1:])

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

  parser.add_option('--android-sdk-tools',
                    help='Android sdk build tools directory.')
  parser.add_option('--output-directory',
                    default=os.getcwd(),
                    help='Path to the output build directory.')
  parser.add_option('--dex-path', help='Dex output path.')
  parser.add_option('--configuration-name',
                    help='The build CONFIGURATION_NAME.')
  parser.add_option('--proguard-enabled',
                    help='"true" if proguard is enabled.')
  parser.add_option('--proguard-enabled-input-path',
                    help=('Path to dex in Release mode when proguard '
                          'is enabled.'))
  parser.add_option('--no-locals',
                    help='Exclude locals list from the dex file.')
  parser.add_option('--multi-dex', default=False, action='store_true',
                    help='Create multiple dex files.')
  parser.add_option('--inputs', help='A list of additional input paths.')
  parser.add_option('--excluded-paths',
                    help='A list of paths to exclude from the dex file.')
  parser.add_option('--main-dex-list-paths',
                    help='A list of paths containing a list of the classes to '
                         'include in the main dex.')

  options, paths = parser.parse_args(args)

  required_options = ('android_sdk_tools',)
  build_utils.CheckOptions(options, parser, required=required_options)

  if (options.proguard_enabled == 'true'
      and options.configuration_name == 'Release'):
    paths = [options.proguard_enabled_input_path]

  if options.inputs:
    paths += build_utils.ParseGypList(options.inputs)

  if options.excluded_paths:
    # Excluded paths are relative to the output directory.
    exclude_paths = build_utils.ParseGypList(options.excluded_paths)
    paths = [p for p in paths if not
             os.path.relpath(p, options.output_directory) in exclude_paths]

  if options.multi_dex and options.main_dex_list_paths:
    DoMultiDex(options, paths)
  else:
    if options.multi_dex:
      logging.warning('--multi-dex is unused without --main-dex-list-paths')
    elif options.main_dex_list_paths:
      logging.warning('--main-dex-list-paths is unused without --multi-dex')
    DoDex(options, paths)

  if options.depfile:
    build_utils.WriteDepfile(
        options.depfile,
        paths + build_utils.GetPythonDependencies())
예제 #2
0
def main():
    options = ParseArgs()
    android_jar = os.path.join(options.android_sdk, 'android.jar')
    aapt = options.aapt_path

    with build_utils.TempDir() as temp_dir:
        package_command = [
            aapt,
            'package',
            '--version-code',
            options.version_code,
            '--version-name',
            options.version_name,
            '-M',
            options.android_manifest,
            '--no-crunch',
            '-f',
            '--auto-add-overlay',
            '-I',
            android_jar,
            '-F',
            options.apk_path,
            '--ignore-assets',
            build_utils.AAPT_IGNORE_PATTERN,
        ]

        if options.no_compress:
            for ext in options.no_compress.split(','):
                package_command += ['-0', ext]
        if options.shared_resources:
            package_command.append('--shared-lib')

        if options.asset_dir and os.path.exists(options.asset_dir):
            package_command += ['-A', options.asset_dir]

        if options.resource_zips:
            dep_zips = build_utils.ParseGypList(options.resource_zips)
            for z in dep_zips:
                subdir = os.path.join(temp_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 += PackageArgsForExtractedZip(subdir)

        if options.create_density_splits:
            for config in DENSITY_SPLITS.itervalues():
                package_command.extend(('--split', ','.join(config)))

        language_splits = None
        if options.language_splits:
            language_splits = build_utils.ParseGypList(options.language_splits)
            for lang in language_splits:
                package_command.extend(('--split', lang))

        if 'Debug' in options.configuration_name:
            package_command += ['--debug-mode']

        build_utils.CheckOutput(package_command,
                                print_stdout=False,
                                print_stderr=False)

        if options.create_density_splits or language_splits:
            CheckForMissedConfigs(options.apk_path,
                                  options.create_density_splits,
                                  language_splits)

        if options.create_density_splits:
            RenameDensitySplits(options.apk_path)

        if options.depfile:
            build_utils.WriteDepfile(options.depfile,
                                     build_utils.GetPythonDependencies())
def main():
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--inputs', help='The template files to process.')
    parser.add_option('--output',
                      help='The output file to generate. Valid '
                      'only if there is a single input.')
    parser.add_option('--outputs-zip',
                      help='A zip file containing the processed '
                      'templates. Required if there are multiple inputs.')
    parser.add_option('--inputs-base-dir',
                      help='A common ancestor directory of '
                      'the inputs. Each output\'s path in the output zip will '
                      'match the relative path from INPUTS_BASE_DIR to the '
                      'input. Required if --output-zip is given.')
    parser.add_option('--loader-base-dir',
                      help='Base path used by the template '
                      'loader. Must be a common ancestor directory of '
                      'the inputs. Defaults to DIR_SOURCE_ROOT.',
                      default=host_paths.DIR_SOURCE_ROOT)
    parser.add_option('--variables',
                      help='Variables to be made available in the '
                      'template processing environment, as a GYP list (e.g. '
                      '--variables "channel=beta mstone=39")',
                      default='')
    options, args = parser.parse_args()

    build_utils.CheckOptions(options, parser, required=['inputs'])
    inputs = build_utils.ParseGypList(options.inputs)

    if (options.output is None) == (options.outputs_zip is None):
        parser.error('Exactly one of --output and --output-zip must be given')
    if options.output and len(inputs) != 1:
        parser.error('--output cannot be used with multiple inputs')
    if options.outputs_zip and not options.inputs_base_dir:
        parser.error(
            '--inputs-base-dir must be given when --output-zip is used')
    if args:
        parser.error('No positional arguments should be given.')

    variables = {}
    for v in build_utils.ParseGypList(options.variables):
        if '=' not in v:
            parser.error('--variables argument must contain "=": ' + v)
        name, _, value = v.partition('=')
        variables[name] = value

    loader = RecordingFileSystemLoader(options.loader_base_dir)
    env = jinja2.Environment(loader=loader,
                             undefined=jinja2.StrictUndefined,
                             line_comment_prefix='##')
    if options.output:
        ProcessFile(env, inputs[0], options.loader_base_dir, options.output,
                    variables)
    else:
        ProcessFiles(env, inputs, options.loader_base_dir,
                     options.inputs_base_dir, options.outputs_zip, variables)

    if options.depfile:
        deps = loader.get_loaded_templates(
        ) + build_utils.GetPythonDependencies()
        build_utils.WriteDepfile(options.depfile, deps)
예제 #4
0
def main(argv):
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--build-config', help='Path to build_config output.')
    parser.add_option('--type',
                      help='Type of this target (e.g. android_library).')
    parser.add_option(
        '--possible-deps-configs',
        help='List of paths for dependency\'s build_config files. Some '
        'dependencies may not write build_config files. Missing build_config '
        'files are handled differently based on the type of this target.')

    # android_resources options
    parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
    parser.add_option('--resources-zip',
                      help='Path to target\'s resources zip.')
    parser.add_option('--r-text', help='Path to target\'s R.txt file.')
    parser.add_option('--package-name',
                      help='Java package name for these resources.')
    parser.add_option('--android-manifest', help='Path to android manifest.')

    # android_assets options
    parser.add_option('--asset-sources', help='List of asset sources.')
    parser.add_option('--asset-renaming-sources',
                      help='List of asset sources with custom destinations.')
    parser.add_option('--asset-renaming-destinations',
                      help='List of asset custom destinations.')
    parser.add_option('--disable-asset-compression',
                      action='store_true',
                      help='Whether to disable asset compression.')

    # java library options
    parser.add_option('--jar-path', help='Path to target\'s jar output.')
    parser.add_option(
        '--supports-android',
        action='store_true',
        help='Whether this library supports running on the Android platform.')
    parser.add_option(
        '--requires-android',
        action='store_true',
        help='Whether this library requires running on the Android platform.')
    parser.add_option(
        '--bypass-platform-checks',
        action='store_true',
        help='Bypass checks for support/require Android platform.')

    # android library options
    parser.add_option('--dex-path', help='Path to target\'s dex output.')

    # native library options
    parser.add_option('--native-libs', help='List of top-level native libs.')
    parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.')

    # apk options
    parser.add_option('--apk-path', help='Path to the target\'s apk output.')

    parser.add_option(
        '--tested-apk-config',
        help=
        'Path to the build config of the tested apk (for an instrumentation '
        'test apk).')
    parser.add_option('--proguard-enabled',
                      action='store_true',
                      help='Whether proguard is enabled for this apk.')
    parser.add_option('--proguard-info',
                      help='Path to the proguard .info output for this apk.')

    options, args = parser.parse_args(argv)

    if args:
        parser.error('No positional arguments should be given.')

    required_options_map = {
        'java_library': ['build_config', 'jar_path'],
        'android_assets': ['build_config'],
        'android_resources': ['build_config', 'resources_zip'],
        'android_apk':
        ['build_config', 'jar_path', 'dex_path', 'resources_zip'],
        'deps_dex': ['build_config', 'dex_path'],
        'resource_rewriter': ['build_config']
    }
    required_options = required_options_map.get(options.type)
    if not required_options:
        raise Exception('Unknown type: <%s>' % options.type)

    if options.native_libs:
        required_options.append('readelf_path')

    build_utils.CheckOptions(options, parser, required_options)

    if options.type == 'java_library':
        if options.supports_android and not options.dex_path:
            raise Exception(
                'java_library that supports Android requires a dex path.')

        if options.requires_android and not options.supports_android:
            raise Exception(
                '--supports-android is required when using --requires-android')

    possible_deps_config_paths = build_utils.ParseGypList(
        options.possible_deps_configs)

    allow_unknown_deps = (options.type in ('android_apk', 'android_assets',
                                           'android_resources'))
    unknown_deps = [
        c for c in possible_deps_config_paths if not os.path.exists(c)
    ]
    if unknown_deps and not allow_unknown_deps:
        raise Exception('Unknown deps: ' + str(unknown_deps))

    direct_deps_config_paths = [
        c for c in possible_deps_config_paths if not c in unknown_deps
    ]

    deps = Deps(direct_deps_config_paths)
    direct_library_deps = deps.Direct('java_library')
    all_library_deps = deps.All('java_library')

    direct_resources_deps = deps.Direct('android_resources')
    all_resources_deps = deps.All('android_resources')
    # Resources should be ordered with the highest-level dependency first so that
    # overrides are done correctly.
    all_resources_deps.reverse()

    if options.type == 'android_apk' and options.tested_apk_config:
        tested_apk_deps = Deps([options.tested_apk_config])
        tested_apk_resources_deps = tested_apk_deps.All('android_resources')
        all_resources_deps = [
            d for d in all_resources_deps if not d in tested_apk_resources_deps
        ]

    # Initialize some common config.
    config = {
        'deps_info': {
            'name': os.path.basename(options.build_config),
            'path': options.build_config,
            'type': options.type,
            'deps_configs': direct_deps_config_paths,
        }
    }
    deps_info = config['deps_info']

    if options.type == 'java_library' and not options.bypass_platform_checks:
        deps_info['requires_android'] = options.requires_android
        deps_info['supports_android'] = options.supports_android

        deps_require_android = (
            all_resources_deps +
            [d['name'] for d in all_library_deps if d['requires_android']])
        deps_not_support_android = ([
            d['name'] for d in all_library_deps if not d['supports_android']
        ])

        if deps_require_android and not options.requires_android:
            raise Exception(
                'Some deps require building for the Android platform: ' +
                str(deps_require_android))

        if deps_not_support_android and options.supports_android:
            raise Exception('Not all deps support the Android platform: ' +
                            str(deps_not_support_android))

    if options.type in ['java_library', 'android_apk']:
        javac_classpath = [c['jar_path'] for c in direct_library_deps]
        java_full_classpath = [c['jar_path'] for c in all_library_deps]
        deps_info['resources_deps'] = [c['path'] for c in all_resources_deps]
        deps_info['jar_path'] = options.jar_path
        if options.type == 'android_apk' or options.supports_android:
            deps_info['dex_path'] = options.dex_path
        if options.type == 'android_apk':
            deps_info['apk_path'] = options.apk_path
        config['javac'] = {
            'classpath': javac_classpath,
        }
        config['java'] = {'full_classpath': java_full_classpath}

    if options.type == 'java_library':
        # Only resources might have srcjars (normal srcjar targets are listed in
        # srcjar_deps). A resource's srcjar contains the R.java file for those
        # resources, and (like Android's default build system) we allow a library to
        # refer to the resources in any of its dependents.
        config['javac']['srcjars'] = [
            c['srcjar'] for c in direct_resources_deps if 'srcjar' in c
        ]

    if options.type == 'android_apk':
        # Apks will get their resources srcjar explicitly passed to the java step.
        config['javac']['srcjars'] = []

    if options.type == 'android_assets':
        all_asset_sources = []
        if options.asset_renaming_sources:
            all_asset_sources.extend(
                build_utils.ParseGypList(options.asset_renaming_sources))
        if options.asset_sources:
            all_asset_sources.extend(
                build_utils.ParseGypList(options.asset_sources))

        deps_info['assets'] = {'sources': all_asset_sources}
        if options.asset_renaming_destinations:
            deps_info['assets']['outputs'] = (build_utils.ParseGypList(
                options.asset_renaming_destinations))
        if options.disable_asset_compression:
            deps_info['assets']['disable_compression'] = True

    if options.type == 'android_resources':
        deps_info['resources_zip'] = options.resources_zip
        if options.srcjar:
            deps_info['srcjar'] = options.srcjar
        if options.android_manifest:
            manifest = AndroidManifest(options.android_manifest)
            deps_info['package_name'] = manifest.GetPackageName()
        if options.package_name:
            deps_info['package_name'] = options.package_name
        if options.r_text:
            deps_info['r_text'] = options.r_text

    if options.type in ('android_resources', 'android_apk',
                        'resource_rewriter'):
        config['resources'] = {}
        config['resources']['dependency_zips'] = [
            c['resources_zip'] for c in all_resources_deps
        ]
        config['resources']['extra_package_names'] = []
        config['resources']['extra_r_text_files'] = []

    if options.type == 'android_apk' or options.type == 'resource_rewriter':
        config['resources']['extra_package_names'] = [
            c['package_name'] for c in all_resources_deps
            if 'package_name' in c
        ]
        config['resources']['extra_r_text_files'] = [
            c['r_text'] for c in all_resources_deps if 'r_text' in c
        ]

    if options.type in ['android_apk', 'deps_dex']:
        deps_dex_files = [c['dex_path'] for c in all_library_deps]

    proguard_enabled = options.proguard_enabled
    if options.type == 'android_apk':
        deps_info['proguard_enabled'] = proguard_enabled

    if proguard_enabled:
        deps_info['proguard_info'] = options.proguard_info
        config['proguard'] = {}
        proguard_config = config['proguard']
        proguard_config['input_paths'] = [options.jar_path
                                          ] + java_full_classpath
        proguard_config['tested_apk_info'] = ''

    # An instrumentation test apk should exclude the dex files that are in the apk
    # under test.
    if options.type == 'android_apk' and options.tested_apk_config:
        tested_apk_deps = Deps([options.tested_apk_config])
        tested_apk_library_deps = tested_apk_deps.All('java_library')
        tested_apk_deps_dex_files = [
            c['dex_path'] for c in tested_apk_library_deps
        ]
        deps_dex_files = [
            p for p in deps_dex_files if not p in tested_apk_deps_dex_files
        ]

        tested_apk_config = GetDepConfig(options.tested_apk_config)
        expected_tested_package = tested_apk_config['package_name']
        AndroidManifest(options.android_manifest).CheckInstrumentation(
            expected_tested_package)
        if tested_apk_config['proguard_enabled']:
            assert proguard_enabled, (
                'proguard must be enabled for instrumentation'
                ' apks if it\'s enabled for the tested apk')
            proguard_config['tested_apk_info'] = tested_apk_config[
                'proguard_info']

        deps_info['tested_apk_path'] = tested_apk_config['apk_path']

    # Dependencies for the final dex file of an apk or a 'deps_dex'.
    if options.type in ['android_apk', 'deps_dex']:
        config['final_dex'] = {}
        dex_config = config['final_dex']
        if proguard_enabled:
            # When proguard is enabled, the proguarded jar contains the code for all
            # of the dependencies.
            deps_dex_files = []
        dex_config['dependency_dex_files'] = deps_dex_files

    if options.type == 'android_apk':
        config['dist_jar'] = {
            'dependency_jars': [c['jar_path'] for c in all_library_deps]
        }
        manifest = AndroidManifest(options.android_manifest)
        deps_info['package_name'] = manifest.GetPackageName()
        if not options.tested_apk_config and manifest.GetInstrumentation():
            # This must then have instrumentation only for itself.
            manifest.CheckInstrumentation(manifest.GetPackageName())

        library_paths = []
        java_libraries_list_holder = [None]
        libraries = build_utils.ParseGypList(options.native_libs or '[]')
        if libraries:

            def recompute_ordered_libraries():
                libraries_dir = os.path.dirname(libraries[0])
                write_ordered_libraries.SetReadelfPath(options.readelf_path)
                write_ordered_libraries.SetLibraryDirs([libraries_dir])
                all_deps = (
                    write_ordered_libraries.
                    GetSortedTransitiveDependenciesForBinaries(libraries))
                # Create a java literal array with the "base" library names:
                # e.g. libfoo.so -> foo
                java_libraries_list_holder[0] = (
                    '{%s}' % ','.join(['"%s"' % s[3:-3] for s in all_deps]))
                library_paths.extend(
                    write_ordered_libraries.FullLibraryPath(x)
                    for x in all_deps)

            # This step takes about 600ms on a z620 for chrome_apk, so it's worth
            # caching.
            md5_check.CallAndRecordIfStale(recompute_ordered_libraries,
                                           record_path=options.build_config +
                                           '.nativelibs.md5.stamp',
                                           input_paths=libraries,
                                           output_paths=[options.build_config])
            if not library_paths:
                prev_config = build_utils.ReadJson(options.build_config)
                java_libraries_list_holder[0] = (
                    prev_config['native']['java_libraries_list'])
                library_paths.extend(prev_config['native']['libraries'])

        config['native'] = {
            'libraries': library_paths,
            'java_libraries_list': java_libraries_list_holder[0],
        }
        config['assets'], config['uncompressed_assets'] = (_MergeAssets(
            deps.All('android_assets')))

    build_utils.WriteJson(config, options.build_config, only_if_changed=True)

    if options.depfile:
        build_utils.WriteDepfile(
            options.depfile,
            deps.AllConfigPaths() + build_utils.GetPythonDependencies())
예제 #5
0
def _ParseOptions(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(
      '--incremental',
      action='store_true',
      help='Whether to re-use .class files rather than recompiling them '
           '(when possible).')
  parser.add_option(
      '--javac-includes',
      default='',
      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(
      '--processor',
      dest='processors',
      action='append',
      help='Annotation processor to use.')
  parser.add_option(
      '--processor-arg',
      dest='processor_args',
      action='append',
      help='key=value arguments for the annotation processors.')
  parser.add_option(
      '--provider-configuration',
      dest='provider_configurations',
      action='append',
      help='File to specify a service provider. Will be included '
           'in the jar under META-INF/services.')
  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('--jar-path', help='Jar output path.')
  parser.add_option('--stamp', help='Path to touch on success.')

  options, args = parser.parse_args(argv)
  build_utils.CheckOptions(options, parser, required=('jar_path',))

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

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

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

  if options.src_gendirs:
    options.src_gendirs = build_utils.ParseGypList(options.src_gendirs)

  options.javac_includes = build_utils.ParseGypList(options.javac_includes)
  options.jar_excluded_classes = (
      build_utils.ParseGypList(options.jar_excluded_classes))
  return options, args
예제 #6
0
파일: lint.py 프로젝트: bopopescu/Emma
def main():
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--lint-path', help='Path to lint executable.')
    parser.add_option('--config-path', help='Path to lint suppressions file.')
    parser.add_option('--processed-config-path',
                      help='Path to processed lint suppressions file.')
    parser.add_option('--manifest-path', help='Path to AndroidManifest.xml')
    parser.add_option('--result-path', help='Path to XML lint result file.')
    parser.add_option('--product-dir', help='Path to product dir.')
    parser.add_option('--src-dirs', help='Directories containing java files.')
    parser.add_option('--java-files', help='Paths to java files.')
    parser.add_option('--jar-path', help='Jar file containing class files.')
    parser.add_option('--resource-dir', help='Path to resource dir.')
    parser.add_option('--can-fail-build',
                      action='store_true',
                      help='If set, script will exit with nonzero exit status'
                      ' if lint errors are present')
    parser.add_option('--stamp', help='Path to touch on success.')
    parser.add_option('--enable',
                      action='store_true',
                      help='Run lint instead of just touching stamp.')

    options, _ = parser.parse_args()

    build_utils.CheckOptions(options,
                             parser,
                             required=[
                                 'lint_path', 'config_path',
                                 'processed_config_path', 'manifest_path',
                                 'result_path', 'product_dir', 'jar_path'
                             ])

    if options.enable:
        sources = []
        if options.src_dirs:
            src_dirs = build_utils.ParseGypList(options.src_dirs)
            sources = build_utils.FindInDirectories(src_dirs, '*.java')
        elif options.java_files:
            sources = build_utils.ParseGypList(options.java_files)
        else:
            print 'One of --src-dirs or --java-files must be specified.'
            return 1

        input_paths = [
            options.lint_path,
            options.config_path,
            options.manifest_path,
            options.jar_path,
        ]
        input_paths.extend(sources)
        if options.resource_dir:
            input_paths.extend(
                build_utils.FindInDirectory(options.resource_dir, '*'))

        input_strings = [options.processed_config_path]
        output_paths = [options.result_path]

        build_utils.CallAndWriteDepfileIfStale(
            lambda changes: _OnStaleMd5(changes,
                                        options.lint_path,
                                        options.config_path,
                                        options.processed_config_path,
                                        options.manifest_path,
                                        options.result_path,
                                        options.product_dir,
                                        sources,
                                        options.jar_path,
                                        resource_dir=options.resource_dir,
                                        can_fail_build=options.can_fail_build),
            options,
            input_paths=input_paths,
            input_strings=input_strings,
            output_paths=output_paths,
            pass_changes=True)
예제 #7
0
def main():
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)

    parser.add_argument('--lint-path',
                        required=True,
                        help='Path to lint executable.')
    parser.add_argument('--product-dir',
                        required=True,
                        help='Path to product dir.')
    parser.add_argument('--result-path',
                        required=True,
                        help='Path to XML lint result file.')
    parser.add_argument(
        '--cache-dir',
        required=True,
        help='Path to the directory in which the android cache '
        'directory tree should be stored.')
    parser.add_argument('--platform-xml-path',
                        required=True,
                        help='Path to api-platforms.xml')
    parser.add_argument('--android-sdk-version',
                        help='Version (API level) of the Android SDK used for '
                        'building.')
    parser.add_argument(
        '--create-cache',
        action='store_true',
        help='Mark the lint cache file as an output rather than '
        'an input.')
    parser.add_argument(
        '--can-fail-build',
        action='store_true',
        help='If set, script will exit with nonzero exit status'
        ' if lint errors are present')
    parser.add_argument('--config-path',
                        help='Path to lint suppressions file.')
    parser.add_argument('--enable',
                        action='store_true',
                        help='Run lint instead of just touching stamp.')
    parser.add_argument('--jar-path', help='Jar file containing class files.')
    parser.add_argument('--java-files', help='Paths to java files.')
    parser.add_argument('--manifest-path', help='Path to AndroidManifest.xml')
    parser.add_argument('--classpath',
                        default=[],
                        action='append',
                        help='GYP-list of classpath .jar files')
    parser.add_argument('--processed-config-path',
                        help='Path to processed lint suppressions file.')
    parser.add_argument('--resource-dir', help='Path to resource dir.')
    parser.add_argument('--resource-sources',
                        default=[],
                        action='append',
                        help='GYP-list of resource sources (directories with '
                        'resources or archives created by resource-generating '
                        'tasks.')
    parser.add_argument('--silent',
                        action='store_true',
                        help='If set, script will not log anything.')
    parser.add_argument('--src-dirs',
                        help='Directories containing java files.')
    parser.add_argument('--stamp', help='Path to touch on success.')

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

    if args.enable:
        sources = []
        if args.src_dirs:
            src_dirs = build_utils.ParseGypList(args.src_dirs)
            sources = build_utils.FindInDirectories(src_dirs, '*.java')
        elif args.java_files:
            sources = build_utils.ParseGypList(args.java_files)

        if args.config_path and not args.processed_config_path:
            parser.error(
                '--config-path specified without --processed-config-path')
        elif args.processed_config_path and not args.config_path:
            parser.error(
                '--processed-config-path specified without --config-path')

        input_paths = [
            args.lint_path,
            args.platform_xml_path,
        ]
        if args.config_path:
            input_paths.append(args.config_path)
        if args.jar_path:
            input_paths.append(args.jar_path)
        if args.manifest_path:
            input_paths.append(args.manifest_path)
        if sources:
            input_paths.extend(sources)
        classpath = []
        for gyp_list in args.classpath:
            classpath.extend(build_utils.ParseGypList(gyp_list))
        input_paths.extend(classpath)

        resource_sources = []
        if args.resource_dir:
            # Backward compatibility with GYP
            resource_sources += [args.resource_dir]

        for gyp_list in args.resource_sources:
            resource_sources += build_utils.ParseGypList(gyp_list)

        for resource_source in resource_sources:
            if os.path.isdir(resource_source):
                input_paths.extend(
                    build_utils.FindInDirectory(resource_source, '*'))
            else:
                input_paths.append(resource_source)

        input_strings = []
        if args.android_sdk_version:
            input_strings.append(args.android_sdk_version)
        if args.processed_config_path:
            input_strings.append(args.processed_config_path)

        output_paths = [args.result_path]

        build_utils.CallAndWriteDepfileIfStale(
            lambda: _OnStaleMd5(args.lint_path,
                                args.config_path,
                                args.processed_config_path,
                                args.manifest_path,
                                args.result_path,
                                args.product_dir,
                                sources,
                                args.jar_path,
                                args.cache_dir,
                                args.android_sdk_version,
                                resource_sources,
                                classpath=classpath,
                                can_fail_build=args.can_fail_build,
                                silent=args.silent),
            args,
            input_paths=input_paths,
            input_strings=input_strings,
            output_paths=output_paths,
            depfile_deps=classpath)
예제 #8
0
def main(argv):
    options, _ = ParseArgs(argv)

    library_classpath = [options.android_sdk_jar]
    input_jars = build_utils.ParseGypList(options.input_jars_paths)

    dependency_class_filters = [
        '*R.class', '*R$*.class', '*Manifest.class', '*BuildConfig.class'
    ]

    if options.testapp:
        build_utils.MergeZips(options.test_jar_path, input_jars,
                              dependency_class_filters)

    if options.configuration_name == 'Release' and options.proguard_enabled:
        proguard_cmd = [
            'java',
            '-jar',
            options.proguard_jar_path,
            '-forceprocessing',
            '-libraryjars',
            ':'.join(library_classpath),
            '-dump',
            options.obfuscated_jar_path + '.dump',
            '-printseeds',
            options.obfuscated_jar_path + '.seeds',
            '-printusage',
            options.obfuscated_jar_path + '.usage',
            '-printmapping',
            options.obfuscated_jar_path + '.mapping',
        ]

        exclude_paths = []
        configs = build_utils.ParseGypList(options.proguard_configs)
        if (options.tested_apk_obfuscated_jar_path
                and options.tested_apk_obfuscated_jar_path != '/'):
            # configs should only contain the process_resources.py generated config.
            assert len(configs) == 1, (
                'test apks should not have custom proguard configs: ' +
                str(configs))
            tested_jar_info = build_utils.ReadJson(
                options.tested_apk_obfuscated_jar_path + '.info')
            exclude_paths = tested_jar_info['inputs']
            configs = tested_jar_info['configs']
            proguard_cmd += [
                '-dontobfuscate',
                '-dontoptimize',
                '-dontshrink',
                '-dontskipnonpubliclibraryclassmembers',
                '-libraryjars',
                options.tested_apk_obfuscated_jar_path,
                '-applymapping',
                options.tested_apk_obfuscated_jar_path + '.mapping',
            ]

        proguard_injars = [p for p in input_jars if p not in exclude_paths]
        proguard_cmd += ['-injars', ':'.join(proguard_injars)]

        for config_file in configs:
            proguard_cmd += ['-include', config_file]

        # The output jar must be specified after inputs.
        proguard_cmd += ['-outjars', options.obfuscated_jar_path]

        build_utils.CheckOutput(proguard_cmd)

        this_info = {'inputs': proguard_injars, 'configs': configs}

        build_utils.WriteJson(this_info, options.obfuscated_jar_path + '.info')
    else:
        output_files = [
            options.obfuscated_jar_path, options.obfuscated_jar_path + '.info',
            options.obfuscated_jar_path + '.dump',
            options.obfuscated_jar_path + '.seeds',
            options.obfuscated_jar_path + '.usage',
            options.obfuscated_jar_path + '.mapping'
        ]
        for f in output_files:
            if os.path.exists(f):
                os.remove(f)
            build_utils.Touch(f)

    if options.stamp:
        build_utils.Touch(options.stamp)
예제 #9
0
def main(args):
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--android-sdk-tools',
                        required=True,
                        help='Android sdk build tools directory.')
    parser.add_argument(
        '--main-dex-rules-path',
        action='append',
        default=[],
        dest='main_dex_rules_paths',
        help='A file containing a list of proguard rules to use '
        'in determining the class to include in the '
        'main dex.')
    parser.add_argument('--main-dex-list-path',
                        required=True,
                        help='The main dex list file to generate.')
    parser.add_argument(
        '--enabled-configurations',
        help='The build configurations for which a main dex list'
        ' should be generated.')
    parser.add_argument('--configuration-name',
                        help='The current build configuration.')
    parser.add_argument('--multidex-configuration-path',
                        help='A JSON file containing multidex build '
                        'configuration.')
    parser.add_argument('--inputs',
                        help='JARs for which a main dex list should be '
                        'generated.')
    parser.add_argument('paths',
                        nargs='*',
                        default=[],
                        help='JARs for which a main dex list should be '
                        'generated.')

    args = parser.parse_args(build_utils.ExpandFileArgs(args))

    if args.multidex_configuration_path:
        with open(args.multidex_configuration_path) as multidex_config_file:
            multidex_config = json.loads(multidex_config_file.read())

        if not multidex_config.get('enabled', False):
            return 0

    if args.inputs:
        args.paths.extend(build_utils.ParseGypList(args.inputs))

    shrinked_android_jar = os.path.abspath(
        os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar'))
    dx_jar = os.path.abspath(
        os.path.join(args.android_sdk_tools, 'lib', 'dx.jar'))
    rules_file = os.path.abspath(
        os.path.join(args.android_sdk_tools, 'mainDexClasses.rules'))

    proguard_cmd = [
        constants.PROGUARD_SCRIPT_PATH,
        '-forceprocessing',
        '-dontwarn',
        '-dontoptimize',
        '-dontobfuscate',
        '-dontpreverify',
        '-libraryjars',
        shrinked_android_jar,
        '-include',
        rules_file,
    ]
    for m in args.main_dex_rules_paths:
        proguard_cmd.extend(['-include', m])

    main_dex_list_cmd = [
        'java',
        '-cp',
        dx_jar,
        'com.android.multidex.MainDexListBuilder',
    ]

    input_paths = list(args.paths)
    input_paths += [
        shrinked_android_jar,
        dx_jar,
        rules_file,
    ]
    input_paths += args.main_dex_rules_paths

    input_strings = [
        proguard_cmd,
        main_dex_list_cmd,
    ]

    output_paths = [
        args.main_dex_list_path,
    ]

    build_utils.CallAndWriteDepfileIfStale(lambda: _OnStaleMd5(
        proguard_cmd, main_dex_list_cmd, args.paths, args.main_dex_list_path),
                                           args,
                                           input_paths=input_paths,
                                           input_strings=input_strings,
                                           output_paths=output_paths)

    return 0
예제 #10
0
파일: javac.py 프로젝트: vmiura/chromium
def _ParseOptions(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(
        '--incremental',
        action='store_true',
        help='Whether to re-use .class files rather than recompiling them '
        '(when possible).')
    parser.add_option(
        '--javac-includes',
        default='',
        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('--processor',
                      dest='processors',
                      action='append',
                      help='Annotation processor to use.')
    parser.add_option(
        '--processor-arg',
        dest='processor_args',
        action='append',
        help='key=value arguments for the annotation processors.')
    parser.add_option(
        '--provider-configuration',
        dest='provider_configurations',
        action='append',
        help='File to specify a service provider. Will be included '
        'in the jar under META-INF/services.')
    parser.add_option(
        '--additional-jar-file',
        dest='additional_jar_files',
        action='append',
        help=
        'Additional files to package into jar. By default, only Java .class '
        'files are packaged into the jar. Files should be specified in '
        'format <filename>:<path to be placed in 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('--jar-path', help='Jar output path.')
    parser.add_option('--stamp', help='Path to touch on success.')

    options, args = parser.parse_args(argv)
    build_utils.CheckOptions(options, parser, required=('jar_path', ))

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

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

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

    additional_jar_files = []
    for arg in options.additional_jar_files or []:
        filepath, jar_filepath = arg.split(':')
        additional_jar_files.append((filepath, jar_filepath))
    options.additional_jar_files = additional_jar_files

    if options.src_gendirs:
        options.src_gendirs = build_utils.ParseGypList(options.src_gendirs)

    options.javac_includes = build_utils.ParseGypList(options.javac_includes)
    options.jar_excluded_classes = (build_utils.ParseGypList(
        options.jar_excluded_classes))

    java_files = []
    for arg in args:
        # Interpret a path prefixed with @ as a file containing a list of sources.
        if arg.startswith('@'):
            java_files.extend(build_utils.ReadSourcesList(arg[1:]))
        else:
            java_files.append(arg)

    return options, java_files
예제 #11
0
def main(argv):
  parser = optparse.OptionParser()
  build_utils.AddDepfileOption(parser)
  parser.add_option('--build-config', help='Path to build_config output.')
  parser.add_option(
      '--type',
      help='Type of this target (e.g. android_library).')
  parser.add_option(
      '--deps-configs',
      help='List of paths for dependency\'s build_config files. ')

  # android_resources options
  parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
  parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
  parser.add_option('--r-text', help='Path to target\'s R.txt file.')
  parser.add_option('--package-name',
      help='Java package name for these resources.')
  parser.add_option('--android-manifest', help='Path to android manifest.')
  parser.add_option('--is-locale-resource', action='store_true',
                    help='Whether it is locale resource.')
  parser.add_option('--resource-dirs', action='append', default=[],
                    help='GYP-list of resource dirs')

  # android_assets options
  parser.add_option('--asset-sources', help='List of asset sources.')
  parser.add_option('--asset-renaming-sources',
                    help='List of asset sources with custom destinations.')
  parser.add_option('--asset-renaming-destinations',
                    help='List of asset custom destinations.')
  parser.add_option('--disable-asset-compression', action='store_true',
                    help='Whether to disable asset compression.')

  # java library options
  parser.add_option('--jar-path', help='Path to target\'s jar output.')
  parser.add_option('--java-sources-file', help='Path to .sources file')
  parser.add_option('--supports-android', action='store_true',
      help='Whether this library supports running on the Android platform.')
  parser.add_option('--requires-android', action='store_true',
      help='Whether this library requires running on the Android platform.')
  parser.add_option('--bypass-platform-checks', action='store_true',
      help='Bypass checks for support/require Android platform.')

  # android library options
  parser.add_option('--dex-path', help='Path to target\'s dex output.')

  # native library options
  parser.add_option('--shared-libraries-runtime-deps',
                    help='Path to file containing runtime deps for shared '
                         'libraries.')

  # apk options
  parser.add_option('--apk-path', help='Path to the target\'s apk output.')
  parser.add_option('--incremental-apk-path',
                    help="Path to the target's incremental apk output.")
  parser.add_option('--incremental-install-script-path',
                    help="Path to the target's generated incremental install "
                    "script.")

  parser.add_option('--tested-apk-config',
      help='Path to the build config of the tested apk (for an instrumentation '
      'test apk).')
  parser.add_option('--proguard-enabled', action='store_true',
      help='Whether proguard is enabled for this apk.')
  parser.add_option('--proguard-info',
      help='Path to the proguard .info output for this apk.')
  parser.add_option('--has-alternative-locale-resource', action='store_true',
      help='Whether there is alternative-locale-resource in direct deps')

  options, args = parser.parse_args(argv)

  if args:
    parser.error('No positional arguments should be given.')

  required_options_map = {
      'java_binary': ['build_config', 'jar_path'],
      'java_library': ['build_config', 'jar_path'],
      'java_prebuilt': ['build_config', 'jar_path'],
      'android_assets': ['build_config'],
      'android_resources': ['build_config', 'resources_zip'],
      'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'],
      'deps_dex': ['build_config', 'dex_path'],
      'resource_rewriter': ['build_config'],
      'group': ['build_config'],
  }
  required_options = required_options_map.get(options.type)
  if not required_options:
    raise Exception('Unknown type: <%s>' % options.type)

  build_utils.CheckOptions(options, parser, required_options)

  # Java prebuilts are the same as libraries except for in gradle files.
  is_java_prebuilt = options.type == 'java_prebuilt'
  if is_java_prebuilt:
    options.type = 'java_library'

  if options.type == 'java_library':
    if options.supports_android and not options.dex_path:
      raise Exception('java_library that supports Android requires a dex path.')

    if options.requires_android and not options.supports_android:
      raise Exception(
          '--supports-android is required when using --requires-android')

  direct_deps_config_paths = build_utils.ParseGypList(options.deps_configs)
  direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths,
                                                      options.type)

  deps = Deps(direct_deps_config_paths)
  all_inputs = deps.AllConfigPaths() + build_utils.GetPythonDependencies()

  # Remove other locale resources if there is alternative_locale_resource in
  # direct deps.
  if options.has_alternative_locale_resource:
    alternative = [r['path'] for r in deps.Direct('android_resources')
                   if r.get('is_locale_resource')]
    # We can only have one locale resources in direct deps.
    if len(alternative) != 1:
      raise Exception('The number of locale resource in direct deps is wrong %d'
                       % len(alternative))
    unwanted = [r['path'] for r in deps.All('android_resources')
                if r.get('is_locale_resource') and r['path'] not in alternative]
    for p in unwanted:
      deps.RemoveNonDirectDep(p)


  direct_library_deps = deps.Direct('java_library')
  all_library_deps = deps.All('java_library')

  all_resources_deps = deps.All('android_resources')
  # Resources should be ordered with the highest-level dependency first so that
  # overrides are done correctly.
  all_resources_deps.reverse()

  if options.type == 'android_apk' and options.tested_apk_config:
    tested_apk_deps = Deps([options.tested_apk_config])
    tested_apk_resources_deps = tested_apk_deps.All('android_resources')
    all_resources_deps = [
        d for d in all_resources_deps if not d in tested_apk_resources_deps]

  # Initialize some common config.
  # Any value that needs to be queryable by dependents must go within deps_info.
  config = {
    'deps_info': {
      'name': os.path.basename(options.build_config),
      'path': options.build_config,
      'type': options.type,
      'deps_configs': direct_deps_config_paths
    },
    # Info needed only by generate_gradle.py.
    'gradle': {}
  }
  deps_info = config['deps_info']
  gradle = config['gradle']

  # Required for generating gradle files.
  if options.type == 'java_library':
    deps_info['is_prebuilt'] = is_java_prebuilt

  if options.android_manifest:
    gradle['android_manifest'] = options.android_manifest
  if options.type in ('java_binary', 'java_library', 'android_apk'):
    if options.java_sources_file:
      gradle['java_sources_file'] = options.java_sources_file
    gradle['dependent_prebuilt_jars'] = deps.PrebuiltJarPaths()
    gradle['dependent_projects'] = (
        [c['path'] for c in direct_library_deps if not c['is_prebuilt']])


  if (options.type in ('java_binary', 'java_library') and
      not options.bypass_platform_checks):
    deps_info['requires_android'] = options.requires_android
    deps_info['supports_android'] = options.supports_android

    deps_require_android = (all_resources_deps +
        [d['name'] for d in all_library_deps if d['requires_android']])
    deps_not_support_android = (
        [d['name'] for d in all_library_deps if not d['supports_android']])

    if deps_require_android and not options.requires_android:
      raise Exception('Some deps require building for the Android platform: ' +
          str(deps_require_android))

    if deps_not_support_android and options.supports_android:
      raise Exception('Not all deps support the Android platform: ' +
          str(deps_not_support_android))

  if options.type in ('java_binary', 'java_library', 'android_apk'):
    deps_info['resources_deps'] = [c['path'] for c in all_resources_deps]
    deps_info['jar_path'] = options.jar_path
    if options.type == 'android_apk' or options.supports_android:
      deps_info['dex_path'] = options.dex_path
    if options.type == 'android_apk':
      deps_info['apk_path'] = options.apk_path
      deps_info['incremental_apk_path'] = options.incremental_apk_path
      deps_info['incremental_install_script_path'] = (
          options.incremental_install_script_path)

    # Classpath values filled in below (after applying tested_apk_config).
    config['javac'] = {}


  if options.type in ('java_binary', 'java_library'):
    # Only resources might have srcjars (normal srcjar targets are listed in
    # srcjar_deps). A resource's srcjar contains the R.java file for those
    # resources, and (like Android's default build system) we allow a library to
    # refer to the resources in any of its dependents.
    config['javac']['srcjars'] = [
        c['srcjar'] for c in all_resources_deps if 'srcjar' in c]

    # Used to strip out R.class for android_prebuilt()s.
    if options.type == 'java_library':
      config['javac']['resource_packages'] = [
          c['package_name'] for c in all_resources_deps if 'package_name' in c]

  if options.type == 'android_apk':
    # Apks will get their resources srcjar explicitly passed to the java step.
    config['javac']['srcjars'] = []

  if options.type == 'android_assets':
    all_asset_sources = []
    if options.asset_renaming_sources:
      all_asset_sources.extend(
          build_utils.ParseGypList(options.asset_renaming_sources))
    if options.asset_sources:
      all_asset_sources.extend(build_utils.ParseGypList(options.asset_sources))

    deps_info['assets'] = {
        'sources': all_asset_sources
    }
    if options.asset_renaming_destinations:
      deps_info['assets']['outputs'] = (
          build_utils.ParseGypList(options.asset_renaming_destinations))
    if options.disable_asset_compression:
      deps_info['assets']['disable_compression'] = True

  if options.type == 'android_resources':
    deps_info['resources_zip'] = options.resources_zip
    if options.srcjar:
      deps_info['srcjar'] = options.srcjar
    if options.android_manifest:
      manifest = AndroidManifest(options.android_manifest)
      deps_info['package_name'] = manifest.GetPackageName()
    if options.package_name:
      deps_info['package_name'] = options.package_name
    if options.r_text:
      deps_info['r_text'] = options.r_text
    if options.is_locale_resource:
      deps_info['is_locale_resource'] = True

    deps_info['resources_dirs'] = []
    if options.resource_dirs:
      for gyp_list in options.resource_dirs:
        deps_info['resources_dirs'].extend(build_utils.ParseGypList(gyp_list))

  if options.supports_android and options.type in ('android_apk',
                                                   'java_library'):
    # Lint all resources that are not already linted by a dependent library.
    owned_resource_dirs = set()
    owned_resource_zips = set()
    for c in all_resources_deps:
      # Always use resources_dirs in favour of resources_zips so that lint error
      # messages have paths that are closer to reality (and to avoid needing to
      # extract during lint).
      if c['resources_dirs']:
        owned_resource_dirs.update(c['resources_dirs'])
      else:
        owned_resource_zips.add(c['resources_zip'])

    for c in all_library_deps:
      if c['supports_android']:
        owned_resource_dirs.difference_update(c['owned_resources_dirs'])
        owned_resource_zips.difference_update(c['owned_resources_zips'])
    deps_info['owned_resources_dirs'] = list(owned_resource_dirs)
    deps_info['owned_resources_zips'] = list(owned_resource_zips)

  if options.type in ('android_resources','android_apk', 'resource_rewriter'):
    config['resources'] = {}
    config['resources']['dependency_zips'] = [
        c['resources_zip'] for c in all_resources_deps]
    config['resources']['extra_package_names'] = []
    config['resources']['extra_r_text_files'] = []

  if options.type == 'android_apk' or options.type == 'resource_rewriter':
    config['resources']['extra_package_names'] = [
        c['package_name'] for c in all_resources_deps if 'package_name' in c]
    config['resources']['extra_r_text_files'] = [
        c['r_text'] for c in all_resources_deps if 'r_text' in c]

  if options.type in ['android_apk', 'deps_dex']:
    deps_dex_files = [c['dex_path'] for c in all_library_deps]

  if options.type in ('java_binary', 'java_library', 'android_apk'):
    javac_classpath = [c['jar_path'] for c in direct_library_deps]
    java_full_classpath = [c['jar_path'] for c in all_library_deps]

  # An instrumentation test apk should exclude the dex files that are in the apk
  # under test.
  if options.type == 'android_apk' and options.tested_apk_config:
    tested_apk_config = GetDepConfig(options.tested_apk_config)

    expected_tested_package = tested_apk_config['package_name']
    AndroidManifest(options.android_manifest).CheckInstrumentation(
        expected_tested_package)
    if tested_apk_config['proguard_enabled']:
      assert options.proguard_enabled, ('proguard must be enabled for '
          'instrumentation apks if it\'s enabled for the tested apk.')

    # Include in the classpath classes that are added directly to the apk under
    # test (those that are not a part of a java_library).
    javac_classpath.append(tested_apk_config['jar_path'])
    java_full_classpath.append(tested_apk_config['jar_path'])

    # Exclude dex files from the test apk that exist within the apk under test.
    # TODO(agrieve): When proguard is enabled, this filtering logic happens
    #     within proguard_util.py. Move the logic for the proguard case into
    #     here as well.
    tested_apk_library_deps = tested_apk_deps.All('java_library')
    tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps]
    deps_dex_files = [
        p for p in deps_dex_files if not p in tested_apk_deps_dex_files]

  if options.type == 'android_apk':
    deps_info['proguard_enabled'] = options.proguard_enabled
    deps_info['proguard_info'] = options.proguard_info
    config['proguard'] = {}
    proguard_config = config['proguard']
    proguard_config['input_paths'] = [options.jar_path] + java_full_classpath

  # Dependencies for the final dex file of an apk or a 'deps_dex'.
  if options.type in ['android_apk', 'deps_dex']:
    config['final_dex'] = {}
    dex_config = config['final_dex']
    dex_config['dependency_dex_files'] = deps_dex_files

  if options.type in ('java_binary', 'java_library', 'android_apk'):
    config['javac']['classpath'] = javac_classpath
    config['javac']['interface_classpath'] = [
        _AsInterfaceJar(p) for p in javac_classpath]
    config['java'] = {
      'full_classpath': java_full_classpath
    }

  if options.type == 'android_apk':
    dependency_jars = [c['jar_path'] for c in all_library_deps]
    all_interface_jars = [
        _AsInterfaceJar(p) for p in dependency_jars + [options.jar_path]]
    config['dist_jar'] = {
      'dependency_jars': dependency_jars,
      'all_interface_jars': all_interface_jars,
    }
    manifest = AndroidManifest(options.android_manifest)
    deps_info['package_name'] = manifest.GetPackageName()
    if not options.tested_apk_config and manifest.GetInstrumentation():
      # This must then have instrumentation only for itself.
      manifest.CheckInstrumentation(manifest.GetPackageName())

    library_paths = []
    java_libraries_list = None
    runtime_deps_files = build_utils.ParseGypList(
        options.shared_libraries_runtime_deps or '[]')
    if runtime_deps_files:
      library_paths = _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files)
      # Create a java literal array with the "base" library names:
      # e.g. libfoo.so -> foo
      java_libraries_list = ('{%s}' % ','.join(
          ['"%s"' % s[3:-3] for s in library_paths]))

    all_inputs.extend(runtime_deps_files)
    config['native'] = {
      'libraries': library_paths,
      'java_libraries_list': java_libraries_list,
    }
    config['assets'], config['uncompressed_assets'] = (
        _MergeAssets(deps.All('android_assets')))

  build_utils.WriteJson(config, options.build_config, only_if_changed=True)

  if options.depfile:
    build_utils.WriteDepfile(options.depfile, all_inputs)
예제 #12
0
def main():
  parser = argparse.ArgumentParser()

  parser.add_argument(
      '-v', '--verbose', action='count', help='Enable verbose logging.')
  parser.add_argument(
      '-a', '--auxclasspath', default=None, dest='auxclasspath',
      help='Set aux classpath for analysis.')
  parser.add_argument(
      '--auxclasspath-gyp', dest='auxclasspath_gyp',
      help='A gyp list containing the aux classpath for analysis')
  parser.add_argument(
      '-o', '--only-analyze', default=None,
      dest='only_analyze', help='Only analyze the given classes and packages.')
  parser.add_argument(
      '-e', '--exclude', default=None, dest='exclude',
      help='Exclude bugs matching given filter.')
  parser.add_argument(
      '-l', '--release-build', action='store_true', dest='release_build',
      help='Analyze release build instead of debug.')
  parser.add_argument(
      '-f', '--findbug-args', default=None, dest='findbug_args',
      help='Additional findbug arguments.')
  parser.add_argument(
      '-b', '--base-dir', default=_DEFAULT_BASE_DIR,
      dest='base_dir', help='Base directory for configuration file.')
  parser.add_argument(
      '--output-file', dest='output_file',
      help='Path to save the output to.')
  parser.add_argument(
      '--stamp', help='Path to touch on success.')
  parser.add_argument(
      '--depfile', help='Path to the depfile. This must be specified as the '
                        "action's first output.")

  parser.add_argument(
      'jar_paths', metavar='JAR_PATH', nargs='+',
      help='JAR file to analyze')

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

  run_tests_helper.SetLogLevel(args.verbose)

  if args.auxclasspath:
    args.auxclasspath = args.auxclasspath.split(':')
  elif args.auxclasspath_gyp:
    args.auxclasspath = build_utils.ParseGypList(args.auxclasspath_gyp)

  if args.base_dir:
    if not args.exclude:
      args.exclude = os.path.join(args.base_dir, 'findbugs_exclude.xml')

  findbugs_command, findbugs_warnings = findbugs.Run(
      args.exclude, args.only_analyze, args.auxclasspath,
      args.output_file, args.findbug_args, args.jar_paths)

  if findbugs_warnings:
    print
    print '*' * 80
    print 'FindBugs run via:'
    print findbugs_command
    print
    print 'FindBugs reported the following issues:'
    for warning in sorted(findbugs_warnings):
      print str(warning)
    print '*' * 80
    print
  else:
    if args.depfile:
      build_utils.WriteDepfile(
          args.depfile,
          build_utils.GetPythonDependencies() + args.auxclasspath
              + args.jar_paths)
    if args.stamp:
      build_utils.Touch(args.stamp)

  return len(findbugs_warnings)
예제 #13
0
def _ParseArgs(args):
  parser = argparse.ArgumentParser()
  build_utils.AddDepfileOption(parser)
  parser.add_argument('--assets',
                      help='GYP-list of files to add as assets in the form '
                           '"srcPath:zipPath", where ":zipPath" is optional.',
                      default='[]')
  parser.add_argument('--write-asset-list',
                      action='store_true',
                      help='Whether to create an assets/assets_list file.')
  parser.add_argument('--uncompressed-assets',
                      help='Same as --assets, except disables compression.',
                      default='[]')
  parser.add_argument('--resource-apk',
                      help='An .ap_ file built using aapt',
                      required=True)
  parser.add_argument('--output-apk',
                      help='Path to the output file',
                      required=True)
  parser.add_argument('--dex-file',
                      help='Path to the classes.dex to use')
  parser.add_argument('--native-libs',
                      action='append',
                      help='GYP-list of native libraries to include. '
                           'Can be specified multiple times.',
                      default=[])
  parser.add_argument('--secondary-native-libs',
                      action='append',
                      help='GYP-list of native libraries for secondary '
                           'android-abi. Can be specified multiple times.',
                      default=[])
  parser.add_argument('--android-abi',
                      help='Android architecture to use for native libraries')
  parser.add_argument('--secondary-android-abi',
                      help='The secondary Android architecture to use for'
                           'secondary native libraries')
  parser.add_argument('--native-lib-placeholders',
                      help='GYP-list of native library placeholders to add.',
                      default='[]')
  parser.add_argument('--emma-device-jar',
                      help='Path to emma_device.jar to include.')
  parser.add_argument('--uncompress-shared-libraries',
                      action='store_true',
                      help='Uncompress shared libraries')
  options = parser.parse_args(args)
  options.assets = build_utils.ParseGypList(options.assets)
  options.uncompressed_assets = build_utils.ParseGypList(
      options.uncompressed_assets)
  options.native_lib_placeholders = build_utils.ParseGypList(
      options.native_lib_placeholders)
  all_libs = []
  for gyp_list in options.native_libs:
    all_libs.extend(build_utils.ParseGypList(gyp_list))
  options.native_libs = all_libs
  secondary_libs = []
  for gyp_list in options.secondary_native_libs:
    secondary_libs.extend(build_utils.ParseGypList(gyp_list))
  options.secondary_native_libs = secondary_libs


  if not options.android_abi and (options.native_libs or
                                  options.native_lib_placeholders):
    raise Exception('Must specify --android-abi with --native-libs')
  if not options.secondary_android_abi and options.secondary_native_libs:
    raise Exception('Must specify --secondary-android-abi with'
                    ' --secondary-native-libs')
  return options
예제 #14
0
def main(argv):
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--abi', help='Android ABI being used in the build.')
    parser.add_argument('--binary-files',
                        default='',
                        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',
                        default='',
                        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))

    options.binary_files = build_utils.ParseGypList(options.binary_files)
    options.js_bindings = build_utils.ParseGypList(options.js_bindings)
    options.native_libraries = build_utils.ParseGypList(
        options.native_libraries)

    # 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, options.binary_files)

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

    # Copy JS API binding files.
    CopyJSBindingFiles(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'))

    # Write a depfile so that these files, which are not tracked directly by GN,
    # also trigger a re-run of this script when modified.
    build_utils.WriteDepfile(
        options.depfile,
        options.binary_files + options.native_libraries + options.js_bindings)
예제 #15
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))

    # 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, stderr_filter=FilterCrunchStderr,
                              fail_func=DidCrunchFail)

    ZipResources(zip_resource_dirs, options.resource_zip_out)

    if options.all_resources_zip_out:
      CombineZips([options.resource_zip_out] + dep_zips,
                  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)
예제 #16
0
def main(argv):
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--build-config', help='Path to build_config output.')
    parser.add_option('--type',
                      help='Type of this target (e.g. android_library).')
    parser.add_option(
        '--possible-deps-configs',
        help='List of paths for dependency\'s build_config files. Some '
        'dependencies may not write build_config files. Missing build_config '
        'files are handled differently based on the type of this target.')

    # android_resources options
    parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
    parser.add_option('--resources-zip',
                      help='Path to target\'s resources zip.')

    # android_library options
    parser.add_option('--jar-path', help='Path to target\'s jar output.')

    options, args = parser.parse_args(argv)

    if args:
        parser.error('No positional arguments should be given.')

    required_options = ('build_config', 'type')
    build_utils.CheckOptions(options, parser, required_options)

    if not options.type in ['android_library', 'android_resources']:
        raise Exception('Unknown type: <%s>' % options.type)

    if options.type == 'android_library':
        required_options = ('jar_path', )
        build_utils.CheckOptions(options, parser, required_options)

    possible_deps_configs = build_utils.ParseGypList(
        options.possible_deps_configs)
    for c in possible_deps_configs:
        if not os.path.exists(c):
            # Currently we only allow deps to things that write build_config files.
            raise Exception('Unknown dep type: ' + c)

    direct_deps_config_paths = possible_deps_configs
    all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths)

    direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths]
    all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths]

    direct_library_deps = DepsOfType('android_library', direct_deps_configs)
    all_resources_deps = DepsOfType('android_resources', all_deps_configs)

    # Initialize some common config.
    config = {
        'deps_info': {
            'path': options.build_config,
            'type': options.type,
            'deps_configs': direct_deps_config_paths,
        }
    }
    deps_info = config['deps_info']

    if options.type == 'android_library':
        javac_classpath = [c['jar_path'] for c in direct_library_deps]
        deps_info['jar_path'] = options.jar_path
        config['javac'] = {
            'classpath': javac_classpath,
        }
        # Only resources might have srcjars (normal srcjar targets are listed in
        # srcjar_deps). A resource's srcjar contains the R.java file for those
        # resources, and (like Android's default build system) we allow a library to
        # refer to the resources in any of its dependents.
        config['javac']['srcjars'] = [
            c['srcjar'] for c in all_resources_deps if 'srcjar' in c
        ]

    if options.type == 'android_resources':
        deps_info['resources_zip'] = options.resources_zip
        if options.srcjar:
            deps_info['srcjar'] = options.srcjar
        config['resources'] = {}
        config['resources']['dependency_zips'] = [
            c['resources_zip'] for c in all_resources_deps
        ]

    build_utils.WriteJson(config, options.build_config, only_if_changed=True)

    if options.depfile:
        build_utils.WriteDepfile(
            options.depfile,
            all_deps_config_paths + build_utils.GetPythonDependencies())
예제 #17
0
def main(argv):
  parser = optparse.OptionParser()
  build_utils.AddDepfileOption(parser)
  parser.add_option('--build-config', help='Path to build_config output.')
  parser.add_option(
      '--type',
      help='Type of this target (e.g. android_library).')
  parser.add_option(
      '--possible-deps-configs',
      help='List of paths for dependency\'s build_config files. Some '
      'dependencies may not write build_config files. Missing build_config '
      'files are handled differently based on the type of this target.')

  # android_resources options
  parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
  parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
  parser.add_option('--package-name',
      help='Java package name for these resources.')
  parser.add_option('--android-manifest', help='Path to android manifest.')

  # java library options
  parser.add_option('--jar-path', help='Path to target\'s jar output.')
  parser.add_option('--supports-android', action='store_true',
      help='Whether this library supports running on the Android platform.')
  parser.add_option('--requires-android', action='store_true',
      help='Whether this library requires running on the Android platform.')
  parser.add_option('--bypass-platform-checks', action='store_true',
      help='Bypass checks for support/require Android platform.')

  # android library options
  parser.add_option('--dex-path', help='Path to target\'s dex output.')

  # native library options
  parser.add_option('--native-libs', help='List of top-level native libs.')
  parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.')

  options, args = parser.parse_args(argv)

  if args:
    parser.error('No positional arguments should be given.')


  if not options.type in [
      'java_library', 'android_resources', 'android_apk']:
    raise Exception('Unknown type: <%s>' % options.type)

  required_options = ['build_config'] + {
      'java_library': ['jar_path'],
      'android_resources': ['resources_zip'],
      'android_apk': ['jar_path', 'dex_path', 'resources_zip']
    }[options.type]

  if options.native_libs:
    required_options.append('readelf_path')

  build_utils.CheckOptions(options, parser, required_options)

  if options.type == 'java_library':
    if options.supports_android and not options.dex_path:
      raise Exception('java_library that supports Android requires a dex path.')

    if options.requires_android and not options.supports_android:
      raise Exception(
          '--supports-android is required when using --requires-android')

  possible_deps_config_paths = build_utils.ParseGypList(
      options.possible_deps_configs)

  allow_unknown_deps = options.type == 'android_apk'
  unknown_deps = [
      c for c in possible_deps_config_paths if not os.path.exists(c)]
  if unknown_deps and not allow_unknown_deps:
    raise Exception('Unknown deps: ' + str(unknown_deps))

  direct_deps_config_paths = [
      c for c in possible_deps_config_paths if not c in unknown_deps]
  all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths)

  direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths]
  all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths]

  direct_library_deps = DepsOfType('java_library', direct_deps_configs)
  all_library_deps = DepsOfType('java_library', all_deps_configs)

  direct_resources_deps = DepsOfType('android_resources', direct_deps_configs)
  all_resources_deps = DepsOfType('android_resources', all_deps_configs)

  # Initialize some common config.
  config = {
    'deps_info': {
      'name': os.path.basename(options.build_config),
      'path': options.build_config,
      'type': options.type,
      'deps_configs': direct_deps_config_paths,
    }
  }
  deps_info = config['deps_info']


  if options.type == 'java_library' and not options.bypass_platform_checks:
    deps_info['requires_android'] = options.requires_android
    deps_info['supports_android'] = options.supports_android

    deps_require_android = (all_resources_deps +
        [d['name'] for d in all_library_deps if d['requires_android']])
    deps_not_support_android = (
        [d['name'] for d in all_library_deps if not d['supports_android']])

    if deps_require_android and not options.requires_android:
      raise Exception('Some deps require building for the Android platform: ' +
          str(deps_require_android))

    if deps_not_support_android and options.supports_android:
      raise Exception('Not all deps support the Android platform: ' +
          str(deps_not_support_android))


  if options.type in ['java_library', 'android_apk']:
    javac_classpath = [c['jar_path'] for c in direct_library_deps]
    java_full_classpath = [c['jar_path'] for c in all_library_deps]
    deps_info['resources_deps'] = [c['path'] for c in all_resources_deps]
    deps_info['jar_path'] = options.jar_path
    if options.type == 'android_apk' or options.supports_android:
      deps_info['dex_path'] = options.dex_path
    config['javac'] = {
      'classpath': javac_classpath,
    }
    config['java'] = {
      'full_classpath': java_full_classpath
    }

  if options.type == 'java_library':
    # Only resources might have srcjars (normal srcjar targets are listed in
    # srcjar_deps). A resource's srcjar contains the R.java file for those
    # resources, and (like Android's default build system) we allow a library to
    # refer to the resources in any of its dependents.
    config['javac']['srcjars'] = [
        c['srcjar'] for c in direct_resources_deps if 'srcjar' in c]

  if options.type == 'android_apk':
    # Apks will get their resources srcjar explicitly passed to the java step.
    config['javac']['srcjars'] = []

  if options.type == 'android_resources':
    deps_info['resources_zip'] = options.resources_zip
    if options.srcjar:
      deps_info['srcjar'] = options.srcjar
    if options.package_name:
      deps_info['package_name'] = options.package_name

  if options.type == 'android_resources' or options.type == 'android_apk':
    config['resources'] = {}
    config['resources']['dependency_zips'] = [
        c['resources_zip'] for c in all_resources_deps]
    config['resources']['extra_package_names'] = []

  if options.type == 'android_apk':
    config['resources']['extra_package_names'] = [
        c['package_name'] for c in all_resources_deps if 'package_name' in c]


  # Dependencies for the final dex file of an apk or the standalone .dex.jar
  # output of a library.
  if options.type == 'android_apk' or (options.type == "java_library"
                                       and options.supports_android):
    config['final_dex'] = {}
    dex_config = config['final_dex']
    # TODO(cjhopman): proguard version
    dex_deps_files = [c['dex_path'] for c in all_library_deps]
    dex_config['dependency_dex_files'] = dex_deps_files

  if options.type == 'android_apk':
    config['dist_jar'] = {
      'dependency_jars': [
        c['jar_path'] for c in all_library_deps
      ]
    }

    library_paths = []
    java_libraries_list = []
    if options.native_libs:
      libraries = build_utils.ParseGypList(options.native_libs)
      if libraries:
        libraries_dir = os.path.dirname(libraries[0])
        write_ordered_libraries.SetReadelfPath(options.readelf_path)
        write_ordered_libraries.SetLibraryDirs([libraries_dir])
        all_native_library_deps = (
            write_ordered_libraries.GetSortedTransitiveDependenciesForBinaries(
                libraries))
        # Create a java literal array with the "base" library names:
        # e.g. libfoo.so -> foo
        java_libraries_list = '{%s}' % ','.join(
            ['"%s"' % s[3:-3] for s in all_native_library_deps])
        library_paths = map(
            write_ordered_libraries.FullLibraryPath, all_native_library_deps)

      config['native'] = {
        'libraries': library_paths,
        'java_libraries_list': java_libraries_list
      }

  build_utils.WriteJson(config, options.build_config, only_if_changed=True)

  if options.depfile:
    build_utils.WriteDepfile(
        options.depfile,
        all_deps_config_paths + build_utils.GetPythonDependencies())
예제 #18
0
def _RunInstrumentCommand(_command, options, _, option_parser):
    """Instruments jar files using EMMA.

  Args:
    command: String indicating the command that was received to trigger
        this function.
    options: optparse options dictionary.
    args: List of extra args from optparse.
    option_parser: optparse.OptionParser object.

  Returns:
    An exit code.
  """
    if not (options.input_path and options.output_path
            and options.coverage_file and options.sources_list_file and
            (options.source_files or options.source_dirs) and options.src_root
            and options.emma_jar):
        option_parser.error('All arguments are required.')

    if os.path.exists(options.coverage_file):
        os.remove(options.coverage_file)
    temp_dir = tempfile.mkdtemp()
    try:
        cmd = [
            'java', '-cp', options.emma_jar, 'emma', 'instr', '-ip',
            options.input_path, '-ix', options.filter_string, '-d', temp_dir,
            '-out', options.coverage_file, '-m', 'fullcopy'
        ]
        build_utils.CheckOutput(cmd)

        # File is not generated when filter_string doesn't match any files.
        if not os.path.exists(options.coverage_file):
            build_utils.Touch(options.coverage_file)

        temp_jar_dir = os.path.join(temp_dir, 'lib')
        jars = os.listdir(temp_jar_dir)
        if len(jars) != 1:
            print('Error: multiple output files in: %s' % (temp_jar_dir))
            return 1

        # Delete output_path first to avoid modifying input_path in the case where
        # input_path is a hardlink to output_path. http://crbug.com/571642
        if os.path.exists(options.output_path):
            os.unlink(options.output_path)
        shutil.move(os.path.join(temp_jar_dir, jars[0]), options.output_path)
    finally:
        shutil.rmtree(temp_dir)

    if options.source_dirs:
        source_dirs = build_utils.ParseGypList(options.source_dirs)
    else:
        source_dirs = _GetSourceDirsFromSourceFiles(options.source_files)
    _CreateSourcesListFile(source_dirs, options.sources_list_file,
                           options.src_root)

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

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

    return 0
예제 #19
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('--exclude-packing-list',
                      default='',
                      help='Names of any libraries explicitly not packed')
    parser.add_option('--android-pack-relocations',
                      help='Path to the relocations packer 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')
    parser.add_option('--filelistjson',
                      help='Output path of filelist.json to write')

    options, _ = parser.parse_args(args)
    enable_packing = (options.enable_packing == '1'
                      and options.configuration_name == 'Release')
    exclude_packing_set = set(
        build_utils.ParseGypList(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)

    output_paths = []
    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))
        output_paths.append(output_path)

        if enable_packing and library not in exclude_packing_set:
            PackLibraryRelocations(options.android_pack_relocations,
                                   library_path, output_path)
        else:
            CopyLibraryUnchanged(library_path, output_path)

    if options.filelistjson:
        build_utils.WriteJson({'files': output_paths}, options.filelistjson)

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

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

    return 0
예제 #20
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('--script-output-path',
                        help='Output path for executable script.')
    parser.add_argument('--depfile',
                        help='Path to the depfile. This must be specified as '
                        "the action's first output.")
    # We need to intercept any test runner path arguments and make all
    # of the paths relative to the output script directory.
    group = parser.add_argument_group('Test runner path arguments.')
    group.add_argument('--additional-apk',
                       action='append',
                       dest='additional_apks',
                       default=[])
    group.add_argument('--additional-apk-list')
    group.add_argument('--apk-under-test')
    group.add_argument('--isolate-file-path')
    group.add_argument('--output-directory')
    group.add_argument('--test-apk')
    group.add_argument('--coverage-dir')
    args, test_runner_args = parser.parse_known_args(
        build_utils.ExpandFileArgs(args))

    def RelativizePathToScript(path):
        """Returns the path relative to the output script directory."""
        return os.path.relpath(path, os.path.dirname(args.script_output_path))

    test_runner_path = os.path.join(os.path.dirname(__file__), os.path.pardir,
                                    'test_runner.py')
    test_runner_path = RelativizePathToScript(test_runner_path)

    test_runner_path_args = []
    if args.additional_apk_list:
        args.additional_apks.extend(
            build_utils.ParseGypList(args.additional_apk_list))
    if args.additional_apks:
        test_runner_path_args.extend(
            ('--additional-apk', RelativizePathToScript(a))
            for a in args.additional_apks)
    if args.apk_under_test:
        test_runner_path_args.append(
            ('--apk-under-test', RelativizePathToScript(args.apk_under_test)))
    if args.isolate_file_path:
        test_runner_path_args.append(
            ('--isolate-file-path',
             RelativizePathToScript(args.isolate_file_path)))
    if args.output_directory:
        test_runner_path_args.append(
            ('--output-directory',
             RelativizePathToScript(args.output_directory)))
    if args.test_apk:
        test_runner_path_args.append(
            ('--test-apk', RelativizePathToScript(args.test_apk)))
    if args.coverage_dir:
        test_runner_path_args.append(
            ('--coverage-dir', RelativizePathToScript(args.coverage_dir)))

    with open(args.script_output_path, 'w') as script:
        script.write(
            SCRIPT_TEMPLATE.format(
                test_runner_path=str(test_runner_path),
                test_runner_args=str(test_runner_args),
                test_runner_path_args=str(test_runner_path_args)))

    os.chmod(args.script_output_path, 0750)

    if args.depfile:
        build_utils.WriteDepfile(args.depfile,
                                 build_utils.GetPythonDependencies())
예제 #21
0
파일: lint.py 프로젝트: junhuac/MQUIC
def main():
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)

    parser.add_argument('--lint-path',
                        required=True,
                        help='Path to lint executable.')
    parser.add_argument('--product-dir',
                        required=True,
                        help='Path to product dir.')
    parser.add_argument('--result-path',
                        required=True,
                        help='Path to XML lint result file.')
    parser.add_argument(
        '--cache-dir',
        required=True,
        help='Path to the directory in which the android cache '
        'directory tree should be stored.')
    parser.add_argument('--platform-xml-path',
                        required=True,
                        help='Path to api-platforms.xml')
    parser.add_argument(
        '--create-cache',
        action='store_true',
        help='Mark the lint cache file as an output rather than '
        'an input.')
    parser.add_argument(
        '--can-fail-build',
        action='store_true',
        help='If set, script will exit with nonzero exit status'
        ' if lint errors are present')
    parser.add_argument('--config-path',
                        help='Path to lint suppressions file.')
    parser.add_argument('--enable',
                        action='store_true',
                        help='Run lint instead of just touching stamp.')
    parser.add_argument('--jar-path', help='Jar file containing class files.')
    parser.add_argument('--java-files', help='Paths to java files.')
    parser.add_argument('--manifest-path', help='Path to AndroidManifest.xml')
    parser.add_argument('--processed-config-path',
                        help='Path to processed lint suppressions file.')
    parser.add_argument('--resource-dir', help='Path to resource dir.')
    parser.add_argument('--silent',
                        action='store_true',
                        help='If set, script will not log anything.')
    parser.add_argument('--src-dirs',
                        help='Directories containing java files.')
    parser.add_argument('--stamp', help='Path to touch on success.')

    args = parser.parse_args()

    if args.enable:
        sources = []
        if args.src_dirs:
            src_dirs = build_utils.ParseGypList(args.src_dirs)
            sources = build_utils.FindInDirectories(src_dirs, '*.java')
        elif args.java_files:
            sources = build_utils.ParseGypList(args.java_files)

        if args.config_path and not args.processed_config_path:
            parser.error(
                '--config-path specified without --processed-config-path')
        elif args.processed_config_path and not args.config_path:
            parser.error(
                '--processed-config-path specified without --config-path')

        input_paths = [
            args.lint_path,
            args.platform_xml_path,
        ]
        if args.config_path:
            input_paths.append(args.config_path)
        if args.jar_path:
            input_paths.append(args.jar_path)
        if args.manifest_path:
            input_paths.append(args.manifest_path)
        if args.resource_dir:
            input_paths.extend(
                build_utils.FindInDirectory(args.resource_dir, '*'))
        if sources:
            input_paths.extend(sources)

        input_strings = []
        if args.processed_config_path:
            input_strings.append(args.processed_config_path)

        output_paths = [args.result_path]

        build_utils.CallAndWriteDepfileIfStale(
            lambda changes: _OnStaleMd5(changes,
                                        args.lint_path,
                                        args.config_path,
                                        args.processed_config_path,
                                        args.manifest_path,
                                        args.result_path,
                                        args.product_dir,
                                        sources,
                                        args.jar_path,
                                        args.cache_dir,
                                        resource_dir=args.resource_dir,
                                        can_fail_build=args.can_fail_build,
                                        silent=args.silent),
            args,
            input_paths=input_paths,
            input_strings=input_strings,
            output_paths=output_paths,
            pass_changes=True)
예제 #22
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(
      '--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(
      '--classes-dir',
      help='Directory for compiled .class files.')
  parser.add_option('--jar-path', help='Jar output path.')

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

  options, args = parser.parse_args(argv)

  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 = 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)
      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

    DoJavac(
        classpath,
        classes_dir,
        options.chromium_code,
        java_files)

    if options.jar_path:
      jar.JarDirectory(classes_dir,
                       build_utils.ParseGypList(options.jar_excluded_classes),
                       options.jar_path)

    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)
def _ParseArgs(args):
  """Parses command line options.

  Returns:
    An options object as from optparse.OptionsParser.parse_args()
  """
  parser = optparse.OptionParser()
  build_utils.AddDepfileOption(parser)

  parser.add_option('--android-sdk-jar',
                    help='the path to android jar file.')
  parser.add_option('--aapt-path',
                    help='path to the Android aapt tool')
  parser.add_option('--non-constant-id', action='store_true')

  parser.add_option('--android-manifest', help='AndroidManifest.xml path')
  parser.add_option('--custom-package', help='Java package for R.java')
  parser.add_option(
      '--shared-resources',
      action='store_true',
      help='Make a resource package that can be loaded by a different'
      'application at runtime to access the package\'s resources.')
  parser.add_option(
      '--app-as-shared-lib',
      action='store_true',
      help='Make a resource package that can be loaded as shared library.')

  parser.add_option('--resource-dirs',
                    help='Directories containing resources of this target.')
  parser.add_option('--dependencies-res-zips',
                    help='Resources from dependents.')

  parser.add_option('--resource-zip-out',
                    help='Path for output zipped resources.')

  parser.add_option('--R-dir',
                    help='directory to hold generated R.java.')
  parser.add_option('--srcjar-out',
                    help='Path to srcjar to contain generated R.java.')
  parser.add_option('--r-text-out',
                    help='Path to store the R.txt file generated by appt.')

  parser.add_option('--proguard-file',
                    help='Path to proguard.txt generated file')

  parser.add_option(
      '--v14-skip',
      action="store_true",
      help='Do not generate nor verify v14 resources')

  parser.add_option(
      '--extra-res-packages',
      help='Additional package names to generate R.java files for')
  parser.add_option(
      '--extra-r-text-files',
      help='For each additional package, the R.txt file should contain a '
      'list of resources to be included in the R.java file in the format '
      'generated by aapt')
  parser.add_option(
      '--include-all-resources',
      action='store_true',
      help='Include every resource ID in every generated R.java file '
      '(ignoring R.txt).')

  parser.add_option(
      '--all-resources-zip-out',
      help='Path for output of all resources. This includes resources in '
      'dependencies.')

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

  options, positional_args = parser.parse_args(args)

  if positional_args:
    parser.error('No positional arguments should be given.')

  # Check that required options have been provided.
  required_options = (
      'android_sdk_jar',
      'aapt_path',
      'android_manifest',
      'dependencies_res_zips',
      'resource_dirs',
      'resource_zip_out',
      )
  build_utils.CheckOptions(options, parser, required=required_options)

  if (options.R_dir is None) == (options.srcjar_out is None):
    raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.')

  options.resource_dirs = build_utils.ParseGypList(options.resource_dirs)
  options.dependencies_res_zips = (
      build_utils.ParseGypList(options.dependencies_res_zips))

  # Don't use [] as default value since some script explicitly pass "".
  if options.extra_res_packages:
    options.extra_res_packages = (
        build_utils.ParseGypList(options.extra_res_packages))
  else:
    options.extra_res_packages = []

  if options.extra_r_text_files:
    options.extra_r_text_files = (
        build_utils.ParseGypList(options.extra_r_text_files))
  else:
    options.extra_r_text_files = []

  return options
예제 #24
0
파일: javac.py 프로젝트: spWang/buildroot
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('--jar-source-path', help='Source jar output path.')
    parser.add_option(
        '--jar-source-base-dir',
        help=
        'Base directory for the source files included in the output source jar.'
    )
    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.jar_source_path:
                jar.Jar(java_files, options.jar_source_base_dir,
                        options.jar_source_path)

        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)
예제 #25
0
def _ParseArgs(args):
    args = build_utils.ExpandFileArgs(args)

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

    parser.add_option('--android-sdk-tools',
                      help='Android sdk build tools directory.')
    parser.add_option('--output-directory',
                      default=os.getcwd(),
                      help='Path to the output build directory.')
    parser.add_option('--dex-path', help='Dex output path.')
    parser.add_option('--configuration-name',
                      help='The build CONFIGURATION_NAME.')
    parser.add_option('--proguard-enabled',
                      help='"true" if proguard is enabled.')
    parser.add_option('--debug-build-proguard-enabled',
                      help='"true" if proguard is enabled for debug build.')
    parser.add_option('--proguard-enabled-input-path',
                      help=('Path to dex in Release mode when proguard '
                            'is enabled.'))
    parser.add_option('--no-locals',
                      default='0',
                      help='Exclude locals list from the dex file.')
    parser.add_option('--incremental',
                      action='store_true',
                      help='Enable incremental builds when possible.')
    parser.add_option('--inputs', help='A list of additional input paths.')
    parser.add_option('--excluded-paths',
                      help='A list of paths to exclude from the dex file.')
    parser.add_option('--main-dex-list-path',
                      help='A file containing a list of the classes to '
                      'include in the main dex.')
    parser.add_option(
        '--multidex-configuration-path',
        help='A JSON file containing multidex build configuration.')
    parser.add_option('--multi-dex',
                      default=False,
                      action='store_true',
                      help='Generate multiple dex files.')

    options, paths = parser.parse_args(args)

    required_options = ('android_sdk_tools', )
    build_utils.CheckOptions(options, parser, required=required_options)

    if options.multidex_configuration_path:
        with open(options.multidex_configuration_path) as multidex_config_file:
            multidex_config = json.loads(multidex_config_file.read())
        options.multi_dex = multidex_config.get('enabled', False)

    if options.multi_dex and not options.main_dex_list_path:
        logging.warning(
            'multidex cannot be enabled without --main-dex-list-path')
        options.multi_dex = False
    elif options.main_dex_list_path and not options.multi_dex:
        logging.warning(
            '--main-dex-list-path is unused if multidex is not enabled')

    if options.inputs:
        options.inputs = build_utils.ParseGypList(options.inputs)
    if options.excluded_paths:
        options.excluded_paths = build_utils.ParseGypList(
            options.excluded_paths)

    return options, paths
예제 #26
0
def _ParseArgs(args):
  """Parses command line options.

  Returns:
    An options object as from optparse.OptionsParser.parse_args()
  """
  parser = optparse.OptionParser()
  build_utils.AddDepfileOption(parser)
  parser.add_option('--android-sdk-jar',
                    help='path to the Android SDK jar.')
  parser.add_option('--aapt-path',
                    help='path to the Android aapt tool')

  parser.add_option('--configuration-name',
                    help='Gyp\'s configuration name (Debug or Release).')

  parser.add_option('--android-manifest', help='AndroidManifest.xml path')
  parser.add_option('--version-code', help='Version code for apk.')
  parser.add_option('--version-name', help='Version name for apk.')
  parser.add_option(
      '--shared-resources',
      action='store_true',
      help='Make a resource package that can be loaded by a different'
      'application at runtime to access the package\'s resources.')
  parser.add_option(
      '--app-as-shared-lib',
      action='store_true',
      help='Make a resource package that can be loaded as shared library')
  parser.add_option('--resource-zips',
                    default='[]',
                    help='zip files containing resources to be packaged')
  parser.add_option('--asset-dir',
                    help='directories containing assets to be packaged')
  parser.add_option('--no-compress', help='disables compression for the '
                    'given comma separated list of extensions')
  parser.add_option(
      '--create-density-splits',
      action='store_true',
      help='Enables density splits')
  parser.add_option('--language-splits',
                    default='[]',
                    help='GYP list of languages to create splits for')

  parser.add_option('--apk-path',
                    help='Path to output (partial) apk.')

  options, positional_args = parser.parse_args(args)

  if positional_args:
    parser.error('No positional arguments should be given.')

  # Check that required options have been provided.
  required_options = ('android_sdk_jar', 'aapt_path', 'configuration_name',
                      'android_manifest', 'version_code', 'version_name',
                      'apk_path')

  build_utils.CheckOptions(options, parser, required=required_options)

  options.resource_zips = build_utils.ParseGypList(options.resource_zips)
  options.language_splits = build_utils.ParseGypList(options.language_splits)
  return options