Jeremy Leconte | 0c4059c | 2022-04-04 07:58:40 +0200 | [diff] [blame^] | 1 | #!/usr/bin/env vpython3 |
| 2 | # Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. |
| 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license |
| 5 | # that can be found in the LICENSE file in the root of the source |
| 6 | # tree. An additional intellectual property rights grant can be found |
| 7 | # in the file PATENTS. All contributing project authors may |
| 8 | # be found in the AUTHORS file in the root of the source tree. |
| 9 | """Script to generate the test spec JSON files and the mixins.pyl file from the |
| 10 | ADDITIONAL_MIXINS dictonary. Calls Chromium's generate_buildbot_json. |
| 11 | """ |
| 12 | |
| 13 | import json |
| 14 | import os |
| 15 | import sys |
| 16 | |
| 17 | _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 18 | _SRC_DIR = os.path.dirname(os.path.dirname(_SCRIPT_DIR)) |
| 19 | sys.path.insert(0, _SRC_DIR) |
| 20 | sys.path.insert(0, os.path.join(_SRC_DIR, 'testing', 'buildbot')) |
| 21 | |
| 22 | from testing.buildbot import generate_buildbot_json |
| 23 | |
| 24 | # Add custom mixins here. |
| 25 | ADDITIONAL_MIXINS = { |
| 26 | 'result_adapter': { |
| 27 | 'resultdb': { |
| 28 | 'result_format': 'json' |
| 29 | }, |
| 30 | }, |
| 31 | } |
| 32 | MIXIN_FILE_NAME = os.path.join(_SCRIPT_DIR, 'mixins.pyl') |
| 33 | MIXINS_PYL_TEMPLATE = """\ |
| 34 | # GENERATED FILE - DO NOT EDIT. |
| 35 | # Generated by {script_name} using data from |
| 36 | # {data_source} |
| 37 | # |
| 38 | # Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. |
| 39 | # |
| 40 | # Use of this source code is governed by a BSD-style license |
| 41 | # that can be found in the LICENSE file in the root of the source |
| 42 | # tree. An additional intellectual property rights grant can be found |
| 43 | # in the file PATENTS. All contributing project authors may |
| 44 | # be found in the AUTHORS file in the root of the source tree. |
| 45 | |
| 46 | {mixin_data} |
| 47 | """ |
| 48 | |
| 49 | |
| 50 | def main(): |
| 51 | chromium_args = generate_buildbot_json.BBJSONGenerator.parse_args(argv=None) |
| 52 | chromium_generator = generate_buildbot_json.BBJSONGenerator(chromium_args) |
| 53 | chromium_generator.load_configuration_files() |
| 54 | |
| 55 | override_args = ['--pyl-files-dir', _SCRIPT_DIR] |
| 56 | webrtc_args = generate_buildbot_json.BBJSONGenerator.parse_args(override_args) |
| 57 | webrtc_generator = generate_buildbot_json.BBJSONGenerator(webrtc_args) |
| 58 | webrtc_generator.load_configuration_files() |
| 59 | webrtc_generator.resolve_configuration_files() |
| 60 | |
| 61 | seen_mixins = set() |
| 62 | for waterfall in webrtc_generator.waterfalls: |
| 63 | seen_mixins = seen_mixins.union(waterfall.get('mixins', set())) |
| 64 | for bot_name, tester in waterfall['machines'].items(): |
| 65 | del bot_name |
| 66 | seen_mixins = seen_mixins.union(tester.get('mixins', set())) |
| 67 | for suite in webrtc_generator.test_suites.values(): |
| 68 | for test in suite.values(): |
| 69 | seen_mixins = seen_mixins.union(test.get('mixins', set())) |
| 70 | |
| 71 | found_mixins = ADDITIONAL_MIXINS.copy() |
| 72 | for mixin in seen_mixins: |
| 73 | if mixin not in found_mixins: |
| 74 | found_mixins[mixin] = chromium_generator.mixins[mixin] |
| 75 | |
| 76 | format_data = { |
| 77 | 'script_name': os.path.basename(__file__), |
| 78 | 'data_source': 'waterfall.pyl and Chromium\'s mixins.pyl', |
| 79 | 'mixin_data': json.dumps(dict(sorted(found_mixins.items())), indent=2), |
| 80 | } |
| 81 | with open(MIXIN_FILE_NAME, 'w') as f: |
| 82 | f.write(MIXINS_PYL_TEMPLATE.format(**format_data)) |
| 83 | f.close() |
| 84 | |
| 85 | return webrtc_generator.main() |
| 86 | |
| 87 | |
| 88 | if __name__ == '__main__': # pragma: no cover |
| 89 | sys.exit(main()) |