mirror of https://github.com/golang/go.git
internal/imports: clean up dead code
Now that we're storing module information per-directory, we don't need to pre-compute the need for a replace statement. And we never have the package name in the place it used to be set. Change-Id: I3b0845dc49f52f8c449840410dbb786fe903d29d Reviewed-on: https://go-review.googlesource.com/c/tools/+/212861 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
9a28a1fa70
commit
1e586a538e
|
|
@ -488,14 +488,15 @@ func (r *ModuleResolver) canonicalize(info directoryPackageInfo) (*pkg, error) {
|
|||
dirInMod := info.dir[len(mod.Dir)+len("/"):]
|
||||
importPath = path.Join(mod.Path, filepath.ToSlash(dirInMod))
|
||||
}
|
||||
} else if info.needsReplace {
|
||||
} else if !strings.HasPrefix(importPath, info.moduleName) {
|
||||
// The module's name doesn't match the package's import path. It
|
||||
// probably needs a replace directive we don't have.
|
||||
return nil, fmt.Errorf("package in %q is not valid without a replace statement", info.dir)
|
||||
}
|
||||
|
||||
res := &pkg{
|
||||
importPathShort: importPath,
|
||||
dir: info.dir,
|
||||
packageName: info.packageName, // may not be populated if the caller didn't ask for it
|
||||
relevance: relevance,
|
||||
}
|
||||
// We may have discovered a package that has a different version
|
||||
|
|
@ -559,7 +560,6 @@ func (r *ModuleResolver) scanDirForPackage(root gopathwalk.Root, dir string) dir
|
|||
dir: dir,
|
||||
rootType: root.Type,
|
||||
nonCanonicalImportPath: importPath,
|
||||
needsReplace: false,
|
||||
moduleDir: modDir,
|
||||
moduleName: modName,
|
||||
}
|
||||
|
|
@ -567,14 +567,6 @@ func (r *ModuleResolver) scanDirForPackage(root gopathwalk.Root, dir string) dir
|
|||
// stdlib packages are always in scope, despite the confusing go.mod
|
||||
return result
|
||||
}
|
||||
// Check that this package is not obviously impossible to import.
|
||||
if !strings.HasPrefix(importPath, modName) {
|
||||
// The module's declared path does not match
|
||||
// its expected path. It probably needs a
|
||||
// replace directive we don't have.
|
||||
result.needsReplace = true
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,10 +49,6 @@ type directoryPackageInfo struct {
|
|||
// nonCanonicalImportPath is the package's expected import path. It may
|
||||
// not actually be importable at that path.
|
||||
nonCanonicalImportPath string
|
||||
// needsReplace is true if the nonCanonicalImportPath does not match the
|
||||
// module's declared path, making it impossible to import without a
|
||||
// replace directive.
|
||||
needsReplace bool
|
||||
|
||||
// Module-related information.
|
||||
moduleDir string // The directory that is the module root of this dir.
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ func TestModCacheInfo(t *testing.T) {
|
|||
status: directoryScanned,
|
||||
dir: "mypackage",
|
||||
nonCanonicalImportPath: "example.com/mypackage",
|
||||
needsReplace: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
@ -83,7 +82,6 @@ func TestModCacheInfo(t *testing.T) {
|
|||
info: directoryPackageInfo{
|
||||
dir: "mypackage/other",
|
||||
nonCanonicalImportPath: "example.com/mypackage/other",
|
||||
needsReplace: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue