Skip to content

Commit c3271dd

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 f0c71e4 commit c3271dd

8 files changed

Lines changed: 262 additions & 7 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ __pycache__
2727
scratch/
2828
# clangd
2929
.cache
30+
31+
# JSON schema
32+
node_modules/
33+
tool_schema.json

flake.nix

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,21 @@
7474

7575
commonPackages = with pkgs; [
7676
cmake
77+
d2
78+
dtc
79+
ftditool-cli
7780
gnumake
78-
screen
79-
picocom
8081
gtkwave
8182
openfpgaloader
82-
ftditool-cli
8383
openocd
84-
uv
84+
picocom
8585
pythonEnv
86+
screen
87+
srecord
88+
uv
8689
verilator
8790
verible
88-
srecord
89-
d2
90-
dtc
91+
wget
9192
];
9293
in {
9394
formatter = pkgs.alejandra;

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"ajv-cli": "^5.0.0"
4+
}
5+
}

pyproject.toml

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

4244
[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.0.40",
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:
24+
print('Error: The tool data file was not found.')
25+
raise SystemExit(1) from FileNotFoundError
26+
except json.JSONDecodeError:
27+
print('Error: Failed to decode JSON from the file.')
28+
raise SystemExit(2) from json.JSONDecodeError
29+
except urllib.error.URLError:
30+
print('Failed to fetch tool schema.')
31+
raise SystemExit(3) from urllib.error.URLError
32+
33+
try:
34+
jsonschema.validate(instance=tool_data, schema=schema)
35+
except jsonschema.ValidationError:
36+
print('Tool data is invalid according to the schema.')
37+
raise SystemExit(10) from jsonschema.ValidationError
38+
39+
# If we get here the tool data has successfully been validated.
40+
raise SystemExit(0)

uv.lock

Lines changed: 165 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)