-
-
Notifications
You must be signed in to change notification settings - Fork 662
/
cc.go
48 lines (45 loc) · 1.18 KB
/
cc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"errors"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"syscall"
)
func cc(args []string) error {
cc := os.Getenv("GO_CC")
if cc == "" {
return errors.New("GO_CC environment variable not set")
}
ccroot := os.Getenv("GO_CC_ROOT")
if ccroot == "" {
return errors.New("GO_CC_ROOT environment variable not set")
}
normalized := []string{cc}
normalized = append(normalized, args...)
transformArgs(normalized, cgoAbsEnvFlags, func(s string) string {
if strings.HasPrefix(s, cgoAbsPlaceholder) {
trimmed := strings.TrimPrefix(s, cgoAbsPlaceholder)
abspath := filepath.Join(ccroot, trimmed)
if _, err := os.Stat(abspath); err == nil {
// Only return the abspath if it exists, otherwise it
// means that either it won't have any effect or the original
// value was not a relpath (e.g. a path with a XCODE placehold from
// macos cc_wrapper)
return abspath
}
return trimmed
}
return s
})
if runtime.GOOS == "windows" {
cmd := exec.Command(normalized[0], normalized[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
} else {
return syscall.Exec(normalized[0], normalized, os.Environ())
}
}