def _UpdateCompileCommandsIfNeeded(compile_commands, files_list, target_os=None): """ Filters compile database to only include required files, and makes it more clang-tool friendly on Windows. Args: compile_commands: List of the contents of compile database. files_list: List of required files for processing. Can be None to specify no filtering. Returns: List of the contents of the compile database after processing. """ if sys.platform == 'win32' and files_list: relative_paths = set([os.path.relpath(f) for f in files_list]) filtered_compile_commands = [] for entry in compile_commands: file_path = os.path.relpath( os.path.join(entry['directory'], entry['file'])) if file_path in relative_paths: filtered_compile_commands.append(entry) else: filtered_compile_commands = compile_commands return compile_db.ProcessCompileDatabaseIfNeeded(filtered_compile_commands, target_os)
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)
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)