Skip to content

Commit 9e50b14

Browse files
[tools] Define tools and validate schema
This adds a file called tool_data.json which specifies all the tools that we are dependent on. The commit also valides this against a standard schema defined here: https://github.com/marnovandermaas/tool-schema/blob/main/tool_schema.json It also checks the schema using a Python library.
1 parent 166a3f8 commit 9e50b14

7 files changed

Lines changed: 295 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ jobs:
5757
run: |
5858
util/clang_tidy.py
5959
60+
- name: Tool schema validation
61+
run: |
62+
util/tool_schema_validate.py
63+
6064
verilator-test:
6165
runs-on: ["self-hosted", "nixos", "X64"]
6266
needs: lint-check

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ scratch/
3030

3131
# SD card image file
3232
sd.img
33+
34+
# JSON schema
35+
tool_schema.json

flake.nix

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,22 @@
7575
commonPackages = with pkgs; [
7676
bison
7777
cmake
78+
d2
79+
dtc
7880
flex
81+
ftditool-cli
7982
gnumake
80-
screen
81-
picocom
8283
gtkwave
8384
openfpgaloader
84-
ftditool-cli
8585
openocd
86-
uv
86+
picocom
8787
pythonEnv
88-
verible
88+
screen
8989
srecord
90-
d2
91-
dtc
90+
uv
91+
verilator
92+
verible
93+
wget
9294
];
9395
in {
9496
formatter = pkgs.alejandra;

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ dependencies = [
3737
"dvsim>=1.33",
3838
"svgwrite>=1.4.3",
3939
"pyelftools>=0.32",
40+
# Tool schema validation.
41+
"jsonschema>=4.26.0",
42+
"types-jsonschema>=4.26.0",
4043
]
4144

4245
[tool.setuptools]

tool_data.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"name": "FuseSoC",
4+
"vendor": "olofk",
5+
"version": "2.4.3",
6+
"source-url": "https://github.com/olofk/fusesoc",
7+
"doc-url": "https://fusesoc.readthedocs.io/en/stable/index.html",
8+
"comment": "FuseSoC is a build system for digital hardware."
9+
},
10+
{
11+
"name": "Jasper",
12+
"vendor": "Cadence",
13+
"version": "2025.09p002",
14+
"comment": "Formal verification."
15+
},
16+
{
17+
"name": "Verilator",
18+
"vendor": "Veripool",
19+
"version": "v5.040",
20+
"comment": "Open source simulation tool."
21+
},
22+
{
23+
"name": "Vivado",
24+
"vendor": "Xilinx",
25+
"version": "v2021.1",
26+
"comment": "Used to build bitstreams for Genesys 2."
27+
},
28+
{
29+
"name": "Xcelium",
30+
"vendor": "Cadence",
31+
"version": "24.03-s007",
32+
"comment": "Provides xrun for simulations and is used to run our full DV environment."
33+
}
34+
]

util/tool_schema_validate.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
# Copyright lowRISC contributors (COSMIC project).
3+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
import jsonschema
7+
8+
try:
9+
import json
10+
import pathlib
11+
import urllib.error
12+
import urllib.request
13+
14+
url_string = ('https://raw.githubusercontent.com/'
15+
'marnovandermaas/tool-schema/refs/'
16+
'heads/main/tool_schema.json')
17+
18+
with urllib.request.urlopen(url_string) as url:
19+
schema = json.loads(url.read())
20+
21+
with pathlib.Path('tool_data.json').open() as valid_data_file:
22+
tool_data = json.load(valid_data_file)
23+
except FileNotFoundError as err:
24+
print('Error: The tool data file was not found.')
25+
raise SystemExit(1) from err
26+
except json.JSONDecodeError as err:
27+
print('Error: Failed to decode JSON from the file.')
28+
raise SystemExit(2) from err
29+
except urllib.error.URLError as err:
30+
print('Failed to fetch tool schema.')
31+
raise SystemExit(3) from err
32+
33+
try:
34+
jsonschema.validate(instance=tool_data, schema=schema)
35+
except jsonschema.ValidationError as err:
36+
print('Tool data is invalid according to the schema.')
37+
raise SystemExit(10) from err
38+
39+
# If we get here the tool data has successfully been validated.
40+
raise SystemExit(0)

uv.lock

Lines changed: 202 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)