]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: avoid indexing GOROOT packages when the compiler is 'gccgo'
authorBryan C. Mills <bcmills@google.com>
Tue, 12 Jul 2022 14:48:47 +0000 (10:48 -0400)
committerBryan Mills <bcmills@google.com>
Tue, 12 Jul 2022 21:54:02 +0000 (21:54 +0000)
The gccgo compiler does not load standard-library packages from
GOROOT/src, so we cannot load those packages from the GOROOT/src
index when using that compiler.

This fixes TestScript/gccgo_link_c (and perhaps other gccgo tests)
when a 'gccgo' executable is present. Unfortunately, only a few
builders caught the broken test because 'gccgo' is not installed
on most Go project builders (see #35786).

For #53577.
Fixes #53815.

Change-Id: I11a5cf6dbf4ac9893c4d02bd6ab7ef60f67b1e87
Reviewed-on: https://go-review.googlesource.com/c/go/+/417094
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/internal/modindex/read.go
src/go/build/build.go

index 38ddfec70fb53d7dde07be097ee3e72f854fa040..707f17e1ab56147069d8dccbe078eaf236a0fa03 100644 (file)
@@ -139,6 +139,9 @@ func GetPackage(modroot, pkgdir string) (*IndexPackage, error) {
        if !errors.Is(err, errNotFromModuleCache) {
                return nil, err
        }
+       if cfg.BuildContext.Compiler == "gccgo" && str.HasPathPrefix(modroot, cfg.GOROOTsrc) {
+               return nil, err // gccgo has no sources for GOROOT packages.
+       }
        return openIndexPackage(modroot, pkgdir)
 }
 
index bfe3f444ca714bfbd49b946a79ae11ac89124bf8..dfb37b8f3435a68f2ec1b2d808c2a1cee4c313b9 100644 (file)
@@ -715,6 +715,9 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
                                tried.goroot = dir
                        }
                        if ctxt.Compiler == "gccgo" && goroot.IsStandardPackage(ctxt.GOROOT, ctxt.Compiler, path) {
+                               // TODO(bcmills): Setting p.Dir here is misleading, because gccgo
+                               // doesn't actually load its standard-library packages from this
+                               // directory. See if we can leave it unset.
                                p.Dir = ctxt.joinPath(ctxt.GOROOT, "src", path)
                                p.Goroot = true
                                p.Root = ctxt.GOROOT