diff options
author | Russ Cox <rsc@golang.org> | 2016-01-27 10:05:18 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2016-01-27 18:03:15 +0000 |
commit | 4223675913762a12cd23871fbd003d8a68cb49a1 (patch) | |
tree | fcac590bd8acce00c28592540cbd313734ecedf0 /src/cmd/go/pkg.go | |
parent | 1023d63f7f0ee31f5810e3e5598227c85442a1e2 (diff) | |
download | go-git-4223675913762a12cd23871fbd003d8a68cb49a1.tar.gz |
cmd/go: refine definition of 'standard' import paths to include vendored code
The vendored copy of golang.org/x/net/http/hpack was being treated
as not standard, which in turn was making it not subject to the mtime
exception for rebuilding the standard library in a release, which in turn
was making net/http look out of date.
One fix and three tests:
- Fix the definition of standard.
- Test that everything in $GOROOT/src/ is standard during 'go test cmd/go'.
(In general there can be non-standard things in $GOROOT/src/, but this
test implies that you can do that or you can run 'go test cmd/go',
but not both. That's fine.)
- Test that 'go list std cmd' shows our vendored code.
- Enforce that no standard package can depend on a non-standard one.
Also fix a few error printing nits.
Fixes #13713.
Change-Id: I1f943f1c354174c199e9b52075c11ee44198e81b
Reviewed-on: https://go-review.googlesource.com/18978
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/go/pkg.go')
-rw-r--r-- | src/cmd/go/pkg.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go index 0507841c6b..112f820d80 100644 --- a/src/cmd/go/pkg.go +++ b/src/cmd/go/pkg.go @@ -153,7 +153,7 @@ func (p *Package) copyBuild(pp *build.Package) { p.ConflictDir = pp.ConflictDir // TODO? Target p.Goroot = pp.Goroot - p.Standard = p.Goroot && p.ImportPath != "" && !strings.Contains(p.ImportPath, ".") + p.Standard = p.Goroot && p.ImportPath != "" && isStandardImportPath(p.ImportPath) p.GoFiles = pp.GoFiles p.CgoFiles = pp.CgoFiles p.IgnoredGoFiles = pp.IgnoredGoFiles @@ -177,6 +177,19 @@ func (p *Package) copyBuild(pp *build.Package) { p.XTestImports = pp.XTestImports } +// isStandardImportPath reports whether $GOROOT/src/path should be considered +// part of the standard distribution. For historical reasons we allow people to add +// their own code to $GOROOT instead of using $GOPATH, but we assume that +// code will start with a domain name (dot in the first element). +func isStandardImportPath(path string) bool { + i := strings.Index(path, "/") + if i < 0 { + i = len(path) + } + elem := path[:i] + return !strings.Contains(elem, ".") +} + // A PackageError describes an error loading information about a package. type PackageError struct { ImportStack []string // shortest path from package named on command line to this one @@ -362,7 +375,7 @@ func loadImport(path, srcDir string, parent *Package, stk *importStack, importPo err = fmt.Errorf("code in directory %s expects import %q", bp.Dir, bp.ImportComment) } p.load(stk, bp, err) - if p.Error != nil && len(importPos) > 0 { + if p.Error != nil && p.Error.Pos == "" && len(importPos) > 0 { pos := importPos[0] pos.Filename = shortPath(pos.Filename) p.Error.Pos = pos.String() @@ -933,6 +946,17 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package } } } + if p.Standard && !p1.Standard && p.Error == nil { + p.Error = &PackageError{ + ImportStack: stk.copy(), + Err: fmt.Sprintf("non-standard import %q in standard package %q", path, p.ImportPath), + } + pos := p.build.ImportPos[path] + if len(pos) > 0 { + p.Error.Pos = pos[0].String() + } + } + path = p1.ImportPath importPaths[i] = path if i < len(p.Imports) { |