go/loader: use build.AllowVendor during Import on Go 1.6 and later

Makes programs like ssadump work on packages using vendored code,
for example net/http.

For golang/go#12278.
Depends on CL 17726 in main repository.

Change-Id: Ibabf564e397044a0f449087124dd96161081baaf
Reviewed-on: https://go-review.googlesource.com/17727
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Russ Cox 2015-12-11 00:00:02 -05:00
parent 1cdaff4a02
commit 34ae141ecc
3 changed files with 24 additions and 1 deletions

View File

@ -458,8 +458,9 @@ func (conf *Config) Load() (*Program, error) {
conf.FindPackage = func(ctxt *build.Context, path string) (*build.Package, error) { conf.FindPackage = func(ctxt *build.Context, path string) (*build.Package, error) {
// TODO(adonovan): cache calls to build.Import // TODO(adonovan): cache calls to build.Import
// so we don't do it three times per test package. // so we don't do it three times per test package.
// (Note that this is difficult due to vendoring.)
ioLimit <- true ioLimit <- true
bp, err := ctxt.Import(path, conf.Cwd, 0) bp, err := ctxt.Import(path, conf.Cwd, importMode)
<-ioLimit <-ioLimit
if _, ok := err.(*build.NoGoError); ok { if _, ok := err.(*build.NoGoError); ok {
return bp, nil // empty directory is not an error return bp, nil // empty directory is not an error

11
go/loader/loader_go15.go Normal file
View File

@ -0,0 +1,11 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !go1.6
package loader
import "go/build"
var importMode build.ImportMode = 0

11
go/loader/loader_go16.go Normal file
View File

@ -0,0 +1,11 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build go1.6
package loader
import "go/build"
var importMode build.ImportMode = build.AllowVendor