blob: 51ff71db8952e22a01e96546296d33971bc7708b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/env vpython3
# Copyright 2023 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Perform pre-submit checks on testcase.yaml files"""
# [VPYTHON:BEGIN]
# python_version: "3.8"
# wheel: <
# name: "infra/python/wheels/pyyaml-py3"
# version: "version:5.3.1"
# >
# [VPYTHON:END]
import sys
from typing import List, Optional
import preupload.lib
import yaml # pylint: disable=import-error
BLOCKED_FIELDS = {
"CONF_FILE": "extra_conf_files",
"OVERLAY_CONFIG": "extra_overlay_confs",
"DTC_OVERLAY_FILE": "extra_dtc_overlay_files",
}
def main(argv: Optional[List[str]] = None) -> Optional[int]:
"""Look at all testcase.yaml files passed in on commandline for invalid fields."""
return_code = 0
parser = preupload.lib.argument_parser()
args = parser.parse_args(argv)
for filename in args.filename:
if filename.name == "/testcase.yaml":
lines = preupload.lib.cat_file(args, filename)
data = yaml.load(lines, Loader=yaml.SafeLoader)
def scan_section(section, filename):
nonlocal return_code
if "extra_args" in section:
for field, replacement in BLOCKED_FIELDS.items():
if field in section["extra_args"]:
print(
f"error: Don't specify {field} in "
f"`extra_args`. Use `{replacement}`: "
f"{filename}",
file=sys.stderr,
)
return_code = 1
if "common" in data:
scan_section(data["common"], filename)
if "tests" in data:
for section in data["tests"]:
scan_section(data["tests"][section], filename)
continue
return return_code
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
|