mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
go/packages: remove dependency on imports
Copy imports.VendorlessPath into go/packages to avoid an unnecessary dependency on imports. Change-Id: Ie77c2fb87f2199f139ece9f3d1b707f065fc1a79 Reviewed-on: https://go-review.googlesource.com/128996 Reviewed-by: Michael Matloob <matloob@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
af5e78811a
commit
00d4fcd841
@ -16,7 +16,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/internal/cgo"
|
||||
"golang.org/x/tools/imports"
|
||||
)
|
||||
|
||||
// TODO(matloob): Delete this file once Go 1.12 is released.
|
||||
@ -62,7 +61,7 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error)
|
||||
}
|
||||
continue
|
||||
}
|
||||
importMap[imports.VendorlessPath(id)] = &Package{ID: id}
|
||||
importMap[vendorlessPath(id)] = &Package{ID: id}
|
||||
}
|
||||
return importMap
|
||||
}
|
||||
@ -172,6 +171,20 @@ func golistDriverFallback(cfg *Config, words ...string) (*driverResponse, error)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
// vendorlessPath returns the devendorized version of the import path ipath.
|
||||
// For example, VendorlessPath("foo/bar/vendor/a/b") returns "a/b".
|
||||
// Copied from golang.org/x/tools/imports/fix.go.
|
||||
func vendorlessPath(ipath string) string {
|
||||
// Devendorize for use in import statement.
|
||||
if i := strings.LastIndex(ipath, "/vendor/"); i >= 0 {
|
||||
return ipath[i+len("/vendor/"):]
|
||||
}
|
||||
if strings.HasPrefix(ipath, "vendor/") {
|
||||
return ipath[len("vendor/"):]
|
||||
}
|
||||
return ipath
|
||||
}
|
||||
|
||||
// getDeps runs an initial go list to determine all the dependency packages.
|
||||
func getDeps(cfg *Config, words ...string) (originalSet map[string]*jsonPackage, deps []string, err error) {
|
||||
buf, err := golist(cfg, golistArgsFallback(cfg, words))
|
||||
|
Loading…
x
Reference in New Issue
Block a user