distro: introduce PackageSets

This replaces Packages() and BuildPackages() by returning a map of
package sets, the semantics of which is up to the distro to define.

They are meant to be depsolved and the result returned back as a
map to Manifest(), with the same keys.

No functional change.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2021-03-09 17:35:28 +00:00
parent 4805eeedf8
commit 9e2e009ac8
24 changed files with 210 additions and 161 deletions

View file

@ -187,20 +187,32 @@ func (t *imageType) BuildPackages() []string {
return packages
}
func (t *imageType) PackageSets(bp blueprint.Blueprint) map[string]rpmmd.PackageSet {
includePackages, excludePackages := t.Packages(bp)
return map[string]rpmmd.PackageSet{
"packages": {
Include: includePackages,
Exclude: excludePackages,
},
"build-packages": {
Include: t.BuildPackages(),
},
}
}
func (t *imageType) Manifest(c *blueprint.Customizations,
options distro.ImageOptions,
repos []rpmmd.RepoConfig,
packageSpecs,
buildPackageSpecs []rpmmd.PackageSpec,
packageSpecSets map[string][]rpmmd.PackageSpec,
seed int64) (distro.Manifest, error) {
pipeline, err := t.pipeline(c, options, repos, packageSpecs, buildPackageSpecs)
pipeline, err := t.pipeline(c, options, repos, packageSpecSets["packages"], packageSpecSets["build-packages"])
if err != nil {
return distro.Manifest{}, err
}
return json.Marshal(
osbuild.Manifest{
Sources: *sources(append(packageSpecs, buildPackageSpecs...)),
Sources: *sources(append(packageSpecSets["packages"], packageSpecSets["build-packages"]...)),
Pipeline: *pipeline,
},
)

View file

@ -121,13 +121,15 @@ func TestImageType_BuildPackages(t *testing.T) {
t.Errorf("d.GetArch(%v) returned err = %v; expected nil", archLabel, err)
continue
}
buildPkgs := itStruct.PackageSets(blueprint.Blueprint{})["build-packages"]
assert.NotNil(t, buildPkgs)
if itLabel == "fedora-iot-commit" {
// For now we only include rpm-ostree when building fedora-iot-commit image types, this we may want
// to reconsider. The only reason to specia-case it is that it might pull in a lot of dependencies
// for a niche usecase.
assert.ElementsMatch(t, append(buildPackages[archLabel], "rpm-ostree"), itStruct.BuildPackages())
assert.ElementsMatch(t, append(buildPackages[archLabel], "rpm-ostree"), buildPkgs.Include)
} else {
assert.ElementsMatch(t, buildPackages[archLabel], itStruct.BuildPackages())
assert.ElementsMatch(t, buildPackages[archLabel], buildPkgs.Include)
}
}
}
@ -286,15 +288,16 @@ func TestImageType_BasePackages(t *testing.T) {
for _, pkgMap := range pkgMaps {
imgType, err := arch.GetImageType(pkgMap.name)
assert.NoError(t, err)
basePackages, excludedPackages := imgType.Packages(blueprint.Blueprint{})
packages := imgType.PackageSets(blueprint.Blueprint{})["packages"]
assert.NotNil(t, packages)
assert.Equalf(
t,
append(pkgMap.basePackages, pkgMap.bootloaderPackages...),
basePackages,
packages.Include,
"image type: %s",
pkgMap.name,
)
assert.Equalf(t, pkgMap.excludedPackages, excludedPackages, "image type: %s", pkgMap.name)
assert.Equalf(t, pkgMap.excludedPackages, packages.Exclude, "image type: %s", pkgMap.name)
}
}
@ -320,7 +323,7 @@ func TestDistro_ManifestError(t *testing.T) {
arch, _ := f33distro.GetArch(archName)
for _, imgTypeName := range arch.ListImageTypes() {
imgType, _ := arch.GetImageType(imgTypeName)
_, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, nil, nil, 0)
_, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, nil, 0)
if imgTypeName == "fedora-iot-commit" {
assert.EqualError(t, err, "kernel boot parameter customizations are not supported for ostree types")
} else {