From a0b50c16850c5a0f83dd57b939275a9250715d60 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 24 Nov 2024 20:01:54 +0100 Subject: [PATCH 1/7] readme: Completely forgot to document `bob sh` --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 990827df..1e3bf18f 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,21 @@ To run a project with Bob, run: bob run ``` +Alternatively, you can enter the temporary installation prefix environment with: + +```console +bob sh +``` + +This will use the value stored in the `$SHELL` environment variable to launch a shell inside of that prefix, similar to a Python virtual environment. +You can also just run any command you want by passing it to `bob sh`, like so: + +```console +bob sh echo \$PATH +``` + +This will print out the value of the `$PATH` environment variable, and it should be prepended by the `bin` directory of the temporary installation prefix. + ### Installing Bob always helps his grandma install [Linux Mint](https://linuxmint.com/) on her computer! 👵 From ede6eb8376e728f6868489bd5c5c7daa9d0b8020 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 24 Nov 2024 20:06:01 +0100 Subject: [PATCH 2/7] readme: Actually, we need `sh -c` to evaluate `$PATH` --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e3bf18f..311b1e0d 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,11 @@ This will use the value stored in the `$SHELL` environment variable to launch a You can also just run any command you want by passing it to `bob sh`, like so: ```console -bob sh echo \$PATH +bob sh echo test +bob sh sh -c "echo \$PATH" ``` -This will print out the value of the `$PATH` environment variable, and it should be prepended by the `bin` directory of the temporary installation prefix. +The second command will print out the value of the `$PATH` environment variable, and it should be prepended by the `bin` directory of the temporary installation prefix. ### Installing From a7ad68900299fec87e2fed22e24c355b8ca1c090 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 24 Nov 2024 20:06:21 +0100 Subject: [PATCH 3/7] sh: No idea how that happened --- src/bsys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bsys.c b/src/bsys.c index e4175e33..e0c354b5 100644 --- a/src/bsys.c +++ b/src/bsys.c @@ -172,7 +172,7 @@ int bsys_sh(bsys_t const* bsys, int argc, char* argv[]) { } else { - for (int i = 1; i < argc; i++) { + for (int i = 0; i < argc; i++) { cmd_add(&cmd, argv[i]); } } From c3a63abeead2f315fad89623a0efc2d1f068edf6 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 24 Nov 2024 20:08:41 +0100 Subject: [PATCH 4/7] sh: Explicit message when entering shell, because it's not always clear --- src/bsys.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bsys.c b/src/bsys.c index e0c354b5..9156d4da 100644 --- a/src/bsys.c +++ b/src/bsys.c @@ -168,6 +168,7 @@ int bsys_sh(bsys_t const* bsys, int argc, char* argv[]) { return -1; } + LOG_SUCCESS("Entering shell ('%s').", shell); cmd_add(&cmd, shell); } From 9c5856feb8a8239f6d169ea8284e9368b317ad77 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 24 Nov 2024 20:18:17 +0100 Subject: [PATCH 5/7] tests: Tests for `bob sh` --- tests/sh.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/sh.sh diff --git a/tests/sh.sh b/tests/sh.sh new file mode 100644 index 00000000..748198c2 --- /dev/null +++ b/tests/sh.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +. tests/common.sh + +# Test the 'bob sh' command. +# Also kind of a regression test for the following PR: +# https://github.com/inobulles/bob/pull/77 + +if [ "$(bob sh echo test | tail -n1)" != "test" ]; then + echo "Failed to run command in shell." >&2 + exit 1 +fi + +if [ "$(bob sh sh -c "echo \$PATH" | tail -n1 | cut -d':' -f1)" != ".bob/prefix/bin" ]; then + echo "Temporary installation prefix not in \$PATH." >&2 + exit 1 +fi + +# XXX Can't really test 'bob sh' on it's own "properly" I don't think. + +export SHELL=uname + +if [ "$(bob sh | tail -n1)" != "$(uname)" ]; then + echo "Failed to run command in shell." >&2 + exit 1 +fi From cbdab67c11d8aa8274cd2c71abbc29268e08f16e Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 24 Nov 2024 20:29:11 +0100 Subject: [PATCH 6/7] sh: Don't require the setting of `POSIXLY_CORRECT` on Linux --- README.md | 2 +- src/bsys.c | 6 ++++++ tests/sh.sh | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 311b1e0d..46758c86 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ You can also just run any command you want by passing it to `bob sh`, like so: ```console bob sh echo test -bob sh sh -c "echo \$PATH" +bob sh -- sh -c "echo \$PATH" ``` The second command will print out the value of the `$PATH` environment variable, and it should be prepended by the `bin` directory of the temporary installation prefix. diff --git a/src/bsys.c b/src/bsys.c index 9156d4da..0469c5a3 100644 --- a/src/bsys.c +++ b/src/bsys.c @@ -174,6 +174,12 @@ int bsys_sh(bsys_t const* bsys, int argc, char* argv[]) { else { for (int i = 0; i < argc; i++) { + // On BSD/macOS, getopt doesn't consume the '--' argument. + + if (strcmp(argv[i], "--") == 0) { + continue; + } + cmd_add(&cmd, argv[i]); } } diff --git a/tests/sh.sh b/tests/sh.sh index 748198c2..7acfa433 100644 --- a/tests/sh.sh +++ b/tests/sh.sh @@ -11,7 +11,7 @@ if [ "$(bob sh echo test | tail -n1)" != "test" ]; then exit 1 fi -if [ "$(bob sh sh -c "echo \$PATH" | tail -n1 | cut -d':' -f1)" != ".bob/prefix/bin" ]; then +if [ "$(bob sh -- sh -c "echo \$PATH" | tail -n1 | cut -d':' -f1)" != ".bob/prefix/bin" ]; then echo "Temporary installation prefix not in \$PATH." >&2 exit 1 fi From 0f3626acc77a1c7f6b344b73a77a091e99bfc813 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 24 Nov 2024 20:31:20 +0100 Subject: [PATCH 7/7] run: Don't require the setting of `POSIXLY_CORRECT` on Linux And bring this stuff out into `cmd_add_argv`. --- src/bsys.c | 10 +--------- src/bsys/bob/main.c | 4 +--- src/cmd.c | 12 ++++++++++++ src/cmd.h | 1 + 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/bsys.c b/src/bsys.c index 0469c5a3..175149d3 100644 --- a/src/bsys.c +++ b/src/bsys.c @@ -173,15 +173,7 @@ int bsys_sh(bsys_t const* bsys, int argc, char* argv[]) { } else { - for (int i = 0; i < argc; i++) { - // On BSD/macOS, getopt doesn't consume the '--' argument. - - if (strcmp(argv[i], "--") == 0) { - continue; - } - - cmd_add(&cmd, argv[i]); - } + cmd_add_argv(&cmd, argc, argv); } if (cmd_exec_inplace(&cmd) < 0) { diff --git a/src/bsys/bob/main.c b/src/bsys/bob/main.c index 9f11f2be..6e2a7ba7 100644 --- a/src/bsys/bob/main.c +++ b/src/bsys/bob/main.c @@ -284,9 +284,7 @@ found:; // Then, add the arguments passed to the Bob frontend. // If there is no default runner, just pass the arguments from the frontend onwards. - for (ssize_t i = 0; i < argc; i++) { - cmd_add(&cmd, argv[i]); - } + cmd_add_argv(&cmd, argc, argv); // Make sure there actually is something in the command. diff --git a/src/cmd.c b/src/cmd.c index 25f32c9d..8861e251 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -71,6 +71,18 @@ __attribute__((__format__(__printf__, 2, 3))) void cmd_addf(cmd_t* cmd, char con va_end(va); } +void cmd_add_argv(cmd_t* cmd, int argc, char* argv[]) { + for (ssize_t i = 0; i < argc; i++) { + // On BSD/macOS, getopt doesn't consume the '--' argument. + + if (strcmp(argv[i], "--") == 0) { + continue; + } + + cmd_add(cmd, argv[i]); + } +} + static bool is_executable(char const* path) { struct stat sb; diff --git a/src/cmd.h b/src/cmd.h index ca21e081..ee449f2e 100644 --- a/src/cmd.h +++ b/src/cmd.h @@ -21,6 +21,7 @@ typedef struct { void cmd_create(cmd_t* cmd, ...); void cmd_add(cmd_t* cmd, char const* arg); __attribute__((__format__(__printf__, 2, 3))) void cmd_addf(cmd_t* cmd, char const* fmt, ...); +void cmd_add_argv(cmd_t* cmd, int argc, char* argv[]); int cmd_exec_inplace(cmd_t* cmd); pid_t cmd_exec_async(cmd_t* cmd); int cmd_exec(cmd_t* cmd);