Updated shared build environments

Updated check for errors.
Updated go.mod
Added .vscode launch
This commit is contained in:
notzippy@gmail.com
2022-02-20 17:16:12 -08:00
parent b562bd2dc5
commit ea5acb720f
10 changed files with 125 additions and 52 deletions

View File

@@ -13,7 +13,13 @@ import (
func CmdInit(c *exec.Cmd, addGoPath bool, basePath string) {
c.Dir = basePath
// Dep does not like paths that are not real, convert all paths in go to real paths
// Fetch the rest of the env variables
c.Env = ReducedEnv(addGoPath)
}
func ReducedEnv(addGoPath bool) []string {
realPath := &bytes.Buffer{}
env := []string{}
if addGoPath {
for _, p := range filepath.SplitList(build.Default.GOPATH) {
rp, _ := filepath.EvalSymlinks(p)
@@ -23,14 +29,18 @@ func CmdInit(c *exec.Cmd, addGoPath bool, basePath string) {
realPath.WriteString(rp)
}
// Go 1.8 fails if we do not include the GOROOT
c.Env = []string{"GOPATH=" + realPath.String(), "GOROOT=" + os.Getenv("GOROOT")}
env = []string{"GOPATH=" + realPath.String(), "GOROOT=" + os.Getenv("GOROOT")}
}
// Fetch the rest of the env variables
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
if pair[0] == "GOPATH" || pair[0] == "GOROOT" {
// Always exclude gomodcache
if pair[0] == "GOMODCACHE" {
continue
} else if !addGoPath && (pair[0] == "GOPATH" || pair[0] == "GOROOT") {
}
c.Env = append(c.Env, e)
env = append(env, e)
}
return env
}

View File

@@ -358,9 +358,10 @@ func findSrcPaths(appPath string, packagesList []string) (sourcePathsmap map[str
// Use packages to fetch
// by not specifying env, we will use the default env
config := &packages.Config{
Mode: packages.NeedName | packages.NeedFiles,
Mode: packages.NeedName | packages.NeedFiles | packages.NeedDeps,
Dir: appPath,
}
config.Env = ReducedEnv(false)
sourcePathsmap = map[string]string{}
Logger.Infof("Environment path %s root %s config env %s", os.Getenv("GOPATH"), os.Getenv("GOROOT"), config.Env)