Skip to content

Commit 32ed536

Browse files
committed
Added to apio.ini escaping of # and ; in values so they don't interpreted as comments.
1 parent 6828b73 commit 32ed536

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

apio/managers/project.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ def _determine_default_env_name(
342342
# -- All done.
343343
return env_name
344344

345+
@staticmethod
346+
def _unescape_value(s: str) -> str:
347+
"""Unescape # and ; in values. This allows to add these two
348+
chars in values."""
349+
s = s.replace("\\#", "#")
350+
s = s.replace("\\;", ";")
351+
return s
352+
345353
@staticmethod
346354
def _parse_env_options(
347355
env_name: str,
@@ -364,11 +372,11 @@ def _parse_env_options(
364372
# -- Add common options that are not in env section
365373
for name, val in common_section.items():
366374
if name not in env_section:
367-
result[name] = val
375+
result[name] = Project._unescape_value(val)
368376

369377
# -- Add all the options from the env section.
370378
for name, val in env_section.items():
371-
result[name] = val
379+
result[name] = Project._unescape_value(val)
372380

373381
# -- check that all the required options exist.
374382
for option_spec in ENV_OPTIONS_SPEC.values():

docs/project-file.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ section and the require configuration options.
77

88
```
99
[env:default]
10-
board = alhambra-ii ; Board id
11-
top-module = Main ; Top Verilog module name
10+
board = alhambra-ii
11+
top-module = Main
1212
```
1313

1414
Below is a more complex `apio.ini` file that contains two `[env:name]` sections named `env1` and `env2`, a `[common]` section with settings that are shared by all envs, and an `[apio]` section the selects the `env2` as the default env.
@@ -254,3 +254,16 @@ yosys-extra-options =
254254
-dsp
255255
-verbose
256256
```
257+
258+
In the example below, the command `write_verilog` is added to the Yosys
259+
build command to generate all file `_build/default/hardware-synth.v` with
260+
a flattened representation of the synthesized design. This is helpful when
261+
diagnosing Yosys related synthesis issues.
262+
263+
```
264+
[env:my-env]
265+
board = alhambra-ii
266+
top-module = leds
267+
yosys-extra-options =
268+
\; write_verilog _build/my-env/hardware-synth.v
269+
``

tests/unit_tests/managers/test_project.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_required_options_only_env(
128128

129129

130130
def test_list_options(apio_runner: ApioRunner, capsys: LogCaptureFixture):
131-
"""Tests list optionss."""
131+
"""Tests list options."""
132132

133133
project, _ = load_apio_ini(
134134
apio_ini={
@@ -155,6 +155,32 @@ def test_list_options(apio_runner: ApioRunner, capsys: LogCaptureFixture):
155155
]
156156

157157

158+
def test_escaping(apio_runner: ApioRunner, capsys: LogCaptureFixture):
159+
"""Tests escaping of comment markers in values.."""
160+
161+
project, _ = load_apio_ini(
162+
apio_ini={
163+
"[env:default]": {
164+
"board": "alhambra-ii",
165+
"top-module": "my_top_module",
166+
"constraint-file": " \\; value ",
167+
"yosys-extra-options": " k1=\\;v1 k2=v2; \n ; "
168+
"Comment \n k3=v3\\# \n\n",
169+
}
170+
},
171+
env_arg=None,
172+
apio_runner=apio_runner,
173+
capsys=capsys,
174+
)
175+
176+
assert project.get_str_option("constraint-file") == "; value"
177+
178+
assert project.get_list_option("yosys-extra-options") == [
179+
"k1=;v1 k2=v2;",
180+
"k3=v3#",
181+
]
182+
183+
158184
def test_legacy_board_id(apio_runner: ApioRunner, capsys: LogCaptureFixture):
159185
"""Tests with 'board' option having a legacy board id. It should
160186
be converted to the canonical board id"""

0 commit comments

Comments
 (0)