info.GoVersion = loaded.goVersion[m.Path]
}
- if cfg.BuildMod == "vendor" {
- // The vendor directory doesn't contain enough information to reconstruct
- // anything more about the module.
- return info
- }
-
- // complete fills in the extra fields in m.
- complete := func(m *modinfo.ModulePublic) {
+ // completeFromModCache fills in the extra fields in m using the module cache.
+ completeFromModCache := func(m *modinfo.ModulePublic) {
if m.Version != "" {
if q, err := Query(m.Path, m.Version, "", nil); err != nil {
m.Error = &modinfo.ModuleError{Err: err.Error()}
}
if !fromBuildList {
- complete(info)
+ completeFromModCache(info) // Will set m.Error in vendor mode.
return info
}
r := Replacement(m)
if r.Path == "" {
- complete(info)
+ if cfg.BuildMod == "vendor" {
+ // It's tempting to fill in the "Dir" field to point within the vendor
+ // directory, but that would be misleading: the vendor directory contains
+ // a flattened package tree, not complete modules, and it can even
+ // interleave packages from different modules if one module path is a
+ // prefix of the other.
+ } else {
+ completeFromModCache(info)
+ }
return info
}
info.Replace.Dir = filepath.Join(ModRoot(), r.Path)
}
}
- complete(info.Replace)
- info.Dir = info.Replace.Dir
- info.GoMod = filepath.Join(info.Dir, "go.mod")
+ if cfg.BuildMod != "vendor" {
+ completeFromModCache(info.Replace)
+ info.Dir = info.Replace.Dir
+ info.GoMod = filepath.Join(info.Dir, "go.mod")
+ }
return info
}
! stderr 'finding'
! stderr 'lookup disabled'
+# 'go list' should provide the original replacement directory as the module's
+# replacement path.
+go list -mod=vendor -f '{{with .Module}}{{with .Replace}}{{.Path}}{{end}}{{end}}' rsc.io/quote/v3
+stdout '.*[/\\]not-rsc.io[/\\]quote[/\\]v3'
+
# The same module can't be used as two different paths.
cd multiple-paths
! go mod vendor
rsc.io/quote/v3 v3.0.0
not-rsc.io/quote/v3 v3.0.0
)
-replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0
\ No newline at end of file
+replace not-rsc.io/quote/v3 => rsc.io/quote/v3 v3.0.0