Exemplo n.º 1
0
    def __init__(self, build_path=None):
        """Initializes a TrafficAnnotationTestsChecker object.

    Args:
      build_path: str Absolute or relative path to a fully compiled build
          directory.
    """
        self.tools = NetworkTrafficAnnotationTools(build_path)
Exemplo n.º 2
0
    def __init__(self, build_path=None):
        """Initializes a NetworkTrafficAnnotationChecker object.

    Args:
      build_path: str Absolute or relative path to a fully compiled build
          directory. If not specified, the script tries to find it based on
          relative position of this file (src/tools/traffic_annotation).
    """
        self.tools = NetworkTrafficAnnotationTools(build_path)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
    def __init__(self, build_path=None, annotations_filename=None):
        """Initializes a TrafficAnnotationTestsChecker object.

    Args:
      build_path: str Absolute or relative path to a fully compiled build
          directory.
    """
        self.tools = NetworkTrafficAnnotationTools(build_path)
        self.last_result = None
        self.persist_annotations = bool(annotations_filename)
        if not annotations_filename:
            annotations_file = tempfile.NamedTemporaryFile()
            annotations_filename = annotations_file.name
            annotations_file.close()
        self.annotations_filename = annotations_filename
Exemplo n.º 5
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