aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/go/main.go')
-rw-r--r--src/cmd/go/main.go64
1 files changed, 34 insertions, 30 deletions
diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go
index 02174a56ff..16361e02ca 100644
--- a/src/cmd/go/main.go
+++ b/src/cmd/go/main.go
@@ -145,24 +145,6 @@ func main() {
os.Exit(2)
}
- if err := buildcfg.Error; err != nil {
- fmt.Fprintf(os.Stderr, "go: %v\n", buildcfg.Error)
- os.Exit(2)
- }
-
- // Set environment (GOOS, GOARCH, etc) explicitly.
- // In theory all the commands we invoke should have
- // the same default computation of these as we do,
- // but in practice there might be skew
- // This makes sure we all agree.
- cfg.OrigEnv = os.Environ()
- cfg.CmdEnv = envcmd.MkEnv()
- for _, env := range cfg.CmdEnv {
- if os.Getenv(env.Name) != env.Value {
- os.Setenv(env.Name, env.Value)
- }
- }
-
BigCmdLoop:
for bigCmd := base.Go; ; {
for _, cmd := range bigCmd.Commands {
@@ -188,18 +170,7 @@ BigCmdLoop:
if !cmd.Runnable() {
continue
}
- cmd.Flag.Usage = func() { cmd.Usage() }
- if cmd.CustomFlags {
- args = args[1:]
- } else {
- base.SetFromGOFLAGS(&cmd.Flag)
- cmd.Flag.Parse(args[1:])
- args = cmd.Flag.Args()
- }
- ctx := maybeStartTrace(context.Background())
- ctx, span := trace.StartSpan(ctx, fmt.Sprint("Running ", cmd.Name(), " command"))
- cmd.Run(ctx, cmd, args)
- span.Done()
+ invoke(cmd, args)
base.Exit()
return
}
@@ -213,6 +184,39 @@ BigCmdLoop:
}
}
+func invoke(cmd *base.Command, args []string) {
+ // 'go env' handles checking the build config
+ if cmd != envcmd.CmdEnv {
+ buildcfg.Check()
+ }
+
+ // Set environment (GOOS, GOARCH, etc) explicitly.
+ // In theory all the commands we invoke should have
+ // the same default computation of these as we do,
+ // but in practice there might be skew
+ // This makes sure we all agree.
+ cfg.OrigEnv = os.Environ()
+ cfg.CmdEnv = envcmd.MkEnv()
+ for _, env := range cfg.CmdEnv {
+ if os.Getenv(env.Name) != env.Value {
+ os.Setenv(env.Name, env.Value)
+ }
+ }
+
+ cmd.Flag.Usage = func() { cmd.Usage() }
+ if cmd.CustomFlags {
+ args = args[1:]
+ } else {
+ base.SetFromGOFLAGS(&cmd.Flag)
+ cmd.Flag.Parse(args[1:])
+ args = cmd.Flag.Args()
+ }
+ ctx := maybeStartTrace(context.Background())
+ ctx, span := trace.StartSpan(ctx, fmt.Sprint("Running ", cmd.Name(), " command"))
+ cmd.Run(ctx, cmd, args)
+ span.Done()
+}
+
func init() {
base.Usage = mainUsage
}