def main(): parser = argparse.ArgumentParser() parser.add_argument('--options-file', type=Path, help='optional file to read options from') args, argv = parser.parse_known_args() if args.options_file is not None: argv = args.options_file.read_text(encoding="utf-8").split() parser.add_argument( '--build-path', type=Path, help='Specifies a compiled build directory, e.g. out/Debug.') parser.add_argument( '--generate-compdb', action='store_true', help='Generate a new compile_commands.json before running') parser.add_argument('--no-filter', action='store_true', help='Do not filter files based on compdb entries') parser.add_argument('file_paths', nargs='+', type=Path, help='List of files to process.') args = parser.parse_args(argv) if not args.no_filter: tools = NetworkTrafficAnnotationTools(args.build_path) compdb_files = tools.GetCompDBFiles(args.generate_compdb) annotation_definitions = [] # Parse all the files. # TODO(crbug/966883): Do this in parallel. for file_path in args.file_paths: if not args.no_filter and file_path.resolve() not in compdb_files: continue try: annotation_definitions.extend(extract_annotations(file_path)) except SourceCodeParsingError: traceback.print_exc() return EX_PARSE_ERROR # Print output. for annotation in annotation_definitions: print(annotation.extractor_output_string()) # If all files were successfully checked for annotations but none of them had # any, print something so that the traffic_annotation_auditor knows there was # no error so that the files get checked for deleted annotations. if not annotation_definitions: print('No annotations in these files.') return 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( '--build-path', help='Specifies a compiled build directory, e.g. out/Debug.') parser.add_argument( '--generate-compdb', action='store_true', help='Generate a new compile_commands.json before running') parser.add_argument('--no-filter', action='store_true', help='Do not filter files based on compdb entries') parser.add_argument('file_paths', nargs='+', help='List of files to process.') args = parser.parse_args(argv) tools = NetworkTrafficAnnotationTools(args.build_path) compdb_files = tools.GetCompDBFiles(args.generate_compdb) annotation_definitions = [] # Parse all the files. # TODO(crbug/966883): Do this in parallel. for file_path in args.file_paths: if not args.no_filter and os.path.abspath( file_path) not in compdb_files: continue annotation_definitions.extend(extract_annotations(file_path)) # Print output. for annotation in annotation_definitions: print(annotation.clang_tool_output_string()) return 0