summaryrefslogtreecommitdiff
path: root/libgo/go/cmd/go/internal/envcmd/env.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/cmd/go/internal/envcmd/env.go')
-rw-r--r--libgo/go/cmd/go/internal/envcmd/env.go37
1 files changed, 27 insertions, 10 deletions
diff --git a/libgo/go/cmd/go/internal/envcmd/env.go b/libgo/go/cmd/go/internal/envcmd/env.go
index 603f7b5060c..afadbade38e 100644
--- a/libgo/go/cmd/go/internal/envcmd/env.go
+++ b/libgo/go/cmd/go/internal/envcmd/env.go
@@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"os"
+ "path/filepath"
"runtime"
"strings"
@@ -16,11 +17,12 @@ import (
"cmd/go/internal/cache"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
+ "cmd/go/internal/modload"
"cmd/go/internal/work"
)
var CmdEnv = &base.Command{
- UsageLine: "env [-json] [var ...]",
+ UsageLine: "go env [-json] [var ...]",
Short: "print Go environment information",
Long: `
Env prints Go environment information.
@@ -52,17 +54,16 @@ func MkEnv() []cfg.EnvVar {
{Name: "GOBIN", Value: cfg.GOBIN},
{Name: "GOCACHE", Value: cache.DefaultDir()},
{Name: "GOEXE", Value: cfg.ExeSuffix},
+ {Name: "GOFLAGS", Value: os.Getenv("GOFLAGS")},
{Name: "GOHOSTARCH", Value: runtime.GOARCH},
{Name: "GOHOSTOS", Value: runtime.GOOS},
{Name: "GOOS", Value: cfg.Goos},
{Name: "GOPATH", Value: cfg.BuildContext.GOPATH},
+ {Name: "GOPROXY", Value: os.Getenv("GOPROXY")},
{Name: "GORACE", Value: os.Getenv("GORACE")},
{Name: "GOROOT", Value: cfg.GOROOT},
{Name: "GOTMPDIR", Value: os.Getenv("GOTMPDIR")},
{Name: "GOTOOLDIR", Value: base.ToolDir},
-
- // disable escape codes in clang errors
- {Name: "TERM", Value: "dumb"},
}
if work.GccgoBin != "" {
@@ -78,6 +79,8 @@ func MkEnv() []cfg.EnvVar {
env = append(env, cfg.EnvVar{Name: "GO386", Value: cfg.GO386})
case "mips", "mipsle":
env = append(env, cfg.EnvVar{Name: "GOMIPS", Value: cfg.GOMIPS})
+ case "mips64", "mips64le":
+ env = append(env, cfg.EnvVar{Name: "GOMIPS64", Value: cfg.GOMIPS64})
}
cc := cfg.DefaultCC(cfg.Goos, cfg.Goarch)
@@ -111,6 +114,18 @@ func findEnv(env []cfg.EnvVar, name string) string {
// ExtraEnvVars returns environment variables that should not leak into child processes.
func ExtraEnvVars() []cfg.EnvVar {
+ gomod := ""
+ if modload.Init(); modload.ModRoot != "" {
+ gomod = filepath.Join(modload.ModRoot, "go.mod")
+ }
+ return []cfg.EnvVar{
+ {Name: "GOMOD", Value: gomod},
+ }
+}
+
+// ExtraEnvVarsCostly returns environment variables that should not leak into child processes
+// but are costly to evaluate.
+func ExtraEnvVarsCostly() []cfg.EnvVar {
var b work.Builder
b.Init()
cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{})
@@ -120,6 +135,7 @@ func ExtraEnvVars() []cfg.EnvVar {
return nil
}
cmd := b.GccCmd(".", "")
+
return []cfg.EnvVar{
// Note: Update the switch in runEnv below when adding to this list.
{Name: "CGO_CFLAGS", Value: strings.Join(cflags, " ")},
@@ -134,13 +150,14 @@ func ExtraEnvVars() []cfg.EnvVar {
func runEnv(cmd *base.Command, args []string) {
env := cfg.CmdEnv
+ env = append(env, ExtraEnvVars()...)
- // Do we need to call ExtraEnvVars, which is a bit expensive?
+ // Do we need to call ExtraEnvVarsCostly, which is a bit expensive?
// Only if we're listing all environment variables ("go env")
// or the variables being requested are in the extra list.
- needExtra := true
+ needCostly := true
if len(args) > 0 {
- needExtra = false
+ needCostly = false
for _, arg := range args {
switch arg {
case "CGO_CFLAGS",
@@ -150,12 +167,12 @@ func runEnv(cmd *base.Command, args []string) {
"CGO_LDFLAGS",
"PKG_CONFIG",
"GOGCCFLAGS":
- needExtra = true
+ needCostly = true
}
}
}
- if needExtra {
- env = append(env, ExtraEnvVars()...)
+ if needCostly {
+ env = append(env, ExtraEnvVarsCostly()...)
}
if len(args) > 0 {