-
Notifications
You must be signed in to change notification settings - Fork 249
[bin-wrappers] Reduce/improve when we create bin wrappers #1522
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
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,11 @@ import ( | |
"go.jetpack.io/devbox/internal/xdg" | ||
) | ||
|
||
type devboxer interface { | ||
NixBins(ctx context.Context) ([]string, error) | ||
ShellEnvHash(ctx context.Context) (string, error) | ||
ShellEnvHashKey() string | ||
ProjectDir() string | ||
type CreateWrappersArgs struct { | ||
NixBins []string | ||
ShellEnvHash string | ||
ShellEnvHashKey string | ||
ProjectDir string | ||
} | ||
|
||
//go:embed wrapper.sh.tmpl | ||
|
@@ -37,44 +37,35 @@ var wrapperTemplate = template.Must(template.New("wrapper").Parse(wrapper)) | |
var devboxSymlinkDir = xdg.CacheSubpath(filepath.Join("devbox", "bin", "current")) | ||
|
||
// CreateWrappers creates wrappers for all the executables in nix paths | ||
func CreateWrappers(ctx context.Context, devbox devboxer) error { | ||
func CreateWrappers(ctx context.Context, args CreateWrappersArgs) error { | ||
defer debug.FunctionTimer().End() | ||
shellEnvHash, err := devbox.ShellEnvHash(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Remove all old wrappers | ||
_ = os.RemoveAll(filepath.Join(devbox.ProjectDir(), plugin.WrapperPath)) | ||
_ = os.RemoveAll(filepath.Join(args.ProjectDir, plugin.WrapperPath)) | ||
|
||
// Recreate the bin wrapper directory | ||
destPath := filepath.Join(wrapperBinPath(devbox)) | ||
destPath := filepath.Join(wrapperBinPath(args.ProjectDir)) | ||
_ = os.MkdirAll(destPath, 0o755) | ||
|
||
bashPath := cmdutil.GetPathOrDefault("bash", "/bin/bash") | ||
|
||
bins, err := devbox.NixBins(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
if err := CreateDevboxSymlinkIfPossible(); err != nil { | ||
return err | ||
} | ||
|
||
for _, bin := range bins { | ||
if err = createWrapper(&createWrapperArgs{ | ||
devboxer: devbox, | ||
BashPath: bashPath, | ||
Command: bin, | ||
ShellEnvHash: shellEnvHash, | ||
DevboxSymlinkDir: devboxSymlinkDir, | ||
destPath: filepath.Join(destPath, filepath.Base(bin)), | ||
for _, bin := range args.NixBins { | ||
if err := createWrapper(&createWrapperArgs{ | ||
CreateWrappersArgs: args, | ||
BashPath: bashPath, | ||
Command: bin, | ||
DevboxSymlinkDir: devboxSymlinkDir, | ||
destPath: filepath.Join(destPath, filepath.Base(bin)), | ||
}); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
} | ||
|
||
return createSymlinksForSupportDirs(devbox.ProjectDir()) | ||
return createSymlinksForSupportDirs(args.ProjectDir) | ||
} | ||
|
||
// CreateDevboxSymlinkIfPossible creates a symlink to the devbox binary. | ||
|
@@ -134,12 +125,11 @@ func CreateDevboxSymlinkIfPossible() error { | |
} | ||
|
||
type createWrapperArgs struct { | ||
devboxer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! thank god we removed this. |
||
CreateWrappersArgs | ||
BashPath string | ||
Command string | ||
ShellEnvHash string | ||
DevboxSymlinkDir string | ||
destPath string | ||
DevboxSymlinkDir string | ||
} | ||
|
||
func createWrapper(args *createWrapperArgs) error { | ||
|
@@ -200,6 +190,6 @@ func createSymlinksForSupportDirs(projectDir string) error { | |
return nil | ||
} | ||
|
||
func wrapperBinPath(devbox devboxer) string { | ||
return filepath.Join(devbox.ProjectDir(), plugin.WrapperBinPath) | ||
func wrapperBinPath(projectDir string) string { | ||
return filepath.Join(projectDir, plugin.WrapperBinPath) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't we save the lockfile here, after the config has been changed? Similar to the end of AddPackages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually not needed in either because
ensurePackagesAreInstalled
already doeslockfile.Tidy
will remove from
Add()