• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env vpython3
2# Copyright 2021 The ANGLE Project 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"""Script to generate the test spec JSON files. Calls Chromium's generate_buildbot_json.
6
7=== NOTE: DO NOT RUN THIS SCRIPT DIRECTLY. ===
8Run scripts/run_code_generation.py instead to update necessary hashes.
9
10"""
11
12import os
13import pprint
14import sys
15import subprocess
16
17d = os.path.dirname
18THIS_DIR = d(os.path.abspath(__file__))
19TESTING_BBOT_DIR = os.path.join(d(d(THIS_DIR)), 'testing', 'buildbot')
20sys.path.insert(0, TESTING_BBOT_DIR)
21
22import generate_buildbot_json
23
24# Add custom mixins here.
25ADDITIONAL_MIXINS = {
26    'angle_skia_gold_test': {
27        '$mixin_append': {
28            'args': [
29                '--git-revision=${got_angle_revision}',
30                # BREAK GLASS IN CASE OF EMERGENCY
31                # Uncommenting this argument will bypass all interactions with Skia
32                # Gold in any tests that use it. This is meant as a temporary
33                # emergency stop in case of a Gold outage that's affecting the bots.
34                # '--bypass-skia-gold-functionality',
35            ],
36            'precommit_args': [
37                '--gerrit-issue=${patch_issue}',
38                '--gerrit-patchset=${patch_set}',
39                '--buildbucket-id=${buildbucket_build_id}',
40            ],
41        }
42    },
43}
44
45MIXIN_FILE_NAME = os.path.join(THIS_DIR, 'mixins.pyl')
46MIXINS_PYL_TEMPLATE = """\
47# GENERATED FILE - DO NOT EDIT.
48# Generated by {script_name} using data from {data_source}
49#
50# Copyright 2021 The ANGLE Project Authors. All rights reserved.
51# Use of this source code is governed by a BSD-style license that can be
52# found in the LICENSE file.
53#
54# This is a .pyl, or "Python Literal", file. You can treat it just like a
55# .json file, with the following exceptions:
56# * all keys must be quoted (use single quotes, please);
57# * comments are allowed, using '#' syntax; and
58# * trailing commas are allowed.
59#
60# For more info see Chromium's mixins.pyl in testing/buildbot.
61
62{mixin_data}
63"""
64
65
66def main():
67    if len(sys.argv) > 1:
68        gen_bb_json = os.path.join(TESTING_BBOT_DIR, 'generate_buildbot_json.py')
69        mixins_pyl = os.path.join(TESTING_BBOT_DIR, 'mixins.pyl')
70        inputs = [
71            'test_suite_exceptions.pyl', 'test_suites.pyl', 'variants.pyl', 'waterfalls.pyl',
72            gen_bb_json, mixins_pyl
73        ]
74        outputs = ['angle.json', 'mixins.pyl']
75        if sys.argv[1] == 'inputs':
76            print(','.join(inputs))
77        elif sys.argv[1] == 'outputs':
78            print(','.join(outputs))
79        else:
80            print('Invalid script parameters')
81            return 1
82        return 0
83
84    chromium_args = generate_buildbot_json.BBJSONGenerator.parse_args(sys.argv[1:])
85    chromium_generator = generate_buildbot_json.BBJSONGenerator(chromium_args)
86    chromium_generator.load_configuration_files()
87
88    override_args = sys.argv[1:] + ['--pyl-files-dir', THIS_DIR]
89    angle_args = generate_buildbot_json.BBJSONGenerator.parse_args(override_args)
90    angle_generator = generate_buildbot_json.BBJSONGenerator(angle_args)
91    angle_generator.load_configuration_files()
92    angle_generator.resolve_configuration_files()
93
94    seen_mixins = set()
95    for waterfall in angle_generator.waterfalls:
96        seen_mixins = seen_mixins.union(waterfall.get('mixins', set()))
97        for bot_name, tester in waterfall['machines'].items():
98            seen_mixins = seen_mixins.union(tester.get('mixins', set()))
99    for suite in angle_generator.test_suites.values():
100        if isinstance(suite, list):
101            # Don't care about this, it's a composition, which shouldn't include a
102            # swarming mixin.
103            continue
104        for test in suite.values():
105            assert isinstance(test, dict)
106            seen_mixins = seen_mixins.union(test.get('mixins', set()))
107
108    found_mixins = ADDITIONAL_MIXINS.copy()
109    for mixin in seen_mixins:
110        if mixin in found_mixins:
111            continue
112        assert (mixin in chromium_generator.mixins), 'Error with %s mixin' % mixin
113        found_mixins[mixin] = chromium_generator.mixins[mixin]
114
115    pp = pprint.PrettyPrinter(indent=2)
116
117    format_data = {
118        'script_name': os.path.basename(__file__),
119        'data_source': 'waterfall.pyl and Chromium\'s mixins.pyl',
120        'mixin_data': pp.pformat(found_mixins),
121    }
122    generated_mixin_pyl = MIXINS_PYL_TEMPLATE.format(**format_data)
123
124    with open(MIXIN_FILE_NAME, 'w') as f:
125        f.write(generated_mixin_pyl)
126        f.close()
127
128    return angle_generator.main()
129
130
131if __name__ == '__main__':  # pragma: no cover
132    sys.exit(main())
133