From 4cceb0b403c486ccafa506e307ac911be6482653 Mon Sep 17 00:00:00 2001 From: Ridai Govinda Pombo Date: Tue, 2 Jun 2020 11:50:50 -0300 Subject: [PATCH] Prepend to path should be in one place One version of PrependToPath function, used by buildpacks. --- buildpacks/anaconda.go | 4 ++-- buildpacks/dart.go | 4 ++-- buildpacks/golang.go | 6 ++++-- buildpacks/homebrew.go | 10 ++++++---- buildpacks/protoc.go | 4 ++-- buildpacks/python.go | 3 +-- buildpacks/yarn.go | 4 ++-- plumbing/util.go | 11 ----------- 8 files changed, 19 insertions(+), 27 deletions(-) diff --git a/buildpacks/anaconda.go b/buildpacks/anaconda.go index 0e0d162c..963f6b6f 100644 --- a/buildpacks/anaconda.go +++ b/buildpacks/anaconda.go @@ -5,7 +5,6 @@ import ( "os" "path/filepath" - . "github.com/yourbase/yb/plumbing" "github.com/yourbase/yb/plumbing/log" "github.com/yourbase/yb/runtime" . "github.com/yourbase/yb/types" @@ -127,7 +126,8 @@ func (bt AnacondaBuildTool) DownloadUrl() string { func (bt AnacondaBuildTool) Setup() error { installDir := bt.InstallDir() - PrependToPath(filepath.Join(installDir, "bin")) + t := bt.spec.InstallTarget + t.PrependToPath(filepath.Join(installDir, "bin")) setupDir := bt.spec.PackageDir for _, cmd := range []string{ diff --git a/buildpacks/dart.go b/buildpacks/dart.go index 67c20e3e..f1b41a80 100644 --- a/buildpacks/dart.go +++ b/buildpacks/dart.go @@ -5,7 +5,6 @@ import ( "path/filepath" "strings" - . "github.com/yourbase/yb/plumbing" "github.com/yourbase/yb/plumbing/log" . "github.com/yourbase/yb/types" ) @@ -80,7 +79,8 @@ func (bt DartBuildTool) DartDir() string { func (bt DartBuildTool) Setup() error { dartDir := bt.DartDir() cmdPath := filepath.Join(dartDir, "bin") - PrependToPath(cmdPath) + t := bt.spec.InstallTarget + t.PrependToPath(cmdPath) return nil } diff --git a/buildpacks/golang.go b/buildpacks/golang.go index d11cdab4..15b72b9a 100644 --- a/buildpacks/golang.go +++ b/buildpacks/golang.go @@ -86,8 +86,10 @@ func (bt GolangBuildTool) Setup() error { cmdPath := filepath.Join(golangDir, "bin") t.PrependToPath(cmdPath) for _, pathElement := range goPathElements { - pathBinDir := filepath.Join(pathElement, "bin") - t.PrependToPath(pathBinDir) + if pathElement != "" { + pathBinDir := filepath.Join(pathElement, "bin") + t.PrependToPath(pathBinDir) + } } log.Infof("Setting GOROOT to %s", golangDir) diff --git a/buildpacks/homebrew.go b/buildpacks/homebrew.go index fbc5350b..df6b3dd6 100644 --- a/buildpacks/homebrew.go +++ b/buildpacks/homebrew.go @@ -75,12 +75,13 @@ func (bt HomebrewBuildTool) PackagePrefix(packageString string) (string, error) func (bt HomebrewBuildTool) PackageInstalled() bool { prefix, err := bt.PackagePrefix(bt.PackageVersionString()) + t := bt.spec.InstallTarget if err != nil { return false } if prefix != "" { - return PathExists(prefix) + return t.PathExists(prefix) } return false @@ -228,6 +229,7 @@ func (bt HomebrewBuildTool) InstallLinux() error { } func (bt HomebrewBuildTool) Setup() error { + t := bt.spec.InstallTarget if bt.IsPackage() { prefixPath, err := bt.PackagePrefix(bt.PackageVersionString()) if err != nil { @@ -236,12 +238,12 @@ func (bt HomebrewBuildTool) Setup() error { binDir := filepath.Join(prefixPath, "bin") sbinDir := filepath.Join(prefixPath, "sbin") - PrependToPath(binDir) - PrependToPath(sbinDir) + t.PrependToPath(binDir) + t.PrependToPath(sbinDir) } else { brewDir := bt.HomebrewDir() brewBinDir := filepath.Join(brewDir, "bin") - PrependToPath(brewBinDir) + t.PrependToPath(brewBinDir) brewLibDir := filepath.Join(brewDir, "lib") runtime.SetEnv("LD_LIBRARY_PATH", brewLibDir) } diff --git a/buildpacks/protoc.go b/buildpacks/protoc.go index feb4c49b..5d54909a 100644 --- a/buildpacks/protoc.go +++ b/buildpacks/protoc.go @@ -6,7 +6,6 @@ import ( "path/filepath" "strings" - . "github.com/yourbase/yb/plumbing" "github.com/yourbase/yb/plumbing/log" . "github.com/yourbase/yb/types" ) @@ -81,9 +80,10 @@ func (bt ProtocBuildTool) ProtocDir() string { func (bt ProtocBuildTool) Setup() error { protocDir := bt.ProtocDir() + t := bt.spec.InstallTarget cmdPath := filepath.Join(protocDir, "bin") - PrependToPath(cmdPath) + t.PrependToPath(cmdPath) return nil } diff --git a/buildpacks/python.go b/buildpacks/python.go index b1187069..dbeb87b8 100644 --- a/buildpacks/python.go +++ b/buildpacks/python.go @@ -127,11 +127,11 @@ func (bt PythonBuildTool) Setup() error { condaDir := bt.AnacondaInstallDir() envDir := bt.EnvironmentDir() t := bt.spec.InstallTarget + t.PrependToPath(filepath.Join(condaDir, "bin")) if t.PathExists(envDir) { log.Infof("environment installed in %s", envDir) } else { - newPath := fmt.Sprintf("PATH=%s:%s", filepath.Join(condaDir, "bin"), t.GetDefaultPath()) setupDir := bt.spec.PackageDir condaBin := filepath.Join(condaDir, "bin", "conda") @@ -146,7 +146,6 @@ func (bt PythonBuildTool) Setup() error { Command: cmd, Interactive: false, Directory: setupDir, - Environment: []string{newPath}, } if err := t.Run(p); err != nil { diff --git a/buildpacks/yarn.go b/buildpacks/yarn.go index cf42aa11..64ec0491 100644 --- a/buildpacks/yarn.go +++ b/buildpacks/yarn.go @@ -5,7 +5,6 @@ import ( "os" "path/filepath" - . "github.com/yourbase/yb/plumbing" "github.com/yourbase/yb/plumbing/log" . "github.com/yourbase/yb/types" ) @@ -75,9 +74,10 @@ func (bt YarnBuildTool) Install() error { } func (bt YarnBuildTool) Setup() error { + t := bt.spec.InstallTarget yarnDir := bt.YarnDir() cmdPath := filepath.Join(yarnDir, "bin") - PrependToPath(cmdPath) + t.PrependToPath(cmdPath) return nil } diff --git a/plumbing/util.go b/plumbing/util.go index 6453f9ac..6a8196c3 100644 --- a/plumbing/util.go +++ b/plumbing/util.go @@ -25,17 +25,6 @@ import ( const SNIFFLEN = 8000 -func PrependToPath(dir string) { - currentPath := os.Getenv("PATH") - // Only prepend if it's not already the head; presume that - // whomever asked for this wants to be at the front so it's okay if it's - // duplicated later - if !strings.HasPrefix(currentPath, dir) { - newPath := fmt.Sprintf("%s:%s", dir, currentPath) - os.Setenv("PATH", newPath) - } -} - func ConfigFilePath(filename string) string { u, _ := user.Current() configDir := filepath.Join(u.HomeDir, ".config", "yb")