From 77fb4ac65bb95fd9e0749b8a64c85c703410a740 Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Wed, 19 Oct 2022 15:21:19 -0400 Subject: [PATCH] Finalize SCL feature --- peridot/builder/v1/workflow/arch.go | 18 +++++----- peridot/builder/v1/workflow/srpm.go | 18 +++++----- peridot/builder/v1/workflow/sync.go | 54 +++++++++++++++++++++++------ peridot/db/psql/package.go | 4 +-- utils/pointer.go | 3 +- 5 files changed, 65 insertions(+), 32 deletions(-) diff --git a/peridot/builder/v1/workflow/arch.go b/peridot/builder/v1/workflow/arch.go index 615bfeaf..4be20f9b 100644 --- a/peridot/builder/v1/workflow/arch.go +++ b/peridot/builder/v1/workflow/arch.go @@ -662,17 +662,17 @@ func (c *Controller) BuildArchActivity(ctx context.Context, projectId string, pa return err } - var pkgGroup []string = DefaultBuildPkgGroup + var pkgGroup = DefaultBuildPkgGroup - if len(project.BuildStagePackages) != 0 { - pkgGroup = project.BuildStagePackages - } + if len(project.BuildStagePackages) != 0 { + pkgGroup = project.BuildStagePackages + } - if len(pkgEo.DependsOn) != 0 { - for _, pkg := range pkgEo.DependsOn { - pkgGroup = append(pkgGroup, pkg) - } - } + if len(pkgEo.DependsOn) != 0 { + for _, pkg := range pkgEo.DependsOn { + pkgGroup = append(pkgGroup, pkg) + } + } hostArch := os.Getenv("REAL_BUILD_ARCH") err = c.writeMockConfig(&project, packageVersion, extraOptions, arch, hostArch, pkgGroup) diff --git a/peridot/builder/v1/workflow/srpm.go b/peridot/builder/v1/workflow/srpm.go index 686026b8..b23d1495 100644 --- a/peridot/builder/v1/workflow/srpm.go +++ b/peridot/builder/v1/workflow/srpm.go @@ -416,16 +416,16 @@ func (c *Controller) BuildSRPMActivity(ctx context.Context, upstreamPrefix strin return fmt.Errorf("could not find spec file: %v", err) } - var pkgGroup []string = DefaultSrpmBuildPkgGroup + var pkgGroup = DefaultSrpmBuildPkgGroup - if len(project.SrpmStagePackages) != 0 { - pkgGroup = project.SrpmStagePackages - } - if len(pkgEo.DependsOn) != 0 { - for _, pkg := range pkgEo.DependsOn { - pkgGroup = append(pkgGroup, pkg) - } - } + if len(project.SrpmStagePackages) != 0 { + pkgGroup = project.SrpmStagePackages + } + if len(pkgEo.DependsOn) != 0 { + for _, pkg := range pkgEo.DependsOn { + pkgGroup = append(pkgGroup, pkg) + } + } hostArch := os.Getenv("REAL_BUILD_ARCH") extraOptions.EnableNetworking = true diff --git a/peridot/builder/v1/workflow/sync.go b/peridot/builder/v1/workflow/sync.go index 7bf83a55..88252049 100644 --- a/peridot/builder/v1/workflow/sync.go +++ b/peridot/builder/v1/workflow/sync.go @@ -35,6 +35,7 @@ import ( "encoding/base64" "encoding/xml" "fmt" + "github.com/gobwas/glob" "io/ioutil" "os" "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) { // handle scoped packages relationships on packages for injection into build root for _, scopedPackage := range groupInstallOptionSet.ScopedPackage { - // Search by name to allow globbing to support pkg-* - pkgs, err := tx.GetPackagesInProject(&peridotpb.PackageFilters{Name: wrapperspb.String(scopedPackage.Name)}, req.ProjectId.Value, 0, 1) + filters := &peridotpb.PackageFilters{NameExact: wrapperspb.String(scopedPackage.Name)} + 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 { return nil, fmt.Errorf("failed to get package %s: %w", scopedPackage.Name, err) } 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 { - return nil, fmt.Errorf("failed to set scoped package options for package %s", scopedPackage.Name) + + var dbPkgs []models.Package + 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 @@ -489,21 +521,21 @@ func kindCatalogGroupInstallOptions(tx peridotdb.Access, req *peridotpb.SyncCata // Proces scoped packages scopedPackages, err := processGroupInstallScopedPackageOptions(tx, req, groupInstallOption.Srpm) 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) // Process build root packages srpmPackages, err := processGroupInstallOptionSet(groupInstallOption.Srpm) 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) 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) - + ret.SrpmPackages = append(ret.SrpmPackages, srpmPackages...) ret.BuildPackages = append(ret.BuildPackages, buildPackages...) } @@ -811,7 +843,7 @@ func (c *Controller) SyncCatalogActivity(req *peridotpb.SyncCatalogRequest) (*pe cg1 := &peridotpb.CatalogGroupInstallOptions{} err = prototext.Unmarshal(bts, cg1) 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) default: diff --git a/peridot/db/psql/package.go b/peridot/db/psql/package.go index 68650aef..949571c4 100644 --- a/peridot/db/psql/package.go +++ b/peridot/db/psql/package.go @@ -335,7 +335,7 @@ func (a *Access) GetExtraOptionsForPackage(projectId string, packageName string) var ret models.ExtraOptions err := a.query.Get( &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, packageName, ) @@ -358,7 +358,7 @@ func (a *Access) SetGroupInstallOptionsForPackage(projectId string, packageName `, projectId, packageName, - dependsOn, + dependsOn, ) return err } diff --git a/utils/pointer.go b/utils/pointer.go index 5bc8f26e..237f8670 100644 --- a/utils/pointer.go +++ b/utils/pointer.go @@ -119,5 +119,6 @@ func Bool(b bool) *bool { } func Pointer[T any](t T) *T { - return &t + s := t + return &s }