From 6d4da06d3647607081819e444be60259225d0efe Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Sat, 10 Mar 2012 03:42:23 +0800 Subject: [PATCH] cmd/dist, cmd/go: move CGO_ENABLED from 'go tool dist env' to 'go env' So that we don't duplicate knowledge about which OS/ARCH combination supports cgo. Also updated src/run.bash and src/sudo.bash to use 'go env'. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5792055 --- src/cmd/dist/build.c | 18 ------------------ src/cmd/go/env.go | 6 ++++++ src/run.bash | 2 +- src/sudo.bash | 2 +- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c index d5fcfbedb30..acd7347aa89 100644 --- a/src/cmd/dist/build.c +++ b/src/cmd/dist/build.c @@ -52,19 +52,6 @@ static char *okgoos[] = { "windows", }; -// The known cgo-enabled combinations. -// This list is also known to ../../pkg/go/build/build.go. -static char *okcgo[] = { - "darwin/386", - "darwin/amd64", - "linux/386", - "linux/amd64", - "freebsd/386", - "freebsd/amd64", - "windows/386", - "windows/amd64", -}; - static void rmworkdir(void); // find reports the first index of p in l[0:n], or else -1. @@ -1321,11 +1308,6 @@ cmdenv(int argc, char **argv) xprintf(format, "GOTOOLDIR", tooldir); xprintf(format, "GOCHAR", gochar); - if(find(bprintf(&b, "%s/%s", goos, goarch), okcgo, nelem(okcgo)) >= 0) - xprintf(format, "CGO_ENABLED", "1"); - else - xprintf(format, "CGO_ENABLED", "0"); - if(pflag) { sep = ":"; if(streq(gohostos, "windows")) diff --git a/src/cmd/go/env.go b/src/cmd/go/env.go index 804dc8e63fd..d5b0348096c 100644 --- a/src/cmd/go/env.go +++ b/src/cmd/go/env.go @@ -45,6 +45,12 @@ func mkEnv() []envVar { {"GOGCCFLAGS", strings.Join(b.gccCmd(".")[3:], " ")}, } + if buildContext.CgoEnabled { + env = append(env, envVar{"CGO_ENABLED", "1"}) + } else { + env = append(env, envVar{"CGO_ENABLED", "0"}) + } + return env } diff --git a/src/run.bash b/src/run.bash index 0e4600b0adb..430ee76dbae 100755 --- a/src/run.bash +++ b/src/run.bash @@ -5,7 +5,7 @@ set -e -eval $(go tool dist env) +eval $(go env) unset CDPATH # in case user has it set diff --git a/src/sudo.bash b/src/sudo.bash index 78cdb0b8a77..cccebd34277 100755 --- a/src/sudo.bash +++ b/src/sudo.bash @@ -17,7 +17,7 @@ if [[ ! -d /usr/local/bin ]]; then exit 2 fi -eval $(go tool dist env) +eval $(go env) cd $(dirname $0) for i in prof cov do