Skip to content

Commit 8f1f0dc

Browse files
authored
[runx] Use single path for all runx binaries (#1544)
## Summary This allows adding and removing runx binaries inside a devbox environment without having to shellenv again. ## How was it tested? ``` devbox shell which envsec devbox add runx:jetpack-io/envsec which envsec devbox rm runx:jetpack-io/envsec which envsec ```
1 parent ca4d880 commit 8f1f0dc

File tree

6 files changed

+38
-13
lines changed

6 files changed

+38
-13
lines changed

devbox.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"packages": [
33
"go@latest",
4-
"runx:golangci/golangci-lint@latest"
4+
"runx:golangci/golangci-lint@latest",
5+
"runx:mvdan/gofumpt@latest"
56
],
67
"env": {
78
"GOENV": "off",

devbox.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"runx:golangci/golangci-lint@latest": {
2525
"resolved": "golangci/[email protected]",
2626
"version": "v1.54.2"
27+
},
28+
"runx:mvdan/gofumpt@latest": {
29+
"resolved": "mvdan/[email protected]",
30+
"version": "v0.5.0"
2731
}
2832
}
2933
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/stretchr/testify v1.8.4
3939
github.com/wk8/go-ordered-map/v2 v2.1.8
4040
github.com/zealic/go2node v0.1.0
41-
go.jetpack.io/pkg v0.0.0-20231006204718-f59feb213022
41+
go.jetpack.io/pkg v0.0.0-20231010185527-78c6902d51f7
4242
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17
4343
golang.org/x/mod v0.12.0
4444
golang.org/x/sync v0.3.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ go.jetpack.io/pkg v0.0.0-20231002215645-9afeb0623fd3 h1:aMydtVCHn7dfotOyV41VAxX5
339339
go.jetpack.io/pkg v0.0.0-20231002215645-9afeb0623fd3/go.mod h1:iaf3e/aENp5luwYFlfCxj+GsiwqHagbvRAY3bIdEgGA=
340340
go.jetpack.io/pkg v0.0.0-20231006204718-f59feb213022 h1:8TRpo0lYh1Y6zec8Px0yXbnVRXXs+yUPU+TnHNsREdA=
341341
go.jetpack.io/pkg v0.0.0-20231006204718-f59feb213022/go.mod h1:iaf3e/aENp5luwYFlfCxj+GsiwqHagbvRAY3bIdEgGA=
342+
go.jetpack.io/pkg v0.0.0-20231010185527-78c6902d51f7 h1:QGNfUfKmGtjPgYNgmXwsUa9+AN7rdcRx3N6Mfy5BXS0=
343+
go.jetpack.io/pkg v0.0.0-20231010185527-78c6902d51f7/go.mod h1:iaf3e/aENp5luwYFlfCxj+GsiwqHagbvRAY3bIdEgGA=
342344
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
343345
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
344346
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=

internal/impl/devbox.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,18 +1210,40 @@ func (d *Devbox) Lockfile() *lock.File {
12101210
}
12111211

12121212
func (d *Devbox) RunXPaths(ctx context.Context) (string, error) {
1213-
packages := lo.Filter(d.InstallablePackages(), devpkg.IsRunX)
1214-
paths := []string{}
1215-
for _, pkg := range packages {
1213+
runxBinPath := filepath.Join(d.projectDir, ".devbox", "virtenv", "runx", "bin")
1214+
if err := os.RemoveAll(runxBinPath); err != nil {
1215+
return "", err
1216+
}
1217+
if err := os.MkdirAll(runxBinPath, 0o755); err != nil {
1218+
return "", err
1219+
}
1220+
1221+
for _, pkg := range d.InstallablePackages() {
1222+
if !pkg.IsRunX() {
1223+
continue
1224+
}
12161225
lockedPkg, err := d.lockfile.Resolve(pkg.Raw)
12171226
if err != nil {
12181227
return "", err
12191228
}
1220-
p, err := pkgtype.RunXClient().Install(ctx, lockedPkg.Resolved)
1229+
paths, err := pkgtype.RunXClient().Install(ctx, lockedPkg.Resolved)
12211230
if err != nil {
12221231
return "", err
12231232
}
1224-
paths = append(paths, p...)
1233+
for _, path := range paths {
1234+
// create symlink to all files in p
1235+
files, err := os.ReadDir(path)
1236+
if err != nil {
1237+
return "", err
1238+
}
1239+
for _, file := range files {
1240+
src := filepath.Join(path, file.Name())
1241+
dst := filepath.Join(runxBinPath, file.Name())
1242+
if err := os.Symlink(src, dst); err != nil && !errors.Is(err, os.ErrExist) {
1243+
return "", err
1244+
}
1245+
}
1246+
}
12251247
}
1226-
return envpath.JoinPathLists(paths...), nil
1248+
return runxBinPath, nil
12271249
}

scripts/gofumpt.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/bin/bash
22

3-
mkdir -p dist/tools
4-
export GOBIN="$PWD/dist/tools"
5-
go install mvdan.cc/gofumpt@latest
6-
7-
find . -name '*.go' -exec "$GOBIN/gofumpt" -extra -w {} \+
3+
find . -name '*.go' -exec gofumpt -extra -w {} \+
84

95
if [ -n "${CI:-}" ]; then
106
git diff --exit-code

0 commit comments

Comments
 (0)