def main():
  """Compare the flags with the checked in list."""
  parser = argparse.ArgumentParser()
  diff_utils.AddCommandLineFlags(parser)
  parser.add_argument('--current-flags',
                      help='Path to flags to check against expectations.')
  options = parser.parse_args()

  flags = ParseFlags(options.current_flags)
  flags = MergeFlags(flags)

  msg = """
This expectation file is meant to inform the build team about changes to
flags used when building native libraries in chrome (most importantly any
that relate to security). This is to ensure the flags are replicated when
building native libraries outside of the repo. Please update the .expected
files and a WATCHLIST entry will alert the build team to your change."""
  diff_utils.CheckExpectations('\n'.join(sorted(flags)),
                               options,
                               custom_msg=msg)
예제 #2
0
def _ParseArgs(args):
    """Parses command line options.

  Returns:
    An options object as from argparse.ArgumentParser.parse_args()
  """
    parser, input_opts, output_opts = resource_utils.ResourceArgsParser()

    input_opts.add_argument('--aapt2-path',
                            required=True,
                            help='Path to the Android aapt2 tool.')
    input_opts.add_argument('--android-manifest',
                            required=True,
                            help='AndroidManifest.xml path.')
    input_opts.add_argument(
        '--r-java-root-package-name',
        default='base',
        help='Short package name for this target\'s root R java file (ex. '
        'input of "base" would become gen.base_module). Defaults to "base".')
    group = input_opts.add_mutually_exclusive_group()
    group.add_argument(
        '--shared-resources',
        action='store_true',
        help='Make all resources in R.java non-final and allow the resource IDs '
        'to be reset to a different package index when the apk is loaded by '
        'another application at runtime.')
    group.add_argument(
        '--app-as-shared-lib',
        action='store_true',
        help='Same as --shared-resources, but also ensures all resource IDs are '
        'directly usable from the APK loaded as an application.')

    input_opts.add_argument(
        '--package-id',
        type=int,
        help='Decimal integer representing custom package ID for resources '
        '(instead of 127==0x7f). Cannot be used with --shared-resources.')

    input_opts.add_argument(
        '--package-name',
        help='Package name that will be used to create R class.')

    input_opts.add_argument('--rename-manifest-package',
                            help='Package name to force AAPT to use.')

    input_opts.add_argument(
        '--arsc-package-name',
        help='Package name to set in manifest of resources.arsc file. This is '
        'only used for apks under test.')

    input_opts.add_argument(
        '--shared-resources-allowlist',
        help='An R.txt file acting as a allowlist for resources that should be '
        'non-final and have their package ID changed at runtime in R.java. '
        'Implies and overrides --shared-resources.')

    input_opts.add_argument(
        '--shared-resources-allowlist-locales',
        default='[]',
        help=
        'Optional GN-list of locales. If provided, all strings corresponding'
        ' to this locale list will be kept in the final output for the '
        'resources identified through --shared-resources-allowlist, even '
        'if --locale-allowlist is being used.')

    input_opts.add_argument(
        '--use-resource-ids-path',
        help='Use resource IDs generated by aapt --emit-ids.')

    input_opts.add_argument(
        '--extra-main-r-text-files',
        help=
        'Additional R.txt files that will be added to the root R.java file, '
        'but not packaged in the generated resources.arsc. If these resources '
        'entries contain duplicate resources with the generated R.txt file, they '
        'must be identical.')

    input_opts.add_argument('--debuggable',
                            action='store_true',
                            help='Whether to add android:debuggable="true".')

    input_opts.add_argument('--version-code', help='Version code for apk.')
    input_opts.add_argument('--version-name', help='Version name for apk.')
    input_opts.add_argument('--min-sdk-version',
                            required=True,
                            help='android:minSdkVersion for APK.')
    input_opts.add_argument('--target-sdk-version',
                            required=True,
                            help="android:targetSdkVersion for APK.")
    input_opts.add_argument(
        '--max-sdk-version',
        help="android:maxSdkVersion expected in AndroidManifest.xml.")
    input_opts.add_argument('--manifest-package',
                            help='Package name of the AndroidManifest.xml.')

    input_opts.add_argument(
        '--locale-allowlist',
        default='[]',
        help='GN list of languages to include. All other language configs will '
        'be stripped out. List may include a combination of Android locales '
        'or Chrome locales.')
    input_opts.add_argument(
        '--resource-exclusion-regex',
        default='',
        help='File-based filter for resources (applied before compiling)')
    input_opts.add_argument(
        '--resource-exclusion-exceptions',
        default='[]',
        help='GN list of globs that say which files to include even '
        'when --resource-exclusion-regex is set.')

    input_opts.add_argument(
        '--dependencies-res-zip-overlays',
        help='GN list with subset of --dependencies-res-zips to use overlay '
        'semantics for.')

    input_opts.add_argument(
        '--values-filter-rules',
        help='GN list of source_glob:regex for filtering resources after they '
        'are compiled. Use this to filter out entries within values/ files.')

    input_opts.add_argument('--png-to-webp',
                            action='store_true',
                            help='Convert png files to webp format.')

    input_opts.add_argument('--webp-binary',
                            default='',
                            help='Path to the cwebp binary.')
    input_opts.add_argument('--webp-cache-dir',
                            help='The directory to store webp image cache.')

    input_opts.add_argument(
        '--no-xml-namespaces',
        action='store_true',
        help='Whether to strip xml namespaces from processed xml resources.')
    input_opts.add_argument(
        '--short-resource-paths',
        action='store_true',
        help='Whether to shorten resource paths inside the apk or module.')
    input_opts.add_argument(
        '--strip-resource-names',
        action='store_true',
        help=
        'Whether to strip resource names from the resource table of the apk '
        'or module.')

    output_opts.add_argument('--arsc-path', help='Apk output for arsc format.')
    output_opts.add_argument('--proto-path',
                             help='Apk output for proto format.')
    group = input_opts.add_mutually_exclusive_group()
    group.add_argument(
        '--optimized-arsc-path',
        help='Output for `aapt2 optimize` for arsc format (enables the step).')
    group.add_argument(
        '--optimized-proto-path',
        help='Output for `aapt2 optimize` for proto format (enables the step).'
    )
    input_opts.add_argument(
        '--resources-config-paths',
        default='[]',
        help='GN list of paths to aapt2 resources config files.')

    output_opts.add_argument(
        '--info-path', help='Path to output info file for the partial apk.')

    output_opts.add_argument(
        '--srcjar-out',
        required=True,
        help='Path to srcjar to contain generated R.java.')

    output_opts.add_argument('--r-text-out',
                             help='Path to store the generated R.txt file.')

    output_opts.add_argument('--proguard-file',
                             help='Path to proguard.txt generated file.')

    output_opts.add_argument(
        '--proguard-file-main-dex',
        help='Path to proguard.txt generated file for main dex.')

    output_opts.add_argument('--emit-ids-out',
                             help='Path to file produced by aapt2 --emit-ids.')

    output_opts.add_argument(
        '--resources-path-map-out-path',
        help='Path to file produced by aapt2 that maps original resource paths '
        'to shortened resource paths inside the apk or module.')

    input_opts.add_argument(
        '--is-bundle-module',
        action='store_true',
        help='Whether resources are being generated for a bundle module.')

    input_opts.add_argument(
        '--uses-split',
        help='Value to set uses-split to in the AndroidManifest.xml.')

    input_opts.add_argument(
        '--extra-verification-manifest',
        help='Path to AndroidManifest.xml which should be merged into base '
        'manifest when performing verification.')

    diff_utils.AddCommandLineFlags(parser)
    options = parser.parse_args(args)

    resource_utils.HandleCommonOptions(options)

    options.locale_allowlist = build_utils.ParseGnList(
        options.locale_allowlist)
    options.shared_resources_allowlist_locales = build_utils.ParseGnList(
        options.shared_resources_allowlist_locales)
    options.resource_exclusion_exceptions = build_utils.ParseGnList(
        options.resource_exclusion_exceptions)
    options.dependencies_res_zip_overlays = build_utils.ParseGnList(
        options.dependencies_res_zip_overlays)
    options.values_filter_rules = build_utils.ParseGnList(
        options.values_filter_rules)
    options.extra_main_r_text_files = build_utils.ParseGnList(
        options.extra_main_r_text_files)
    options.resources_config_paths = build_utils.ParseGnList(
        options.resources_config_paths)

    if options.optimized_proto_path and not options.proto_path:
        # We could write to a temp file, but it's simpler to require it.
        parser.error('--optimized-proto-path requires --proto-path')

    if not options.arsc_path and not options.proto_path:
        parser.error('One of --arsc-path or --proto-path is required.')

    if options.resources_path_map_out_path and not options.short_resource_paths:
        parser.error(
            '--resources-path-map-out-path requires --short-resource-paths')

    if options.package_id and options.shared_resources:
        parser.error(
            '--package-id and --shared-resources are mutually exclusive')

    return options
예제 #3
0
def _ParseOptions():
    args = build_utils.ExpandFileArgs(sys.argv[1:])
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--r8-path',
                        required=True,
                        help='Path to the R8.jar to use.')
    parser.add_argument('--desugar-jdk-libs-json',
                        help='Path to desugar_jdk_libs.json.')
    parser.add_argument('--input-paths',
                        action='append',
                        required=True,
                        help='GN-list of .jar files to optimize.')
    parser.add_argument('--desugar-jdk-libs-jar',
                        help='Path to desugar_jdk_libs.jar.')
    parser.add_argument('--desugar-jdk-libs-configuration-jar',
                        help='Path to desugar_jdk_libs_configuration.jar.')
    parser.add_argument('--output-path',
                        help='Path to the generated .jar file.')
    parser.add_argument('--proguard-configs',
                        action='append',
                        required=True,
                        help='GN-list of configuration files.')
    parser.add_argument('--apply-mapping',
                        help='Path to ProGuard mapping to apply.')
    parser.add_argument('--mapping-output',
                        required=True,
                        help='Path for ProGuard to output mapping file to.')
    parser.add_argument(
        '--extra-mapping-output-paths',
        help='GN-list of additional paths to copy output mapping file to.')
    parser.add_argument('--classpath',
                        action='append',
                        help='GN-list of .jar files to include as libraries.')
    parser.add_argument('--main-dex-rules-path',
                        action='append',
                        help='Path to main dex rules for multidex'
                        '- only works with R8.')
    parser.add_argument('--min-api',
                        help='Minimum Android API level compatibility.')
    parser.add_argument('--verbose',
                        '-v',
                        action='store_true',
                        help='Print all ProGuard output')
    parser.add_argument('--repackage-classes',
                        help='Package all optimized classes are put in.')
    parser.add_argument(
        '--disable-outlining',
        action='store_true',
        help='Disable the outlining optimization provided by R8.')
    parser.add_argument('--disable-checkdiscard',
                        action='store_true',
                        help='Disable -checkdiscard directives')
    parser.add_argument('--sourcefile', help='Value for source file attribute')
    parser.add_argument(
        '--force-enable-assertions',
        action='store_true',
        help='Forcefully enable javac generated assertion code.')
    parser.add_argument(
        '--feature-jars',
        action='append',
        help='GN list of path to jars which comprise the corresponding feature.'
    )
    parser.add_argument(
        '--dex-dest',
        action='append',
        dest='dex_dests',
        help='Destination for dex file of the corresponding feature.')
    parser.add_argument('--feature-name',
                        action='append',
                        dest='feature_names',
                        help='The name of the feature module.')
    parser.add_argument('--warnings-as-errors',
                        action='store_true',
                        help='Treat all warnings as errors.')
    parser.add_argument('--show-desugar-default-interface-warnings',
                        action='store_true',
                        help='Enable desugaring warnings.')
    parser.add_argument(
        '--stamp',
        help='File to touch upon success. Mutually exclusive with --output-path'
    )
    parser.add_argument(
        '--desugared-library-keep-rule-output',
        help='Path to desugared library keep rule output file.')

    diff_utils.AddCommandLineFlags(parser)
    options = parser.parse_args(args)

    if options.feature_names:
        if options.output_path:
            parser.error('Feature splits cannot specify an output in GN.')
        if not options.actual_file and not options.stamp:
            parser.error('Feature splits require a stamp file as output.')
    elif not options.output_path:
        parser.error('Output path required when feature splits aren\'t used')

    options.classpath = build_utils.ParseGnList(options.classpath)
    options.proguard_configs = build_utils.ParseGnList(
        options.proguard_configs)
    options.input_paths = build_utils.ParseGnList(options.input_paths)
    options.extra_mapping_output_paths = build_utils.ParseGnList(
        options.extra_mapping_output_paths)

    if options.feature_names:
        if 'base' not in options.feature_names:
            parser.error(
                '"base" feature required when feature arguments are used.')
        if len(options.feature_names) != len(options.feature_jars) or len(
                options.feature_names) != len(options.dex_dests):
            parser.error('Invalid feature argument lengths.')

        options.feature_jars = [
            build_utils.ParseGnList(x) for x in options.feature_jars
        ]

    return options
예제 #4
0
def _ParseOptions():
  args = build_utils.ExpandFileArgs(sys.argv[1:])
  parser = argparse.ArgumentParser()
  build_utils.AddDepfileOption(parser)
  parser.add_argument('--r8-path',
                      required=True,
                      help='Path to the R8.jar to use.')
  parser.add_argument(
      '--desugar-jdk-libs-json', help='Path to desugar_jdk_libs.json.')
  parser.add_argument('--input-paths',
                      action='append',
                      required=True,
                      help='GN-list of .jar files to optimize.')
  parser.add_argument('--desugar-jdk-libs-jar',
                      help='Path to desugar_jdk_libs.jar.')
  parser.add_argument('--desugar-jdk-libs-configuration-jar',
                      help='Path to desugar_jdk_libs_configuration.jar.')
  parser.add_argument('--output-path', help='Path to the generated .jar file.')
  parser.add_argument(
      '--proguard-configs',
      action='append',
      required=True,
      help='GN-list of configuration files.')
  parser.add_argument(
      '--apply-mapping', help='Path to ProGuard mapping to apply.')
  parser.add_argument(
      '--mapping-output',
      required=True,
      help='Path for ProGuard to output mapping file to.')
  parser.add_argument(
      '--extra-mapping-output-paths',
      help='GN-list of additional paths to copy output mapping file to.')
  parser.add_argument(
      '--classpath',
      action='append',
      help='GN-list of .jar files to include as libraries.')
  parser.add_argument('--main-dex-rules-path',
                      action='append',
                      help='Path to main dex rules for multidex.')
  parser.add_argument(
      '--min-api', help='Minimum Android API level compatibility.')
  parser.add_argument('--enable-obfuscation',
                      action='store_true',
                      help='Minify symbol names')
  parser.add_argument(
      '--verbose', '-v', action='store_true', help='Print all ProGuard output')
  parser.add_argument(
      '--repackage-classes', help='Package all optimized classes are put in.')
  parser.add_argument(
      '--disable-outlining',
      action='store_true',
      help='Disable the outlining optimization provided by R8.')
  parser.add_argument(
    '--disable-checks',
    action='store_true',
    help='Disable -checkdiscard directives and missing symbols check')
  parser.add_argument('--sourcefile', help='Value for source file attribute')
  parser.add_argument(
      '--force-enable-assertions',
      action='store_true',
      help='Forcefully enable javac generated assertion code.')
  parser.add_argument(
      '--feature-jars',
      action='append',
      help='GN list of path to jars which comprise the corresponding feature.')
  parser.add_argument(
      '--dex-dest',
      action='append',
      dest='dex_dests',
      help='Destination for dex file of the corresponding feature.')
  parser.add_argument(
      '--feature-name',
      action='append',
      dest='feature_names',
      help='The name of the feature module.')
  parser.add_argument(
      '--uses-split',
      action='append',
      help='List of name pairs separated by : mapping a feature module to a '
      'dependent feature module.')
  parser.add_argument(
      '--keep-rules-targets-regex',
      metavar='KEEP_RULES_REGEX',
      help='If passed outputs keep rules for references from all other inputs '
      'to the subset of inputs that satisfy the KEEP_RULES_REGEX.')
  parser.add_argument(
      '--keep-rules-output-path',
      help='Output path to the keep rules for references to the '
      '--keep-rules-targets-regex inputs from the rest of the inputs.')
  parser.add_argument('--warnings-as-errors',
                      action='store_true',
                      help='Treat all warnings as errors.')
  parser.add_argument('--show-desugar-default-interface-warnings',
                      action='store_true',
                      help='Enable desugaring warnings.')
  parser.add_argument('--dump-inputs',
                      action='store_true',
                      help='Use when filing R8 bugs to capture inputs.'
                      ' Stores inputs to r8inputs.zip')
  parser.add_argument(
      '--stamp',
      help='File to touch upon success. Mutually exclusive with --output-path')
  parser.add_argument('--desugared-library-keep-rule-output',
                      help='Path to desugared library keep rule output file.')

  diff_utils.AddCommandLineFlags(parser)
  options = parser.parse_args(args)

  if options.feature_names:
    if options.output_path:
      parser.error('Feature splits cannot specify an output in GN.')
    if not options.actual_file and not options.stamp:
      parser.error('Feature splits require a stamp file as output.')
  elif not options.output_path:
    parser.error('Output path required when feature splits aren\'t used')

  if bool(options.keep_rules_targets_regex) != bool(
      options.keep_rules_output_path):
    raise Exception('You must path both --keep-rules-targets-regex and '
                    '--keep-rules-output-path')

  options.classpath = build_utils.ParseGnList(options.classpath)
  options.proguard_configs = build_utils.ParseGnList(options.proguard_configs)
  options.input_paths = build_utils.ParseGnList(options.input_paths)
  options.extra_mapping_output_paths = build_utils.ParseGnList(
      options.extra_mapping_output_paths)

  if options.feature_names:
    if 'base' not in options.feature_names:
      parser.error('"base" feature required when feature arguments are used.')
    if len(options.feature_names) != len(options.feature_jars) or len(
        options.feature_names) != len(options.dex_dests):
      parser.error('Invalid feature argument lengths.')

    options.feature_jars = [
        build_utils.ParseGnList(x) for x in options.feature_jars
    ]

  split_map = {}
  if options.uses_split:
    for split_pair in options.uses_split:
      child, parent = split_pair.split(':')
      for name in (child, parent):
        if name not in options.feature_names:
          parser.error('"%s" referenced in --uses-split not present.' % name)
      split_map[child] = parent
  options.uses_split = split_map

  return options
예제 #5
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.')
  parser.add_argument(
      '--java-resources', help='GYP-list of java_resources JARs to include.')
  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.')
  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('--format', choices=['apk', 'bundle-module'],
                      default='apk', help='Specify output format.')
  parser.add_argument('--dex-file',
                      help='Path to the classes.dex to use')
  parser.add_argument(
      '--jdk-libs-dex-file',
      help='Path to classes.dex created by dex_jdk_libs.py')
  parser.add_argument('--uncompress-dex', action='store_true',
                      help='Store .dex files uncompressed in the APK')
  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(
      '--is-multi-abi',
      action='store_true',
      help='Will add a placeholder for the missing ABI if no native libs or '
      'placeholders are set for either the primary or secondary ABI. Can only '
      'be set if both --android-abi and --secondary-android-abi are set.')
  parser.add_argument(
      '--native-lib-placeholders',
      help='GYP-list of native library placeholders to add.')
  parser.add_argument(
      '--secondary-native-lib-placeholders',
      help='GYP-list of native library placeholders to add '
      'for the secondary ABI')
  parser.add_argument('--uncompress-shared-libraries', default='False',
      choices=['true', 'True', 'false', 'False'],
      help='Whether to uncompress native shared libraries. Argument must be '
           'a boolean value.')
  parser.add_argument(
      '--apksigner-jar', help='Path to the apksigner executable.')
  parser.add_argument('--zipalign-path',
                      help='Path to the zipalign executable.')
  parser.add_argument('--key-path',
                      help='Path to keystore for signing.')
  parser.add_argument('--key-passwd',
                      help='Keystore password')
  parser.add_argument('--key-name',
                      help='Keystore name')
  parser.add_argument(
      '--min-sdk-version', required=True, help='Value of APK\'s minSdkVersion')
  parser.add_argument(
      '--best-compression',
      action='store_true',
      help='Use zip -9 rather than zip -1')
  parser.add_argument(
      '--library-always-compress',
      action='append',
      help='The list of library files that we always compress.')
  parser.add_argument(
      '--library-renames',
      action='append',
      help='The list of library files that we prepend crazy. to their names.')
  parser.add_argument('--warnings-as-errors',
                      action='store_true',
                      help='Treat all warnings as errors.')
  diff_utils.AddCommandLineFlags(parser)
  options = parser.parse_args(args)
  options.assets = build_utils.ParseGnList(options.assets)
  options.uncompressed_assets = build_utils.ParseGnList(
      options.uncompressed_assets)
  options.native_lib_placeholders = build_utils.ParseGnList(
      options.native_lib_placeholders)
  options.secondary_native_lib_placeholders = build_utils.ParseGnList(
      options.secondary_native_lib_placeholders)
  options.java_resources = build_utils.ParseGnList(options.java_resources)
  options.native_libs = build_utils.ParseGnList(options.native_libs)
  options.secondary_native_libs = build_utils.ParseGnList(
      options.secondary_native_libs)
  options.library_always_compress = build_utils.ParseGnList(
      options.library_always_compress)
  options.library_renames = build_utils.ParseGnList(options.library_renames)

  # --apksigner-jar, --zipalign-path, --key-xxx arguments are
  # required when building an APK, but not a bundle module.
  if options.format == 'apk':
    required_args = [
        'apksigner_jar', 'zipalign_path', 'key_path', 'key_passwd', 'key_name'
    ]
    for required in required_args:
      if not vars(options)[required]:
        raise Exception('Argument --%s is required for APKs.' % (
            required.replace('_', '-')))

  options.uncompress_shared_libraries = \
      options.uncompress_shared_libraries in [ 'true', 'True' ]

  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 or
      options.secondary_native_lib_placeholders):
    raise Exception('Must specify --secondary-android-abi with'
                    ' --secondary-native-libs')
  if options.is_multi_abi and not (options.android_abi
                                   and options.secondary_android_abi):
    raise Exception('Must specify --is-multi-abi with both --android-abi '
                    'and --secondary-android-abi.')
  return options