diff --git a/pkg/compiler/compiler.go b/pkg/compiler/compiler.go index 12ee8de7..01a3e75b 100644 --- a/pkg/compiler/compiler.go +++ b/pkg/compiler/compiler.go @@ -1256,6 +1256,11 @@ func (cs *LuetCompiler) FromPackage(p pkg.Package) (*compilerspec.LuetCompilatio cs.inheritSpecBuildOptions(newSpec) + // Update the package in the compiler database to catch updates from NewLuetCompilationSpec + if err := cs.Database.UpdatePackage(newSpec.Package); err != nil { + return nil, errors.Wrap(err, "failed updating new package entry in compiler database") + } + return newSpec, err } diff --git a/pkg/compiler/types/spec/spec.go b/pkg/compiler/types/spec/spec.go index 8c7768ea..8aa883ca 100644 --- a/pkg/compiler/types/spec/spec.go +++ b/pkg/compiler/types/spec/spec.go @@ -23,11 +23,11 @@ import ( "github.com/mitchellh/hashstructure/v2" options "github.com/mudler/luet/pkg/compiler/types/options" + "github.com/ghodss/yaml" pkg "github.com/mudler/luet/pkg/package" "github.com/mudler/luet/pkg/solver" "github.com/otiai10/copy" dirhash "golang.org/x/mod/sumdb/dirhash" - yaml "gopkg.in/yaml.v2" ) type LuetCompilationspecs []LuetCompilationSpec @@ -157,11 +157,31 @@ func (cs *LuetCompilationSpec) signature() Signature { func NewLuetCompilationSpec(b []byte, p pkg.Package) (*LuetCompilationSpec, error) { var spec LuetCompilationSpec + var packageDefinition pkg.DefaultPackage err := yaml.Unmarshal(b, &spec) if err != nil { return &spec, err } - spec.Package = p.(*pkg.DefaultPackage) + err = yaml.Unmarshal(b, &packageDefinition) + if err != nil { + return &spec, err + } + + // Update requires/conflict/provides + // When we have been passed a bytes slice, parse it as a package + // and updates requires/conflicts/provides. + // This is required in order to allow manipulation of such fields with templating + copy := *p.(*pkg.DefaultPackage) + spec.Package = © + if len(packageDefinition.GetRequires()) != 0 { + spec.Package.Requires(packageDefinition.GetRequires()) + } + if len(packageDefinition.GetConflicts()) != 0 { + spec.Package.Conflicts(packageDefinition.GetConflicts()) + } + if len(packageDefinition.GetProvides()) != 0 { + spec.Package.SetProvides(packageDefinition.GetProvides()) + } return &spec, nil } func (cs *LuetCompilationSpec) GetSourceAssertion() solver.PackagesAssertions {