feat(prebuild): add builder opt to build tasks.
This commit is contained in:
parent
02e3334949
commit
2dd6046697
9 changed files with 38 additions and 13 deletions
|
|
@ -30,6 +30,6 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b ABI3) Apply(profile string) (string, error) {
|
func (b ABI3) Apply(opt *Option, profile string) (string, error) {
|
||||||
return regAbi4To3.Replace(profile), nil
|
return regAbi4To3.Replace(profile), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Complain) Apply(profile string) (string, error) {
|
func (b Complain) Apply(opt *Option, profile string) (string, error) {
|
||||||
flags := []string{}
|
flags := []string{}
|
||||||
matches := regFlags.FindStringSubmatch(profile)
|
matches := regFlags.FindStringSubmatch(profile)
|
||||||
if len(matches) != 0 {
|
if len(matches) != 0 {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ package builder
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/arduino/go-paths-helper"
|
||||||
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
"github.com/roddhjav/apparmor.d/pkg/prebuild/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -21,7 +22,20 @@ var (
|
||||||
// Main directive interface
|
// Main directive interface
|
||||||
type Builder interface {
|
type Builder interface {
|
||||||
cfg.BaseInterface
|
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) {
|
func Register(names ...string) {
|
||||||
|
|
@ -37,3 +51,15 @@ func Register(names ...string) {
|
||||||
func RegisterBuilder(d Builder) {
|
func RegisterBuilder(d Builder) {
|
||||||
Builders[d.Name()] = d
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,8 @@ func TestBuilder_Apply(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := tt.b.Apply(tt.profile)
|
opt := &Option{}
|
||||||
|
got, err := tt.b.Apply(opt, tt.profile)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("Builder.Apply() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("Builder.Apply() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,6 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Dev) Apply(profile string) (string, error) {
|
func (b Dev) Apply(opt *Option, profile string) (string, error) {
|
||||||
return regDev.Replace(profile), nil
|
return regDev.Replace(profile), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Enforce) Apply(profile string) (string, error) {
|
func (b Enforce) Apply(opt *Option, profile string) (string, error) {
|
||||||
matches := regFlags.FindStringSubmatch(profile)
|
matches := regFlags.FindStringSubmatch(profile)
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
return profile, nil
|
return profile, nil
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,6 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b FullSystemPolicy) Apply(profile string) (string, error) {
|
func (b FullSystemPolicy) Apply(opt *Option, profile string) (string, error) {
|
||||||
return regFullSystemPolicy.Replace(profile), nil
|
return regFullSystemPolicy.Replace(profile), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Userspace) Apply(profile string) (string, error) {
|
func (b Userspace) Apply(opt *Option, profile string) (string, error) {
|
||||||
p := aa.DefaultTunables()
|
p := aa.DefaultTunables()
|
||||||
p.ParseVariables(profile)
|
p.ParseVariables(profile)
|
||||||
p.ResolveAttachments()
|
p.ResolveAttachments()
|
||||||
|
|
|
||||||
|
|
@ -83,12 +83,10 @@ func Build() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, b := range builder.Builds {
|
profile, err = builder.Run(file, profile)
|
||||||
profile, err = b.Apply(profile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
profile, err = directive.Run(file, profile)
|
profile, err = directive.Run(file, profile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue