diff options
author | Bryan C. Mills <bcmills@google.com> | 2021-02-22 17:05:32 -0500 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2021-03-10 21:00:52 +0000 |
commit | 2ceb79db526eabff880a8a03caab07258883b216 (patch) | |
tree | 576e9a8553b73a555398d9f5aba39b6a69d63ff6 | |
parent | b7f0fb6d9eb9a2c1b2beb9ecd58bdbf3571dd5cd (diff) | |
download | go-2ceb79db526eabff880a8a03caab07258883b216.tar.gz go-2ceb79db526eabff880a8a03caab07258883b216.zip |
cmd/go/internal/modload: make EditBuildList report whether the build list was changed
For #36460
Change-Id: I8dd6e6f998a217a4287212815ce61209df6f007f
Reviewed-on: https://go-review.googlesource.com/c/go/+/296609
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
-rw-r--r-- | src/cmd/go/internal/modget/get.go | 11 | ||||
-rw-r--r-- | src/cmd/go/internal/modload/buildlist.go | 17 | ||||
-rw-r--r-- | src/cmd/go/internal/work/build.go | 2 |
3 files changed, 17 insertions, 13 deletions
diff --git a/src/cmd/go/internal/modget/get.go b/src/cmd/go/internal/modget/get.go index 9340a582e5..6b416d3622 100644 --- a/src/cmd/go/internal/modget/get.go +++ b/src/cmd/go/internal/modget/get.go @@ -30,7 +30,6 @@ import ( "fmt" "os" "path/filepath" - "reflect" "runtime" "sort" "strings" @@ -1635,7 +1634,8 @@ func (r *resolver) updateBuildList(ctx context.Context, additions []module.Versi } } - if err := modload.EditBuildList(ctx, additions, resolved); err != nil { + changed, err := modload.EditBuildList(ctx, additions, resolved) + if err != nil { var constraint *modload.ConstraintError if !errors.As(err, &constraint) { base.Errorf("go get: %v", err) @@ -1654,12 +1654,11 @@ func (r *resolver) updateBuildList(ctx context.Context, additions []module.Versi } return false } - - buildList := modload.LoadAllModules(ctx) - if reflect.DeepEqual(r.buildList, buildList) { + if !changed { return false } - r.buildList = buildList + + r.buildList = modload.LoadAllModules(ctx) r.buildListVersion = make(map[string]string, len(r.buildList)) for _, m := range r.buildList { r.buildListVersion[m.Path] = m.Version diff --git a/src/cmd/go/internal/modload/buildlist.go b/src/cmd/go/internal/modload/buildlist.go index 5de26357e1..3412548efc 100644 --- a/src/cmd/go/internal/modload/buildlist.go +++ b/src/cmd/go/internal/modload/buildlist.go @@ -12,6 +12,7 @@ import ( "context" "fmt" "os" + "reflect" "strings" "golang.org/x/mod/module" @@ -81,12 +82,12 @@ func Selected(path string) (version string) { // If the versions listed in mustSelect are mutually incompatible (due to one of // the listed modules requiring a higher version of another), EditBuildList // returns a *ConstraintError and leaves the build list in its previous state. -func EditBuildList(ctx context.Context, add, mustSelect []module.Version) error { +func EditBuildList(ctx context.Context, add, mustSelect []module.Version) (changed bool, err error) { LoadModFile(ctx) final, err := editBuildList(ctx, buildList, add, mustSelect) if err != nil { - return err + return false, err } selected := make(map[string]module.Version, len(final)) @@ -106,14 +107,18 @@ func EditBuildList(ctx context.Context, add, mustSelect []module.Version) error } if !inconsistent { - buildList = final additionalExplicitRequirements = make([]string, 0, len(mustSelect)) for _, m := range mustSelect { if m.Version != "none" { additionalExplicitRequirements = append(additionalExplicitRequirements, m.Path) } } - return nil + changed := false + if !reflect.DeepEqual(buildList, final) { + buildList = final + changed = true + } + return changed, nil } // We overshot one or more of the modules in mustSelect, which means that @@ -136,7 +141,7 @@ func EditBuildList(ctx context.Context, add, mustSelect []module.Version) error m, queue = queue[0], queue[1:] required, err := reqs.Required(m) if err != nil { - return err + return false, err } for _, r := range required { if _, ok := reason[r]; !ok { @@ -164,7 +169,7 @@ func EditBuildList(ctx context.Context, add, mustSelect []module.Version) error } } - return &ConstraintError{ + return false, &ConstraintError{ Conflicts: conflicts, } } diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index 0e7af6d33f..a80eb27798 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -836,7 +836,7 @@ func installOutsideModule(ctx context.Context, args []string) { // Since we are in NoRoot mode, the build list initially contains only // the dummy command-line-arguments module. Add a requirement on the // module that provides the packages named on the command line. - if err := modload.EditBuildList(ctx, nil, []module.Version{installMod}); err != nil { + if _, err := modload.EditBuildList(ctx, nil, []module.Version{installMod}); err != nil { base.Fatalf("go install %s: %v", args[0], err) } |