Skip to content

Commit 1a56655

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modload: migrate editBuildList to use a structured requirement graph
For #36460 Change-Id: Ic87d7e25402bb938d2872d33d26c4bf397776d1b Reviewed-on: https://go-review.googlesource.com/c/go/+/308517 Trust: Bryan C. Mills <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 9c1b769 commit 1a56655

File tree

3 files changed

+356
-159
lines changed

3 files changed

+356
-159
lines changed

src/cmd/go/internal/modload/buildlist.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"context"
1313
"fmt"
1414
"os"
15-
"reflect"
1615
"runtime"
1716
"strings"
1817
"sync"
@@ -455,71 +454,6 @@ func EditBuildList(ctx context.Context, add, mustSelect []module.Version) (chang
455454
return changed, err
456455
}
457456

458-
func editRequirements(ctx context.Context, rs *Requirements, add, mustSelect []module.Version) (edited *Requirements, changed bool, err error) {
459-
mg, err := rs.Graph(ctx)
460-
if err != nil {
461-
return nil, false, err
462-
}
463-
buildList := mg.BuildList()
464-
465-
final, err := editBuildList(ctx, buildList, add, mustSelect)
466-
if err != nil {
467-
return nil, false, err
468-
}
469-
470-
if !reflect.DeepEqual(final, buildList) {
471-
changed = true
472-
} else if len(mustSelect) == 0 {
473-
// No change to the build list and no explicit roots to promote, so we're done.
474-
return rs, false, nil
475-
}
476-
477-
var rootPaths []string
478-
for _, m := range mustSelect {
479-
if m.Version != "none" && m.Path != Target.Path {
480-
rootPaths = append(rootPaths, m.Path)
481-
}
482-
}
483-
for _, m := range final[1:] {
484-
if v, ok := rs.rootSelected(m.Path); ok && (v == m.Version || rs.direct[m.Path]) {
485-
// m.Path was formerly a root, and either its version hasn't changed or
486-
// we believe that it provides a package directly imported by a package
487-
// or test in the main module. For now we'll assume that it is still
488-
// relevant. If we actually load all of the packages and tests in the
489-
// main module (which we are not doing here), we can revise the explicit
490-
// roots at that point.
491-
rootPaths = append(rootPaths, m.Path)
492-
}
493-
}
494-
495-
if go117LazyTODO {
496-
// mvs.Req is not lazy, and in a lazily-loaded module we don't want
497-
// to minimize the roots anyway. (Instead, we want to retain explicit
498-
// root paths so that they remain explicit: only 'go mod tidy' should
499-
// remove roots.)
500-
}
501-
502-
min, err := mvs.Req(Target, rootPaths, &mvsReqs{roots: final[1:]})
503-
if err != nil {
504-
return nil, false, err
505-
}
506-
507-
// A module that is not even in the build list necessarily cannot provide
508-
// any imported packages. Mark as direct only the direct modules that are
509-
// still in the build list.
510-
//
511-
// TODO(bcmills): Would it make more sense to leave the direct map as-is
512-
// but allow it to refer to modules that are no longer in the build list?
513-
// That might complicate updateRoots, but it may be cleaner in other ways.
514-
direct := make(map[string]bool, len(rs.direct))
515-
for _, m := range final {
516-
if rs.direct[m.Path] {
517-
direct[m.Path] = true
518-
}
519-
}
520-
return newRequirements(rs.depth, min, direct), changed, nil
521-
}
522-
523457
// A ConstraintError describes inconsistent constraints in EditBuildList
524458
type ConstraintError struct {
525459
// Conflict lists the source of the conflict for each version in mustSelect

0 commit comments

Comments
 (0)