Skip to content
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

Development dependency global installation workaround #89

Merged
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
24 changes: 15 additions & 9 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,22 @@ func validateBuildDependencies() {
continue
}

env := map[string]string{
// Disable module mode to install development dependencies to prevent to pollute the project module file.
// This is a necessary workaround until the Go toolchain is able to install packages globally without
// updating the module file when the "go get" command is run from within the project root directory.
// See https://github.com/golang/go/issues/30515 for more details or more details and proposed solutions
// that might be added to Go's build tools in future versions.
"GO111MODULE": "off"}

prt.Infof("Installing required build dependency: %s", color.CyanString(bd.PackageName))
if err = sh.RunWith(env, goExec, "get", "-u", bd.PackageName); err != nil {
c := exec.Command(goExec, "get", "-u", bd.PackageName)
// Run installations outside of the project root directory to prevent the pollution of the project's Go module
// file.
// This is a necessary workaround until the Go toolchain is able to install packages globally without
// updating the module file when the "go get" command is run from within the project root directory.
// See https://github.com/golang/go/issues/30515 for more details or more details and proposed solutions
// that might be added to Go's build tools in future versions.
c.Dir = os.TempDir()
c.Env = os.Environ()
// Explicitly enable "module" mode to install development dependencies to allow to use pinned module versions.
env := map[string]string{"GO111MODULE": "on"}
for k, v := range env {
c.Env = append(c.Env, k+"="+v)
}
if err = c.Run(); err != nil {
prt.Errorf("Failed to install required build dependency %s: %v", color.CyanString(bd.PackageName), err)
prt.Warnf("Please install manually: %s", color.CyanString("go get -u %s", bd.PackageName))
os.Exit(1)
Expand Down