Andrey Bokhanko has uploaded this change for review.
cgo: Check presence of a C compiler
Currently we print a cryptic message is a C compiler doesn't exist.
This patch adds more graceful handling.
Fixes #44271
Change-Id: I44f16ef6eb2853fee22fa1d996e41ec6c9ee82f1
---
M src/cmd/cgo/main.go
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go
index 5767c54..c7755b5 100644
--- a/src/cmd/cgo/main.go
+++ b/src/cmd/cgo/main.go
@@ -20,6 +20,7 @@
"io"
"io/ioutil"
"os"
+ "os/exec"
"path/filepath"
"reflect"
"runtime"
@@ -302,6 +303,15 @@
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 '%s' can't be found. Check that you have a C compiler "+
+ "installed and added to your PATH.", gccName)
+ os.Exit(2)
+ }
+
// Record CGO_LDFLAGS from the environment for external linking.
if ldflags := os.Getenv("CGO_LDFLAGS"); ldflags != "" {
args, err := splitQuoted(ldflags)
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Andrey Bokhanko uploaded patch set #2 to this change.
cgo: Check presence of a C compiler
Currently we print a cryptic message is a C compiler doesn't exist.
This patch adds more graceful handling.
Fixes #44271
Change-Id: I44f16ef6eb2853fee22fa1d996e41ec6c9ee82f1
---
M src/cmd/cgo/main.go
1 file changed, 10 insertions(+), 0 deletions(-)
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andrey Bokhanko, Ian Lance Taylor.
2 comments:
Patchset:
Thanks, this is good. I added Ian as a reviewer, he might have better words.
File src/cmd/cgo/main.go:
C compiler \"%s\" can't be found. Check that you have a C compiler "+
"installed and added to your PATH.
Definitely an improvement. I think I would add mention of cgo so that when cgo is invoked behind the curtains (for example, in the case of race detection), it provides a clue to reduce the size of a user's problem space.
So, maybe:
"C compiler \"%s\" can't be found for cgo command. Check that you have a C compiler "+
"installed and added to your PATH."
Ian, or you, may have a better way to phrase this.
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: David Chase, Ian Lance Taylor.
1 comment:
File src/cmd/cgo/main.go:
C compiler \"%s\" can't be found. Check that you have a C compiler "+
"installed and added to your PATH.
Definitely an improvement. […]
Thanks!
As for mentioning cgo, fatalf already prints "cgo:" prefix, so on my Linux box the message looks like this:
cgo: C compiler "gcc" can't be found. Check that you have a C compiler installed and added to your PATH.
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andrey Bokhanko, Ian Lance Taylor.
Patch set 2:Code-Review +2
1 comment:
File src/cmd/cgo/main.go:
C compiler \"%s\" can't be found. Check that you have a C compiler "+
"installed and added to your PATH.
Thanks! […]
Great!
I'd like to wait a hair longer for Ian, but for now, LGTM.
Actually I think we have to anyway, might need a second "trust" vote, not sure.
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andrey Bokhanko.
3 comments:
Commit Message:
Patch Set #2, Line 7: cgo: Check presence of a C compiler
cmd/cgo: check whether C compiler exists
File src/cmd/cgo/main.go:
Patch Set #2, Line 310: fatalf("C compiler \"%s\" can't be found. Check that you have a C compiler "+
Use %q instead of \"%s\".
Also no need for a line break here, there is no line length limit.
Patch Set #2, Line 311: "installed and added to your PATH.", gccName)
I think a message like
fatalf("C compiler %q not found: %v", gccName, err)
will suffice. The error returned by exec.LookPath will help.
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andrey Bokhanko.
Andrey Bokhanko uploaded patch set #3 to this change.
cgo: Check presence of a C compiler
Currently we print a cryptic message if a C compiler doesn't exist.
This patch adds more graceful handling.
Fixes #44271
Change-Id: I44f16ef6eb2853fee22fa1d996e41ec6c9ee82f1
---
M src/cmd/cgo/main.go
1 file changed, 9 insertions(+), 0 deletions(-)
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor.
2 comments:
Patchset:
Ian, thanks for the review! Fixed you comment; please take a look.
File src/cmd/cgo/main.go:
Patch Set #2, Line 311: "installed and added to your PATH.", gccName)
I think a message like […]
Done as you suggested. Now the message looks like so (on my Linux box):
$ export CC=clang
$ go build ./issue44271.go
# runtime/cgo
cgo: C compiler "clang" not found: exec: "clang": executable file not found in $PATH
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor.
1 comment:
File src/cmd/cgo/main.go:
Patch Set #2, Line 310: fatalf("C compiler \"%s\" can't be found. Check that you have a C compiler "+
Use %q instead of \"%s\". […]
Fixed
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andrey Bokhanko.
1 comment:
Commit Message:
Patch Set #2, Line 7: cgo: Check presence of a C compiler
cmd/cgo: check whether C compiler exists
Please update the topic sentence as suggested. Thanks. See https://golang.org/wiki/CommitMessage.
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andrey Bokhanko.
Andrey Bokhanko uploaded patch set #4 to this change.
cgo: check whether C compiler exists
Currently we print a cryptic message if a C compiler doesn't exist.
This patch adds more graceful handling.
Fixes #44271
Change-Id: I44f16ef6eb2853fee22fa1d996e41ec6c9ee82f1
---
M src/cmd/cgo/main.go
1 file changed, 9 insertions(+), 0 deletions(-)
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor.
1 comment:
Commit Message:
Patch Set #2, Line 7: cgo: Check presence of a C compiler
Please update the topic sentence as suggested. Thanks. See https://golang.org/wiki/CommitMessage.
Done
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Ian Lance Taylor.
Andrey Bokhanko uploaded patch set #5 to this change.
cmd/cgo: check whether C compiler exists
Currently we print a cryptic message if a C compiler doesn't exist.
This patch adds more graceful handling.
Fixes #44271
Change-Id: I44f16ef6eb2853fee22fa1d996e41ec6c9ee82f1
---
M src/cmd/cgo/main.go
1 file changed, 9 insertions(+), 0 deletions(-)
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Andrey Bokhanko.
Patch set 5:Run-TryBot +1
Attention is currently required from: Andrey Bokhanko.
Patch set 5:Code-Review +2
1 comment:
Patchset:
Thanks.
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.
Ian Lance Taylor submitted this change.
cmd/cgo: check whether C compiler exists
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 <ia...@golang.org>
TryBot-Result: Go Bot <go...@golang.org>
Reviewed-by: Ian Lance Taylor <ia...@golang.org>
Reviewed-by: David Chase <drc...@google.com>
---
M src/cmd/cgo/main.go
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go
index 5767c54..77ac5e0 100644
--- a/src/cmd/cgo/main.go
+++ b/src/cmd/cgo/main.go
@@ -20,6 +20,7 @@
"io"
"io/ioutil"
"os"
+ "os/exec"
"path/filepath"
"reflect"
"runtime"
@@ -302,6 +303,14 @@
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)
To view, visit change 301249. To unsubscribe, or for help writing mail filters, visit settings.