main.go
1.78 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//===- main.go - Clang compiler wrapper for building libgo ----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This is a wrapper for Clang that passes invocations with -fdump-go-spec to
// GCC, and rewrites -fplan9-extensions to -fms-extensions. It is intended to
// go away once libgo's build no longer uses these flags.
//
//===----------------------------------------------------------------------===//
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func runproc(name string, argv []string) {
path, err := exec.LookPath(name)
if err != nil {
fmt.Fprintf(os.Stderr, "cc-wrapper: could not find %s: %v\n", name, err)
os.Exit(1)
}
proc, err := os.StartProcess(path, append([]string{name}, argv...), &os.ProcAttr{
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
})
if err != nil {
fmt.Fprintf(os.Stderr, "cc-wrapper: could not start %s: %v\n", name, err)
os.Exit(1)
}
state, err := proc.Wait()
if err != nil {
fmt.Fprintf(os.Stderr, "cc-wrapper: could not wait for %s: %v\n", name, err)
os.Exit(1)
}
if state.Success() {
os.Exit(0)
} else {
os.Exit(1)
}
}
func main() {
newargs := make([]string, len(os.Args)-1)
for i, arg := range os.Args[1:] {
switch {
case strings.HasPrefix(arg, "-fdump-go-spec"):
runproc("gcc", os.Args[1:])
case arg == "-fplan9-extensions":
newargs[i] = "-fms-extensions"
newargs = append(newargs, "-Wno-microsoft")
default:
newargs[i] = arg
}
}
ccargs := strings.Split(os.Getenv("REAL_CC"), "@SPACE@")
runproc(ccargs[0], append(ccargs[1:], newargs...))
}