]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: support Import of local import path in standard library for gccgo
authorIan Lance Taylor <iant@golang.org>
Tue, 25 Sep 2018 22:16:17 +0000 (15:16 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 25 Sep 2018 23:10:02 +0000 (23:10 +0000)
It's possible for a local import path to refer to a standard library
package. This was not being correctly handled for gccgo. When using
gccgo, change the code to permit the existing lexical test, and to
accept a missing directory for a standard package found via a local
impor path.

Change-Id: Ia9829e55c0ff62e7d1f01a1d6dc9fcff521501ca
Reviewed-on: https://go-review.googlesource.com/137439
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/go/build/build.go

index 14b007c25a7a501a21b983b8135326b299dea1fc..fc8d37789f8ee6f8f18cdc4f8a978771fdbf940c 100644 (file)
@@ -544,7 +544,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
                inTestdata := func(sub string) bool {
                        return strings.Contains(sub, "/testdata/") || strings.HasSuffix(sub, "/testdata") || strings.HasPrefix(sub, "testdata/") || sub == "testdata"
                }
-               if ctxt.GOROOT != "" && ctxt.Compiler != "gccgo" {
+               if ctxt.GOROOT != "" {
                        root := ctxt.joinPath(ctxt.GOROOT, "src")
                        if sub, ok := ctxt.hasSubdir(root, p.Dir); ok && !inTestdata(sub) {
                                p.Goroot = true
@@ -715,6 +715,11 @@ Found:
        // non-nil *Package returned when an error occurs.
        // We need to do this before we return early on FindOnly flag.
        if IsLocalImport(path) && !ctxt.isDir(p.Dir) {
+               if ctxt.Compiler == "gccgo" && p.Goroot {
+                       // gccgo has no sources for GOROOT packages.
+                       return p, nil
+               }
+
                // package was not found
                return p, fmt.Errorf("cannot find package %q in:\n\t%s", path, p.Dir)
        }