示例#1
0
def main(argv):
  parser = argparse.ArgumentParser()
  parser.add_argument('-p', required=True, help='Path to build directory')
  parser.add_argument('targets',
                      nargs='*',
                      help='Additional targets to pass to ninja')
  parser.add_argument(
      '--target_os',
      choices=[
          'android',
          'chromeos',
          'fuchsia',
          'ios',
          'linux',
          'mac',
          'nacl',
          'win',
      ],
      help='Target OS - see `gn help target_os`. Set to "win" when ' +
      'cross-compiling Windows from Linux or another host')
  parser.add_argument(
      '-o',
      help='File to write the compilation database to. Defaults to stdout')

  args = parser.parse_args()

  compdb_text = json.dumps(compile_db.ProcessCompileDatabaseIfNeeded(
      compile_db.GenerateWithNinja(args.p, args.targets), args.target_os),
                           indent=2)
  if args.o is None:
    print(compdb_text)
  else:
    with open(args.o, 'w') as f:
      f.write(compdb_text)
示例#2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--tool', required=True, help='clang tool to run')
    parser.add_argument('--all', action='store_true')
    parser.add_argument(
        '--generate-compdb',
        action='store_true',
        help='regenerate the compile database before running the tool')
    parser.add_argument('--shard', metavar='<n>-of-<count>')
    parser.add_argument(
        '-p',
        required=True,
        help='path to the directory that contains the compile database')
    parser.add_argument(
        'path_filter',
        nargs='*',
        help='optional paths to filter what files the tool is run on')
    parser.add_argument('--tool-args',
                        nargs='*',
                        help='optional arguments passed to the tool')
    args = parser.parse_args()

    os.environ['PATH'] = '%s%s%s' % (os.path.abspath(
        os.path.join(os.path.dirname(__file__),
                     '../../../third_party/llvm-build/Release+Asserts/bin')),
                                     os.pathsep, os.environ['PATH'])

    if args.generate_compdb:
        with open(os.path.join(args.p, 'compile_commands.json'), 'w') as f:
            f.write(compile_db.GenerateWithNinja(args.p))

    if args.all:
        source_filenames = set(_GetFilesFromCompileDB(args.p))
    else:
        git_filenames = set(_GetFilesFromGit(args.path_filter))
        # Filter out files that aren't C/C++/Obj-C/Obj-C++.
        extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm'))
        source_filenames = [
            f for f in git_filenames if os.path.splitext(f)[1] in extensions
        ]

    if args.shard:
        total_length = len(source_filenames)
        match = re.match(r'(\d+)-of-(\d+)$', args.shard)
        # Input is 1-based, but modular arithmetic is 0-based.
        shard_number = int(match.group(1)) - 1
        shard_count = int(match.group(2))
        source_filenames = [
            f[1] for f in enumerate(sorted(source_filenames))
            if f[0] % shard_count == shard_number
        ]
        print 'Shard %d-of-%d will process %d entries out of %d' % (
            shard_number, shard_count, len(source_filenames), total_length)

    dispatcher = _CompilerDispatcher(args.tool, args.tool_args, args.p,
                                     source_filenames)
    dispatcher.Run()
    return -dispatcher.failed_count
示例#3
0
def main(argv):
  parser = argparse.ArgumentParser()
  parser.add_argument(
      '-p',
      required=True,
      help='Path to build directory')
  args = parser.parse_args()

  print compile_db.GenerateWithNinja(args.p)
示例#4
0
def AddTargetsForArch(arch, combined):
    build_dir = PrepareBuildDir(arch, "debug")
    commands = compile_db.ProcessCompileDatabase(
        compile_db.GenerateWithNinja(build_dir, ["all"]), [])
    added = 0
    for c in commands:
        key = c["file"]
        if key not in combined:
            combined[key] = c
            added += 1
    print("%s: added %d compile commands" % (arch, added))
示例#5
0
def main():
    args = ParseArgs()
    os.chdir(args.p)
    if args.generate_compdb:
        compile_db.GenerateWithNinja('.')
    db = compile_db.Read('.')
    for record in db:
        if os.path.normpath(os.path.join(args.p,
                                         record['file'])) == args.target_file:
            return BuildIt(record, args.prefix, args.compiler, args.suffix)
    print 'error: could not find %s in compile DB!' % args.target_file
    return 1
示例#6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('tool', help='clang tool to run')
    parser.add_argument('--all', action='store_true')
    parser.add_argument(
        '--generate-compdb',
        action='store_true',
        help='regenerate the compile database before running the tool')
    parser.add_argument(
        'compile_database',
        help='path to the directory that contains the compile database')
    parser.add_argument(
        'path_filter',
        nargs='*',
        help='optional paths to filter what files the tool is run on')
    parser.add_argument('--tool-args',
                        nargs='*',
                        help='optional arguments passed to the tool')
    args = parser.parse_args()

    os.environ['PATH'] = '%s%s%s' % (os.path.abspath(
        os.path.join(os.path.dirname(__file__),
                     '../../../third_party/llvm-build/Release+Asserts/bin')),
                                     os.pathsep, os.environ['PATH'])

    if args.generate_compdb:
        compile_db.GenerateWithNinja(args.compile_database)

    if args.all:
        filenames = set(_GetFilesFromCompileDB(args.compile_database))
        source_filenames = filenames
    else:
        filenames = set(_GetFilesFromGit(args.path_filter))
        # Filter out files that aren't C/C++/Obj-C/Obj-C++.
        extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm'))
        source_filenames = [
            f for f in filenames if os.path.splitext(f)[1] in extensions
        ]
    dispatcher = _CompilerDispatcher(args.tool, args.tool_args,
                                     args.compile_database, source_filenames)
    dispatcher.Run()
    # Filter out edits to files that aren't in the git repository, since it's not
    # useful to modify files that aren't under source control--typically, these
    # are generated files or files in a git submodule that's not part of Chromium.
    _ApplyEdits({
        k: v
        for k, v in dispatcher.edits.iteritems()
        if os.path.realpath(k) in filenames
    })
    return -dispatcher.failed_count
示例#7
0
def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('tool', help='clang tool to run')
  parser.add_argument('--all', action='store_true')
  parser.add_argument(
      '--generate-compdb',
      action='store_true',
      help='regenerate the compile database before running the tool')
  parser.add_argument(
      'compile_database',
      help='path to the directory that contains the compile database')
  parser.add_argument(
      'path_filter',
      nargs='*',
      help='optional paths to filter what files the tool is run on')
  parser.add_argument(
      '--tool-args', nargs='*',
      help='optional arguments passed to the tool')
  args = parser.parse_args()

  os.environ['PATH'] = '%s%s%s' % (
      os.path.abspath(os.path.join(
          os.path.dirname(__file__),
          '../../../third_party/llvm-build/Release+Asserts/bin')),
      os.pathsep,
      os.environ['PATH'])

  if args.generate_compdb:
    compile_db.GenerateWithNinja(args.compile_database)

  if args.all:
    source_filenames = set(_GetFilesFromCompileDB(args.compile_database))
  else:
    git_filenames = set(_GetFilesFromGit(args.path_filter))
    # Filter out files that aren't C/C++/Obj-C/Obj-C++.
    extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm'))
    source_filenames = [f
                        for f in git_filenames
                        if os.path.splitext(f)[1] in extensions]

  dispatcher = _CompilerDispatcher(args.tool, args.tool_args,
                                   args.compile_database,
                                   source_filenames)
  dispatcher.Run()
  return -dispatcher.failed_count
示例#8
0
def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('-p', required=True, help='Path to build directory')
    parser.add_argument('targets',
                        nargs='*',
                        help='Additional targets to pass to ninja')
    parser.add_argument(
        '-o',
        help='File to write the compilation database to. Defaults to stdout')

    args = parser.parse_args()

    compdb_text = json.dumps(
        compile_db.ProcessCompileDatabaseIfNeeded(
            compile_db.GenerateWithNinja(args.p, args.targets)))
    if args.o is None:
        print(compdb_text)
    else:
        with open(args.o, 'w') as f:
            f.write(compdb_text)
示例#9
0
  def GetCompDBFiles(self, generate_compdb):
    """Gets the list of files.

    Args:
      generate_compdb: if true, generate a new compdb and write it to
                       compile_commands.json.

    Returns:
      A set of absolute filepaths, with all compile-able C++ files (based on the
      compilation database).
    """
    if generate_compdb:
      compile_commands = compile_db.GenerateWithNinja(self.build_path)
      compdb_path = os.path.join(self.build_path, 'compile_commands.json')
      with open(compdb_path, 'w') as f:
        f.write(json.dumps(compile_commands, indent=2))

    compdb = compile_db.Read(self.build_path)
    return set(
        os.path.abspath(os.path.join(self.build_path, e['file']))
        for e in compdb)
示例#10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--options-file',
                        help='optional file to read options from')
    args, argv = parser.parse_known_args()
    if args.options_file:
        argv = open(args.options_file).read().split()

    parser.add_argument('--tool', required=True, help='clang tool to run')
    parser.add_argument('--all', action='store_true')
    parser.add_argument(
        '--generate-compdb',
        action='store_true',
        help='regenerate the compile database before running the tool')
    parser.add_argument('--shard', metavar='<n>-of-<count>')
    parser.add_argument(
        '-p',
        required=True,
        help='path to the directory that contains the compile database')
    parser.add_argument(
        '--target_os',
        choices=['android', 'chromeos', 'ios', 'linux', 'nacl', 'mac', 'win'],
        help='Target OS - see `gn help target_os`. Set to "win" when ' +
        'cross-compiling Windows from Linux or another host')
    parser.add_argument(
        'path_filter',
        nargs='*',
        help='optional paths to filter what files the tool is run on')
    parser.add_argument('--tool-arg',
                        nargs='?',
                        action='append',
                        help='optional arguments passed to the tool')
    parser.add_argument('--tool-path',
                        nargs='?',
                        help='optional path to the tool directory')
    args = parser.parse_args(argv)

    if args.tool_path:
        tool_path = os.path.abspath(args.tool_path)
    else:
        tool_path = os.path.abspath(
            os.path.join(
                os.path.dirname(__file__),
                '../../../third_party/llvm-build/Release+Asserts/bin'))
    if not os.path.exists(tool_path):
        sys.stderr.write('tool not found: %s\n' % tool_path)
        return -1

    if args.all:
        # Reading source files is postponed to after possible regeneration of
        # compile_commands.json.
        source_filenames = None
    else:
        git_filenames = set(_GetFilesFromGit(args.path_filter))
        # Filter out files that aren't C/C++/Obj-C/Obj-C++.
        extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm'))
        source_filenames = [
            f for f in git_filenames if os.path.splitext(f)[1] in extensions
        ]

    if args.generate_compdb:
        compile_commands = compile_db.GenerateWithNinja(args.p)
        compile_commands = _UpdateCompileCommandsIfNeeded(
            compile_commands, source_filenames, args.target_os)
        with open(os.path.join(args.p, 'compile_commands.json'), 'w') as f:
            f.write(json.dumps(compile_commands, indent=2))

    compdb_entries = set(_GetEntriesFromCompileDB(args.p, source_filenames))

    if args.shard:
        total_length = len(compdb_entries)
        match = re.match(r'(\d+)-of-(\d+)$', args.shard)
        # Input is 1-based, but modular arithmetic is 0-based.
        shard_number = int(match.group(1)) - 1
        shard_count = int(match.group(2))
        compdb_entries = [
            f for i, f in enumerate(sorted(compdb_entries))
            if i % shard_count == shard_number
        ]
        print('Shard %d-of-%d will process %d entries out of %d' %
              (shard_number, shard_count, len(compdb_entries), total_length))

    dispatcher = _CompilerDispatcher(os.path.join(tool_path, args.tool),
                                     args.tool_arg, args.p, compdb_entries)
    dispatcher.Run()
    return -dispatcher.failed_count