blob: f8bb1698f8c526fcb9785e3122d1ff57402b63f6 [file] [log] [blame]
Scott Johnsond16af112019-10-17 15:03:58 -07001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4"""
Philipp Wagner14a3fee2019-11-21 10:07:02 +00005Dashboard project JSON file validation
Scott Johnsond16af112019-10-17 15:03:58 -07006"""
7
8import logging as log
9import sys
10
11
12def check_keys(obj, required_keys, optional_keys, err_prefix):
13 error = 0
14 for x in required_keys:
15 if not x in obj:
16 error += 1
17 log.error(err_prefix + " missing required key " + x)
18 for x in obj:
19 type = ''
20 if x in required_keys:
21 type = required_keys[x][0]
22 elif x in optional_keys:
23 type = optional_keys[x][0]
24 else:
25 log.warning(err_prefix + " contains extra key " + x)
26
27 return error
28
29
30field_required = {
31 'name': ['s', "module name"],
32 'version': ['s', "module version"],
33 'life_stage': ['s', "life stage of module"]
34}
35field_optional = {
Srikrishna Iyerd1f896e2020-03-05 13:52:40 -080036 'design_spec':
37 ['s', "path to the design specification, relative to repo root"],
38 'dv_plan': ['s', "path to the DV plan, relative to repo root"],
Srikrishna Iyer84dac532020-04-02 21:45:21 -070039 'hw_checklist': ['s', "path to the hw_checklist, relative to repo root"],
Sam Elliott108420c2020-04-20 19:56:54 +010040 'sw_checklist': ['s', "path to the sw_checklist, relative to repo root"],
Scott Johnsond16af112019-10-17 15:03:58 -070041 'design_stage': ['s', "design stage of module"],
Sam Elliott108420c2020-04-20 19:56:54 +010042 'dif_stage': ['s', 'DIF stage of module'],
Scott Johnsond16af112019-10-17 15:03:58 -070043 'verification_stage': ['s', "verification stage of module"],
44 'notes': ['s', "random notes"],
45}
46
Eunchan Kimf3039d72019-11-18 08:50:26 -080047entry_required = {
48 'version': ['s', "module version"],
49 'life_stage': ['s', "life stage of module"]
50}
51entry_optional = {
52 'design_stage': ['s', "design stage of module"],
53 'verification_stage': ['s', "verification stage of module"],
Sam Elliott108420c2020-04-20 19:56:54 +010054 'dif_stage': ['s', 'DIF stage of module'],
Eunchan Kimf3039d72019-11-18 08:50:26 -080055 'commit_id': ['s', "Staged commit ID"],
56 'notes': ['s', "notes"],
57}
58
Scott Johnsond16af112019-10-17 15:03:58 -070059
60def validate(regs):
61 if not 'name' in regs:
62 log.error("Component has no name. Aborting.")
63 return 1
64 component = regs['name']
65
Eunchan Kimf3039d72019-11-18 08:50:26 -080066 # If `revisions` is not in the object keys, the tool runs previous
67 # version checker, which has only one version entry.
68 if not "revisions" in regs:
69 error = check_keys(regs, field_required, field_optional, component)
70 if (error > 0):
71 log.error("Component has top level errors. Aborting.")
72 return error
73
74 # Assumes `revisions` field exists in the Hjson object.
75 # It iterates the entries in the `revisions` group.
76 error = 0
77 if not isinstance(regs['revisions'], list):
78 error += 1
79 log.error("`revisions` field should be a list of version entries")
80 return error
81
82 for rev in regs['revisions']:
83 error += check_keys(rev, entry_required, entry_optional, component)
84
Scott Johnsond16af112019-10-17 15:03:58 -070085 if (error > 0):
Eunchan Kimf3039d72019-11-18 08:50:26 -080086 log.error("Component has errors in revision field. Aborting.")
Scott Johnsond16af112019-10-17 15:03:58 -070087
88 return error