• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# Copyright 2017 The Chromium Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""//testing/scripts wrapper for the network traffic annotations checks.
6This script is used to run check_annotations.py on the trybots to ensure that
7all network traffic annotations have correct syntax and semantics, and all
8functions requiring annotations have one.
9
10This is a wrapper around tools/traffic_annotation/scripts/auditor.py.
11
12See tools/traffic_annotation/scripts/auditor/README.md for instructions on
13running locally."""
14
15import json
16import os
17import sys
18import tempfile
19
20import common
21
22
23def main_run(args):
24  errors_file, errors_filename = tempfile.mkstemp()
25  os.close(errors_file)
26
27  command_line = [
28      sys.executable,
29      os.path.join(common.SRC_DIR, 'tools', 'traffic_annotation', 'scripts',
30                   'check_annotations.py'),
31      '--build-path',
32      args.build_dir,
33      '--errors-file',
34      errors_filename,
35  ]
36  rc = common.run_command(command_line)
37
38  failures = []
39  if rc:
40    with open(errors_filename, encoding='utf-8') as f:
41      failures = json.load(f) or ['Please refer to stdout for errors.']
42  common.record_local_script_results('check_network_annotations', args.output,
43                                     failures, True)
44
45  return rc
46
47
48def main_compile_targets(args):
49  json.dump(['traffic_annotation_auditor_dependencies'], args.output)
50
51
52if __name__ == '__main__':
53  funcs = {
54      'run': main_run,
55      'compile_targets': main_compile_targets,
56  }
57  sys.exit(common.run_script(sys.argv[1:], funcs))
58