mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
tools: fallout from flipped sense of build.IgnoreVendor flag
(See https://go-review.googlesource.com/#/c/18450) Details: - delete buildutil.AllowVendor flag. Instead use unexported 'go16' var in each package that needs it. - delete buildutil.StripVendor; was never needed. - remove inapplicable vendoring comments from loader14.go - importgraph: go1.5: don't bother checking for 1.6 before calling absolutize (minor simplifiication and deoptimization). Tested on 1.4.1, 1.5, and ~1.6 (tip). Change-Id: If692b0df2eb6c120a9c09d7b1ed99f1b4c6b0826 Reviewed-on: https://go-review.googlesource.com/18452 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
dd6e749ee1
commit
10712091e1
@ -1,14 +0,0 @@
|
||||
// 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 buildutil
|
||||
|
||||
import "go/build"
|
||||
|
||||
// AllowVendor is a synonym for zero.
|
||||
// It allows applications to refer to the go/build.AllowVendor
|
||||
// feature whether or not it is supported.
|
||||
const AllowVendor build.ImportMode = 0
|
@ -1,14 +0,0 @@
|
||||
// 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 buildutil
|
||||
|
||||
import "go/build"
|
||||
|
||||
// AllowVendor is a synonym for go/build.AllowVendor.
|
||||
// It allows applications to refer to the AllowVendor
|
||||
// feature whether or not it is supported.
|
||||
const AllowVendor build.ImportMode = build.AllowVendor
|
14
go/buildutil/go16_test.go
Normal file
14
go/buildutil/go16_test.go
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
// Incomplete source tree on Android.
|
||||
|
||||
// +build !android
|
||||
// +build go1.6
|
||||
|
||||
package buildutil_test
|
||||
|
||||
func init() {
|
||||
go16 = true
|
||||
}
|
@ -90,15 +90,6 @@ func dirHasPrefix(dir, prefix string) bool {
|
||||
return len(dir) >= len(prefix) && strings.EqualFold(dir[:len(prefix)], prefix)
|
||||
}
|
||||
|
||||
// StripVendor removes the "vendor" segment and all preceding ones
|
||||
// from a slash-segmented path. (See go/build.AllowVendor.)
|
||||
func StripVendor(path string) string {
|
||||
if i := strings.LastIndex(path, "/vendor/"); i >= 0 {
|
||||
return path[i+len("/vendor/"):]
|
||||
}
|
||||
return strings.TrimPrefix(path, "vendor/")
|
||||
}
|
||||
|
||||
// -- Effective methods of file system interface -------------------------
|
||||
|
||||
// (go/build.Context defines these as methods, but does not export them.)
|
||||
|
@ -18,6 +18,8 @@ import (
|
||||
"golang.org/x/tools/go/buildutil"
|
||||
)
|
||||
|
||||
var go16 bool // Go version >= go1.6
|
||||
|
||||
func TestContainingPackage(t *testing.T) {
|
||||
// unvirtualized:
|
||||
goroot := runtime.GOROOT()
|
||||
@ -31,7 +33,7 @@ func TestContainingPackage(t *testing.T) {
|
||||
"golang.org/x/tools/go/buildutil"},
|
||||
}
|
||||
// TODO(adonovan): simplify after Go 1.6.
|
||||
if buildutil.AllowVendor != 0 {
|
||||
if go16 {
|
||||
tests = append(tests, [2]string{
|
||||
gopath + "/src/vendor/golang.org/x/net/http2/hpack/hpack.go",
|
||||
"vendor/golang.org/x/net/http2/hpack",
|
||||
@ -51,22 +53,3 @@ func TestContainingPackage(t *testing.T) {
|
||||
|
||||
// TODO(adonovan): test on virtualized GOPATH too.
|
||||
}
|
||||
|
||||
func TestStripVendor(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
path, want string
|
||||
}{
|
||||
{"", ""},
|
||||
{"a", "a"},
|
||||
{"a/b", "a/b"},
|
||||
{"a/vendor/b", "b"},
|
||||
{"a/b/vendor/c/d", "c/d"},
|
||||
{"vendor/a/b", "a/b"},
|
||||
{"a/vendor", "a/vendor"},
|
||||
} {
|
||||
if got := buildutil.StripVendor(test.path); got != test.want {
|
||||
t.Errorf("StripVendor(%q) = %q, want %q",
|
||||
test.path, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
go/loader/go16.go
Normal file
13
go/loader/go16.go
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2013 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"
|
||||
|
||||
func init() {
|
||||
ignoreVendor = build.IgnoreVendor
|
||||
}
|
12
go/loader/go16_test.go
Normal file
12
go/loader/go16_test.go
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright 2013 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
|
||||
// +build !android
|
||||
|
||||
package loader_test
|
||||
|
||||
func init() {
|
||||
go16 = true
|
||||
}
|
@ -23,9 +23,10 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/tools/go/ast/astutil"
|
||||
"golang.org/x/tools/go/buildutil"
|
||||
)
|
||||
|
||||
var ignoreVendor build.ImportMode
|
||||
|
||||
const trace = false // show timing info for type-checking
|
||||
|
||||
// Config specifies the configuration for loading a whole program from
|
||||
@ -503,7 +504,7 @@ func (conf *Config) Load() (*Program, error) {
|
||||
// Load the initially imported packages and their dependencies,
|
||||
// in parallel.
|
||||
// No vendor check on packages imported from the command line.
|
||||
infos, importErrors := imp.importAll("", conf.Cwd, conf.ImportPkgs, 0)
|
||||
infos, importErrors := imp.importAll("", conf.Cwd, conf.ImportPkgs, ignoreVendor)
|
||||
for _, ie := range importErrors {
|
||||
conf.TypeChecker.Error(ie.err) // failed to create package
|
||||
errpkgs = append(errpkgs, ie.path)
|
||||
@ -521,7 +522,7 @@ func (conf *Config) Load() (*Program, error) {
|
||||
}
|
||||
|
||||
// No vendor check on packages imported from command line.
|
||||
bp, err := imp.findPackage(importPath, conf.Cwd, 0)
|
||||
bp, err := imp.findPackage(importPath, conf.Cwd, ignoreVendor)
|
||||
if err != nil {
|
||||
// Package not found, or can't even parse package declaration.
|
||||
// Already reported by previous loop; ignore it.
|
||||
@ -768,7 +769,7 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err
|
||||
from.Pkg.Path())
|
||||
}
|
||||
|
||||
bp, err := imp.findPackage(to, from.dir, buildutil.AllowVendor)
|
||||
bp, err := imp.findPackage(to, from.dir, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -966,7 +967,7 @@ func (imp *importer) addFiles(info *PackageInfo, files []*ast.File, cycleCheck b
|
||||
}
|
||||
// TODO(adonovan): opt: make the caller do scanImports.
|
||||
// Callers with a build.Package can skip it.
|
||||
imp.importAll(fromPath, info.dir, scanImports(files), buildutil.AllowVendor)
|
||||
imp.importAll(fromPath, info.dir, scanImports(files), 0)
|
||||
|
||||
if trace {
|
||||
fmt.Fprintf(os.Stderr, "%s: start %q (%d)\n",
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"time"
|
||||
|
||||
"golang.org/x/tools/go/ast/astutil"
|
||||
"golang.org/x/tools/go/buildutil"
|
||||
"golang.org/x/tools/go/types"
|
||||
)
|
||||
|
||||
@ -502,7 +501,6 @@ func (conf *Config) Load() (*Program, error) {
|
||||
|
||||
// Load the initially imported packages and their dependencies,
|
||||
// in parallel.
|
||||
// No vendor check on packages imported from the command line.
|
||||
infos, importErrors := imp.importAll("", conf.Cwd, conf.ImportPkgs, 0)
|
||||
for _, ie := range importErrors {
|
||||
conf.TypeChecker.Error(ie.err) // failed to create package
|
||||
@ -520,7 +518,6 @@ func (conf *Config) Load() (*Program, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
// No vendor check on packages imported from command line.
|
||||
bp, err := imp.findPackage(importPath, conf.Cwd, 0)
|
||||
if err != nil {
|
||||
// Package not found, or can't even parse package declaration.
|
||||
@ -768,7 +765,7 @@ func (imp *importer) doImport(from *PackageInfo, to string) (*types.Package, err
|
||||
from.Pkg.Path())
|
||||
}
|
||||
|
||||
bp, err := imp.findPackage(to, from.dir, buildutil.AllowVendor)
|
||||
bp, err := imp.findPackage(to, from.dir, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -966,7 +963,7 @@ func (imp *importer) addFiles(info *PackageInfo, files []*ast.File, cycleCheck b
|
||||
}
|
||||
// TODO(adonovan): opt: make the caller do scanImports.
|
||||
// Callers with a build.Package can skip it.
|
||||
imp.importAll(fromPath, info.dir, scanImports(files), buildutil.AllowVendor)
|
||||
imp.importAll(fromPath, info.dir, scanImports(files), 0)
|
||||
|
||||
if trace {
|
||||
fmt.Fprintf(os.Stderr, "%s: start %q (%d)\n",
|
||||
|
@ -24,6 +24,8 @@ import (
|
||||
"golang.org/x/tools/go/loader"
|
||||
)
|
||||
|
||||
var go16 bool // Go version >= go1.6
|
||||
|
||||
// TestFromArgs checks that conf.FromArgs populates conf correctly.
|
||||
// It does no I/O.
|
||||
func TestFromArgs(t *testing.T) {
|
||||
@ -396,7 +398,7 @@ func TestCwd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoad_vendor(t *testing.T) {
|
||||
if buildutil.AllowVendor == 0 {
|
||||
if !go16 {
|
||||
// Vendoring requires Go 1.6.
|
||||
// TODO(adonovan): delete in due course.
|
||||
t.Skip()
|
||||
@ -434,7 +436,7 @@ func TestLoad_vendor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVendorCwd(t *testing.T) {
|
||||
if buildutil.AllowVendor == 0 {
|
||||
if !go16 {
|
||||
// Vendoring requires Go 1.6.
|
||||
// TODO(adonovan): delete in due course.
|
||||
t.Skip()
|
||||
|
12
refactor/importgraph/go16_test.go
Normal file
12
refactor/importgraph/go16_test.go
Normal file
@ -0,0 +1,12 @@
|
||||
// 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 !android
|
||||
// +build go1.6
|
||||
|
||||
package importgraph_test
|
||||
|
||||
func init() {
|
||||
go16 = true
|
||||
}
|
@ -82,7 +82,7 @@ func Build(ctxt *build.Context) (forward, reverse Graph, errors map[string]error
|
||||
defer wg.Done()
|
||||
|
||||
sema <- 1
|
||||
bp, err := ctxt.Import(path, "", buildutil.AllowVendor)
|
||||
bp, err := ctxt.Import(path, "", 0)
|
||||
<-sema
|
||||
|
||||
if err != nil {
|
||||
@ -105,25 +105,22 @@ func Build(ctxt *build.Context) (forward, reverse Graph, errors map[string]error
|
||||
// 840ms: nonblocking cache with duplicate suppression
|
||||
// 340ms: original code (no vendor check)
|
||||
// TODO(adonovan): optimize, somehow.
|
||||
absolutize := func(path string) string { return path }
|
||||
if buildutil.AllowVendor != 0 {
|
||||
memo := make(map[string]string)
|
||||
absolutize = func(path string) string {
|
||||
canon, ok := memo[path]
|
||||
if !ok {
|
||||
sema <- 1
|
||||
bp2, _ := ctxt.Import(path, bp.Dir, build.FindOnly|buildutil.AllowVendor)
|
||||
<-sema
|
||||
memo := make(map[string]string)
|
||||
absolutize := func(path string) string {
|
||||
canon, ok := memo[path]
|
||||
if !ok {
|
||||
sema <- 1
|
||||
bp2, _ := ctxt.Import(path, bp.Dir, build.FindOnly)
|
||||
<-sema
|
||||
|
||||
if bp2 != nil {
|
||||
canon = bp2.ImportPath
|
||||
} else {
|
||||
canon = path
|
||||
}
|
||||
memo[path] = canon
|
||||
if bp2 != nil {
|
||||
canon = bp2.ImportPath
|
||||
} else {
|
||||
canon = path
|
||||
}
|
||||
return canon
|
||||
memo[path] = canon
|
||||
}
|
||||
return canon
|
||||
}
|
||||
|
||||
if bp != nil {
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/go/buildutil"
|
||||
"golang.org/x/tools/refactor/importgraph"
|
||||
|
||||
_ "crypto/hmac" // just for test, below
|
||||
@ -23,6 +22,8 @@ import (
|
||||
|
||||
const this = "golang.org/x/tools/refactor/importgraph"
|
||||
|
||||
var go16 bool // Go version >= go1.6
|
||||
|
||||
func TestBuild(t *testing.T) {
|
||||
forward, reverse, errors := importgraph.Build(&build.Default)
|
||||
|
||||
@ -49,7 +50,7 @@ func TestBuild(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test vendor packages appear under their absolute names.
|
||||
if buildutil.AllowVendor != 0 { // hack: Go 1.6+ only
|
||||
if go16 { // hack: Go 1.6+ only
|
||||
if !forward["net/http"]["vendor/golang.org/x/net/http2/hpack"] {
|
||||
t.Errorf("forward[net/http] does not include vendor/golang.org/x/net/http2/hpack: %v",
|
||||
strings.Replace(fmt.Sprint(forward["net/http"]), ":true", "", -1))
|
||||
|
Loading…
x
Reference in New Issue
Block a user