зеркало из https://github.com/golang/dep.git
Move ignores out of params, into RootManifest
This commit is contained in:
Родитель
e0f23844a2
Коммит
74270825c7
|
@ -9,11 +9,15 @@ import (
|
|||
func TestHashInputs(t *testing.T) {
|
||||
fix := basicFixtures["shared dependency with overlapping constraints"]
|
||||
|
||||
rm := fix.rootmanifest().(simpleRootManifest)
|
||||
rm.ig = map[string]bool{
|
||||
"foo": true,
|
||||
"bar": true,
|
||||
}
|
||||
params := SolveParameters{
|
||||
RootDir: string(fix.ds[0].n),
|
||||
ImportRoot: fix.ds[0].n,
|
||||
Manifest: fix.ds[0],
|
||||
Ignore: []string{"foo", "bar"},
|
||||
Manifest: rm,
|
||||
}
|
||||
|
||||
s, err := Prepare(params, newdepspecSM(fix.ds, nil))
|
||||
|
|
36
manifest.go
36
manifest.go
|
@ -34,13 +34,13 @@ type RootManifest interface {
|
|||
// users should be encouraged to use them only as a last resort; they do not
|
||||
// "play well with others" (that is their express goal), and overreliance on
|
||||
// them can harm the ecosystem as a whole.
|
||||
Overrides() []ProjectConstraint
|
||||
Overrides() map[ProjectRoot]Override
|
||||
|
||||
// IngorePackages returns a list of import paths to ignore. These import
|
||||
// paths can be in the root project, or from elsewhere. Ignoring a package
|
||||
// means that both it and its (unique) imports will be disregarded by all
|
||||
// relevant solver operations.
|
||||
IgnorePackages() []string
|
||||
// IngorePackages returns a set of import paths to ignore. These import
|
||||
// paths can be within the root project, or part of other projects. Ignoring
|
||||
// a package means that both it and its (unique) imports will be disregarded
|
||||
// by all relevant solver operations.
|
||||
IgnorePackages() map[string]bool
|
||||
}
|
||||
|
||||
// SimpleManifest is a helper for tools to enumerate manifest data. It's
|
||||
|
@ -64,6 +64,30 @@ func (m SimpleManifest) TestDependencyConstraints() []ProjectConstraint {
|
|||
return m.TestDeps
|
||||
}
|
||||
|
||||
// simpleRootManifest exists so that we have a safe value to swap into solver
|
||||
// params when a nil Manifest is provided.
|
||||
//
|
||||
// Also, for tests.
|
||||
type simpleRootManifest struct {
|
||||
c []ProjectConstraint
|
||||
tc []ProjectConstraint
|
||||
ovr map[ProjectRoot]Override
|
||||
ig map[string]bool
|
||||
}
|
||||
|
||||
func (m simpleRootManifest) DependencyConstraints() []ProjectConstraint {
|
||||
return m.c
|
||||
}
|
||||
func (m simpleRootManifest) TestDependencyConstraints() []ProjectConstraint {
|
||||
return m.tc
|
||||
}
|
||||
func (m simpleRootManifest) Overrides() map[ProjectRoot]Override {
|
||||
return m.ovr
|
||||
}
|
||||
func (m simpleRootManifest) IgnorePackages() map[string]bool {
|
||||
return m.ig
|
||||
}
|
||||
|
||||
// prepManifest ensures a manifest is prepared and safe for use by the solver.
|
||||
// This entails two things:
|
||||
//
|
||||
|
|
|
@ -287,6 +287,7 @@ type pident struct {
|
|||
|
||||
type specfix interface {
|
||||
name() string
|
||||
rootmanifest() RootManifest
|
||||
specs() []depspec
|
||||
maxTries() int
|
||||
expectErrs() []string
|
||||
|
@ -346,6 +347,13 @@ func (f basicFixture) solution() map[string]Version {
|
|||
return f.r
|
||||
}
|
||||
|
||||
func (f basicFixture) rootmanifest() RootManifest {
|
||||
return simpleRootManifest{
|
||||
c: f.ds[0].deps,
|
||||
tc: f.ds[0].devdeps,
|
||||
}
|
||||
}
|
||||
|
||||
// A table of basicFixtures, used in the basic solving test set.
|
||||
var basicFixtures = map[string]basicFixture{
|
||||
// basic fixtures
|
||||
|
|
|
@ -521,6 +521,19 @@ func (f bimodalFixture) solution() map[string]Version {
|
|||
return f.r
|
||||
}
|
||||
|
||||
func (f bimodalFixture) rootmanifest() RootManifest {
|
||||
m := simpleRootManifest{
|
||||
c: f.ds[0].deps,
|
||||
tc: f.ds[0].devdeps,
|
||||
ig: make(map[string]bool),
|
||||
}
|
||||
for _, ig := range f.ignore {
|
||||
m.ig[ig] = true
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// bmSourceManager is an SM specifically for the bimodal fixtures. It composes
|
||||
// the general depspec SM, and differs from it in how it answers static analysis
|
||||
// calls, and its support for package ignores and dep lock data.
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -88,7 +87,7 @@ func solveBasicsAndCheck(fix basicFixture, t *testing.T) (res Solution, err erro
|
|||
params := SolveParameters{
|
||||
RootDir: string(fix.ds[0].n),
|
||||
ImportRoot: ProjectRoot(fix.ds[0].n),
|
||||
Manifest: fix.ds[0],
|
||||
Manifest: fix.rootmanifest(),
|
||||
Lock: dummyLock{},
|
||||
Downgrade: fix.downgrade,
|
||||
ChangeAll: fix.changeall,
|
||||
|
@ -138,9 +137,8 @@ func solveBimodalAndCheck(fix bimodalFixture, t *testing.T) (res Solution, err e
|
|||
params := SolveParameters{
|
||||
RootDir: string(fix.ds[0].n),
|
||||
ImportRoot: ProjectRoot(fix.ds[0].n),
|
||||
Manifest: fix.ds[0],
|
||||
Manifest: fix.rootmanifest(),
|
||||
Lock: dummyLock{},
|
||||
Ignore: fix.ignore,
|
||||
Downgrade: fix.downgrade,
|
||||
ChangeAll: fix.changeall,
|
||||
}
|
||||
|
@ -293,7 +291,7 @@ func TestRootLockNoVersionPairMatching(t *testing.T) {
|
|||
params := SolveParameters{
|
||||
RootDir: string(fix.ds[0].n),
|
||||
ImportRoot: ProjectRoot(fix.ds[0].n),
|
||||
Manifest: fix.ds[0],
|
||||
Manifest: fix.rootmanifest(),
|
||||
Lock: l2,
|
||||
}
|
||||
|
||||
|
@ -414,27 +412,3 @@ func TestBadSolveOpts(t *testing.T) {
|
|||
// swap them back...not sure if this matters, but just in case
|
||||
overrideMkBridge()
|
||||
}
|
||||
|
||||
func TestIgnoreDedupe(t *testing.T) {
|
||||
fix := basicFixtures["no dependencies"]
|
||||
|
||||
ig := []string{"foo", "foo", "bar"}
|
||||
params := SolveParameters{
|
||||
RootDir: string(fix.ds[0].n),
|
||||
ImportRoot: ProjectRoot(fix.ds[0].n),
|
||||
Manifest: fix.ds[0],
|
||||
Ignore: ig,
|
||||
}
|
||||
|
||||
s, _ := Prepare(params, newdepspecSM(basicFixtures["no dependencies"].ds, nil))
|
||||
ts := s.(*solver)
|
||||
|
||||
expect := map[string]bool{
|
||||
"foo": true,
|
||||
"bar": true,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(ts.ig, expect) {
|
||||
t.Errorf("Expected solver's ignore list to be deduplicated map, got %v", ts.ig)
|
||||
}
|
||||
}
|
||||
|
|
37
solver.go
37
solver.go
|
@ -42,11 +42,12 @@ type SolveParameters struct {
|
|||
// A non-empty string is required.
|
||||
ImportRoot ProjectRoot
|
||||
|
||||
// The root manifest. This contains all the dependencies, constraints, and
|
||||
// other controls available to the root project.
|
||||
// The root manifest. This contains all the dependency constraints
|
||||
// associated with normal Manifests, as well as the particular controls
|
||||
// afforded only to the root project.
|
||||
//
|
||||
// May be nil, but for most cases, that would be unwise.
|
||||
Manifest Manifest
|
||||
Manifest RootManifest
|
||||
|
||||
// The root lock. Optional. Generally, this lock is the output of a previous
|
||||
// solve run.
|
||||
|
@ -55,11 +56,6 @@ type SolveParameters struct {
|
|||
// in the lock, unless ToChange or ChangeAll settings indicate otherwise.
|
||||
Lock Lock
|
||||
|
||||
// A list of packages (import paths) to ignore. These can be in the root
|
||||
// project, or from elsewhere. Ignoring a package means that both it and its
|
||||
// imports will be disregarded by all relevant solver operations.
|
||||
Ignore []string
|
||||
|
||||
// ToChange is a list of project names that should be changed - that is, any
|
||||
// versions specified for those projects in the root lock file should be
|
||||
// ignored.
|
||||
|
@ -90,8 +86,8 @@ type SolveParameters struct {
|
|||
TraceLogger *log.Logger
|
||||
}
|
||||
|
||||
// solver is a CDCL-style SAT solver with satisfiability conditions hardcoded to
|
||||
// the needs of the Go package management problem space.
|
||||
// solver is a CDCL-style constraint solver with satisfiability conditions
|
||||
// hardcoded to the needs of the Go package management problem space.
|
||||
type solver struct {
|
||||
// The current number of attempts made over the course of this solve. This
|
||||
// number increments each time the algorithm completes a backtrack and
|
||||
|
@ -153,6 +149,10 @@ type solver struct {
|
|||
// the network name to which they currently correspond.
|
||||
names map[ProjectRoot]string
|
||||
|
||||
// A map of ProjectRoot (import path names) to the ProjectConstraint that
|
||||
// should be enforced for those names.
|
||||
ovr map[ProjectRoot]Override
|
||||
|
||||
// A map of the names listed in the root's lock.
|
||||
rlm map[ProjectIdentifier]LockedProject
|
||||
|
||||
|
@ -204,23 +204,20 @@ func Prepare(params SolveParameters, sm SourceManager) (Solver, error) {
|
|||
}
|
||||
|
||||
if params.Manifest == nil {
|
||||
params.Manifest = SimpleManifest{}
|
||||
}
|
||||
|
||||
// Ensure the ignore map is at least initialized
|
||||
ig := make(map[string]bool)
|
||||
if len(params.Ignore) > 0 {
|
||||
for _, pkg := range params.Ignore {
|
||||
ig[pkg] = true
|
||||
}
|
||||
params.Manifest = simpleRootManifest{}
|
||||
}
|
||||
|
||||
s := &solver{
|
||||
params: params,
|
||||
ig: ig,
|
||||
ig: params.Manifest.IgnorePackages(),
|
||||
tl: params.TraceLogger,
|
||||
}
|
||||
|
||||
// Ensure the ignore map is at least initialized
|
||||
if s.ig == nil {
|
||||
s.ig = make(map[string]bool)
|
||||
}
|
||||
|
||||
// Set up the bridge and ensure the root dir is in good, working order
|
||||
// before doing anything else. (This call is stubbed out in tests, via
|
||||
// overriding mkBridge(), so we can run with virtual RootDir.)
|
||||
|
|
7
types.go
7
types.go
|
@ -134,6 +134,13 @@ func (i ProjectIdentifier) normalize() ProjectIdentifier {
|
|||
return i
|
||||
}
|
||||
|
||||
// An Override can be provided by the RootManifest to designate a network name
|
||||
// and constraint that should *always* be used for a given ProjectRoot.
|
||||
type Override struct {
|
||||
NetworkName string
|
||||
Constraint Constraint
|
||||
}
|
||||
|
||||
// Package represents a Go package. It contains a subset of the information
|
||||
// go/build.Package does.
|
||||
type Package struct {
|
||||
|
|
Загрузка…
Ссылка в новой задаче