Beispiel #1
0
def _RunCopyCommand(_command, options, _, option_parser):
    """Copies the jar from input to output locations.

  Also removes any old coverage/sources file.

  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):
        option_parser.error('All arguments are required.')

    if os.path.exists(options.coverage_file):
        os.remove(options.coverage_file)
    if os.path.exists(options.sources_list_file):
        os.remove(options.sources_list_file)

    shutil.copy(options.input_path, options.output_path)

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

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 build_utils.GetPythonDependencies())
Beispiel #2
0
def main():
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)

    parser.add_option('--rezip-apk-jar-path',
                      help='Path to the RezipApk jar file.')
    parser.add_option('--zipalign-path', help='Path to the zipalign tool.')
    parser.add_option('--unsigned-apk-path',
                      help='Path to input unsigned APK.')
    parser.add_option('--final-apk-path',
                      help='Path to output signed and aligned APK.')
    parser.add_option('--key-path', help='Path to keystore for signing.')
    parser.add_option('--key-passwd', help='Keystore password')
    parser.add_option('--key-name', help='Keystore name')
    parser.add_option('--stamp', help='Path to touch on success.')
    parser.add_option(
        '--load-library-from-zip',
        type='int',
        help='If non-zero, build the APK such that the library can be loaded '
        + 'directly from the zip file using the crazy linker. The library ' +
        'will be renamed, uncompressed and page aligned.')

    options, _ = parser.parse_args()

    FinalizeApk(options)

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

    if options.stamp:
        build_utils.Touch(options.stamp)
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--output', help='Path to output jar.')
    parser.add_option('--use-ijars',
                      action='store_true',
                      help='Use .interface.jar rather than the given jars.')
    parser.add_option('--inputs', action='append', help='List of jar inputs.')
    options, _ = parser.parse_args(args)
    build_utils.CheckOptions(options, parser, ['output', 'inputs'])

    input_jars = []
    for inputs_arg in options.inputs:
        input_jars.extend(build_utils.ParseGypList(inputs_arg))

    if options.use_ijars:
        ijar_re = re.compile(r'\.jar$')
        input_jars = [ijar_re.sub('.interface.jar', p) for p in input_jars]

    build_utils.MergeZips(options.output, input_jars)

    if options.depfile:
        build_utils.WriteDepfile(
            options.depfile, input_jars + build_utils.GetPythonDependencies())
def main(args):
    options = _ParseArgs(args)

    def relativize(path):
        script_dir = os.path.dirname(options.script_output_path)
        return path and os.path.relpath(path, script_dir)

    installer_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build',
                                  'android', 'incremental_install',
                                  'installer.py')
    pformat = pprint.pformat
    template_args = {
        'cmd_path': pformat(relativize(installer_path)),
        'apk_path': pformat(relativize(options.apk_path)),
        'output_directory': pformat(relativize(options.output_directory)),
        'native_libs': pformat([relativize(p) for p in options.native_libs]),
        'dex_files': pformat([relativize(p) for p in options.dex_files]),
        'show_proguard_warning': pformat(options.show_proguard_warning),
        'splits': pformat([relativize(p) for p in options.splits]),
    }

    with open(options.script_output_path, 'w') as script:
        script.write(SCRIPT_TEMPLATE.format(**template_args))

    os.chmod(options.script_output_path, 0750)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 build_utils.GetPythonDependencies())
def main(argv):
  argv = build_utils.ExpandFileArgs(argv)
  parser = optparse.OptionParser()
  build_utils.AddDepfileOption(parser)
  parser.add_option('--output', help='Output path for executable script.')
  parser.add_option('--jar-path', help='Path to the main jar.')
  parser.add_option('--main-class',
      help='Name of the java class with the "main" entry point.')
  parser.add_option('--classpath', action='append',
      help='Classpath for running the jar.')
  options, _ = parser.parse_args(argv)

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

  run_dir = os.path.dirname(options.output)
  classpath = [os.path.relpath(p, run_dir) for p in classpath]

  with open(options.output, 'w') as script:
    script.write(script_template.format(
      classpath=('"%s"' % '", "'.join(classpath)),
      main_class=options.main_class))

  os.chmod(options.output, 0750)

  if options.depfile:
    build_utils.WriteDepfile(
        options.depfile,
        build_utils.GetPythonDependencies())
Beispiel #6
0
def main(argv):
    option_parser = optparse.OptionParser()
    build_utils.AddDepfileOption(option_parser)
    option_parser.add_option('--aidl-path', help='Path to the aidl binary.')
    option_parser.add_option('--imports', help='Files to import.')
    option_parser.add_option('--includes',
                             help='Directories to add as import search paths.')
    option_parser.add_option('--srcjar', help='Path for srcjar output.')
    options, args = option_parser.parse_args(argv[1:])

    with build_utils.TempDir() as temp_dir:
        for f in args:
            classname = os.path.splitext(os.path.basename(f))[0]
            output = os.path.join(temp_dir, classname + '.java')
            aidl_cmd = [options.aidl_path]
            aidl_cmd += [
                '-p' + s for s in build_utils.ParseGypList(options.imports)
            ]
            if options.includes is not None:
                aidl_cmd += [
                    '-I' + s
                    for s in build_utils.ParseGypList(options.includes)
                ]
            aidl_cmd += [f, output]
            build_utils.CheckOutput(aidl_cmd)

        build_utils.ZipDir(options.srcjar, temp_dir)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 build_utils.GetPythonDependencies())
Beispiel #7
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--proguard-path',
                      help='Path to the proguard executable.')
    parser.add_option('--input-path',
                      help='Path to the .jar file proguard should run on.')
    parser.add_option('--output-path', help='Path to the generated .jar file.')
    parser.add_option('--proguard-config',
                      help='Path to the proguard configuration file.')
    parser.add_option('--classpath',
                      action='append',
                      help="Classpath for proguard.")
    parser.add_option('--stamp', help='Path to touch on success.')

    options, _ = parser.parse_args(args)

    DoProguard(options)

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

    if options.stamp:
        build_utils.Touch(options.stamp)
Beispiel #8
0
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'
                             ])

    rc = 0

    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
        rc = _RunLint(options.lint_path, options.config_path,
                      options.processed_config_path, options.manifest_path,
                      options.result_path, options.product_dir, sources,
                      options.jar_path, options.resource_dir)

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

    if options.stamp and not rc:
        build_utils.Touch(options.stamp)

    return rc if options.can_fail_build else 0
def main(argv):
    argv = build_utils.ExpandFileArgs(argv)
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--output', help='Output path for executable script.')
    parser.add_option('--jar-path', help='Path to the main jar.')
    parser.add_option(
        '--main-class',
        help='Name of the java class with the "main" entry point.')
    parser.add_option('--classpath',
                      action='append',
                      default=[],
                      help='Classpath for running the jar.')
    parser.add_option(
        '--bootclasspath',
        action='append',
        default=[],
        help='zip/jar files to add to bootclasspath for java cmd.')
    parser.add_option('--noverify',
                      action='store_true',
                      help='JVM flag: noverify.')

    options, extra_program_args = parser.parse_args(argv)

    if (options.noverify):
        noverify_flag = 'java_cmd.append("-noverify")'
    else:
        noverify_flag = ''

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

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

    run_dir = os.path.dirname(options.output)
    bootclasspath = [os.path.relpath(p, run_dir) for p in bootclasspath]
    classpath = [os.path.relpath(p, run_dir) for p in classpath]

    with open(options.output, 'w') as script:
        script.write(
            script_template.format(classpath=('"%s"' % '", "'.join(classpath)),
                                   bootclasspath=('"%s"' %
                                                  '", "'.join(bootclasspath)
                                                  if bootclasspath else ''),
                                   main_class=options.main_class,
                                   extra_program_args=repr(extra_program_args),
                                   noverify_flag=noverify_flag))

    os.chmod(options.output, 0750)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 build_utils.GetPythonDependencies())
Beispiel #10
0
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('--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(build_utils.CHROMIUM_SRC)
    env = jinja2.Environment(loader=loader,
                             undefined=jinja2.StrictUndefined,
                             line_comment_prefix='##')
    if options.output:
        ProcessFile(env, inputs[0], options.output, variables)
    else:
        ProcessFiles(env, inputs, 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)
Beispiel #11
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)))

    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:
      CheckDensityMissedConfigs(options.apk_path)
      RenameDensitySplits(options.apk_path)

    if options.depfile:
      build_utils.WriteDepfile(
          options.depfile,
          build_utils.GetPythonDependencies())
Beispiel #12
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)

        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

        shutil.copy(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
def main():
    options = ParseArgs()
    main_manifest = file(options.main_manifest).read()
    split_manifest = Build(main_manifest, options.split, options.has_code)

    with file(options.out_manifest, 'w') as f:
        f.write(split_manifest)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile, [main_manifest] +
                                 build_utils.GetPythonDependencies())
Beispiel #14
0
def main():
    options = _ParseArgs()
    with open(options.src_manifest) as f:
        main_manifest_data = f.read()
    new_manifest_data = _ProcessManifest(main_manifest_data,
                                         options.disable_isolated_processes)
    with open(options.out_manifest, 'w') as f:
        f.write(new_manifest_data)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile, [options.src_manifest] +
                                 build_utils.GetPythonDependencies())
Beispiel #15
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--inputs',
                        required=True,
                        help='The template files to process.')
    parser.add_argument('--output',
                        help='The output file to generate. Valid '
                        'only if there is a single input.')
    parser.add_argument('--outputs-zip',
                        help='A zip file for the processed '
                        'templates. Required if there are multiple inputs.')
    parser.add_argument('--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_argument(
        '--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_argument('--variables',
                        help='Variables to be made available in '
                        'the template processing environment, as a GYP list '
                        '(e.g. --variables "channel=beta mstone=39")',
                        default='')
    build_utils.AddDepfileOption(parser)
    options = parser.parse_args()

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

    variables = _ParseVariables(options.variables, parser.error)
    processor = JinjaProcessor(options.loader_base_dir, variables=variables)

    if options.output:
        _ProcessFile(processor, inputs[0], options.output)
    else:
        _ProcessFiles(processor, inputs, options.inputs_base_dir,
                      options.outputs_zip)

    if options.depfile:
        deps = processor.GetLoadedTemplates(
        ) + build_utils.GetPythonDependencies()
        build_utils.WriteDepfile(options.depfile, deps)
Beispiel #16
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)
    parser.add_argument('--script-output-path',
                        help='Output path for executable script.',
                        required=True)
    parser.add_argument('--apk-path',
                        help='Path to the .apk to install.',
                        required=True)
    parser.add_argument('--split',
                        action='append',
                        dest='splits',
                        default=[],
                        help='A glob matching the apk splits. '
                        'Can be specified multiple times.')
    parser.add_argument('--lib-dir',
                        help='Path to native libraries directory.')

    options = parser.parse_args(args)

    def relativize(path):
        return os.path.relpath(path,
                               os.path.dirname(options.script_output_path))

    incremental_install_path = os.path.join(constants.DIR_SOURCE_ROOT, 'build',
                                            'android',
                                            'incremental_install.py')
    incremental_install_path = relativize(incremental_install_path)

    incremental_install_path_args = [
        (None, relativize(options.apk_path)),
    ]
    if options.lib_dir:
        incremental_install_path_args.append(
            ('--lib-dir', relativize(options.lib_dir)))
    for split_arg in options.splits:
        incremental_install_path_args.append(
            ('--split', relativize(split_arg)))

    with open(options.script_output_path, 'w') as script:
        script.write(
            SCRIPT_TEMPLATE.format(
                cmd_path=repr(incremental_install_path),
                cmd_args='[]',
                cmd_path_args=repr(incremental_install_path_args)))

    os.chmod(options.script_output_path, 0750)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 build_utils.GetPythonDependencies())
Beispiel #17
0
def main():
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)

    parser.add_option('--jar-path', help='Input .jar path.')
    parser.add_option('--toc-path', help='Output .jar.TOC path.')
    parser.add_option('--stamp', help='Path to touch on success.')

    options, _ = parser.parse_args()

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

    DoJarToc(options)

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

    if options.stamp:
        build_utils.Touch(options.stamp)
Beispiel #18
0
def main():
    options = ParseArgs()
    android_jar = os.path.join(options.android_sdk, 'android.jar')
    aapt = os.path.join(options.android_sdk_tools, 'aapt')

    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,
        ]

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

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

        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)
            MoveImagesToNonMdpiFolders(subdir)
            package_command += ['-S', subdir]

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

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

        if options.depfile:
            build_utils.WriteDepfile(options.depfile,
                                     build_utils.GetPythonDependencies())
Beispiel #19
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('--output-directory')
  group.add_argument('--isolate-file-path')
  group.add_argument('--apk-under-test')
  group.add_argument('--test-apk')
  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.output_directory:
    test_runner_path_args['--output-directory'] = RelativizePathToScript(
        args.output_directory)
  if args.isolate_file_path:
    test_runner_path_args['--isolate-file-path'] = RelativizePathToScript(
        args.isolate_file_path)
  if args.apk_under_test:
    test_runner_path_args['--apk-under-test'] = RelativizePathToScript(
        args.apk_under_test)
  if args.test_apk:
    test_runner_path_args['--test-apk'] = RelativizePathToScript(
        args.test_apk)

  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())
Beispiel #20
0
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('--inputs', help='A list of additional input paths.')
    parser.add_option('--excluded-paths',
                      help='A list of paths to exclude from the dex file.')

    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
        ]

    DoDex(options, paths)

    if options.depfile:
        build_utils.WriteDepfile(options.depfile,
                                 paths + build_utils.GetPythonDependencies())
Beispiel #21
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--output', help='Path to output jar.')
    parser.add_option('--output_native_jar',
                      help='Path to output native library jar.')
    parser.add_option('--dist_jar', help='Flutter shell Java code jar.')
    parser.add_option('--native_lib',
                      action='append',
                      help='Native code library.')
    parser.add_option('--android_abi', help='Native code ABI.')
    parser.add_option('--asset_dir', help='Path to assets.')
    options, _ = parser.parse_args(args)
    build_utils.CheckOptions(
        options, parser, ['output', 'dist_jar', 'native_lib', 'android_abi'])

    input_deps = []

    with zipfile.ZipFile(options.output, 'w', zipfile.ZIP_DEFLATED) as out_zip:
        input_deps.append(options.dist_jar)
        with zipfile.ZipFile(options.dist_jar, 'r') as dist_zip:
            for dist_file in dist_zip.infolist():
                if dist_file.filename.endswith('.class'):
                    out_zip.writestr(dist_file.filename,
                                     dist_zip.read(dist_file.filename))

        for native_lib in options.native_lib:
            input_deps.append(native_lib)
            out_zip.write(
                native_lib, 'lib/%s/%s' %
                (options.android_abi, os.path.basename(native_lib)))

        if options.asset_dir:
            for asset_file in os.listdir(options.asset_dir):
                input_deps.append(asset_file)
                out_zip.write(os.path.join(options.asset_dir, asset_file),
                              'assets/flutter_shared/%s' % asset_file)

    if options.output_native_jar:
        with zipfile.ZipFile(options.output_native_jar, 'w',
                             zipfile.ZIP_DEFLATED) as out_zip:
            for native_lib in options.native_lib:
                out_zip.write(
                    native_lib, 'lib/%s/%s' %
                    (options.android_abi, os.path.basename(native_lib)))

    if options.depfile:
        build_utils.WriteDepfile(
            options.depfile, input_deps + build_utils.GetPythonDependencies())
Beispiel #22
0
def main(args):
    args = build_utils.ExpandFileArgs(args)

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

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

    options, _ = parser.parse_args(args)

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

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

    deps = []

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

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

    if options.stamp:
        build_utils.Touch(options.stamp)
def main(args):
    args = build_utils.ExpandFileArgs(args)

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

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

    options, _ = parser.parse_args(args)

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

    deps = []

    if options.files:
        DoCopy(options, deps)

    if options.renaming_sources:
        DoRenaming(options, deps)

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

    if options.stamp:
        build_utils.Touch(options.stamp)
Beispiel #24
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--output', help='Path to output jar.')
    parser.add_option('--inputs', action='append', help='List of jar inputs.')
    options, _ = parser.parse_args(args)
    build_utils.CheckOptions(options, parser, ['output', 'inputs'])

    input_jars = []
    for inputs_arg in options.inputs:
        input_jars.extend(build_utils.ParseGnList(inputs_arg))

    build_utils.MergeZips(options.output, input_jars)

    if options.depfile:
        build_utils.WriteDepfile(
            options.depfile, input_jars + build_utils.GetPythonDependencies())
Beispiel #25
0
def main():
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option('--locale-paks', help='List of files for res/raw-LOCALE')
    parser.add_option('--resources-zip', help='Path to output resources.zip')
    parser.add_option(
        '--print-languages',
        action='store_true',
        help='Print out the list of languages that cover the given locale paks '
        '(using Android\'s language codes)')

    options, _ = parser.parse_args()
    build_utils.CheckOptions(options, parser, required=['locale_paks'])

    sources = build_utils.ParseGnList(options.locale_paks)

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

    mappings, lang_to_locale_map = ComputeMappings(sources)
    if options.print_languages:
        print '\n'.join(sorted(lang_to_locale_map))

    if options.resources_zip:
        with zipfile.ZipFile(options.resources_zip, 'w',
                             zipfile.ZIP_STORED) as out:
            for mapping in mappings:
                out.write(mapping[0], mapping[1])

            # Create TypedArray resources so ResourceExtractor can enumerate files.
            def WriteValuesFile(lang, names):
                dest_dir = 'values'
                if lang:
                    dest_dir += '-' + lang
                # Always extract en-US.lpak since it's the fallback.
                xml = CreateLocalePaksXml(names + ['en_us.lpak'])
                out.writestr(os.path.join(dest_dir, 'locale-paks.xml'), xml)

            for lang, names in lang_to_locale_map.iteritems():
                WriteValuesFile(lang, names)
            WriteValuesFile(None, [])
Beispiel #26
0
def main():
  parser = optparse.OptionParser()
  build_utils.AddDepfileOption(parser)

  parser.add_option('--input-libraries',
      help='A list of top-level input libraries.')
  parser.add_option('--libraries-dir',
      help='The directory which contains shared libraries.')
  parser.add_option('--readelf', help='Path to the readelf binary.')
  parser.add_option('--output', help='Path to the generated .json file.')
  parser.add_option('--stamp', help='Path to touch on success.')

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

  SetReadelfPath(options.readelf)
  SetLibraryDirs(options.libraries_dir.split(','))

  libraries = build_utils.ParseGypList(options.input_libraries)
  if len(libraries):
    libraries = GetSortedTransitiveDependenciesForBinaries(libraries)

  # Convert to "base" library names: e.g. libfoo.so -> foo
  java_libraries_list = (
      '{%s}' % ','.join(['"%s"' % s[3:-3] for s in libraries]))

  out_json = {
      'libraries': libraries,
      'lib_paths': [FullLibraryPath(l) for l in libraries],
      'java_libraries_list': java_libraries_list
      }
  build_utils.WriteJson(
      out_json,
      options.output,
      only_if_changed=True)

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

  if options.depfile:
    build_utils.WriteDepfile(
        options.depfile,
        libraries + build_utils.GetPythonDependencies())
Beispiel #27
0
def main():
    parser = argparse.ArgumentParser(description='Find Sun Tools Jar')
    parser.add_argument('--depfile',
                        help='Path to depfile. This must be specified as the '
                        'action\'s first output.')
    parser.add_argument('--output', required=True)
    args = parser.parse_args()

    sun_tools_jar_path = FindSunToolsJarPath()

    if sun_tools_jar_path is None:
        raise Exception("Couldn\'t find tools.jar")

    # Using copyfile instead of copy() because copy() calls copymode()
    # We don't want the locked mode because we may copy over this file again
    shutil.copyfile(sun_tools_jar_path, args.output)

    if args.depfile:
        build_utils.WriteDepfile(args.depfile, [sun_tools_jar_path] +
                                 build_utils.GetPythonDependencies())
def main():
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)

    parser.add_option('--include-path', help='Include path for gcc.')
    parser.add_option('--template', help='Path to template.')
    parser.add_option('--output', help='Path for generated file.')
    parser.add_option('--stamp', help='Path to touch on success.')
    parser.add_option('--defines', help='Pre-defines macros', action='append')

    options, _ = parser.parse_args()

    DoGcc(options)

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

    if options.stamp:
        build_utils.Touch(options.stamp)
def main(argv):
  option_parser = optparse.OptionParser()
  build_utils.AddDepfileOption(option_parser)
  option_parser.add_option('--aidl-path', help='Path to the aidl binary.')
  option_parser.add_option('--imports', help='Files to import.')
  option_parser.add_option('--includes',
                           help='Directories to add as import search paths.')
  option_parser.add_option('--srcjar', help='Path for srcjar output.')
  options, args = option_parser.parse_args(argv[1:])

  with build_utils.TempDir() as temp_dir:
    for f in args:
      classname = os.path.splitext(os.path.basename(f))[0]
      output = os.path.join(temp_dir, classname + '.java')
      aidl_cmd = [options.aidl_path]
      aidl_cmd += [
        '-p' + s for s in build_utils.ParseGypList(options.imports)
      ]
      if options.includes is not None:
        aidl_cmd += [
          '-I' + s for s in build_utils.ParseGypList(options.includes)
        ]
      aidl_cmd += [
        f,
        output
      ]
      build_utils.CheckOutput(aidl_cmd)

    with zipfile.ZipFile(options.srcjar, 'w') as srcjar:
      for path in build_utils.FindInDirectory(temp_dir, '*.java'):
        with open(path) as fileobj:
          data = fileobj.read()
        pkg_name = re.search(r'^\s*package\s+(.*?)\s*;', data, re.M).group(1)
        arcname = '%s/%s' % (pkg_name.replace('.', '/'), os.path.basename(path))
        srcjar.writestr(arcname, data)

  if options.depfile:
    build_utils.WriteDepfile(
        options.depfile,
        build_utils.GetPythonDependencies())
Beispiel #30
0
def main(argv):
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option("--protoc", help="Path to protoc binary.")
    parser.add_option("--proto-path", help="Path to proto directory.")
    parser.add_option("--java-out-dir",
                      help="Path to output directory for java files.")
    parser.add_option("--srcjar", help="Path to output srcjar.")
    parser.add_option("--stamp", help="File to touch on success.")
    options, args = parser.parse_args(argv)

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

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

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

    if options.depfile:
        build_utils.WriteDepfile(
            options.depfile,
            args + [options.protoc] + build_utils.GetPythonDependencies())

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