mirror of
https://github.com/mudler/luet.git
synced 2025-09-02 07:45:02 +00:00
Do not call solver multiple times, reuse same assertion
Introduce Cut(), it allows to filter in the assertion to achieve the same hashes
This commit is contained in:
@@ -442,17 +442,13 @@ func (cs *LuetCompiler) ComputeDepTree(p CompilationSpec) (solver.PackagesAssert
|
||||
|
||||
dependencies := solution.Order(cs.Database, p.GetPackage().GetFingerPrint())
|
||||
assertions := solver.PackagesAssertions{}
|
||||
|
||||
for _, assertion := range dependencies { //highly dependent on the order
|
||||
if assertion.Value {
|
||||
nthsolution, err := s.Install([]pkg.Package{assertion.Package})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "While computing a solution for "+p.GetPackage().GetName())
|
||||
}
|
||||
nthsolution := dependencies.Cut(assertion.Package)
|
||||
|
||||
assertion.Hash = solver.PackageHash{
|
||||
BuildHash: nthsolution.Order(cs.Database, assertion.Package.GetFingerPrint()).Drop(assertion.Package).AssertionHash(),
|
||||
PackageHash: nthsolution.Order(cs.Database, assertion.Package.GetFingerPrint()).AssertionHash(),
|
||||
BuildHash: nthsolution.Drop(assertion.Package).AssertionHash(),
|
||||
PackageHash: nthsolution.AssertionHash(),
|
||||
}
|
||||
assertions = append(assertions, assertion)
|
||||
}
|
||||
|
@@ -400,6 +400,11 @@ func (pack *DefaultPackage) BuildFormula(definitiondb PackageDatabase, db Packag
|
||||
|
||||
var formulas []bf.Formula
|
||||
for _, requiredDef := range p.GetRequires() {
|
||||
// TODO: Stabilize this. We allow any of those version to be selected,
|
||||
// at the price that they can't be selected alltogether.
|
||||
// This have the downside that we cannot specify a preference (e.g. The best matching)
|
||||
// unless we have a user-defined version. It means that the solver could
|
||||
// give different output between calls, but they are all legit as they respect the constraints.
|
||||
required, err := definitiondb.FindPackage(requiredDef)
|
||||
if err != nil {
|
||||
packages, err := definitiondb.FindPackages(requiredDef)
|
||||
|
@@ -144,6 +144,7 @@ func (assertions PackagesAssertions) Search(f string) *PackageAssert {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (assertions PackagesAssertions) Order(definitiondb pkg.PackageDatabase, fingerprint string) PackagesAssertions {
|
||||
|
||||
orderedAssertions := PackagesAssertions{}
|
||||
@@ -263,3 +264,18 @@ func (assertions PackagesAssertions) Drop(p pkg.Package) PackagesAssertions {
|
||||
}
|
||||
return ass
|
||||
}
|
||||
|
||||
// Cut returns an assertion list of installed (filter by Value) "cutted" until the package is found (included)
|
||||
func (assertions PackagesAssertions) Cut(p pkg.Package) PackagesAssertions {
|
||||
ass := PackagesAssertions{}
|
||||
|
||||
for _, a := range assertions {
|
||||
if a.Value {
|
||||
ass = append(ass, a)
|
||||
if a.Package.Matches(p) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return ass
|
||||
}
|
||||
|
@@ -246,5 +246,31 @@ var _ = Describe("Decoder", func() {
|
||||
Expect(solution.Order(dbDefinitions, Y.GetFingerPrint()).Drop(Y).AssertionHash() == solution2.Order(dbDefinitions, Z.GetFingerPrint()).Drop(Z).AssertionHash()).To(BeTrue())
|
||||
})
|
||||
|
||||
It("Hashes them, Cuts them and could be used for comparison", func() {
|
||||
|
||||
X := pkg.NewPackage("X", "", []*pkg.DefaultPackage{}, []*pkg.DefaultPackage{})
|
||||
Y := pkg.NewPackage("Y", "", []*pkg.DefaultPackage{X}, []*pkg.DefaultPackage{})
|
||||
Z := pkg.NewPackage("Z", "", []*pkg.DefaultPackage{X}, []*pkg.DefaultPackage{})
|
||||
|
||||
for _, p := range []pkg.Package{X, Y, Z} {
|
||||
_, err := dbDefinitions.CreatePackage(p)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
for _, p := range []pkg.Package{} {
|
||||
_, err := dbInstalled.CreatePackage(p)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
solution, err := s.Install([]pkg.Package{Y})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
solution2, err := s.Install([]pkg.Package{Z})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(solution.Order(dbDefinitions, Y.GetFingerPrint()).Cut(Y).Drop(Y)).To(Equal(solution2.Order(dbDefinitions, Z.GetFingerPrint()).Cut(Z).Drop(Z)))
|
||||
|
||||
Expect(solution.Order(dbDefinitions, Y.GetFingerPrint()).Cut(Y).Drop(Y).AssertionHash()).To(Equal(solution2.Order(dbDefinitions, Z.GetFingerPrint()).Cut(Z).Drop(Z).AssertionHash()))
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user