From 1fbfc2f6eba6cc88a8fb0ae8e83afe80553f65df Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 22 Nov 2022 15:31:06 -0500 Subject: [PATCH] cmd/go: fix the DefaultCC check if CC is an absolute file missing an extension on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This undoes the code (but not test) change from CL 451219, which turns out to be slightly harmful on Windows (because it doesn't resolve the file extension for an absolute CC path) and unnecessary elsewhere (because calling LookPath on a fully-resolved executable path already stats¹ that path before returning it). ¹https://cs.opensource.google/go/go/+/refs/tags/go1.19.3:src/os/exec/lp_unix.go;l=46;drc=027855e8d86f461b50946b006ea032d4b4a7d817 Change-Id: If8c5ba59cbcc9fc289e9325afb9ccdadf374b102 Reviewed-on: https://go-review.googlesource.com/c/go/+/452777 Reviewed-by: Michael Matloob TryBot-Result: Gopher Robot Reviewed-by: Russ Cox Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills --- src/cmd/go/internal/cfg/cfg.go | 9 +-------- src/cmd/go/scriptconds_test.go | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go index f71fcdaeb9..3257140515 100644 --- a/src/cmd/go/internal/cfg/cfg.go +++ b/src/cmd/go/internal/cfg/cfg.go @@ -159,14 +159,7 @@ func defaultContext() build.Context { if ctxt.CgoEnabled { if os.Getenv("CC") == "" { cc := DefaultCC(ctxt.GOOS, ctxt.GOARCH) - if filepath.IsAbs(cc) { - if _, err := os.Stat(cc); os.IsNotExist(err) { - // The default CC is an absolute path that doesn't exist. - // (Perhaps make.bash was run on a system with a C compiler - // installed, and the current system doesn't have it there.) - ctxt.CgoEnabled = false - } - } else if _, err := exec.LookPath(cc); err != nil { + if _, err := exec.LookPath(cc); err != nil { ctxt.CgoEnabled = false } } diff --git a/src/cmd/go/scriptconds_test.go b/src/cmd/go/scriptconds_test.go index 2717dbb4ae..516375021a 100644 --- a/src/cmd/go/scriptconds_test.go +++ b/src/cmd/go/scriptconds_test.go @@ -62,7 +62,7 @@ func defaultCCIsAbsolute(s *script.State) (bool, error) { GOARCH, _ := s.LookupEnv("GOARCH") defaultCC := cfg.DefaultCC(GOOS, GOARCH) if filepath.IsAbs(defaultCC) { - if _, err := os.Stat(defaultCC); err == nil { + if _, err := exec.LookPath(defaultCC); err == nil { return true, nil } } -- 2.50.0