Merge pull request #105170 from liggitt/gomodule-importverifier

Make importverifier package-compatible
This commit is contained in:
Kubernetes Prow Robot 2021-09-21 14:08:49 -07:00 committed by GitHub
commit 2bfb2eba80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -230,9 +230,26 @@ func loadImportRestrictions(configFile string) ([]ImportRestriction, error) {
}
func resolvePackageTree(treeBase string) ([]Package, error) {
// try resolving with $cwd
packages, err := resolvePackageTreeInDir("", treeBase)
if err != nil || len(packages) == 0 {
// if that fails or finds no packages, resolve under ./vendor/$treeBase
stagingPackages, stagingErr := resolvePackageTreeInDir(filepath.Join("./vendor", treeBase), treeBase)
if stagingErr == nil && len(stagingPackages) > 0 {
// if that succeeds, return
return stagingPackages, stagingErr
}
}
// otherwise, return original packages and error
return packages, err
}
func resolvePackageTreeInDir(dir string, treeBase string) ([]Package, error) {
cmd := "go"
args := []string{"list", "-json", fmt.Sprintf("%s...", treeBase)}
stdout, err := exec.Command(cmd, args...).Output()
c := exec.Command(cmd, args...)
c.Dir = dir
stdout, err := c.Output()
if err != nil {
var message string
if ee, ok := err.(*exec.ExitError); ok {