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 6"""//testing/scripts wrapper for the network traffic annotations checks. 7This script is used to run check_annotations.py on the trybots to ensure that 8all network traffic annotations have correct syntax and semantics, and all 9functions requiring annotations have one. 10 11This is a wrapper around tools/traffic_annotation/scripts/auditor.py. 12 13See tools/traffic_annotation/scripts/auditor/README.md for instructions on 14running locally.""" 15 16import json 17import os 18import sys 19import tempfile 20 21# Add src/testing/ into sys.path for importing common without pylint errors. 22sys.path.append( 23 os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) 24from scripts import common 25 26 27def main_run(args): 28 errors_file = tempfile.NamedTemporaryFile() 29 errors_filename = errors_file.name 30 errors_file.close() 31 32 command_line = [ 33 sys.executable, 34 os.path.join(common.SRC_DIR, 'tools', 'traffic_annotation', 'scripts', 35 'check_annotations.py'), 36 '--build-path', 37 os.path.join(args.paths['checkout'], 'out', args.build_config_fs), 38 '--errors-file', 39 errors_filename, 40 ] 41 rc = common.run_command(command_line) 42 43 failures = [] 44 if rc: 45 with open(errors_filename, encoding='utf-8') as f: 46 failures = json.load(f) or ['Please refer to stdout for errors.'] 47 common.record_local_script_results( 48 'check_network_annotations', args.output, failures, True) 49 50 return rc 51 52 53def main_compile_targets(args): 54 json.dump(['traffic_annotation_auditor_dependencies'], args.output) 55 56 57if __name__ == '__main__': 58 funcs = { 59 'run': main_run, 60 'compile_targets': main_compile_targets, 61 } 62 sys.exit(common.run_script(sys.argv[1:], funcs)) 63