Skip to content

Commit

Permalink
Exit with error if target is missing
Browse files Browse the repository at this point in the history
Up until now it was possible to request a target that didn't exist
in the core description file, and FuseSoC would treat it basically
as an empty target and most likely fail later with a cryptic error
message. This was originally done as a compromise to provide
backwards-compatibility with the CAPI1 format, but since we no longer
support that, let's provide the user with a more sensible error
message instead.
  • Loading branch information
olofk committed Dec 11, 2023
1 parent dbfc8f5 commit 095ea6c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fusesoc/capi2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def get_flags(self, target_name):
# Special case for tool as we get it from default_tool
flags["tool"] = str(target["default_tool"])

else:
raise RuntimeError(f"'{self.name}' has no target '{target_name}'")
return flags

def get_flow(self, flags):
Expand Down
3 changes: 3 additions & 0 deletions fusesoc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ def run(fs, args):
except SyntaxError as e:
logger.error(str(e))
exit(1)
except RuntimeError as e:
logger.error(str(e))
exit(1)

# Unconditionally clean out the work root on fresh builds
# if we use the old tool API
Expand Down
4 changes: 3 additions & 1 deletion tests/test_capi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ def test_capi2_get_flags():

core = Core(Core2Parser(), os.path.join(cores_dir, "flags.core"))

assert {} == core.get_flags("bad_target")
with pytest.raises(RuntimeError) as e:
core.get_flags("bad_target")
assert "::flags:0' has no target 'bad_target'" in str(e.value)
assert {} == core.get_flags("noflags")
assert {} == core.get_flags("emptyflags")
assert {"tool": "mytool"} == core.get_flags("emptyflagstool")
Expand Down

0 comments on commit 095ea6c

Please sign in to comment.