Skip to content

Commit

Permalink
Added apio.ini as an implicit dependency of all verilog and testbench…
Browse files Browse the repository at this point in the history
… files to force a rebuild when apio.ini changes.
  • Loading branch information
zapta committed Dec 18, 2024
1 parent 713a7dc commit a4eee7f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
22 changes: 18 additions & 4 deletions apio/scons/scons_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,35 @@ def verilog_src_scanner_func(
Returns a list of files.
"""
# Sanity check. Should be called only to scan verilog files.
assert file_node.name.lower().endswith(
".v"
), f"Not a .v file: {file_node.name}"
# Sanity check. Should be called only to scan verilog files. If this
# fails, this is a programming error rather than a user error.
assert is_verilog_src(
env, file_node.name
), f"Not a src file: {file_node.name}"

# Create the initial set. All source file depend on apio.ini and must
# be built when apio.ini changes.
#
# pylint: disable=fixme
# TODO: add also other config files aush as boards.json and
# programmers.json. Since they are optional, need to figure out how to
# handle the case when they are deleted or created.
includes_set = set()
includes_set.add("apio.ini")

# If the file doesn't exist, this returns an empty string.
file_text = file_node.get_text_contents()
# Get IceStudio includes.
includes = icestudio_list_re.findall(file_text)
includes_set.update(includes)

# Get Standard verilog includes.
includes = verilog_include_re.findall(file_text)
includes_set.update(includes)

# Get a deterministic list. (Does it sort by file.name?)
includes_list = sorted(list(includes_set))

# For debugging
# info(env, f"*** {file_node.name} includes {includes_list}")
return env.File(includes_list)
Expand Down
22 changes: 22 additions & 0 deletions test/integration/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from apio.commands.examples import cli as apio_examples


# Too many statements (60/50) (too-many-statements)
# pylint: disable=too-many-statements
# R0801: Similar lines in 2 files
# pylint: disable=R0801
# R0913: Too many arguments (6/5) (too-many-arguments)
Expand Down Expand Up @@ -84,6 +86,26 @@ def _test_project(
assert "SUCCESS" in result.output
assert getsize(sb.proj_dir / "_build" / binary)

# -- 'apio build' (no change)
result = sb.invoke_apio_cmd(apio_build, proj_arg)
sb.assert_ok(result)
assert "SUCCESS" in result.output
assert "yosys" not in result.output

# -- Modify apio.ini
apio_ini_lines = sb.read_file(
sb.proj_dir / "apio.ini", lines_mode=True
)
apio_ini_lines.append(" ")
sb.write_file(sb.proj_dir / "apio.ini", apio_ini_lines, exists_ok=True)

# -- 'apio build'
# -- Apio.ini modification should triggers a new build.
result = sb.invoke_apio_cmd(apio_build, proj_arg)
sb.assert_ok(result)
assert "SUCCESS" in result.output
assert "yosys" in result.output

# -- 'apio lint'
result = sb.invoke_apio_cmd(apio_lint, proj_arg)
sb.assert_ok(result)
Expand Down
2 changes: 1 addition & 1 deletion test/scons/test_scons_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_dependencies(apio_runner: ApioRunner):

# -- Check the list. The scanner returns the files sorted and
# -- with dulicates removed.
assert file_names == ["apio_testing.vh", "v771499.list"]
assert file_names == ["apio.ini", "apio_testing.vh", "v771499.list"]


def test_has_testbench_name():
Expand Down

0 comments on commit a4eee7f

Please sign in to comment.