]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: make EditBuildList report whether the build list was changed
authorBryan C. Mills <bcmills@google.com>
Mon, 22 Feb 2021 22:05:32 +0000 (17:05 -0500)
committerBryan C. Mills <bcmills@google.com>
Wed, 10 Mar 2021 21:00:52 +0000 (21:00 +0000)
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>
src/cmd/go/internal/modget/get.go
src/cmd/go/internal/modload/buildlist.go
src/cmd/go/internal/work/build.go

index 9340a582e5cb0437540933a12d7e9feac36f526c..6b416d3622e52877fbeecf14d42ff661823616aa 100644 (file)
@@ -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
index 5de26357e1094667344062cdc74648eac9200a12..3412548efc0728f12df8fce8a168624f7f6c0d90 100644 (file)
@@ -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,
        }
 }
index 0e7af6d33f570685d1ac135b30819d08bbd55d08..a80eb277982aeea6261c1d2936afaa3f18b3fdde 100644 (file)
@@ -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)
        }