Replace non portable `bash` shebang by a portable one (that can be run
from `nixos` distro or any other system where `bash` is not under
`/bin/bash`).
When running the `get_bb_env` generated script, make sure that the
`PATH` environment variable includes a select set of minimal
dependencies extracted from the caller's `PATH`. This minimal
set is expected to be just enough for `get_bb_env` to run
(including the sourced `oe-init-build-env` from the `poky` repository).
kas/libkas.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/kas/libkas.py b/kas/libkas.py
index 96ba946..ed15710 100644
--- a/kas/libkas.py
+++ b/kas/libkas.py
@@ -228,8 +228,9 @@ def get_build_environ(build_system):
sys.exit(1)
with tempfile.TemporaryDirectory() as temp_dir:
- script = """#!/bin/bash
+ script = """#!/usr/bin/env bash
set -e
+ export PATH
source %s $1 > /dev/null
env
""" % init_script
@@ -238,8 +239,19 @@ def get_build_environ(build_system):
get_bb_env_file.write_text(script)
get_bb_env_file.chmod(0o775)
+ import shutil
+ dep_cmds = ['bash', 'dirname', 'readlink' ,'python3' ,'sed']
+ path_for_deps = ':'.join(sorted({
+ os.path.dirname(cmd_path) for cmd_path in (
+ shutil.which(cmd) for cmd in dep_cmds
+ )
+ if cmd_path is not None})
+ )
+
env = {}
- env['PATH'] = '/usr/sbin:/usr/bin:/sbin:/bin'
+ from itertools import chain
+ env['PATH'] = ':'.join(
+ chain([path_for_deps], ['/usr/sbin:/usr/bin:/sbin:/bin']))
(_, output) = run_cmd([str(get_bb_env_file), get_context().build_dir],
cwd=init_repo.path, env=env, liveupdate=False)
--
2.36.2