Skip to content

Commit dd9ce16

Browse files
committed
[bin wrappers] fixes for only-path-without-wrappers call
1 parent f19dbfc commit dd9ce16

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

internal/impl/devbox.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ func (d *Devbox) PrintEnv(opts *devopt.PrintEnv) (string, error) {
325325
if opts.OnlyPathWithoutWrappers {
326326
path := []string{}
327327
for _, p := range strings.Split(envs["PATH"], string(filepath.ListSeparator)) {
328-
if !strings.Contains(p, plugin.WrapperPath) {
328+
// Intentionally do not include projectDir with plugin.WrapperBinPath so that
329+
// we filter out bin-wrappers for devbox-global and devbox-project.
330+
if !strings.Contains(p, plugin.WrapperBinPath) {
329331
path = append(path, p)
330332
}
331333
}

internal/wrapnix/wrapper.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"text/template"
1414

1515
"github.com/pkg/errors"
16-
1716
"go.jetpack.io/devbox/internal/cmdutil"
1817
"go.jetpack.io/devbox/internal/nix"
1918
"go.jetpack.io/devbox/internal/plugin"
@@ -48,7 +47,7 @@ func CreateWrappers(ctx context.Context, devbox devboxer) error {
4847
_ = os.RemoveAll(filepath.Join(devbox.ProjectDir(), plugin.WrapperPath))
4948

5049
// Recreate the bin wrapper directory
51-
destPath := filepath.Join(devbox.ProjectDir(), plugin.WrapperBinPath)
50+
destPath := filepath.Join(GetWrapperBinPath(devbox))
5251
_ = os.MkdirAll(destPath, 0755)
5352

5453
bashPath := cmdutil.GetPathOrDefault("bash", "/bin/bash")
@@ -91,13 +90,17 @@ func CreateWrappers(ctx context.Context, devbox devboxer) error {
9190
return errors.WithStack(err)
9291
}
9392
}
94-
if err = createDevboxSymlink(devbox.ProjectDir()); err != nil {
93+
if err = createDevboxSymlink(devbox); err != nil {
9594
return err
9695
}
9796

9897
return createSymlinksForSupportDirs(devbox.ProjectDir())
9998
}
10099

100+
func GetWrapperBinPath(devbox devboxer) string {
101+
return filepath.Join(devbox.ProjectDir(), plugin.WrapperBinPath)
102+
}
103+
101104
type createWrapperArgs struct {
102105
devboxer
103106
BashPath string
@@ -168,15 +171,15 @@ func createSymlinksForSupportDirs(projectDir string) error {
168171

169172
// Creates a symlink for devbox in .devbox/virtenv/.wrappers/bin
170173
// so that devbox can be available inside a pure shell
171-
func createDevboxSymlink(projectDir string) error {
174+
func createDevboxSymlink(devbox devboxer) error {
172175

173176
// Get absolute path for where devbox is called
174177
devboxPath, err := filepath.Abs(os.Args[0])
175178
if err != nil {
176179
return errors.Wrap(err, "failed to create devbox symlink. Devbox command won't be available inside the shell")
177180
}
178181
// Create a symlink between devbox in .wrappers/bin
179-
err = os.Symlink(devboxPath, filepath.Join(projectDir, plugin.WrapperBinPath, "devbox"))
182+
err = os.Symlink(devboxPath, filepath.Join(GetWrapperBinPath(devbox), "devbox"))
180183
if err != nil && !errors.Is(err, fs.ErrExist) {
181184
return errors.Wrap(err, "failed to create devbox symlink. Devbox command won't be available inside the shell")
182185
}

internal/wrapnix/wrapper.sh.tmpl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!{{ .BashPath }}
22

3-
{{/*
3+
{{/*
44
# If env variable has never been set by devbox we set it, but also
55
# default to env value set by user. This means plugin env variables behave a bit
66
# differently than devbox.json env variables which are always set once.
@@ -29,9 +29,13 @@ export {{ .ShellEnvHashKey }}_GUARD=true
2929
eval "$(DO_NOT_TRACK=1 devbox shellenv -c {{ .ProjectDir }})"
3030
fi
3131

32-
# So that we do not invoke other bin-wrappers from
33-
# this bin-wrapper. Instead, we directly invoke the binary from the nix store, which
34-
# should be in PATH.
35-
eval "$(devbox shellenv only-path-without-wrappers)"
32+
{{/*
33+
We call only-path-without-wrappers so that we do not invoke other bin-wrappers from
34+
this bin-wrapper. Instead, we directly invoke the binary from the nix store, which
35+
should be in PATH.
36+
37+
DO_NOT_TRACK=1 can be removed once we optimize segment to queue events.
38+
*/ -}}
39+
eval "$(DO_NOT_TRACK=1 devbox shellenv only-path-without-wrappers -c {{ .ProjectDir }})"
3640

3741
exec {{ .Command }} "$@"

0 commit comments

Comments
 (0)