d0050e2871
This is a followup to CL 199840 and CL 203820. Cumulatively, they caused a previously known bug to trigger more often while also nearly fixing it. This change is a small fixup to CL 199840 that resolves the known bug and prevents it from causing an additional regression in Go 1.14. Part 1 The intention in CL 199840 was to return the same error that 'go list' reported when the package wasn't located, so an early return was added. However, to determine whether the package was located or not, p.Dir was unintentionally checked instead of dir. p is initialized to &Package{ImportPath: path} at top of Context.Import, and its Dir field is never set before that line in importGo is reached. So return errors.New(errStr) was always executed whenever errStr != "". Originally, in CL 125296, the "go list" invocation did not include an '-e' flag, so it would return a non-zero exit code on packages where build constraints exclude all Go files, and importGo would return an error like "go/build: importGo import/path: unexpected output: ...". CL 199840 added an '-e' flag to the "go list" invocation, but checking the wrong dir variable caused partial package information to never get populated, and thus issue #31603 continued to occur, although with a different error message (which ironically included the location of the package that was supposedly "not found"). Now that the right dir is checked, issue #31603 is fixed. Part 2 importGo checks whether it can use the go command to find the directory of a package. In Go 1.13.x and earlier, one of the conditions to use the go command was that the source directory must be provided. CL 203820 made a change such that knowing the source directory was no longer required: // To invoke the go command, -// we must know the source directory, // ... That meant build.Import invocations where srcDir is the empty string: build.Import(path, "", build.FindOnly) Started using the go command to find the directory of the package, and started to run into issue #31603 as well. That's the #37153 regression. Since this change fixes issue #31603, it also fixes issue #37153. Part 3 There is one more thing. Delete the debugImportGo constant, it's unused. Updates #26504 (CL 125296) Updates #34752 (CL 199840) Updates #34860 (CL 203820) Fixes #31603 Fixes #37153 Change-Id: Iaa7dcc45ba0f708a978950c75fa4c836b87006f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/218817 Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
AUTHORS | ||
CONTRIBUTING.md | ||
CONTRIBUTORS | ||
favicon.ico | ||
LICENSE | ||
PATENTS | ||
README.md | ||
robots.txt | ||
SECURITY.md |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://golang.org/dl/.
After downloading a binary release, visit https://golang.org/doc/install or load doc/install.html in your web browser for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source or load doc/install-source.html in your web browser for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.