Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions e2e/generate/test_generate_bootstrap
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/usr/bin/env bash

assert "mise generate bootstrap -w"
# shellcheck disable=SC2016
assert_contains "cat ./bin/mise" 'exec -a "$0" "$MISE_INSTALL_PATH" "$@"'
assert "./bin/mise version"

assert "mise tasks add xxx -- echo 'running xxx'"
assert "mise generate task-stubs --mise-bin ./bin/mise"
assert "./bin/xxx" "running xxx"

assert "mise generate bootstrap -l -w"
# shellcheck disable=SC2016
assert_contains "cat ./bin/mise" 'exec -a "$0" "$MISE_INSTALL_PATH" "$@"'

# ensure that that the commands don't rely on the global mise bin
original_mise="$(which mise)"
Expand Down
2 changes: 1 addition & 1 deletion src/cli/generate/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ __mise_bootstrap() {{
test -f "$MISE_INSTALL_PATH" || install
}}
__mise_bootstrap
exec "$MISE_INSTALL_PATH" "$@"
exec -a "$0" "$MISE_INSTALL_PATH" "$@"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly fixes the issue for the bootstrap script, the same problem exists in other script-generating commands. To ensure consistent behavior and fully resolve the argv[0] preservation issue, similar changes are needed in other files.

Since I can only comment on changed files, I'm leaving this feedback here. Please consider applying fixes to the following:

  1. src/cli/generate/tool_stub.rs:
    In the wrap_with_bootstrap function, the exec call does not preserve argv[0]. It should be changed from:

    exec "$MISE_BIN" tool-stub "$0" "$@"

    to:

    exec -a "$0" "$MISE_BIN" tool-stub "$0" "$@"
  2. src/cli/generate/task_stubs.rs:
    The generated script in the generate function uses #!/bin/sh and an exec call that doesn't preserve argv[0]. This should be updated to use bash and exec -a.
    Change from:

    #!/bin/sh
    exec {mise_bin} run {display_name} "$@"

    to:

    #!/usr/bin/env bash
    exec -a "$0" {mise_bin} run {display_name} "$@"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope for this PR.

This change is limited to mise generate bootstrap. Other generators should be evaluated separately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: this is not the same issue.

This PR is limited to mise generate bootstrap, where preserving argv[0] is required for shim dispatch.

tool_stub.rs passes the original path explicitly to tool-stub, and task_stubs.rs invokes mise run {display_name} directly, so they do not depend on argv[0] in the same way.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve absolute argv0 when re-executing bootstrap binary

Using exec -a "$0" "$MISE_INSTALL_PATH" "$@" forwards relative invocation names (for example ./bin/mise) into argv[0]. On Linux, activate intentionally uses ARGV0 as the executable path (src/cli/activate.rs), so eval "$(./bin/mise activate bash)" now emits hooks that call ./bin/mise and those hooks fail after changing directories away from the project root. Before this change, argv[0] was the absolute install path, so the generated activation hooks remained valid across directories.

Useful? React with 👍 / 👎.

"#
);
Ok(script.trim().to_string())
Expand Down
Loading