"fmt"
"os"
"path/filepath"
- "reflect"
"runtime"
"sort"
"strings"
}
}
- 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)
}
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
"context"
"fmt"
"os"
+ "reflect"
"strings"
"golang.org/x/mod/module"
// 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))
}
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
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 {
}
}
- return &ConstraintError{
+ return false, &ConstraintError{
Conflicts: conflicts,
}
}
// 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)
}