aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-06-05 23:05:40 +0700
committerShulhan <ms@kilabit.info>2018-06-05 23:05:40 +0700
commitdec955d8f85e6ca5515bee53fd25dc8f24da2027 (patch)
tree4ea60cd6cfcfcbffb9faa61e40ffaa56881b2be0
parentd7f5cb4233394a0e810de15ecf2e97a79a9a3acd (diff)
downloadbeku-dec955d8f85e6ca5515bee53fd25dc8f24da2027.tar.xz
NewEnvironment: get or set user PATH from environment
The PATH is used when running specific command, i.e. Run() and GoInstall().
-rw-r--r--env.go14
-rw-r--r--package.go18
-rw-r--r--package_test.go2
3 files changed, 15 insertions, 19 deletions
diff --git a/env.go b/env.go
index bae51dd..1eff448 100644
--- a/env.go
+++ b/env.go
@@ -27,6 +27,7 @@ import (
// packages, and list of missing packages.
//
type Env struct {
+ path string
prefix string
dirBin string
dirPkg string
@@ -66,6 +67,7 @@ func NewEnvironment(vendor, noDeps bool) (env *Env, err error) {
Debug = debugMode(debug)
env = &Env{
+ path: os.Getenv(envPATH),
dirGoRootSrc: filepath.Join(build.Default.GOROOT, dirSrc),
dirBin: filepath.Join(build.Default.GOPATH, dirBin),
dirPkg: filepath.Join(build.Default.GOPATH, dirPkg,
@@ -74,6 +76,10 @@ func NewEnvironment(vendor, noDeps bool) (env *Env, err error) {
vendor: vendor,
}
+ if len(env.path) == 0 {
+ env.path = defPATH
+ }
+
if vendor {
err = env.initVendor()
if err != nil {
@@ -1322,7 +1328,7 @@ func (env *Env) postSync(curPkg, newPkg *Package) (err error) {
// (3)
if len(curPkg.DepsMissing) == 0 {
- _ = curPkg.GoInstall()
+ _ = curPkg.GoInstall(env)
}
fmt.Println("[ENV] postSync >>> Package installed:\n", curPkg)
@@ -1341,12 +1347,12 @@ func (env *Env) build(pkg *Package) (err error) {
if Debug >= DebugL2 {
buildCmdDep = append(buildCmdDep, "-v")
}
- err = pkg.Run(buildCmdDep)
+ err = pkg.Run(env, buildCmdDep)
} else if cmd&buildModeGdm > 0 {
if Debug >= DebugL2 {
buildCmdDep = append(buildCmdDep, "-v")
}
- err = pkg.Run(buildCmdGdm)
+ err = pkg.Run(env, buildCmdGdm)
}
if err != nil {
fmt.Fprintf(defStderr, "[ENV] build %s >>> %s\n",
@@ -1379,7 +1385,7 @@ func (env *Env) reinstallAll() (err error) {
}
if len(pkg.DepsMissing) == 0 {
- _ = pkg.GoInstall()
+ _ = pkg.GoInstall(env)
}
}
return
diff --git a/package.go b/package.go
index a429cdc..b3d735f 100644
--- a/package.go
+++ b/package.go
@@ -238,7 +238,7 @@ func (pkg *Package) RemoveRequiredBy(importPath string) (ok bool) {
//
// Run command on package root directory.
//
-func (pkg *Package) Run(cmds []string) (err error) {
+func (pkg *Package) Run(env *Env, cmds []string) (err error) {
if len(cmds) == 0 {
return
}
@@ -249,13 +249,8 @@ func (pkg *Package) Run(cmds []string) (err error) {
cmd.Args = append(cmd.Args, cmds[1:]...)
}
- path := os.Getenv(envPATH)
- if len(path) == 0 {
- path = defPATH
- }
-
cmd.Env = append(cmd.Env, "GOPATH="+build.Default.GOPATH)
- cmd.Env = append(cmd.Env, "PATH="+path)
+ cmd.Env = append(cmd.Env, "PATH="+env.path)
cmd.Dir = pkg.FullPath
cmd.Stdout = defStdout
cmd.Stderr = defStderr
@@ -516,7 +511,7 @@ func (pkg *Package) load(sec *ini.Section) {
// (1) Set PATH to let go install that require gcc work when invoked from
// non-interactive shell (e.g. buildbot).
//
-func (pkg *Package) GoInstall() (err error) {
+func (pkg *Package) GoInstall(env *Env) (err error) {
//nolint:gas
cmd := exec.Command("go", "install")
if Debug >= DebugL2 {
@@ -524,13 +519,8 @@ func (pkg *Package) GoInstall() (err error) {
}
cmd.Args = append(cmd.Args, "./...")
- path := os.Getenv(envPATH)
- if len(path) == 0 {
- path = defPATH
- }
-
cmd.Env = append(cmd.Env, "GOPATH="+build.Default.GOPATH)
- cmd.Env = append(cmd.Env, "PATH="+path)
+ cmd.Env = append(cmd.Env, "PATH="+env.path)
cmd.Dir = pkg.FullPath
cmd.Stdout = defStdout
cmd.Stderr = defStderr
diff --git a/package_test.go b/package_test.go
index a8632db..ab987e7 100644
--- a/package_test.go
+++ b/package_test.go
@@ -481,7 +481,7 @@ func testGoInstall(t *testing.T) {
testResetOutput(t, true)
- err := c.pkg.GoInstall()
+ err := c.pkg.GoInstall(testEnv)
testResetOutput(t, false)
stdout, stderr := testGetOutput(t)