Skip to content

Commit

Permalink
Allow Python to choose generator interpreter using shutil parameter t…
Browse files Browse the repository at this point in the history
…o generators.
  • Loading branch information
cr1901 committed Sep 14, 2023
1 parent 74a4fa1 commit ad9915c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/user/build_system/generators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Key Description
===================== ===========
command The command to run (relative to the core root) to invoke the generator. FuseSoC will pass a yaml configuration file as the first argument when calling the command.
interpreter If the command requires an interpreter (e.g. python or perl), this will be used called, with the string specified in `command` as the first argument, and the yaml file as the second argument.
shutil If `true`, use Python's `shutil.which` to find the path to the interpreter instead of the system `PATH`. Ignored if no `interpreter`.
cache_type If the result of the generator should be considered cacheable. Legal values are `none`, `input` or `generator`.
file_input_parameters All parameters that are file inputs to the generator. This option can be used when `cache_type` is set to `input` if fusesoc should track if these files change.
===================== ===========
Expand Down
6 changes: 5 additions & 1 deletion fusesoc/capi2/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,13 @@
"type": "string"
},
"interpreter": {
"description": "If the command needs a custom interpreter (such as python) this will be inserted as the first argument before command when calling the generator. The interpreter needs to be on the system PATH.",
"description": "If the command needs a custom interpreter (such as python) this will be inserted as the first argument before command when calling the generator. If shutil is not true, the interpreter needs to be on the system PATH.",
"type": "string"
},
"shutil": {
"description": "If an interpreter is set, use the Python interpreter's shutil.which module to find it.",
"type": "boolean"
},
"cache_type": {
"description": "If the result of the generator should be considered cacheable. Legal values are *none*, *input* or *generator*.",
"type": "string",
Expand Down
6 changes: 5 additions & 1 deletion fusesoc/edalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,11 @@ def _run(self, generator_cwd):
]

if "interpreter" in self.generator:
args[0:0] = [self.generator["interpreter"]]
if self.generator.get("shutil", False):
genpath = shutil.which(self.generator["interpreter"])
args[0:0] = [genpath]
else:
args[0:0] = [self.generator["interpreter"]]

Launcher(args[0], args[1:], cwd=generator_cwd).run()

Expand Down

0 comments on commit ad9915c

Please sign in to comment.