Skip to content

Commit f797efd

Browse files
committed
[FIX] shell: Dash support for init_script
Dash does not support passing arguments to the "." command. The default poky ./oe-init-build-env has this comment: # Normally this is called as '. ./oe-init-build-env <builddir>' # # This works in most shells (not dash), but not all of them pass the arguments # when being sourced. To workaround the shell limitation use "set <builddir>" # prior to sourcing this script. Implement the "set" workaround for dash support. Also, change current working directory to match oe-init-build-env expectation of being sourced from its base directory in dash. Signed-off-by: Yoann Congal <[email protected]>
1 parent 98a8bc1 commit f797efd

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

cooker/cooker.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ def shell(self, build_names: List[str], cmd: List[str]):
10461046
init_script = self.config.layer_dir(
10471047
self.distro.BASE_DIRECTORY + "/" + self.distro.BUILD_SCRIPT
10481048
)
1049+
base_dir = self.config.layer_dir(self.distro.BASE_DIRECTORY)
10491050
shell = os.environ.get("SHELL", "/bin/bash")
10501051

10511052
if len(cmd) >= 1:
@@ -1055,11 +1056,11 @@ def shell(self, build_names: List[str], cmd: List[str]):
10551056
str_cmd, build_dir, init_script, shell
10561057
)
10571058
)
1058-
full_command_line = ". {} {} > /dev/null || exit 1; {}".format(
1059-
init_script, build_dir, str_cmd
1059+
full_command_line = "set {}; . {} {} > /dev/null || exit 1; {}".format(
1060+
build_dir, init_script, build_dir, str_cmd
10601061
)
10611062
if not CookerCall.os.subprocess_run(
1062-
[shell, "-c", full_command_line], None, capture_output=False
1063+
[shell, "-c", full_command_line], base_dir, capture_output=False
10631064
):
10641065
fatal_error("Execution of {} failed.".format(full_command_line))
10651066
else:
@@ -1071,7 +1072,13 @@ def shell(self, build_names: List[str], cmd: List[str]):
10711072

10721073
if not CookerCall.os.replace_process(
10731074
shell,
1074-
[shell, "-c", ". {} {}; {}".format(init_script, build_dir, shell)],
1075+
[
1076+
shell,
1077+
"-c",
1078+
"cd {}; set {}; . {} {}; {}".format(
1079+
base_dir, build_dir, init_script, build_dir, shell
1080+
),
1081+
],
10751082
):
10761083
fatal_error(
10771084
"could not run interactive shell for {} with {}".format(

test/basic/shell/output.ref

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
exec /bin/sh /bin/sh -c . /layers/poky/oe-init-build-env /builds/build-pi2-base; /bin/sh
2-
exec /bin/sh /bin/sh -c . /layers/poky/oe-init-build-env /builds/build-qemu; /bin/sh
3-
/bin/sh -c . /layers/poky/oe-init-build-env /builds/build-qemu > /dev/null || exit 1; echo test
4-
/bin/sh -c . /layers/poky/oe-init-build-env /builds/build-qemu > /dev/null || exit 1; echo 'test with spaces and quotes "'
1+
exec /bin/sh /bin/sh -c cd /layers/poky; set /builds/build-pi2-base; . /layers/poky/oe-init-build-env /builds/build-pi2-base; /bin/sh
2+
exec /bin/sh /bin/sh -c cd /layers/poky; set /builds/build-qemu; . /layers/poky/oe-init-build-env /builds/build-qemu; /bin/sh
3+
cd /layers/poky
4+
/bin/sh -c set /builds/build-qemu; . /layers/poky/oe-init-build-env /builds/build-qemu > /dev/null || exit 1; echo test
5+
cd /layers/poky
6+
/bin/sh -c set /builds/build-qemu; . /layers/poky/oe-init-build-env /builds/build-qemu > /dev/null || exit 1; echo 'test with spaces and quotes "'

0 commit comments

Comments
 (0)