]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: check whether C compiler exists
authorAndrey Bokhanko <andreybokhanko@gmail.com>
Fri, 12 Mar 2021 16:21:18 +0000 (00:21 +0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 17 Mar 2021 20:29:22 +0000 (20:29 +0000)
Currently we print a cryptic message if a C compiler doesn't exist.
This patch adds more graceful handling.

Fixes #44271

Change-Id: I44f16ef6eb2853fee22fa1d996e41ec6c9ee82f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/301249
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/cgo/main.go

index 5767c54307b3dc88455e8d05293b8165c1fdc29b..77ac5e0d3a7f3dca1354724bc71101706b8c8d14 100644 (file)
@@ -20,6 +20,7 @@ import (
        "io"
        "io/ioutil"
        "os"
+       "os/exec"
        "path/filepath"
        "reflect"
        "runtime"
@@ -302,6 +303,14 @@ func main() {
 
        p := newPackage(args[:i])
 
+       // We need a C compiler to be available. Check this.
+       gccName := p.gccBaseCmd()[0]
+       _, err := exec.LookPath(gccName)
+       if err != nil {
+               fatalf("C compiler %q not found: %v", gccName, err)
+               os.Exit(2)
+       }
+
        // Record CGO_LDFLAGS from the environment for external linking.
        if ldflags := os.Getenv("CGO_LDFLAGS"); ldflags != "" {
                args, err := splitQuoted(ldflags)