From ad9915c1ee22b8fae6a1e989af074ed79ee9ccf7 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Wed, 13 Sep 2023 22:54:29 -0400 Subject: [PATCH] Allow Python to choose generator interpreter using shutil parameter to generators. --- doc/source/user/build_system/generators.rst | 1 + fusesoc/capi2/json_schema.py | 6 +++++- fusesoc/edalizer.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/source/user/build_system/generators.rst b/doc/source/user/build_system/generators.rst index 4d4b0fc5..f6e07190 100644 --- a/doc/source/user/build_system/generators.rst +++ b/doc/source/user/build_system/generators.rst @@ -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. ===================== =========== diff --git a/fusesoc/capi2/json_schema.py b/fusesoc/capi2/json_schema.py index 4b341444..28c639a9 100644 --- a/fusesoc/capi2/json_schema.py +++ b/fusesoc/capi2/json_schema.py @@ -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", diff --git a/fusesoc/edalizer.py b/fusesoc/edalizer.py index d51d6e6b..bb6445b4 100644 --- a/fusesoc/edalizer.py +++ b/fusesoc/edalizer.py @@ -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()