move stdLibFn field from rootdata to solver

This commit is contained in:
Jordan Krage 2017-05-17 20:13:59 -05:00
Родитель 300debf6f3
Коммит fc2dc46c3c
4 изменённых файлов: 29 добавлений и 29 удалений

Просмотреть файл

@ -61,7 +61,7 @@ func (s *solver) writeHashingInputs(w io.Writer) {
// getApplicableConstraints will apply overrides, incorporate requireds,
// apply local ignores, drop stdlib imports, and finally trim out
// ineffectual constraints.
for _, pd := range s.rd.getApplicableConstraints() {
for _, pd := range s.rd.getApplicableConstraints(s.stdLibFn) {
writeString(string(pd.Ident.ProjectRoot))
writeString(pd.Ident.Source)
writeString(pd.Constraint.typedString())
@ -69,7 +69,7 @@ func (s *solver) writeHashingInputs(w io.Writer) {
// Write out each discrete import, including those derived from requires.
writeString(hhImportsReqs)
imports := s.rd.externalImportList()
imports := s.rd.externalImportList(s.stdLibFn)
sort.Strings(imports)
for _, im := range imports {
writeString(im)

Просмотреть файл

@ -48,17 +48,14 @@ type rootdata struct {
// The ProjectAnalyzer to use for all GetManifestAndLock calls.
an ProjectAnalyzer
// The function to use to recognize standard library import paths.
stdLibFn func(string) bool
}
// externalImportList returns a list of the unique imports from the root data.
// Ignores and requires are taken into consideration, stdlib is excluded, and
// errors within the local set of package are not backpropagated.
func (rd rootdata) externalImportList() []string {
func (rd rootdata) externalImportList(stdLibFn func(string) bool) []string {
rm, _ := rd.rpt.ToReachMap(true, true, false, rd.ig)
reach := rm.FlattenFn(rd.stdLibFn)
reach := rm.FlattenFn(stdLibFn)
// If there are any requires, slide them into the reach list, as well.
if len(rd.req) > 0 {
@ -82,7 +79,7 @@ func (rd rootdata) externalImportList() []string {
return reach
}
func (rd rootdata) getApplicableConstraints() []workingConstraint {
func (rd rootdata) getApplicableConstraints(stdLibFn func(string) bool) []workingConstraint {
// Merge the normal and test constraints together
pc := rd.rm.DependencyConstraints().merge(rd.rm.TestDependencyConstraints())
@ -116,8 +113,8 @@ func (rd rootdata) getApplicableConstraints() []workingConstraint {
// Walk all dep import paths we have to consider and mark the corresponding
// wc entry in the trie, if any
for _, im := range rd.externalImportList() {
if rd.stdLibFn(im) {
for _, im := range rd.externalImportList(stdLibFn) {
if stdLibFn(im) {
continue
}

Просмотреть файл

@ -27,7 +27,7 @@ func TestRootdataExternalImports(t *testing.T) {
rd := is.(*solver).rd
want := []string{"a", "b"}
got := rd.externalImportList()
got := rd.externalImportList(params.stdLibFn)
if !reflect.DeepEqual(want, got) {
t.Errorf("Unexpected return from rootdata.externalImportList:\n\t(GOT): %s\n\t(WNT): %s", got, want)
}
@ -36,7 +36,7 @@ func TestRootdataExternalImports(t *testing.T) {
rd.req["c"] = true
want = []string{"a", "b", "c"}
got = rd.externalImportList()
got = rd.externalImportList(params.stdLibFn)
if !reflect.DeepEqual(want, got) {
t.Errorf("Unexpected return from rootdata.externalImportList:\n\t(GOT): %s\n\t(WNT): %s", got, want)
}
@ -47,7 +47,7 @@ func TestRootdataExternalImports(t *testing.T) {
rd.rpt.Packages["root"] = poe
// should still be the same
got = rd.externalImportList()
got = rd.externalImportList(params.stdLibFn)
if !reflect.DeepEqual(want, got) {
t.Errorf("Unexpected return from rootdata.externalImportList:\n\t(GOT): %s\n\t(WNT): %s", got, want)
}
@ -57,7 +57,7 @@ func TestRootdataExternalImports(t *testing.T) {
rd.ig["b"] = true
want = []string{"a", "c"}
got = rd.externalImportList()
got = rd.externalImportList(params.stdLibFn)
if !reflect.DeepEqual(want, got) {
t.Errorf("Unexpected return from rootdata.externalImportList:\n\t(GOT): %s\n\t(WNT): %s", got, want)
}
@ -213,7 +213,7 @@ func TestGetApplicableConstraints(t *testing.T) {
t.Run(fix.name, func(t *testing.T) {
fix.mut()
got := rd.getApplicableConstraints()
got := rd.getApplicableConstraints(params.stdLibFn)
if !reflect.DeepEqual(fix.result, got) {
t.Errorf("unexpected applicable constraint set:\n\t(GOT): %+v\n\t(WNT): %+v", got, fix.result)
}

Просмотреть файл

@ -126,6 +126,9 @@ type solver struct {
// Logger used exclusively for trace output, or nil to suppress.
tl *log.Logger
// The function to use to recognize standard library import paths.
stdLibFn func(string) bool
// A bridge to the standard SourceManager. The adapter does some local
// caching of pre-sorted version lists, as well as translation between the
// full-on ProjectIdentifiers that the solver deals with and the simplified
@ -195,16 +198,15 @@ func (params SolveParameters) toRootdata() (rootdata, error) {
}
rd := rootdata{
ig: params.Manifest.IgnoredPackages(),
req: params.Manifest.RequiredPackages(),
ovr: params.Manifest.Overrides(),
rpt: params.RootPackageTree.Copy(),
chng: make(map[ProjectRoot]struct{}),
rlm: make(map[ProjectRoot]LockedProject),
chngall: params.ChangeAll,
dir: params.RootDir,
an: params.ProjectAnalyzer,
stdLibFn: params.stdLibFn,
ig: params.Manifest.IgnoredPackages(),
req: params.Manifest.RequiredPackages(),
ovr: params.Manifest.Overrides(),
rpt: params.RootPackageTree.Copy(),
chng: make(map[ProjectRoot]struct{}),
rlm: make(map[ProjectRoot]LockedProject),
chngall: params.ChangeAll,
dir: params.RootDir,
an: params.ProjectAnalyzer,
}
// Ensure the required, ignore and overrides maps are at least initialized
@ -293,8 +295,9 @@ func Prepare(params SolveParameters, sm SourceManager) (Solver, error) {
}
s := &solver{
tl: params.TraceLogger,
rd: rd,
tl: params.TraceLogger,
stdLibFn: params.stdLibFn,
rd: rd,
}
// Set up the bridge and ensure the root dir is in good, working order
@ -504,7 +507,7 @@ func (s *solver) selectRoot() error {
// If we're looking for root's deps, get it from opts and local root
// analysis, rather than having the sm do it
deps, err := s.intersectConstraintsWithImports(s.rd.combineConstraints(), s.rd.externalImportList())
deps, err := s.intersectConstraintsWithImports(s.rd.combineConstraints(), s.rd.externalImportList(s.stdLibFn))
if err != nil {
// TODO(sdboyer) this could well happen; handle it with a more graceful error
panic(fmt.Sprintf("shouldn't be possible %s", err))
@ -623,7 +626,7 @@ func (s *solver) intersectConstraintsWithImports(deps []workingConstraint, reach
dmap := make(map[ProjectRoot]completeDep)
for _, rp := range reach {
// If it's a stdlib-shaped package, skip it.
if s.rd.stdLibFn(rp) {
if s.stdLibFn(rp) {
continue
}