...
1
2
3
4
5
6
7 package toolchain
8
9 import (
10 "cmd/go/internal/base"
11 "internal/godebug"
12 "os"
13 "os/exec"
14 "runtime"
15 "syscall"
16 )
17
18
19
20
21
22 func execGoToolchain(gotoolchain, dir, exe string) {
23 os.Setenv(targetEnv, gotoolchain)
24 if dir == "" {
25 os.Unsetenv("GOROOT")
26 } else {
27 os.Setenv("GOROOT", dir)
28 }
29
30
31
32
33
34
35
36 if godebug.New("#gotoolchainexec").Value() == "0" || runtime.GOOS == "windows" {
37 cmd := exec.Command(exe, os.Args[1:]...)
38 cmd.Stdin = os.Stdin
39 cmd.Stdout = os.Stdout
40 cmd.Stderr = os.Stderr
41 err := cmd.Run()
42 if err != nil {
43 if e, ok := err.(*exec.ExitError); ok && e.ProcessState != nil {
44 if e.ProcessState.Exited() {
45 os.Exit(e.ProcessState.ExitCode())
46 }
47 base.Fatalf("exec %s: %s", gotoolchain, e.ProcessState)
48 }
49 base.Fatalf("exec %s: %s", exe, err)
50 }
51 os.Exit(0)
52 }
53 err := syscall.Exec(exe, os.Args, os.Environ())
54 base.Fatalf("exec %s: %v", gotoolchain, err)
55 }
56
View as plain text