mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: inject loaderstate into matcher function
This change alters the matcher function in vendorPkg in order to retrieve the go version from the current loaderstate. This commit is part of the overall effort to eliminate global modloader state. Change-Id: Iedb12bdfe4ab3c24dbbf161db1f3842014415c59 Reviewed-on: https://go-review.googlesource.com/c/go/+/711117 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@google.com>
This commit is contained in:
parent
d57c3fd743
commit
7503856d40
1 changed files with 10 additions and 6 deletions
|
|
@ -268,8 +268,8 @@ func moduleLine(m, r module.Version) string {
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func vendorPkg(loaderstate *modload.State, vdir, pkg string) {
|
func vendorPkg(s *modload.State, vdir, pkg string) {
|
||||||
src, realPath, _ := modload.Lookup(loaderstate, "", false, pkg)
|
src, realPath, _ := modload.Lookup(s, "", false, pkg)
|
||||||
if src == "" {
|
if src == "" {
|
||||||
base.Errorf("internal error: no pkg for %s\n", pkg)
|
base.Errorf("internal error: no pkg for %s\n", pkg)
|
||||||
return
|
return
|
||||||
|
|
@ -288,7 +288,11 @@ func vendorPkg(loaderstate *modload.State, vdir, pkg string) {
|
||||||
|
|
||||||
copiedFiles := make(map[string]bool)
|
copiedFiles := make(map[string]bool)
|
||||||
dst := filepath.Join(vdir, pkg)
|
dst := filepath.Join(vdir, pkg)
|
||||||
copyDir(dst, src, matchPotentialSourceFile, copiedFiles)
|
matcher := func(dir string, info fs.DirEntry) bool {
|
||||||
|
goVersion := s.MainModules.GoVersion(s)
|
||||||
|
return matchPotentialSourceFile(dir, info, goVersion)
|
||||||
|
}
|
||||||
|
copyDir(dst, src, matcher, copiedFiles)
|
||||||
if m := modload.PackageModule(realPath); m.Path != "" {
|
if m := modload.PackageModule(realPath); m.Path != "" {
|
||||||
copyMetadata(m.Path, realPath, dst, src, copiedFiles)
|
copyMetadata(m.Path, realPath, dst, src, copiedFiles)
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +319,7 @@ func vendorPkg(loaderstate *modload.State, vdir, pkg string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var embedPatterns []string
|
var embedPatterns []string
|
||||||
if gover.Compare(loaderstate.MainModules.GoVersion(loaderstate), "1.22") >= 0 {
|
if gover.Compare(s.MainModules.GoVersion(s), "1.22") >= 0 {
|
||||||
embedPatterns = bp.EmbedPatterns
|
embedPatterns = bp.EmbedPatterns
|
||||||
} else {
|
} else {
|
||||||
// Maintain the behavior of https://github.com/golang/go/issues/63473
|
// Maintain the behavior of https://github.com/golang/go/issues/63473
|
||||||
|
|
@ -426,12 +430,12 @@ func matchMetadata(dir string, info fs.DirEntry) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// matchPotentialSourceFile reports whether info may be relevant to a build operation.
|
// matchPotentialSourceFile reports whether info may be relevant to a build operation.
|
||||||
func matchPotentialSourceFile(dir string, info fs.DirEntry) bool {
|
func matchPotentialSourceFile(dir string, info fs.DirEntry, goVersion string) bool {
|
||||||
if strings.HasSuffix(info.Name(), "_test.go") {
|
if strings.HasSuffix(info.Name(), "_test.go") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if info.Name() == "go.mod" || info.Name() == "go.sum" {
|
if info.Name() == "go.mod" || info.Name() == "go.sum" {
|
||||||
if gv := modload.LoaderState.MainModules.GoVersion(modload.LoaderState); gover.Compare(gv, "1.17") >= 0 {
|
if gover.Compare(goVersion, "1.17") >= 0 {
|
||||||
// As of Go 1.17, we strip go.mod and go.sum files from dependency modules.
|
// As of Go 1.17, we strip go.mod and go.sum files from dependency modules.
|
||||||
// Otherwise, 'go' commands invoked within the vendor subtree may misidentify
|
// Otherwise, 'go' commands invoked within the vendor subtree may misidentify
|
||||||
// an arbitrary directory within the vendor tree as a module root.
|
// an arbitrary directory within the vendor tree as a module root.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue