Skip to content

Commit f5695f7

Browse files
oharboeclaude
andcommitted
flow: read variables.yaml through yaml2json
The readers of variables.yaml, defaults.py (variables.mk), non_stage_variables.py (util.tcl) and generate-variables-docs.py, read it as JSON on stdin from OpenROAD's yaml2json: $(YAML2JSON) variables.yaml | $(PYTHON_EXE) defaults.py Each fails on empty input, so a missing or failing yaml2json stops make and the stage instead of running with no defaults. YAML2JSON defaults to yaml2json next to OPENROAD_EXE, where OpenROAD's install puts it. variables.json, yaml_to_json.py and the CI step that kept the two in sync are deleted. The variables.yaml CI job builds yaml2json from tools/OpenROAD to regenerate FlowVariables.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018PFLaG12qpV6aKy7cdfwXT Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 593d109 commit f5695f7

11 files changed

Lines changed: 55 additions & 1659 deletions

‎.gitattributes‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
# Make Github ignore the designs folder when determining repo language
22
flow/designs/src/* linguist-vendored
3-
flow/scripts/variables.json linguist-generated=true

‎.github/workflows/github-actions-yaml-test.yml‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ jobs:
1818
fetch-depth: 1
1919
sparse-checkout: |
2020
flow/scripts/generate-variables-docs.py
21-
flow/scripts/yaml_to_json.py
2221
flow/scripts/variables.yaml
23-
flow/scripts/variables.json
2422
docs/user/FlowVariables.md
23+
tools/OpenROAD
2524
yamlfix.toml
2625
.github/requirements/requirements_lock.txt
2726
- uses: actions/setup-python@v7
@@ -31,16 +30,19 @@ jobs:
3130
run: |
3231
python3 -m venv venv
3332
venv/bin/pip install --quiet -r .github/requirements/requirements_lock.txt
33+
- name: Build yaml2json
34+
run: |
35+
git submodule update --init --depth 1 tools/OpenROAD
36+
git -C tools/OpenROAD submodule update --init --depth 1 third-party/sv-elab
37+
cd tools/OpenROAD
38+
bazelisk build //src/yaml2json
39+
echo "YAML2JSON=$(bazelisk cquery --output=files //src/yaml2json 2>/dev/null | sed "s|^|$PWD/|")" >> "$GITHUB_ENV"
3440
- name: Run generate-variables-docs.py
3541
run: |
36-
venv/bin/python3 flow/scripts/generate-variables-docs.py
42+
"$YAML2JSON" flow/scripts/variables.yaml | venv/bin/python3 flow/scripts/generate-variables-docs.py
3743
- name: Check if FlowVariables.md is up to date
3844
run: |
3945
git diff --exit-code docs/user/FlowVariables.md
40-
- name: Check variables.json is up to date
41-
run: |
42-
venv/bin/python3 flow/scripts/yaml_to_json.py
43-
git diff --exit-code flow/scripts/variables.json
4446
- name: Run yamlfix check
4547
run: |
4648
source venv/bin/activate

‎docs/user/FlowVariables.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ configuration file.
342342
| <a name="VIA_IN_PIN_MIN_LAYER"></a>VIA_IN_PIN_MIN_LAYER| Passed as -via_in_pin_bottom_layer to pin_access and detailed_route.| |
343343
| <a name="WIRE_LOAD_MODEL"></a>WIRE_LOAD_MODEL| Name of a Liberty wire_load group applied with set_wire_load_model whenever open.tcl reads timing. OpenSTA applies a wire-load model only to nets without parasitics, so it gives wire delay to timing read before placement and leaves placed and routed timing unaffected. An unknown name is an error. Empty, the default, applies none. A platform whose libraries define no wire_load group can supply one in a Liberty file listed in ADDITIONAL_LIBS.| |
344344
| <a name="WRITE_ODB_AND_SDC_EACH_STAGE"></a>WRITE_ODB_AND_SDC_EACH_STAGE| Save out .sdc and .odb file after each stage, useful to disable when using a single OpenROAD instance to run all stages of the flow.| 1|
345+
| <a name="YAML2JSON"></a>YAML2JSON| The yaml2json executable the flow reads variables.yaml with. It is installed next to openroad, and defaults to yaml2json in the directory of OPENROAD_EXE.| |
345346
| <a name="YOSYS_FLAGS"></a>YOSYS_FLAGS| Flags to pass to yosys.| -v 3|
346347
## synth variables
347348

@@ -650,6 +651,7 @@ configuration file.
650651
- [SWAP_ARITH_OPERATORS](#SWAP_ARITH_OPERATORS)
651652
- [SYNTH_WRAPPED_OPERATORS](#SYNTH_WRAPPED_OPERATORS)
652653
- [WRITE_ODB_AND_SDC_EACH_STAGE](#WRITE_ODB_AND_SDC_EACH_STAGE)
654+
- [YAML2JSON](#YAML2JSON)
653655

654656
## generate_abstract variables
655657

‎flow/scripts/defaults.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python3
22

3+
# Reads variables.yaml as JSON on stdin: $(YAML2JSON) variables.yaml | defaults.py
34
import json
4-
import os
5+
import sys
56

6-
dir_path = os.path.dirname(os.path.realpath(__file__))
7-
8-
json_path = os.path.join(dir_path, "variables.json")
9-
with open(json_path, "r") as file:
10-
data = json.load(file)
7+
text = sys.stdin.read()
8+
if not text:
9+
sys.exit("defaults.py: no input; pipe $YAML2JSON variables.yaml into it")
10+
data = json.loads(text)
1111

1212
for key, value in data.items():
1313
if value.get("default", None) is None:

‎flow/scripts/generate-variables-docs.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33
# the ORFS variables.
44
#
55
# This script injects an autogenerated section in FlowVariables.md with
6-
# information about the variables from variables.yaml.
6+
# information about the variables from variables.yaml, read as JSON on stdin:
7+
#
8+
# yaml2json flow/scripts/variables.yaml | flow/scripts/generate-variables-docs.py
9+
import json
710
import os
8-
import yaml
11+
import sys
912

1013
dir_path = os.path.dirname(os.path.realpath(__file__))
1114

12-
yaml_path = os.path.join(dir_path, "variables.yaml")
13-
14-
with open(yaml_path, "r") as file:
15-
data = yaml.safe_load(file)
15+
text = sys.stdin.read()
16+
if not text:
17+
sys.exit(
18+
"generate-variables-docs.py: no input; pipe yaml2json variables.yaml into it"
19+
)
20+
data = json.loads(text)
1621

1722
preferred_order = ["synth", "floorplan", "place", "cts", "grt", "route", "final"]
1823
stages = {stage for value in data.values() for stage in value.get("stages", [])}

‎flow/scripts/non_stage_variables.py‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#!/usr/bin/env python3
22
#
3-
# Reading .yaml from tcl is tedious and we already have
4-
# a yaml library in Python.
5-
#
63
# This script generates a list of variables known
74
# not to be in the current stage.
5+
#
6+
# Reads variables.yaml as JSON on stdin:
7+
#
8+
# $YAML2JSON variables.yaml | non_stage_variables.py <stage>
89
import json
9-
import os
1010
import sys
1111

12-
dir_path = os.path.dirname(os.path.realpath(__file__))
13-
14-
json_path = os.path.join(dir_path, "variables.json")
15-
with open(json_path, "r") as file:
16-
data = json.load(file)
12+
text = sys.stdin.read()
13+
if not text:
14+
sys.exit("non_stage_variables.py: no input; pipe $YAML2JSON variables.yaml into it")
15+
data = json.loads(text)
1716

1817
for key, value in data.items():
1918
if "stages" not in value:

‎flow/scripts/util.tcl‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,9 @@ proc erase_non_stage_variables { stage_name } {
210210
if { $::env(KEEP_VARS) } {
211211
return
212212
}
213-
# "$::env(SCRIPTS_DIR)/stage_variables.py stage_name" returns list of
214-
# variables to erase.
215-
#
216-
# Tcl yaml package can't be imported in the sta/openroad environment:
217-
#
218-
# https://github.com/The-OpenROAD-Project/OpenROAD/issues/5875
219-
set variables [exec -- $::env(PYTHON_EXE) \
220-
$::env(SCRIPTS_DIR)/non_stage_variables.py $stage_name]
213+
# non_stage_variables.py returns the list of variables to erase.
214+
set variables [exec -- $::env(YAML2JSON) $::env(SCRIPTS_DIR)/variables.yaml \
215+
| $::env(PYTHON_EXE) $::env(SCRIPTS_DIR)/non_stage_variables.py $stage_name]
221216
foreach var $variables {
222217
if { [info exists ::env($var)] } {
223218
unset ::env($var)

0 commit comments

Comments
 (0)