build: add initial build structure for sub packages.

This commit is contained in:
Alexandre Pujol 2024-10-23 14:48:47 +01:00
parent 467b24ccee
commit a1c8260305
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
5 changed files with 391 additions and 37 deletions

View file

@ -6,6 +6,8 @@ package builder
import (
"fmt"
"slices"
"strings"
"github.com/roddhjav/apparmor.d/pkg/paths"
"github.com/roddhjav/apparmor.d/pkg/prebuild"
@ -33,7 +35,7 @@ type Option struct {
func NewOption(file *paths.Path) *Option {
return &Option{
Name: file.Base(),
Name: strings.TrimSuffix(file.Base(), ".apparmor.d"),
File: file,
}
}
@ -41,13 +43,26 @@ func NewOption(file *paths.Path) *Option {
func Register(names ...string) {
for _, name := range names {
if b, present := Builders[name]; present {
Builds = append(Builds, b)
if !slices.Contains(Builds, b) {
Builds = append(Builds, b)
}
} else {
panic(fmt.Sprintf("Unknown builder: %s", name))
}
}
}
func Unregister(names ...string) {
for _, name := range names {
for i, b := range Builds {
if b.Name() == name {
Builds = slices.Delete(Builds, i, i+1)
break
}
}
}
}
func RegisterBuilder(d Builder) {
Builders[d.Name()] = d
}