diff --git a/metapkg/packages/base.py b/metapkg/packages/base.py index d45948e..af4df0b 100644 --- a/metapkg/packages/base.py +++ b/metapkg/packages/base.py @@ -201,6 +201,9 @@ def get_shlibs(self, build: targets.Build) -> list[str]: def get_include_paths(self, build: targets.Build) -> list[pathlib.Path]: return [] + def get_dep_commands(self) -> list[str]: + return [] + def write_file_list_script( self, build: targets.Build, listname: str, entries: list[str] ) -> str: diff --git a/metapkg/packages/python.py b/metapkg/packages/python.py index 1da97d0..27def39 100644 --- a/metapkg/packages/python.py +++ b/metapkg/packages/python.py @@ -409,6 +409,11 @@ def get_build_script(self, build: targets.Build) -> str: if ldflags: build.sh_append_quoted_ldflags(env, ldflags) + paths = build.sh_get_command_paths(self.get_dep_commands(), self) + + if paths: + build.sh_append_paths(env, paths) + binary = True all_build_deps = build.get_bundled_build_reqs(self, recursive=True) diff --git a/metapkg/targets/base.py b/metapkg/targets/base.py index bbf104a..be942f8 100644 --- a/metapkg/targets/base.py +++ b/metapkg/targets/base.py @@ -1570,6 +1570,23 @@ def sh_get_bundled_shlibs_cflags( return flags + def sh_get_command_paths( + self, + commands: Iterable[str], + pkg: mpkg_base.BasePackage, + ) -> list[str]: + paths = set() + src_root = self.get_source_abspath() + for cmd in commands: + cmd_txt = self.sh_get_command( + cmd, package=pkg, relative_to="sourceroot" + ) + if os.path.sep not in cmd_txt: + # Skip global commands + continue + paths.add(src_root / pathlib.Path(cmd_txt).parent) + return [str(p) for p in paths] + def sh_append_global_flags( self, args: Mapping[str, str | pathlib.Path | None] | None = None, @@ -1651,6 +1668,19 @@ def sh_append_ldflags( ) -> None: self.sh_append_quoted_ldflags(args, self.sh_quote_flags(flags)) + def sh_append_paths( + self, + args: dict[str, str | pathlib.Path | None], + paths: list[str] | tuple[str, ...], + ) -> None: + new_paths = self.sh_quote_flags(paths) + old_path = args.get("PATH") + if not old_path: + old_path = os.getenv("PATH") + if old_path: + new_paths = [str(old_path), *new_paths] + args["PATH"] = os.pathsep.join(new_paths) + def sh_configure( self, path: str | pathlib.Path,