Finalize SCL feature

This commit is contained in:
Neil Hanlon 2022-10-19 15:21:19 -04:00
parent 949ab935e6
commit 77fb4ac65b
Signed by: neil
GPG Key ID: 705BC21EC3C70F34
5 changed files with 65 additions and 32 deletions

View File

@ -662,17 +662,17 @@ func (c *Controller) BuildArchActivity(ctx context.Context, projectId string, pa
return err return err
} }
var pkgGroup []string = DefaultBuildPkgGroup var pkgGroup = DefaultBuildPkgGroup
if len(project.BuildStagePackages) != 0 { if len(project.BuildStagePackages) != 0 {
pkgGroup = project.BuildStagePackages pkgGroup = project.BuildStagePackages
} }
if len(pkgEo.DependsOn) != 0 { if len(pkgEo.DependsOn) != 0 {
for _, pkg := range pkgEo.DependsOn { for _, pkg := range pkgEo.DependsOn {
pkgGroup = append(pkgGroup, pkg) pkgGroup = append(pkgGroup, pkg)
} }
} }
hostArch := os.Getenv("REAL_BUILD_ARCH") hostArch := os.Getenv("REAL_BUILD_ARCH")
err = c.writeMockConfig(&project, packageVersion, extraOptions, arch, hostArch, pkgGroup) err = c.writeMockConfig(&project, packageVersion, extraOptions, arch, hostArch, pkgGroup)

View File

@ -416,16 +416,16 @@ func (c *Controller) BuildSRPMActivity(ctx context.Context, upstreamPrefix strin
return fmt.Errorf("could not find spec file: %v", err) return fmt.Errorf("could not find spec file: %v", err)
} }
var pkgGroup []string = DefaultSrpmBuildPkgGroup var pkgGroup = DefaultSrpmBuildPkgGroup
if len(project.SrpmStagePackages) != 0 { if len(project.SrpmStagePackages) != 0 {
pkgGroup = project.SrpmStagePackages pkgGroup = project.SrpmStagePackages
} }
if len(pkgEo.DependsOn) != 0 { if len(pkgEo.DependsOn) != 0 {
for _, pkg := range pkgEo.DependsOn { for _, pkg := range pkgEo.DependsOn {
pkgGroup = append(pkgGroup, pkg) pkgGroup = append(pkgGroup, pkg)
} }
} }
hostArch := os.Getenv("REAL_BUILD_ARCH") hostArch := os.Getenv("REAL_BUILD_ARCH")
extraOptions.EnableNetworking = true extraOptions.EnableNetworking = true

View File

@ -35,6 +35,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"github.com/gobwas/glob"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
@ -454,17 +455,48 @@ func kindCatalogSync(tx peridotdb.Access, req *peridotpb.SyncCatalogRequest, cat
func processGroupInstallScopedPackageOptions(tx peridotdb.Access, req *peridotpb.SyncCatalogRequest, groupInstallOptionSet *peridotpb.CatalogGroupInstallOption) (scopedPackages *peridotpb.CatalogGroupInstallScopedPackage, err error) { func processGroupInstallScopedPackageOptions(tx peridotdb.Access, req *peridotpb.SyncCatalogRequest, groupInstallOptionSet *peridotpb.CatalogGroupInstallOption) (scopedPackages *peridotpb.CatalogGroupInstallScopedPackage, err error) {
// handle scoped packages relationships on packages for injection into build root // handle scoped packages relationships on packages for injection into build root
for _, scopedPackage := range groupInstallOptionSet.ScopedPackage { for _, scopedPackage := range groupInstallOptionSet.ScopedPackage {
// Search by name to allow globbing to support pkg-* filters := &peridotpb.PackageFilters{NameExact: wrapperspb.String(scopedPackage.Name)}
pkgs, err := tx.GetPackagesInProject(&peridotpb.PackageFilters{Name: wrapperspb.String(scopedPackage.Name)}, req.ProjectId.Value, 0, 1) isGlob := false
if strings.HasPrefix(scopedPackage.Name, "*") || strings.HasSuffix(scopedPackage.Name, "*") {
filters.Name = wrapperspb.String(strings.TrimSuffix(strings.TrimPrefix(scopedPackage.Name, "*"), "*"))
filters.NameExact = nil
isGlob = true
}
pkgs, err := tx.GetPackagesInProject(filters, req.ProjectId.Value, 0, -1)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get package %s: %w", scopedPackage.Name, err) return nil, fmt.Errorf("failed to get package %s: %w", scopedPackage.Name, err)
} }
if len(pkgs) == 0 { if len(pkgs) == 0 {
return nil, fmt.Errorf("package %s not found in project %s (cannot set scoped package options)", scopedPackage.Name, req.ProjectId.Value) return nil, fmt.Errorf("package %s not found in project %s (scoped package)", scopedPackage.Name, req.ProjectId.Value)
} }
err = tx.SetGroupInstallOptionsForPackage(req.ProjectId.Value, scopedPackage.Name, scopedPackage.DependsOn)
if err != nil { var dbPkgs []models.Package
return nil, fmt.Errorf("failed to set scoped package options for package %s", scopedPackage.Name) if isGlob {
for _, p := range pkgs {
g, err := glob.Compile(scopedPackage.Name)
if err != nil {
return nil, fmt.Errorf("failed to compile glob %s: %w", scopedPackage.Name, err)
}
if g.Match(p.Name) {
dbPkgs = append(dbPkgs, p)
}
}
} else {
if scopedPackage.Name != pkgs[0].Name {
return nil, fmt.Errorf("package %s not found in project %s (cannot set extra options, not glob)", scopedPackage.Name, req.ProjectId.Value)
}
dbPkgs = append(dbPkgs, pkgs[0])
}
if len(dbPkgs) == 0 {
return nil, fmt.Errorf("package %s not found in project %s (cannot set extra options, glob)", scopedPackage.Name, req.ProjectId.Value)
}
for _, dbPkg := range dbPkgs {
err = tx.SetGroupInstallOptionsForPackage(req.ProjectId.Value, dbPkg.Name, scopedPackage.DependsOn)
if err != nil {
return nil, fmt.Errorf("failed to set scoped package options for package %s", scopedPackage.Name)
}
} }
} }
return scopedPackages, nil return scopedPackages, nil
@ -489,21 +521,21 @@ func kindCatalogGroupInstallOptions(tx peridotdb.Access, req *peridotpb.SyncCata
// Proces scoped packages // Proces scoped packages
scopedPackages, err := processGroupInstallScopedPackageOptions(tx, req, groupInstallOption.Srpm) scopedPackages, err := processGroupInstallScopedPackageOptions(tx, req, groupInstallOption.Srpm)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse srpm groupinstall options") return nil, fmt.Errorf("failed to parse srpm groupinstall options: %s", err.Error())
} }
ret.ScopedPackage = append(ret.ScopedPackage, scopedPackages) ret.ScopedPackage = append(ret.ScopedPackage, scopedPackages)
// Process build root packages // Process build root packages
srpmPackages, err := processGroupInstallOptionSet(groupInstallOption.Srpm) srpmPackages, err := processGroupInstallOptionSet(groupInstallOption.Srpm)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse srpm groupinstall options: %w", err) return nil, fmt.Errorf("failed to parse srpm groupinstall options: %w", err)
} }
buildPackages, err := processGroupInstallOptionSet(groupInstallOption.Build) buildPackages, err := processGroupInstallOptionSet(groupInstallOption.Build)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse build groupinstall options: %w", err) return nil, fmt.Errorf("failed to parse build groupinstall options: %w", err)
} }
err = tx.SetBuildRootPackages(req.ProjectId.Value, srpmPackages, buildPackages) err = tx.SetBuildRootPackages(req.ProjectId.Value, srpmPackages, buildPackages)
ret.SrpmPackages = append(ret.SrpmPackages, srpmPackages...) ret.SrpmPackages = append(ret.SrpmPackages, srpmPackages...)
ret.BuildPackages = append(ret.BuildPackages, buildPackages...) ret.BuildPackages = append(ret.BuildPackages, buildPackages...)
} }
@ -811,7 +843,7 @@ func (c *Controller) SyncCatalogActivity(req *peridotpb.SyncCatalogRequest) (*pe
cg1 := &peridotpb.CatalogGroupInstallOptions{} cg1 := &peridotpb.CatalogGroupInstallOptions{}
err = prototext.Unmarshal(bts, cg1) err = prototext.Unmarshal(bts, cg1)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse kind resf.peridot.v1.CatalogExtraOptions: %w", err) return nil, fmt.Errorf("failed to parse kind resf.peridot.v1.CatalogGroupInstallOptions: %w", err)
} }
groupInstallOptions = append(groupInstallOptions, cg1) groupInstallOptions = append(groupInstallOptions, cg1)
default: default:

View File

@ -335,7 +335,7 @@ func (a *Access) GetExtraOptionsForPackage(projectId string, packageName string)
var ret models.ExtraOptions var ret models.ExtraOptions
err := a.query.Get( err := a.query.Get(
&ret, &ret,
"select id, created_at, updated_at, project_id, package_name, with_flags, without_flags from extra_package_options where project_id = $1 and package_name = $2", "select id, created_at, updated_at, project_id, package_name, with_flags, without_flags, depends_on from extra_package_options where project_id = $1 and package_name = $2",
projectId, projectId,
packageName, packageName,
) )
@ -358,7 +358,7 @@ func (a *Access) SetGroupInstallOptionsForPackage(projectId string, packageName
`, `,
projectId, projectId,
packageName, packageName,
dependsOn, dependsOn,
) )
return err return err
} }

View File

@ -119,5 +119,6 @@ func Bool(b bool) *bool {
} }
func Pointer[T any](t T) *T { func Pointer[T any](t T) *T {
return &t s := t
return &s
} }