OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright 2017 The Chromium Authors. All rights reserved. | 3 # Copyright 2017 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import argparse | 7 import argparse |
8 import json | |
8 import logging | 9 import logging |
9 import os | 10 import os |
11 import shutil | |
10 import sys | 12 import sys |
11 import tempfile | 13 import tempfile |
12 | 14 |
13 from webkitpy.common.system.log_utils import configure_logging | 15 from webkitpy.common.system.log_utils import configure_logging |
14 from webkitpy.layout_tests import merge_results | 16 from webkitpy.layout_tests import merge_results |
15 | 17 |
16 # ------------------------------------------------------------------------ | 18 # ------------------------------------------------------------------------ |
17 | 19 |
18 | 20 |
19 def main(argv): | 21 def main(argv): |
(...skipping 22 matching lines...) Expand all Loading... | |
42 parser.add_argument( | 44 parser.add_argument( |
43 '--results-json-allow-unknown-if-matching', | 45 '--results-json-allow-unknown-if-matching', |
44 action='store_true', default=False, | 46 action='store_true', default=False, |
45 help='Allow unknown values in the result.json file as long as the ' | 47 help='Allow unknown values in the result.json file as long as the ' |
46 'value match on all shards.') | 48 'value match on all shards.') |
47 | 49 |
48 parser.add_argument( | 50 parser.add_argument( |
49 '--output-directory', | 51 '--output-directory', |
50 help='Directory to create the merged results in.') | 52 help='Directory to create the merged results in.') |
51 parser.add_argument( | 53 parser.add_argument( |
54 '--allow-existing-output-directory', | |
55 action='store_true', default=False, | |
56 help='Allow merging results into a directory which already exists.') | |
57 parser.add_argument( | |
52 '--input-directories', nargs='+', | 58 '--input-directories', nargs='+', |
53 help='Directories to merge the results from.') | 59 help='Directories to merge the results from.') |
54 | 60 |
55 # Swarming Isolated Merge Script API | 61 # Swarming Isolated Merge Script API |
56 # script.py --build-properties /s/build.json --output-json /tmp/output.json shard0/output.json shard1/output.json | 62 # script.py --build-properties /s/build.json --output-json /tmp/output.json shard0/output.json shard1/output.json |
57 parser.add_argument( | 63 parser.add_argument( |
58 '-o', '--output-json', | 64 '-o', '--output-json', |
59 help='(Swarming Isolated Merge Script API) Output JSON file to create.') | 65 help='(Swarming Isolated Merge Script API) Output JSON file to create.') |
60 parser.add_argument( | 66 parser.add_argument( |
61 '--build-properties', | 67 '--build-properties', |
62 help='(Swarming Isolated Merge Script API) Build property JSON file prov ided by recipes.') | 68 help='(Swarming Isolated Merge Script API) Build property JSON file prov ided by recipes.') |
69 parser.add_argument( | |
70 '--results-json-override-with-build-property', | |
71 nargs=2, metavar=('RESULT_JSON_KEY', 'BUILD_PROPERTY_KEY'), default=[], | |
72 action='append', | |
73 help='Override the value of a value in the result style JSON file ' | |
74 '(--result-jsons-override-value layout_test_dirs /tmp/output).') | |
63 | 75 |
64 # Script to run after merging the directories together. Normally used with a rchive_layout_test_results.py | 76 # Script to run after merging the directories together. Normally used with a rchive_layout_test_results.py |
65 # scripts/slave/chromium/archive_layout_test_results.py \ | 77 # scripts/slave/chromium/archive_layout_test_results.py \ |
66 # --results-dir /b/rr/tmpIcChUS/w/layout-test-results \ | 78 # --results-dir /b/rr/tmpIcChUS/w/layout-test-results \ |
67 # --build-dir /b/rr/tmpIcChUS/w/src/out \ | 79 # --build-dir /b/rr/tmpIcChUS/w/src/out \ |
68 # --build-number 3665 \ | 80 # --build-number 3665 \ |
69 # --builder-name 'WebKit Linux - RandomOrder' \ | 81 # --builder-name 'WebKit Linux - RandomOrder' \ |
70 # --gs-bucket gs://chromium-layout-test-archives \ | 82 # --gs-bucket gs://chromium-layout-test-archives \ |
71 # --staging-dir /b/c/chrome_staging \ | 83 # --staging-dir /b/c/chrome_staging \ |
72 # --slave-utils-gsutil-py-path /b/rr/tmpIcChUS/rw/scripts/slave/.recipe_ deps/depot_tools/gsutil.py | 84 # --slave-utils-gsutil-py-path /b/rr/tmpIcChUS/rw/scripts/slave/.recipe_ deps/depot_tools/gsutil.py |
73 # in dir /b/rr/tmpIcChUS/w | 85 # in dir /b/rr/tmpIcChUS/w |
74 parser.add_argument( | 86 parser.add_argument( |
75 '--post-merge-script', | 87 '--post-merge-script', |
76 nargs='*', | 88 nargs='*', |
77 help='Script to call after the results have been merged.') | 89 help='Script to call after the results have been merged.') |
78 | 90 |
79 # The position arguments depend on if we are using the isolated merge | 91 # The position arguments depend on if we are using the isolated merge |
80 # script API mode or not. | 92 # script API mode or not. |
81 parser.add_argument( | 93 parser.add_argument( |
82 'positional', nargs='*', | 94 'positional', nargs='*', |
83 help='output.json from shards.') | 95 help='output.json from shards.') |
84 | 96 |
85 args = parser.parse_args(argv) | 97 args = parser.parse_args(argv) |
86 if args.verbose: | 98 if args.verbose: |
87 logging_level = logging.DEBUG | 99 logging_level = logging.DEBUG |
88 else: | 100 else: |
89 logging_level = logging.INFO | 101 logging_level = logging.INFO |
90 configure_logging(logging_level=logging_level) | 102 configure_logging(logging_level=logging_level) |
91 | 103 |
104 logging.info(argv) | |
dsansome
2017/03/21 09:18:34
Remove this line before submitting
mithro
2017/03/21 09:43:01
Done.
| |
105 | |
106 results_json_value_overrides = {} | |
107 | |
92 # Map the isolate arguments back to our output / input arguments. | 108 # Map the isolate arguments back to our output / input arguments. |
93 if args.output_json: | 109 if args.output_json: |
110 logging.info('Running with isolated arguments') | |
94 assert args.positional | 111 assert args.positional |
95 | 112 |
113 if args.results_json_override_with_build_property: | |
114 if not args.build_properties: | |
115 raise SystemError( | |
dsansome
2017/03/21 09:18:35
I would use parser.error(...) instead so it prints
mithro
2017/03/21 09:43:01
Done.
| |
116 '--results-json-override-with-build-property given' | |
117 ' but --build-properties was not.') | |
118 build_properties = json.loads(args.build_properties) | |
119 for result_key, build_prop_key in args.results_json_override_build_p roperty: | |
120 results_json_value_overrides[result_key] = build_properties[buil d_prop_key] | |
121 | |
96 assert not args.output_directory | 122 assert not args.output_directory |
97 args.output_directory = os.path.dirname(args.output_json) | 123 args.output_directory = os.getcwd() |
124 args.allow_existing_output_directory = True | |
98 | 125 |
99 assert not args.input_directories | 126 assert not args.input_directories |
100 args.input_directories = [os.path.dirname(f) for f in args.positional] | 127 args.input_directories = [os.path.dirname(f) for f in args.positional] |
101 args.positional = [] | 128 args.positional = [] |
102 | 129 |
103 # Allow skipping the --input-directories bit, for example, | 130 # Allow skipping the --input-directories bit, for example, |
104 # merge-layout-test-results -o outputdir shard0 shard1 shard2 | 131 # merge-layout-test-results -o outputdir shard0 shard1 shard2 |
105 if args.positional and not args.input_directories: | 132 if args.positional and not args.input_directories: |
106 args.input_directories = args.positional | 133 args.input_directories = args.positional |
107 | 134 |
108 if not args.output_directory: | 135 if not args.output_directory: |
109 args.output_directory = tempfile.mkdtemp(suffix='webkit_layout_test_resu lts.') | 136 args.output_directory = tempfile.mkdtemp(suffix='webkit_layout_test_resu lts.') |
110 | 137 |
111 assert args.output_directory | 138 assert args.output_directory |
112 assert args.input_directories | 139 assert args.input_directories |
113 | 140 |
114 results_json_value_overrides = {} | |
115 for k, v in args.results_json_override_value: | 141 for k, v in args.results_json_override_value: |
116 assert k not in results_json_value_overrides | 142 assert k not in results_json_value_overrides |
117 try: | 143 try: |
118 results_json_value_overrides[k] = eval(v) | 144 results_json_value_overrides[k] = eval(v) |
119 except NameError: | 145 except NameError: |
120 results_json_value_overrides[k] = v | 146 results_json_value_overrides[k] = v |
147 logging.debug('results_json_value_overrides: %r', results_json_value_overrid es) | |
121 | 148 |
122 merger = merge_results.LayoutTestDirMerger( | 149 merger = merge_results.LayoutTestDirMerger( |
123 results_json_value_overrides=results_json_value_overrides, | 150 results_json_value_overrides=results_json_value_overrides, |
124 results_json_allow_unknown_if_matching=args.results_json_allow_unknown_i f_matching) | 151 results_json_allow_unknown_if_matching=args.results_json_allow_unknown_i f_matching) |
152 if os.path.exists(args.output_directory): | |
153 logging.warning('Output directory exists %r', args.output_directory) | |
154 if not args.allow_existing_output_directory: | |
155 raise IOError( | |
156 ('Output directory %s exists!\n' | |
157 'Use --allow-existing-output-directory to continue') % args.out put_directory) | |
125 merger.merge(args.output_directory, args.input_directories) | 158 merger.merge(args.output_directory, args.input_directories) |
126 | 159 |
160 merged_output_json = os.path.join(args.output_directory, 'output.json') | |
161 if os.path.exists(merged_output_json) and args.output_json: | |
162 logging.debug( | |
163 'Copying output.json from %s to %s', merged_output_json, args.output _json) | |
164 shutil.copyfile(merged_output_json, args.output_json) | |
165 | |
127 if args.post_merge_script: | 166 if args.post_merge_script: |
167 logging.debug('Changing directory to %s', args.output_directory) | |
128 os.chdir(args.output_directory) | 168 os.chdir(args.output_directory) |
129 | 169 |
130 post_script = list(args.post_merge_script) | 170 post_script = list(args.post_merge_script) |
131 post_script.append('--result-dir', args.output_directory) | 171 post_script.append('--result-dir', args.output_directory) |
132 | 172 |
173 logging.info('Running post merge script %r', post_script) | |
133 os.execlp(post_script) | 174 os.execlp(post_script) |
134 | 175 |
135 main(sys.argv[1:]) | 176 main(sys.argv[1:]) |
OLD | NEW |