Normalise module paths for use on Windows too

Этот коммит содержится в:
Gavin Taylor 2020-03-03 18:12:19 +00:00
родитель 9a9954aaef
коммит b398ce8066

Просмотреть файл

@ -238,6 +238,9 @@ func maybeVendoredGodog() *build.Package {
return nil return nil
} }
func normaliseLocalImportPath(dir string) string {
return path.Join("_", strings.Map(makeImportValid, filepath.ToSlash(dir)))
}
func importPackage(dir string) *build.Package { func importPackage(dir string) *build.Package {
pkg, _ := build.ImportDir(dir, 0) pkg, _ := build.ImportDir(dir, 0)
@ -245,7 +248,7 @@ func importPackage(dir string) *build.Package {
// taken from go source code // taken from go source code
// see: https://github.com/golang/go/blob/go1.7rc5/src/cmd/go/pkg.go#L279 // see: https://github.com/golang/go/blob/go1.7rc5/src/cmd/go/pkg.go#L279
if pkg != nil && pkg.ImportPath == "." { if pkg != nil && pkg.ImportPath == "." {
pkg.ImportPath = path.Join("_", strings.Map(makeImportValid, filepath.ToSlash(dir))) pkg.ImportPath = normaliseLocalImportPath(dir)
} }
return pkg return pkg
@ -376,7 +379,7 @@ func parseImport(rawPath, rootPath string) string {
return rawPath return rawPath
} }
// Concatenates the module path with the current sub-folders if needed // Concatenates the module path with the current sub-folders if needed
return mod.Path + filepath.ToSlash(strings.TrimPrefix(strings.TrimPrefix(rawPath, "_"), mod.Dir)) return mod.Path + filepath.ToSlash(strings.TrimPrefix(rawPath, normaliseLocalImportPath(mod.Dir)))
} }
// processPackageTestFiles runs through ast of each test // processPackageTestFiles runs through ast of each test