From: Ian Lance Taylor Date: Tue, 25 Sep 2018 22:16:17 +0000 (-0700) Subject: go/build: support Import of local import path in standard library for gccgo X-Git-Tag: go1.12beta1~1007 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=699da6bd134c22ac174ec1accae9ae8218f873f7;p=gostls13.git go/build: support Import of local import path in standard library for gccgo 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 Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/go/build/build.go b/src/go/build/build.go index 14b007c25a..fc8d37789f 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -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) }