feat(prebuild): add builder opt to build tasks.

This commit is contained in:
Alexandre Pujol 2024-05-25 22:32:10 +01:00
parent 02e3334949
commit 2dd6046697
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
9 changed files with 38 additions and 13 deletions

View file

@ -7,6 +7,7 @@ package builder
import (
"fmt"
"github.com/arduino/go-paths-helper"
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
)
@ -21,7 +22,20 @@ var (
// Main directive interface
type Builder interface {
cfg.BaseInterface
Apply(profile string) (string, error)
Apply(opt *Option, profile string) (string, error)
}
// Builder options
type Option struct {
Name string
File *paths.Path
}
func NewOption(file *paths.Path) *Option {
return &Option{
Name: file.Base(),
File: file,
}
}
func Register(names ...string) {
@ -37,3 +51,15 @@ func Register(names ...string) {
func RegisterBuilder(d Builder) {
Builders[d.Name()] = d
}
func Run(file *paths.Path, profile string) (string, error) {
var err error
opt := NewOption(file)
for _, b := range Builds {
profile, err = b.Apply(opt, profile)
if err != nil {
return "", err
}
}
return profile, nil
}