Example #1
0
def main(argv):
    parser = optparse.OptionParser()

    parser.add_option('--android-sdk-root', help='Android sdk root directory.')
    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('--keystore-path', help='Path to keystore for signing.')
    parser.add_option('--stamp', help='Path to touch on success.')

    options, _ = parser.parse_args()

    with tempfile.NamedTemporaryFile() as intermediate_file:
        signed_apk_path = intermediate_file.name
        SignApk(options.keystore_path, options.unsigned_apk_path,
                signed_apk_path)
        AlignApk(options.android_sdk_root, signed_apk_path,
                 options.final_apk_path)

    if options.stamp:
        build_utils.Touch(options.stamp)
Example #2
0
def main(args):
    parser = argparse.ArgumentParser(
        description='Enforce Cronet API requirements.')
    parser.add_argument('--api_jar',
                        help='Path to API jar (i.e. cronet_api.jar)',
                        required=True,
                        metavar='path/to/cronet_api.jar')
    parser.add_argument('--impl_jar',
                        help='Path to implementation jar '
                        '(i.e. cronet_impl_native_java.jar)',
                        required=True,
                        metavar='path/to/cronet_impl_native_java.jar',
                        action='append')
    parser.add_argument('--stamp', help='Path to touch on success.')
    opts = parser.parse_args(args)

    ret = True
    ret = check_api_calls(opts) and ret
    ret = check_api_version(opts) and ret
    if ret and opts.stamp:
        build_utils.Touch(opts.stamp)
    return ret
Example #3
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('--src-dirs', help='Directories containing java files.')
    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('--classpath', help='Classpath for javac.')
    parser.add_option('--output-dir', help='Directory for javac output.')
    parser.add_option('--stamp', help='Path to touch on success.')
    parser.add_option('--chromium-code',
                      type='int',
                      help='Whether code being '
                      'compiled should be built with stricter warnings for '
                      'chromium code.')

    options, _ = parser.parse_args()

    DoJavac(options)

    if options.stamp:
        build_utils.Touch(options.stamp)
Example #4
0
def main(argv):
    parser = optparse.OptionParser()

    parser.add_option('--android-sdk-root', help='Android sdk root directory.')
    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('--keystore-path', help='Path to keystore for signing.')
    parser.add_option('--stamp', help='Path to touch on success.')

    # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
    parser.add_option('--ignore', help='Ignored.')

    options, _ = parser.parse_args()

    signed_apk_path = options.unsigned_apk_path + '.signed.apk'
    SignApk(options.keystore_path, options.unsigned_apk_path, signed_apk_path)
    AlignApk(options.android_sdk_root, signed_apk_path, options.final_apk_path)

    if options.stamp:
        build_utils.Touch(options.stamp)
def main():
    parser = optparse.OptionParser()

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

    global _options
    _options, _ = parser.parse_args()

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

    build_utils.WriteJson(libraries, _options.output, only_if_changed=True)

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

    build_utils.MakeDirectory(options.R_dir)

    # Generate R.java. This R.java contains non-final constants and is used only
    # while compiling the library jar (e.g. chromium_content.jar). When building
    # an apk, a new R.java file with the correct resource -> ID mappings will be
    # generated by merging the resources from all libraries and the main apk
    # project.
    package_command = [
        aapt, 'package', '-m', '-M', options.android_manifest,
        '--auto-add-overlay', '-I', android_jar, '--output-text-symbols',
        options.R_dir, '-J', options.R_dir
    ]
    res_dirs = shlex.split(options.res_dirs)
    for res_dir in res_dirs:
        package_command += ['-S', res_dir]
    if options.non_constant_id:
        package_command.append('--non-constant-id')
    if options.custom_package:
        package_command += ['--custom-package', options.custom_package]
    build_utils.CheckOutput(package_command)

    # Crunch image resources. This shrinks png files and is necessary for 9-patch
    # images to display correctly.
    build_utils.MakeDirectory(options.crunch_output_dir)
    aapt_cmd = [
        aapt, 'crunch', '-S', options.crunch_input_dir, '-C',
        options.crunch_output_dir
    ]
    build_utils.CheckOutput(aapt_cmd, fail_if_stderr=True)

    MoveImagesToNonMdpiFolders(options.crunch_output_dir)

    if options.stamp:
        build_utils.Touch(options.stamp)
    def on_stale_md5():
        _RunLint(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,
                 args.srcjars,
                 args.min_sdk_version,
                 args.manifest_package,
                 resource_sources,
                 disable=disable,
                 classpath=classpath,
                 can_fail_build=args.can_fail_build,
                 include_unexpected=args.include_unexpected_failures,
                 silent=args.silent)

        build_utils.Touch(args.stamp)
Example #8
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()

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

    build_utils.WriteJson(
        {
            'libraries': libraries,
            'java_libraries_list': java_libraries_list
        },
        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())
Example #9
0
def main():
  build_utils.InitLogging('LINT_DEBUG')
  args = _ParseArgs(sys.argv[1:])

  sources = []
  for java_sources_file in args.java_sources:
    sources.extend(build_utils.ReadSourcesList(java_sources_file))
  resource_sources = []
  for resource_sources_file in args.resource_sources:
    resource_sources.extend(build_utils.ReadSourcesList(resource_sources_file))

  possible_depfile_deps = (args.srcjars + args.resource_zips + sources +
                           resource_sources + [
                               args.baseline,
                               args.manifest_path,
                           ])
  depfile_deps = [p for p in possible_depfile_deps if p]

  _RunLint(args.lint_binary_path,
           args.config_path,
           args.manifest_path,
           sources,
           args.classpath,
           args.cache_dir,
           args.android_sdk_version,
           args.srcjars,
           args.min_sdk_version,
           resource_sources,
           args.resource_zips,
           args.android_sdk_root,
           args.lint_gen_dir,
           args.baseline,
           testonly_target=args.testonly,
           warnings_as_errors=args.warnings_as_errors)
  logging.info('Creating stamp file')
  build_utils.Touch(args.stamp)

  if args.depfile:
    build_utils.WriteDepfile(args.depfile, args.stamp, depfile_deps)
Example #10
0
def main(args):
    args = build_utils.ExpandFileArgs(args)

    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(args)

    DoGcc(options)

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

    if options.stamp:
        build_utils.Touch(options.stamp)
Example #11
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)
Example #12
0
def main(args):
    args = build_utils.ExpandFileArgs(args)

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

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

    options, _ = parser.parse_args(args)

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

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

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

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

    if options.stamp:
        build_utils.Touch(options.stamp)
Example #13
0
def main(argv):
    parser = optparse.OptionParser()
    parser.add_option('--apk', help='Path to the apk.')
    parser.add_option('--libraries-json',
                      help='Path to the json list of native libraries.')
    parser.add_option(
        '--target-dir',
        help='Device directory that contains the target libraries for symlinks.'
    )
    parser.add_option(
        '--libraries-dir',
        help='Directory that contains stripped libraries '
        '(used to determine if a library has changed since last push).')
    parser.add_option('--stamp', help='Path to touch on success.')
    options, _ = parser.parse_args()

    required_options = ['apk', 'libraries_json', 'target_dir', 'libraries_dir']
    build_utils.CheckOptions(options, parser, required=required_options)

    CreateLinks(options)

    if options.stamp:
        build_utils.Touch(options.stamp)
Example #14
0
def DoJar(options):
  class_files = build_utils.FindInDirectory(options.classes_dir, '*.class')
  for exclude in build_utils.ParseGypList(options.excluded_classes):
    class_files = filter(
        lambda f: not fnmatch.fnmatch(f, exclude), class_files)

  jar_path = os.path.abspath(options.jar_path)

  # The paths of the files in the jar will be the same as they are passed in to
  # the command. Because of this, the command should be run in
  # options.classes_dir so the .class file paths in the jar are correct.
  jar_cwd = options.classes_dir
  class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files]
  jar_cmd = ['jar', 'cf0', jar_path] + class_files_rel

  record_path = '%s.md5.stamp' % options.jar_path
  md5_check.CallAndRecordIfStale(
      lambda: build_utils.CheckCallDie(jar_cmd, cwd=jar_cwd),
      record_path=record_path,
      input_paths=class_files,
      input_strings=jar_cmd)

  build_utils.Touch(options.jar_path)
Example #15
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = optparse.OptionParser()
    parser.add_option('--libraries-dir',
                      help='Directory that contains stripped libraries.')
    parser.add_option('--device-dir',
                      help='Device directory to push the libraries to.')
    parser.add_option('--libraries', help='List of native libraries.')
    parser.add_option('--stamp', help='Path to touch on success.')
    parser.add_option('--build-device-configuration',
                      help='Path to build device configuration.')
    parser.add_option('--configuration-name',
                      help='The build CONFIGURATION_NAME')
    options, _ = parser.parse_args(args)

    required_options = ['libraries', 'device_dir', 'libraries']
    build_utils.CheckOptions(options, parser, required=required_options)
    constants.SetBuildType(options.configuration_name)

    DoPush(options)

    if options.stamp:
        build_utils.Touch(options.stamp)
Example #16
0
def _WriteFinalRTxtFile(options, aapt_r_txt_path):
    """Determine final R.txt and return its location.

  This handles --r-text-in and --r-text-out options at the same time.

  Args:
    options: The command-line options tuple.
    aapt_r_txt_path: The path to the R.txt generated by aapt.
  Returns:
    Path to the final R.txt file.
  """
    if options.r_text_in:
        r_txt_file = options.r_text_in
    else:
        # When an empty res/ directory is passed, aapt does not write an R.txt.
        r_txt_file = aapt_r_txt_path
        if not os.path.exists(r_txt_file):
            build_utils.Touch(r_txt_file)

    if options.r_text_out:
        shutil.copyfile(r_txt_file, options.r_text_out)

    return r_txt_file
Example #17
0
def main(argv):
  parser = optparse.OptionParser()
  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('--classes-dir', help='Directory containing class files.')
  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', 'src_dirs',
                                 'classes_dir'])

  src_dirs = build_utils.ParseGypList(options.src_dirs)

  rc = 0

  if options.enable:
    rc = _RunLint(options.lint_path, options.config_path,
                  options.processed_config_path,
                  options.manifest_path, options.result_path,
                  options.product_dir, src_dirs, options.classes_dir)

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

  return rc
Example #18
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = optparse.OptionParser()
    parser.add_option('--apk', help='Path to the apk.')
    parser.add_option('--script-host-path',
                      help='Path on the host for the symlink script.')
    parser.add_option(
        '--script-device-path',
        help='Path on the device to push the created symlink script.')
    parser.add_option('--libraries', help='List of native libraries.')
    parser.add_option(
        '--target-dir',
        help='Device directory that contains the target libraries for symlinks.'
    )
    parser.add_option('--stamp', help='Path to touch on success.')
    parser.add_option('--build-device-configuration',
                      help='Path to build device configuration.')
    parser.add_option('--configuration-name',
                      help='The build CONFIGURATION_NAME')
    parser.add_option('--output-directory', help='The output directory')
    options, _ = parser.parse_args(args)

    required_options = [
        'apk', 'libraries', 'script_host_path', 'script_device_path',
        'target_dir', 'configuration_name'
    ]
    build_utils.CheckOptions(options, parser, required=required_options)
    constants.SetBuildType(options.configuration_name)

    devil_chromium.Initialize(
        output_directory=os.path.abspath(options.output_directory))

    CreateSymlinkScript(options)
    TriggerSymlinkScript(options)

    if options.stamp:
        build_utils.Touch(options.stamp)
Example #19
0
def _CreateRTxtAndSrcJar(options, r_txt_path, srcjar_dir):
    # When an empty res/ directory is passed, aapt does not write an R.txt.
    if not os.path.exists(r_txt_path):
        build_utils.Touch(r_txt_path)

    if options.r_text_in:
        r_txt_path = options.r_text_in

    packages = list(options.extra_res_packages)
    r_txt_files = list(options.extra_r_text_files)

    cur_package = options.custom_package
    if not options.custom_package and options.android_manifest:
        cur_package = _ExtractPackageFromManifest(options.android_manifest)

    # Don't create a .java file for the current resource target when:
    # - no package name was provided (either by manifest or build rules),
    # - there was already a dependent android_resources() with the same
    #   package (occurs mostly when an apk target and resources target share
    #   an AndroidManifest.xml)
    if cur_package and cur_package not in packages:
        packages.append(cur_package)
        r_txt_files.append(r_txt_path)

    if packages:
        shared_resources = options.shared_resources or options.app_as_shared_lib
        _CreateRJavaFiles(srcjar_dir, r_txt_path, packages, r_txt_files,
                          shared_resources, options.non_constant_id,
                          options.shared_resources_whitelist,
                          bool(options.apk_path))

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

    if options.r_text_out:
        shutil.copyfile(r_txt_path, options.r_text_out)
Example #20
0
def main(args):
    args = build_utils.ExpandFileArgs(args)
    parser = optparse.OptionParser()
    parser.add_option('--libraries-dir',
                      help='Directory that contains stripped libraries.')
    parser.add_option('--device-dir',
                      help='Device directory to push the libraries to.')
    parser.add_option('--libraries', help='List of native libraries.')
    parser.add_option('--stamp', help='Path to touch on success.')
    parser.add_option('--build-device-configuration',
                      help='Path to build device configuration.')
    parser.add_option('--output-directory', help='The output directory.')
    options, _ = parser.parse_args(args)

    required_options = ['libraries', 'device_dir', 'libraries']
    build_utils.CheckOptions(options, parser, required=required_options)

    devil_chromium.Initialize(
        output_directory=os.path.abspath(options.output_directory))

    DoPush(options)

    if options.stamp:
        build_utils.Touch(options.stamp)
def main():
    parser = optparse.OptionParser()

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

    options, _ = parser.parse_args()

    with tempfile.NamedTemporaryFile() as intermediate_file:
        signed_apk_path = intermediate_file.name
        SignApk(options.key_path, options.key_name, options.key_passwd,
                options.unsigned_apk_path, signed_apk_path)
        AlignApk(options.zipalign_path, signed_apk_path,
                 options.final_apk_path)

    if options.stamp:
        build_utils.Touch(options.stamp)
Example #22
0
def main(args):
  args = build_utils.ExpandFileArgs(args)

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

  parser.add_option('--android-strip',
      help='Path to the toolchain\'s strip binary')
  parser.add_option('--android-strip-arg', action='append',
      help='Argument to be passed to strip')
  parser.add_option('--libraries-dir',
      help='Directory for un-stripped libraries')
  parser.add_option('--stripped-libraries-dir',
      help='Directory for stripped libraries')
  parser.add_option('--libraries',
      help='List of libraries to strip')
  parser.add_option('--stamp', help='Path to touch on success')

  options, _ = parser.parse_args(args)

  libraries = build_utils.ParseGypList(options.libraries)

  build_utils.MakeDirectory(options.stripped_libraries_dir)

  for library in libraries:
    for base_path in options.libraries_dir.split(','):
      library_path = os.path.join(base_path, library)
      if (os.path.exists(library_path)):
        break
    stripped_library_path = os.path.join(
        options.stripped_libraries_dir, library)
    StripLibrary(options.android_strip, options.android_strip_arg, library_path,
        stripped_library_path)

  if options.stamp:
    build_utils.Touch(options.stamp)
Example #23
0
def Jar(class_files, classes_dir, jar_path, manifest_file=None):
  jar_path = os.path.abspath(jar_path)

  # The paths of the files in the jar will be the same as they are passed in to
  # the command. Because of this, the command should be run in
  # options.classes_dir so the .class file paths in the jar are correct.
  jar_cwd = classes_dir
  class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files]
  jar_cmd = ['jar', 'cf0', jar_path]
  if manifest_file:
    jar_cmd[1] += 'm'
    jar_cmd.append(os.path.abspath(manifest_file))
  jar_cmd.extend(class_files_rel)

  record_path = '%s.md5.stamp' % jar_path
  md5_check.CallAndRecordIfStale(
      lambda: build_utils.CheckOutput(jar_cmd, cwd=jar_cwd),
      record_path=record_path,
      input_paths=class_files,
      input_strings=jar_cmd,
      force=not os.path.exists(jar_path),
      )

  build_utils.Touch(jar_path, fail_if_missing=True)
Example #24
0
def DoJar(options):
  class_files = build_utils.FindInDirectory(options.classes_dir, '*.class')
  for exclude in build_utils.ParseGypList(options.excluded_classes):
    class_files = filter(
        lambda f: not fnmatch.fnmatch(f, exclude), class_files)

  jar_path = os.path.abspath(options.jar_path)

  # The paths of the files in the jar will be the same as they are passed in to
  # the command. Because of this, the command should be run in
  # options.classes_dir so the .class file paths in the jar are correct.
  jar_cwd = options.classes_dir
  class_files_rel = [os.path.relpath(f, jar_cwd) for f in class_files]
  jar_cmd = ['jar', 'cf0', jar_path] + class_files_rel


  md5_stamp = '%s.md5' % options.jar_path
  md5_checker = md5_check.Md5Checker(
      stamp=md5_stamp, inputs=class_files, command=jar_cmd)
  if md5_checker.IsStale():
    build_utils.CheckCallDie(jar_cmd, cwd=jar_cwd)
  else:
    build_utils.Touch(options.jar_path)
  md5_checker.Write()
Example #25
0
def _RunCopyCommand(command, options, args, 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_file):
        option_parser.error('All arguments are required.')

    coverage_file = os.path.join(os.path.dirname(options.output_path),
                                 options.coverage_file)
    sources_file = os.path.join(os.path.dirname(options.output_path),
                                options.sources_file)
    if os.path.exists(coverage_file):
        os.remove(coverage_file)
    if os.path.exists(sources_file):
        os.remove(sources_file)

    if os.path.isdir(options.input_path):
        shutil.rmtree(options.output_path, ignore_errors=True)
        shutil.copytree(options.input_path, options.output_path)
    else:
        shutil.copy(options.input_path, options.output_path)

    if options.stamp:
        build_utils.Touch(options.stamp)
def main(argv):
    parser = optparse.OptionParser()

    parser.add_option('--input-libraries',
                      help='A list of top-level input 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.')

    global _options
    _options, _ = parser.parse_args()

    libraries = build_utils.ParseGypList(_options.input_libraries)
    global _libraries_dir
    _libraries_dir = os.path.dirname(libraries[0])
    libraries = [os.path.basename(lib) for lib in libraries]

    libraries = GetSortedTransitiveDependencies(libraries)

    with open(_options.output, 'w') as outfile:
        json.dump(libraries, outfile)

    if _options.stamp:
        build_utils.Touch(_options.stamp)
Example #27
0
def _OnStaleMd5(changes, options, javac_cmd, java_files, classpath_inputs,
                classpath):
  # Don't bother enabling incremental compilation for non-chromium code.
  incremental = options.incremental and options.chromium_code

  with build_utils.TempDir() as temp_dir:
    srcjars = options.java_srcjars

    classes_dir = os.path.join(temp_dir, 'classes')
    os.makedirs(classes_dir)

    changed_paths = None
    # jmake can handle deleted files, but it's a rare case and it would
    # complicate this script's logic.
    if incremental and changes.AddedOrModifiedOnly():
      changed_paths = set(changes.IterChangedPaths())
      # Do a full compile if classpath has changed.
      # jmake doesn't seem to do this on its own... Might be that ijars mess up
      # its change-detection logic.
      if any(p in changed_paths for p in classpath_inputs):
        changed_paths = None

    if options.incremental:
      pdb_path = options.jar_path + '.pdb'

    if incremental:
      # jmake is a compiler wrapper that figures out the minimal set of .java
      # files that need to be rebuilt given a set of .java files that have
      # changed.
      # jmake determines what files are stale based on timestamps between .java
      # and .class files. Since we use .jars, .srcjars, and md5 checks,
      # timestamp info isn't accurate for this purpose. Rather than use jmake's
      # programatic interface (like we eventually should), we ensure that all
      # .class files are newer than their .java files, and convey to jmake which
      # sources are stale by having their .class files be missing entirely
      # (by not extracting them).
      javac_cmd = _ConvertToJMakeArgs(javac_cmd, pdb_path)
      if srcjars:
        _FixTempPathsInIncrementalMetadata(pdb_path, temp_dir)

    srcjar_files = dict()
    if srcjars:
      java_dir = os.path.join(temp_dir, 'java')
      os.makedirs(java_dir)
      for srcjar in options.java_srcjars:
        if changed_paths:
          changed_paths.update(os.path.join(java_dir, f)
                               for f in changes.IterChangedSubpaths(srcjar))
        extracted_files = build_utils.ExtractAll(
            srcjar, path=java_dir, pattern='*.java')
        for path in extracted_files:
          srcjar_files[path] = srcjar
      jar_srcs = build_utils.FindInDirectory(java_dir, '*.java')
      java_files.extend(jar_srcs)
      if changed_paths:
        # Set the mtime of all sources to 0 since we use the absence of .class
        # files to tell jmake which files are stale.
        for path in jar_srcs:
          os.utime(path, (0, 0))

    _CreateInfoFile(java_files, options, srcjar_files)

    if java_files:
      if changed_paths:
        changed_java_files = [p for p in java_files if p in changed_paths]
        if os.path.exists(options.jar_path):
          _ExtractClassFiles(options.jar_path, classes_dir, changed_java_files)
        # Add the extracted files to the classpath. This is required because
        # when compiling only a subset of files, classes that haven't changed
        # need to be findable.
        classpath.append(classes_dir)

      # Can happen when a target goes from having no sources, to having sources.
      # It's created by the call to build_utils.Touch() below.
      if incremental:
        if os.path.exists(pdb_path) and not os.path.getsize(pdb_path):
          os.unlink(pdb_path)

      # Don't include the output directory in the initial set of args since it
      # being in a temp dir makes it unstable (breaks md5 stamping).
      cmd = javac_cmd + ['-d', classes_dir]

      # Pass classpath and source paths as response files to avoid extremely
      # long command lines that are tedius to debug.
      if classpath:
        cmd += ['-classpath', ':'.join(classpath)]

      java_files_rsp_path = os.path.join(temp_dir, 'files_list.txt')
      with open(java_files_rsp_path, 'w') as f:
        f.write(' '.join(java_files))
      cmd += ['@' + java_files_rsp_path]

      # JMake prints out some diagnostic logs that we want to ignore.
      # This assumes that all compiler output goes through stderr.
      stdout_filter = lambda s: ''
      if md5_check.PRINT_EXPLANATIONS:
        stdout_filter = None

      attempt_build = lambda: build_utils.CheckOutput(
          cmd,
          print_stdout=options.chromium_code,
          stdout_filter=stdout_filter,
          stderr_filter=ProcessJavacOutput)
      try:
        attempt_build()
      except build_utils.CalledProcessError as e:
        # Work-around for a bug in jmake (http://crbug.com/551449).
        if 'project database corrupted' not in e.output:
          raise
        print ('Applying work-around for jmake project database corrupted '
               '(http://crbug.com/551449).')
        os.unlink(pdb_path)
        attempt_build()

    if options.incremental and (not java_files or not incremental):
      # Make sure output exists.
      build_utils.Touch(pdb_path)

    jar.JarDirectory(classes_dir,
                     options.jar_path,
                     provider_configurations=options.provider_configurations,
                     additional_files=options.additional_jar_files)
Example #28
0
def main(argv):
    parser = optparse.OptionParser()
    build_utils.AddDepfileOption(parser)
    parser.add_option("--protoc", help="Path to protoc binary.")
    parser.add_option("--proto-path", help="Path to proto directory.")
    parser.add_option("--java-out-dir",
                      help="Path to output directory for java files.")
    parser.add_option("--srcjar", help="Path to output srcjar.")
    parser.add_option("--stamp", help="File to touch on success.")
    parser.add_option("--nano",
                      help="Use to generate nano protos.",
                      action='store_true')
    parser.add_option("--protoc-javalite-plugin-dir",
                      help="Path to protoc java lite plugin directory.")
    options, args = parser.parse_args(argv)

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

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

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

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

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

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

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

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

    libraries = []
    for p in options.classpath:
        # If a jar is part of input no need to include it as library jar.
        if p not in libraries and p not in options.input_paths:
            libraries.append(p)

    # TODO(agrieve): Remove proguard usages.
    if options.r8_path:
        with build_utils.TempDir() as tmp_dir:
            tmp_mapping_path = os.path.join(tmp_dir, 'mapping.txt')
            tmp_proguard_config_path = os.path.join(tmp_dir,
                                                    'proguard_config.txt')
            # If there is no output (no classes are kept), this prevents this script
            # from failing.
            build_utils.Touch(tmp_mapping_path)

            f = cStringIO.StringIO()
            proguard_util.WriteFlagsFile(options.proguard_configs,
                                         f,
                                         exclude_generated=True)
            merged_configs = f.getvalue()
            f.close()
            print_stdout = '-whyareyoukeeping' in merged_configs

            if options.output_path.endswith('.dex'):
                with build_utils.TempDir() as tmp_dex_dir:
                    cmd = _CreateR8Command(options, tmp_mapping_path,
                                           tmp_dex_dir,
                                           tmp_proguard_config_path, libraries)
                    build_utils.CheckOutput(cmd, print_stdout=print_stdout)
                    _MoveTempDexFile(tmp_dex_dir, options.output_path)
            else:
                cmd = _CreateR8Command(options, tmp_mapping_path,
                                       options.output_path,
                                       tmp_proguard_config_path, libraries)
                build_utils.CheckOutput(cmd, print_stdout=print_stdout)

            # Copy output files to correct locations.
            with build_utils.AtomicOutput(options.mapping_output) as mapping:
                # Mapping files generated by R8 include comments that may break
                # some of our tooling so remove those.
                with open(tmp_mapping_path) as tmp:
                    mapping.writelines(l for l in tmp if not l.startswith("#"))

        with build_utils.AtomicOutput(options.output_config) as f:
            f.write(merged_configs)

        if options.expected_configs_file:
            _VerifyExpectedConfigs(options.expected_configs_file,
                                   options.output_config,
                                   options.verify_expected_configs)

        other_inputs = []
        if options.apply_mapping:
            other_inputs += options.apply_mapping

        build_utils.WriteDepfile(options.depfile,
                                 options.output_path,
                                 inputs=options.proguard_configs +
                                 options.input_paths + libraries +
                                 other_inputs,
                                 add_pydeps=False)
    else:
        proguard = proguard_util.ProguardCmdBuilder(options.proguard_path)
        proguard.injars(options.input_paths)
        proguard.configs(options.proguard_configs)
        proguard.config_exclusions(options.proguard_config_exclusions)
        proguard.outjar(options.output_path)
        proguard.mapping_output(options.mapping_output)
        proguard.libraryjars(libraries)
        proguard.verbose(options.verbose)
        # Do not consider the temp file as an input since its name is random.
        input_paths = proguard.GetInputs()

        with tempfile.NamedTemporaryFile() as f:
            if options.apply_mapping:
                input_paths.append(options.apply_mapping)
                # Maintain only class name mappings in the .mapping file in order to
                # work around what appears to be a ProGuard bug in -applymapping:
                #     method 'int close()' is not being kept as 'a', but remapped to 'c'
                _RemoveMethodMappings(options.apply_mapping, f)
                proguard.mapping(f.name)

            input_strings = proguard.build()
            if f.name in input_strings:
                input_strings[input_strings.index(f.name)] = '$M'

            build_utils.CallAndWriteDepfileIfStale(
                proguard.CheckOutput,
                options,
                input_paths=input_paths,
                input_strings=input_strings,
                output_paths=proguard.GetOutputs(),
                depfile_deps=proguard.GetDepfileDeps(),
                add_pydeps=False)
Example #30
0
 def Install():
     device.Install(options.apk_path, reinstall=True)
     RecordInstallMetadata(device, apk_package, metadata_path)
     build_utils.Touch(options.install_record)