Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Sends analyze results to event_mon. | |
| 7 | |
| 8 Needs to be run via tools/scripts/runit.py""" | |
|
chrishall
2016/10/07 06:36:26
is it worth giving an example invocation?
Paweł Hajdan Jr.
2016/10/07 10:50:54
Recipe expectations contain some examples.
| |
| 9 | |
| 10 | |
| 11 import argparse | |
| 12 import json | |
| 13 import sys | |
| 14 | |
| 15 from infra_libs import event_mon | |
| 16 | |
| 17 | |
| 18 def inner_main(args): | |
| 19 event = event_mon.Event(timestamp_kind='POINT') | |
| 20 analyze_event = event.proto.analyze_event | |
| 21 | |
| 22 if args.master_name: | |
| 23 analyze_event.master_name = args.master_name | |
| 24 if args.builder_name: | |
| 25 analyze_event.builder_name = args.builder_name | |
| 26 if args.build_id: | |
| 27 analyze_event.build_id = args.build_id | |
| 28 if args.analyze_input: | |
| 29 analyze_input = json.load(args.analyze_input) | |
| 30 analyze_event.affected_files.extend(analyze_input['files']) | |
| 31 analyze_event.input_test_targets.extend(analyze_input['test_targets']) | |
| 32 analyze_event.input_compile_targets.extend(analyze_input[ | |
| 33 'additional_compile_targets']) | |
| 34 if args.analyze_output: | |
| 35 analyze_output = json.load(args.analyze_output) | |
| 36 | |
| 37 if 'test_targets' in analyze_output: | |
| 38 analyze_event.output_test_targets.extend(analyze_output['test_targets']) | |
| 39 if 'compile_targets' in analyze_output: | |
| 40 analyze_event.output_compile_targets.extend( | |
| 41 analyze_output['compile_targets']) | |
| 42 | |
| 43 if 'error' in analyze_output: | |
| 44 analyze_event.result = analyze_event.AnalyzeResult.Value('ERROR') | |
| 45 elif 'invalid_targets' in analyze_output: | |
| 46 analyze_event.result = analyze_event.AnalyzeResult.Value( | |
| 47 'INVALID_TARGETS') | |
| 48 analyze_event.invalid_targets.extend(analyze_output['invalid_targets']) | |
| 49 elif analyze_output.get('status') == 'Found dependency': | |
| 50 analyze_event.result = analyze_event.AnalyzeResult.Value( | |
| 51 'FOUND_DEPENDENCY') | |
| 52 elif analyze_output.get('status') == 'Found dependency (all)': | |
| 53 analyze_event.result = analyze_event.AnalyzeResult.Value( | |
| 54 'FOUND_DEPENDENCY_ALL') | |
| 55 elif (analyze_output.get('status') == | |
| 56 'No compile necessary (all files ignored)'): | |
| 57 analyze_event.result = analyze_event.AnalyzeResult.Value( | |
| 58 'ALL_FILES_IGNORED') | |
| 59 elif (analyze_output.get('status') == | |
| 60 'Analyze disabled: matched exclusion'): | |
| 61 analyze_event.result = analyze_event.AnalyzeResult.Value( | |
| 62 'MATCHED_EXCLUSION') | |
| 63 elif (analyze_output.get('status') == | |
| 64 'No dependency'): | |
| 65 analyze_event.result = analyze_event.AnalyzeResult.Value( | |
| 66 'NO_COMPILE_NECESSARY') | |
| 67 | |
| 68 print event.proto | |
|
chrishall
2016/10/07 06:36:26
should this print be here?
is this print statemen
Paweł Hajdan Jr.
2016/10/07 10:50:54
I find it useful, at least for now.
| |
| 69 | |
| 70 if event.send(): | |
| 71 return 0 | |
| 72 | |
| 73 return 1 | |
| 74 | |
| 75 | |
| 76 def main(argv): | |
| 77 parser = argparse.ArgumentParser() | |
| 78 parser.add_argument('--master-name', help='Buildbot master name') | |
| 79 parser.add_argument('--builder-name', help='Buildbot builder name') | |
| 80 parser.add_argument('--build-id', help='Build ID (buildnumber)') | |
| 81 parser.add_argument('--analyze-input', help='JSON input passed to analyze', | |
| 82 type=argparse.FileType('r')) | |
| 83 parser.add_argument('--analyze-output', help='JSON output from analyze', | |
| 84 type=argparse.FileType('r')) | |
| 85 event_mon.add_argparse_options(parser) | |
| 86 args = parser.parse_args(argv) | |
| 87 event_mon.process_argparse_options(args) | |
| 88 | |
| 89 try: | |
| 90 return inner_main(args) | |
| 91 finally: | |
| 92 event_mon.close() | |
| 93 | |
| 94 | |
| 95 if __name__ == '__main__': | |
| 96 sys.exit(main(sys.argv[1:])) | |
| OLD | NEW |