gitlab-ci: make explicit tracie is gitlab specific
[mesa.git] / .gitlab-ci / tracie / query_traces_yaml.py
1 #!/usr/bin/python3
2
3 # Copyright (c) 2019 Collabora Ltd
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 # OTHER DEALINGS IN THE SOFTWARE.
22 #
23 # SPDX-License-Identifier: MIT
24
25 import argparse
26 import yaml
27 from traceutil import all_trace_type_names, trace_type_from_name
28 from traceutil import trace_type_from_filename
29
30 def trace_devices(trace):
31 return [e['device'] for e in trace['expectations']]
32
33 def cmd_traces_db_repo(args):
34 with open(args.file, 'r') as f:
35 y = yaml.safe_load(f)
36 print(y['traces-db']['repo'])
37
38 def cmd_traces_db_commit(args):
39 with open(args.file, 'r') as f:
40 y = yaml.safe_load(f)
41 print(y['traces-db']['commit'])
42
43 def cmd_traces(args):
44 with open(args.file, 'r') as f:
45 y = yaml.safe_load(f)
46
47 traces = y['traces']
48 traces = filter(lambda t: trace_type_from_filename(t['path']) in args.trace_types,
49 traces)
50 if args.device_name:
51 traces = filter(lambda t: args.device_name in trace_devices(t), traces)
52
53 traces = list(traces)
54
55 if len(traces) == 0:
56 return
57
58 print('\n'.join((t['path'] for t in traces)))
59
60 def cmd_checksum(args):
61 with open(args.file, 'r') as f:
62 y = yaml.safe_load(f)
63
64 traces = y['traces']
65 trace = next(t for t in traces if t['path'] == args.trace_path)
66 expectation = next(e for e in trace['expectations'] if e['device'] == args.device_name)
67
68 print(expectation['checksum'])
69
70 def main():
71 parser = argparse.ArgumentParser()
72 parser.add_argument('--file', required=True,
73 help='the name of the yaml file')
74
75 subparsers = parser.add_subparsers(help='sub-command help')
76
77 parser_traces_db_repo = subparsers.add_parser('traces_db_repo')
78 parser_traces_db_repo.set_defaults(func=cmd_traces_db_repo)
79
80 parser_traces_db_commit = subparsers.add_parser('traces_db_commit')
81 parser_traces_db_commit.set_defaults(func=cmd_traces_db_commit)
82
83 parser_traces = subparsers.add_parser('traces')
84 parser_traces.add_argument('--device-name', required=False,
85 help="the name of the graphics device used to "
86 "produce images")
87 parser_traces.add_argument('--trace-types', required=False,
88 default=",".join(all_trace_type_names()),
89 help="the types of traces to look for in recursive "
90 "dir walks " "(by default all types)")
91 parser_traces.set_defaults(func=cmd_traces)
92
93 parser_checksum = subparsers.add_parser('checksum')
94 parser_checksum.add_argument('--device-name', required=True,
95 help="the name of the graphics device used to "
96 "produce images")
97 parser_checksum.add_argument('trace_path')
98 parser_checksum.set_defaults(func=cmd_checksum)
99
100 args = parser.parse_args()
101 if hasattr(args, 'trace_types'):
102 args.trace_types = [trace_type_from_name(t) for t in args.trace_types.split(",")]
103
104 args.func(args)
105
106 if __name__ == "__main__":
107 main()