Beispiel #1
0
def _CreateJavaSourceDir(output_dir, entry_output_dir, java_sources_file):
  """Computes and constructs when necessary the list of java source directories.

  1. Computes the root java source directories from the list of files.
  2. Determines whether there are any .java files in them that are not included
     in |java_sources_file|.
  3. If not, returns the list of java source directories. If so, constructs a
     tree of symlinks within |entry_output_dir| of all files in
     |java_sources_file|.
  """
  java_dirs = []
  if java_sources_file:
    java_files = _RebasePath(build_utils.ReadSourcesList(java_sources_file))
    java_dirs = _ComputeJavaSourceDirs(java_files)

    found_java_files = build_utils.FindInDirectories(java_dirs, '*.java')
    unwanted_java_files = set(found_java_files) - set(java_files)
    missing_java_files = set(java_files) - set(found_java_files)
    # Warn only about non-generated files that are missing.
    missing_java_files = [p for p in missing_java_files
                          if not p.startswith(output_dir)]
    if unwanted_java_files:
      logging.debug('Target requires .java symlinks: %s', entry_output_dir)
      symlink_dir = os.path.join(entry_output_dir, _JAVA_SUBDIR)
      _CreateSymlinkTree(entry_output_dir, symlink_dir, java_files, java_dirs)
      java_dirs = [symlink_dir]

    if missing_java_files:
      logging.warning('Some java files were not found: %s', missing_java_files)

  return java_dirs
Beispiel #2
0
def DoJavac(options, args):
    output_dir = options.output_dir

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

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

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

    javac_args = [
        '-g', '-source', '1.5', '-target', '1.5', '-classpath',
        ':'.join(classpath), '-d', output_dir
    ]
    if options.chromium_code:
        javac_args.extend(['-Xlint:unchecked', '-Xlint:deprecation'])
    else:
        # XDignore.symbol.file makes javac compile against rt.jar instead of
        # ct.sym. This means that using a java internal package/class will not
        # trigger a compile warning or error.
        javac_args.extend(['-XDignore.symbol.file'])

    javac_cmd = ['javac'] + javac_args + java_files

    def Compile():
        # Delete the classes directory. This ensures that all .class files in the
        # output are actually from the input .java files. For example, if a .java
        # file is deleted or an inner class is removed, the classes directory should
        # not contain the corresponding old .class file after running this action.
        build_utils.DeleteDirectory(output_dir)
        build_utils.MakeDirectory(output_dir)
        build_utils.CheckOutput(javac_cmd,
                                print_stdout=options.chromium_code,
                                stderr_filter=ColorJavacOutput)

    record_path = '%s/javac.md5.stamp' % options.output_dir
    md5_check.CallAndRecordIfStale(Compile,
                                   record_path=record_path,
                                   input_paths=java_files + jar_inputs,
                                   input_strings=javac_cmd)
Beispiel #3
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
Beispiel #4
0
def DoJavac(options):
    output_dir = options.output_dir

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

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

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

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

    def Compile():
        # Delete the classes directory. This ensures that all .class files in the
        # output are actually from the input .java files. For example, if a .java
        # file is deleted or an inner class is removed, the classes directory should
        # not contain the corresponding old .class file after running this action.
        build_utils.DeleteDirectory(output_dir)
        build_utils.MakeDirectory(output_dir)
        suppress_output = not options.chromium_code
        build_utils.CheckCallDie(javac_cmd, suppress_output=suppress_output)

    record_path = '%s/javac.md5.stamp' % options.output_dir
    md5_check.CallAndRecordIfStale(Compile,
                                   record_path=record_path,
                                   input_paths=java_files + jar_inputs,
                                   input_strings=javac_cmd)
Beispiel #5
0
def main(argv):
    colorama.init()

    argv = build_utils.ExpandFileArgs(argv)
    options, java_files = _ParseOptions(argv)

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

    java_files = _FilterJavaFiles(java_files, options.javac_includes)

    if options.use_errorprone_path:
        javac_path = options.use_errorprone_path
        javac_cmd = [javac_path] + ERRORPRONE_OPTIONS
    else:
        javac_path = distutils.spawn.find_executable('javac')
        javac_cmd = [javac_path]

    javac_cmd.extend((
        '-g',
        # Chromium only allows UTF8 source files.  Being explicit avoids
        # javac pulling a default encoding from the user's environment.
        '-encoding',
        'UTF-8',
        # Make sure we do not pass an empty string to -classpath and -sourcepath.
        '-classpath',
        ':'.join(options.classpath) or ':',
        # Prevent compiler from compiling .java files not listed as inputs.
        # See: http://blog.ltgt.net/most-build-tools-misuse-javac/
        '-sourcepath',
        ':',
    ))

    if options.bootclasspath:
        javac_cmd.extend(['-bootclasspath', ':'.join(options.bootclasspath)])

    if options.java_version:
        javac_cmd.extend([
            '-source',
            options.java_version,
            '-target',
            options.java_version,
        ])

    if options.chromium_code:
        javac_cmd.extend(['-Xlint:unchecked', '-Xlint:deprecation'])
    else:
        # XDignore.symbol.file makes javac compile against rt.jar instead of
        # ct.sym. This means that using a java internal package/class will not
        # trigger a compile warning or error.
        javac_cmd.extend(['-XDignore.symbol.file'])

    if options.processors:
        javac_cmd.extend(['-processor', ','.join(options.processors)])
    if options.processor_args:
        for arg in options.processor_args:
            javac_cmd.extend(['-A%s' % arg])

    classpath_inputs = options.bootclasspath
    if options.classpath:
        if options.classpath[0].endswith('.interface.jar'):
            classpath_inputs.extend(options.classpath)
        else:
            # TODO(agrieve): Remove this .TOC heuristic once GYP is no more.
            for path in options.classpath:
                if os.path.exists(path + '.TOC'):
                    classpath_inputs.append(path + '.TOC')
                else:
                    classpath_inputs.append(path)

    # GN already knows of java_files, so listing them just make things worse when
    # they change.
    depfile_deps = [javac_path] + classpath_inputs + options.java_srcjars
    input_paths = depfile_deps + java_files

    output_paths = [
        options.jar_path,
        options.jar_path.replace('.jar', '.excluded.jar'),
    ]
    if options.incremental:
        output_paths.append(options.jar_path + '.pdb')

    # An escape hatch to be able to check if incremental compiles are causing
    # problems.
    force = int(os.environ.get('DISABLE_INCREMENTAL_JAVAC', 0))

    # List python deps in input_strings rather than input_paths since the contents
    # of them does not change what gets written to the depsfile.
    build_utils.CallAndWriteDepfileIfStale(lambda changes: _OnStaleMd5(
        changes, options, javac_cmd, java_files, classpath_inputs),
                                           options,
                                           depfile_deps=depfile_deps,
                                           input_paths=input_paths,
                                           input_strings=javac_cmd,
                                           output_paths=output_paths,
                                           force=force,
                                           pass_changes=True)
Beispiel #6
0
def main(argv):
  colorama.init()

  argv = build_utils.ExpandFileArgs(argv)

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

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

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

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

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

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

  options, args = parser.parse_args(argv)

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

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

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

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

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

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

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

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

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

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

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

  if options.stamp:
    build_utils.Touch(options.stamp)
Beispiel #7
0
def main():
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)

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

    args = parser.parse_args()

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

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

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

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

        output_paths = [args.result_path]

        build_utils.CallAndWriteDepfileIfStale(
            lambda changes: _OnStaleMd5(changes,
                                        args.lint_path,
                                        args.config_path,
                                        args.processed_config_path,
                                        args.manifest_path,
                                        args.result_path,
                                        args.product_dir,
                                        sources,
                                        args.jar_path,
                                        args.cache_dir,
                                        resource_dir=args.resource_dir,
                                        can_fail_build=args.can_fail_build,
                                        silent=args.silent),
            args,
            input_paths=input_paths,
            input_strings=input_strings,
            output_paths=output_paths,
            pass_changes=True)
Beispiel #8
0
def main(argv):
  colorama.init()

  argv = build_utils.ExpandFileArgs(argv)
  options, java_files = _ParseOptions(argv)

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

  java_files = _FilterJavaFiles(java_files, options.javac_includes)

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

  javac_cmd = ['javac']
  if options.use_errorprone_path:
    javac_cmd = [options.use_errorprone_path] + ERRORPRONE_OPTIONS

  javac_cmd.extend((
      '-g',
      # Chromium only allows UTF8 source files.  Being explicit avoids
      # javac pulling a default encoding from the user's environment.
      '-encoding', 'UTF-8',
      '-classpath', ':'.join(compile_classpath),
      # Prevent compiler from compiling .java files not listed as inputs.
      # See: http://blog.ltgt.net/most-build-tools-misuse-javac/
      '-sourcepath', ''
  ))

  if options.bootclasspath:
    javac_cmd.extend([
        '-bootclasspath', ':'.join(options.bootclasspath),
        '-source', '1.7',
        '-target', '1.7',
        ])

  if options.chromium_code:
    javac_cmd.extend(['-Xlint:unchecked', '-Xlint:deprecation'])
  else:
    # XDignore.symbol.file makes javac compile against rt.jar instead of
    # ct.sym. This means that using a java internal package/class will not
    # trigger a compile warning or error.
    javac_cmd.extend(['-XDignore.symbol.file'])

  classpath_inputs = options.bootclasspath
  # TODO(agrieve): Remove this .TOC heuristic once GYP is no more.
  if options.use_ijars:
    classpath_inputs.extend(compile_classpath)
  else:
    for path in compile_classpath:
      if os.path.exists(path + '.TOC'):
        classpath_inputs.append(path + '.TOC')
      else:
        classpath_inputs.append(path)

  # Compute the list of paths that when changed, we need to rebuild.
  input_paths = classpath_inputs + options.java_srcjars + java_files

  output_paths = [
      options.jar_path,
      options.jar_path.replace('.jar', '.excluded.jar'),
  ]
  if options.incremental:
    output_paths.append(options.jar_path + '.pdb')

  # An escape hatch to be able to check if incremental compiles are causing
  # problems.
  force = int(os.environ.get('DISABLE_INCREMENTAL_JAVAC', 0))

  # List python deps in input_strings rather than input_paths since the contents
  # of them does not change what gets written to the depsfile.
  build_utils.CallAndWriteDepfileIfStale(
      lambda changes: _OnStaleMd5(changes, options, javac_cmd, java_files,
                                  classpath_inputs, runtime_classpath),
      options,
      input_paths=input_paths,
      input_strings=javac_cmd,
      output_paths=output_paths,
      force=force,
      pass_changes=True)
Beispiel #9
0
def main():
    parser = argparse.ArgumentParser()
    build_utils.AddDepfileOption(parser)

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

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

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

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

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

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

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

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

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

        output_paths = [args.result_path]

        build_utils.CallAndWriteDepfileIfStale(
            lambda: _OnStaleMd5(args.lint_path,
                                args.config_path,
                                args.processed_config_path,
                                args.manifest_path,
                                args.result_path,
                                args.product_dir,
                                sources,
                                args.jar_path,
                                args.cache_dir,
                                args.android_sdk_version,
                                resource_sources,
                                classpath=classpath,
                                can_fail_build=args.can_fail_build,
                                silent=args.silent),
            args,
            input_paths=input_paths,
            input_strings=input_strings,
            output_paths=output_paths,
            depfile_deps=classpath)
Beispiel #10
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'
                             ])

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

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

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

        build_utils.CallAndWriteDepfileIfStale(
            lambda changes: _OnStaleMd5(changes,
                                        options.lint_path,
                                        options.config_path,
                                        options.processed_config_path,
                                        options.manifest_path,
                                        options.result_path,
                                        options.product_dir,
                                        sources,
                                        options.jar_path,
                                        resource_dir=options.resource_dir,
                                        can_fail_build=options.can_fail_build),
            options,
            input_paths=input_paths,
            input_strings=input_strings,
            output_paths=output_paths,
            pass_changes=True)