blob: df4f9dd1a6cf2ffd89bf84860516822806dbf820 [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:
Rasmus Madsenef68b812020-12-09 17:37:36 +010025 log.warning(err_prefix + " contains extra key rmn " + x)
26# log.warning('{} contains extra key {!r}'.format(err_prefix, x))
Scott Johnsond16af112019-10-17 15:03:58 -070027
28 return error
29
30
31field_required = {
32 'name': ['s', "module name"],
33 'version': ['s', "module version"],
34 'life_stage': ['s', "life stage of module"]
35}
36field_optional = {
Srikrishna Iyerd1f896e2020-03-05 13:52:40 -080037 'design_spec':
38 ['s', "path to the design specification, relative to repo root"],
Srikrishna Iyer01c56b42021-08-02 12:50:11 -070039 'dv_doc': ['s', "path to the DV document, relative to repo root"],
Srikrishna Iyer84dac532020-04-02 21:45:21 -070040 'hw_checklist': ['s', "path to the hw_checklist, relative to repo root"],
Sam Elliott108420c2020-04-20 19:56:54 +010041 'sw_checklist': ['s', "path to the sw_checklist, relative to repo root"],
Scott Johnsond16af112019-10-17 15:03:58 -070042 'design_stage': ['s', "design stage of module"],
Sam Elliott108420c2020-04-20 19:56:54 +010043 'dif_stage': ['s', 'DIF stage of module'],
Scott Johnsond16af112019-10-17 15:03:58 -070044 'verification_stage': ['s', "verification stage of module"],
45 'notes': ['s', "random notes"],
46}
47
Eunchan Kimf3039d72019-11-18 08:50:26 -080048entry_required = {
49 'version': ['s', "module version"],
50 'life_stage': ['s', "life stage of module"]
51}
52entry_optional = {
53 'design_stage': ['s', "design stage of module"],
54 'verification_stage': ['s', "verification stage of module"],
Sam Elliott108420c2020-04-20 19:56:54 +010055 'dif_stage': ['s', 'DIF stage of module'],
Eunchan Kimf3039d72019-11-18 08:50:26 -080056 'commit_id': ['s', "Staged commit ID"],
57 'notes': ['s', "notes"],
58}
59
Scott Johnsond16af112019-10-17 15:03:58 -070060
61def validate(regs):
62 if not 'name' in regs:
63 log.error("Component has no name. Aborting.")
64 return 1
65 component = regs['name']
66
Eunchan Kimf3039d72019-11-18 08:50:26 -080067 # If `revisions` is not in the object keys, the tool runs previous
68 # version checker, which has only one version entry.
69 if not "revisions" in regs:
70 error = check_keys(regs, field_required, field_optional, component)
71 if (error > 0):
72 log.error("Component has top level errors. Aborting.")
73 return error
74
75 # Assumes `revisions` field exists in the Hjson object.
76 # It iterates the entries in the `revisions` group.
77 error = 0
78 if not isinstance(regs['revisions'], list):
79 error += 1
80 log.error("`revisions` field should be a list of version entries")
81 return error
82
83 for rev in regs['revisions']:
84 error += check_keys(rev, entry_required, entry_optional, component)
85
Scott Johnsond16af112019-10-17 15:03:58 -070086 if (error > 0):
Eunchan Kimf3039d72019-11-18 08:50:26 -080087 log.error("Component has errors in revision field. Aborting.")
Scott Johnsond16af112019-10-17 15:03:58 -070088
89 return error