mirror of
https://github.com/golang/go
synced 2024-11-24 02:20:18 -07:00
cmd/go: fix spurious edges in mod -graph output
The mod -graph output was showing every dependency as an edge from the main module, instead of showing only the things that are listed in go.mod. Fixes #26489. Change-Id: I248fedb1fc9225e2a7a9ddc2f4a84520b3a96138 Reviewed-on: https://go-review.googlesource.com/125657 Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
0cb6b55f43
commit
f37ca81c84
@ -496,7 +496,7 @@ func modPrintJSON() {
|
||||
|
||||
// modPrintGraph prints the -graph output.
|
||||
func modPrintGraph() {
|
||||
reqs := modload.Reqs()
|
||||
reqs := modload.MinReqs()
|
||||
|
||||
format := func(m module.Version) string {
|
||||
if m.Version == "" {
|
||||
|
@ -91,6 +91,7 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
|
||||
Version: m.Version,
|
||||
Main: true,
|
||||
Dir: ModRoot,
|
||||
GoMod: filepath.Join(ModRoot, "go.mod"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +115,15 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
|
||||
m.Version = q.Version
|
||||
m.Time = &q.Time
|
||||
}
|
||||
dir, err := modfetch.DownloadDir(module.Version{Path: m.Path, Version: m.Version})
|
||||
|
||||
mod := module.Version{Path: m.Path, Version: m.Version}
|
||||
gomod, err := modfetch.CachePath(mod, "mod")
|
||||
if err == nil {
|
||||
if info, err := os.Stat(gomod); err == nil && info.Mode().IsRegular() {
|
||||
m.GoMod = gomod
|
||||
}
|
||||
}
|
||||
dir, err := modfetch.DownloadDir(mod)
|
||||
if err == nil {
|
||||
if info, err := os.Stat(dir); err == nil && info.IsDir() {
|
||||
m.Dir = dir
|
||||
@ -142,6 +151,7 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
|
||||
}
|
||||
complete(info.Replace)
|
||||
info.Dir = info.Replace.Dir
|
||||
info.GoMod = filepath.Join(info.Dir, "go.mod")
|
||||
info.Error = nil // ignore error loading original module version (it has been replaced)
|
||||
}
|
||||
|
||||
|
@ -474,6 +474,22 @@ func AllowWriteGoMod() {
|
||||
allowWriteGoMod = true
|
||||
}
|
||||
|
||||
// MinReqs returns a Reqs with minimal dependencies of Target,
|
||||
// as will be written to go.mod.
|
||||
func MinReqs() mvs.Reqs {
|
||||
var direct []string
|
||||
for _, m := range buildList[1:] {
|
||||
if loaded.direct[m.Path] {
|
||||
direct = append(direct, m.Path)
|
||||
}
|
||||
}
|
||||
min, err := mvs.Req(Target, buildList, direct, Reqs())
|
||||
if err != nil {
|
||||
base.Fatalf("go: %v", err)
|
||||
}
|
||||
return &mvsReqs{buildList: append([]module.Version{Target}, min...)}
|
||||
}
|
||||
|
||||
// WriteGoMod writes the current build list back to go.mod.
|
||||
func WriteGoMod() {
|
||||
if !allowWriteGoMod {
|
||||
@ -483,13 +499,8 @@ func WriteGoMod() {
|
||||
modfetch.WriteGoSum()
|
||||
|
||||
if loaded != nil {
|
||||
var direct []string
|
||||
for _, m := range buildList[1:] {
|
||||
if loaded.direct[m.Path] {
|
||||
direct = append(direct, m.Path)
|
||||
}
|
||||
}
|
||||
min, err := mvs.Req(Target, buildList, direct, Reqs())
|
||||
reqs := MinReqs()
|
||||
min, err := reqs.Required(Target)
|
||||
if err != nil {
|
||||
base.Fatalf("go: %v", err)
|
||||
}
|
||||
|
10
src/cmd/go/testdata/script/mod_graph.txt
vendored
Normal file
10
src/cmd/go/testdata/script/mod_graph.txt
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
env GO111MODULE=on
|
||||
|
||||
go mod -graph
|
||||
stdout '^m rsc.io/quote@v1.5.2$'
|
||||
stdout '^rsc.io/quote@v1.5.2 rsc.io/sampler@v1.3.0$'
|
||||
! stdout '^m rsc.io/sampler@v1.3.0$'
|
||||
|
||||
-- go.mod --
|
||||
module m
|
||||
require rsc.io/quote v1.5.2
|
Loading…
Reference in New Issue
Block a user