Skip to content

[bin wrappers] fixes for only-path-without-wrappers call #1163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Jun 15, 2023

Summary

follow up to #1160

correctness:

  • consolidate some code into calling wrapnix.GetWrapperBinPath
  • the earlier code had a bug where I forgot to call -c <project dir>, but that is moot now (see below change)

perf:

  • call DO_NOT_TRACK=1 to minimize segment perf impact
  • simplify OnlyPathWithoutWrappers to directly call os.Getenv("PATH"), remove WrapperBins, and exportify it. This function is used in a very specific context, so we can know we can skip the nix.ComputeEnv calculation.
  • Doing time devbox shellenv only-path-without-wrappers is now consistently ~ 18-25 milliseconds.

I have a slight preference for this over writing PATH to a file and sourcing it, since we may run into correctness issues with that file getting outdated, and it'll introduce perf regression on every shellenv call to write the file.

How was it tested?

  • testscripts pass
  • iex -S mix works

visual inspection:

    1 #!/nix/store/w849dr5qcbrrnxv69sy7kdnifa9jpjyf-bash-5.2-p15/bin/bash
  2
  3
  4
  5 if [[ "$__DEVBOX_SHELLENV_HASH_ac6a60d54a9d1ba6618cce8d40bfdfb50059d814edfe5f49bca3168c5c34e970" != "b1a4903de70aa4d610ecb00ffb3dd755913b4505651e6bebbf41571a406d415c" ]] &    & [[ -z "$__DEVBOX_SHELLENV_HASH_ac6a60d54a9d1ba6618cce8d40bfdfb50059d814edfe5f49bca3168c5c34e970_GUARD" ]]; then
  6 export __DEVBOX_SHELLENV_HASH_ac6a60d54a9d1ba6618cce8d40bfdfb50059d814edfe5f49bca3168c5c34e970_GUARD=true
  7 eval "$(DO_NOT_TRACK=1 devbox shellenv -c /Users/savil/code/jetpack/devbox/examples/development/elixir/elixir_hello)"
  8 fi
  9
 10 eval "$(DO_NOT_TRACK=1 devbox shellenv only-path-without-wrappers -c /Users/savil/code/jetpack/devbox/examples/development/elixir/elixir_hello)"
 11
 12 exec /nix/store/47whvyx9x48ishndcjw71xs7l0a6v6sd-elixir-1.14.4/bin/iex "$@"

Copy link
Collaborator Author

savil commented Jun 15, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@savil savil force-pushed the savil/fix-wrappers branch from dd9ce16 to 1eecb88 Compare June 15, 2023 13:27
@savil savil requested review from LucilleH and mohsenari June 15, 2023 13:31
@savil savil marked this pull request as ready for review June 15, 2023 13:31
@savil savil force-pushed the savil/fix-wrappers branch 5 times, most recently from dc141bd to c312540 Compare June 15, 2023 13:37
devbox.go Outdated
@@ -73,3 +73,7 @@ func GlobalDataPath() (string, error) {
func PrintEnvrcContent(w io.Writer) error {
return impl.PrintEnvrcContent(w)
}

func OnlyPathWithoutWrappers() string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What was the reason for skipping adding this to Devbox interface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its a small utility function which doesn't have any dependency on the core "devbox" struct.

I was going to inline it in boxcli/shellenv.go, but needed the exportify function so added it here.

func OnlyPathWithoutWrappers() string {

path := []string{}
for _, p := range strings.Split(os.Getenv("PATH"), string(filepath.ListSeparator)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

os.Getenv("PATH") works because OnlyPathWithoutWrappers is used only in the context of direnv enabled or inside devbox shell. So the PATH is guaranteed to be a devbox computed PATH.
But it won't work outside that context, if you just run the command you'll get PATH env variable (assuming you don't have devbox global).
So I worry this might be used in future in a different context with the assumption that it will compute a devbox PATH and exclude wrappers bin and introduce a bug.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. The devbox shellenv only-path-without-wrappers command is Hidden, and I can add more comments to clarify its usage. It'll only be used by someone developing devbox code. So, this is low risk.

  2. The internal function could be renamed to ExportSystemPathWithoutWrappers. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah the rename can clarify the usage then

@savil savil requested a review from mohsenari June 15, 2023 17:30
Copy link
Collaborator

@LucilleH LucilleH left a comment

Choose a reason for hiding this comment

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

This solution is much better than the one I suggested in the previous PR!

@savil savil force-pushed the savil/fix-wrappers branch from 4f27836 to 0911fba Compare June 15, 2023 18:55
@savil savil force-pushed the savil/fix-wrappers branch from 0911fba to 089cc4d Compare June 15, 2023 19:01
@savil savil merged commit 0728b41 into main Jun 15, 2023
@savil savil deleted the savil/fix-wrappers branch June 15, 2023 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants