diff --git a/internal/rosa/builtins.go b/internal/rosa/builtins.go index 6d457dbd..dbafa397 100644 --- a/internal/rosa/builtins.go +++ b/internal/rosa/builtins.go @@ -1,10 +1,13 @@ package rosa import ( + "io/fs" + "os" "path" "slices" "strconv" "strings" + "time" "hakurei.app/internal/pkg" ) @@ -115,8 +118,29 @@ func skipGNUTests(tests ...int64) string { return buf.String() } -// builtin contains native and embedded [Artifact] registrations. -var builtin S +var ( + // builtin contains native and embedded [Artifact] registrations. + builtin S + + // parseTime is the duration of early parsing of built-in azalea expressions. + parseTime time.Duration +) + +// ParseTime returns the time taken by early parsing of built-in azalea expressions. +func ParseTime() time.Duration { return parseTime } + +func init() { + sub, err := fs.Sub(builtinAzalea, "package") + if err != nil { + panic(err) + } + t := time.Now() + if err = builtin.RegisterFS(sub); err != nil { + println(err.Error()) + os.Exit(1) + } + parseTime = time.Since(t) +} // New returns the address of a newly populated [S] derived from built-ins. func New() *S { return builtin.Clone() } diff --git a/internal/rosa/builtins_embed.go b/internal/rosa/builtins_embed.go new file mode 100644 index 00000000..2ef42f00 --- /dev/null +++ b/internal/rosa/builtins_embed.go @@ -0,0 +1,11 @@ +//go:build !penv + +package rosa + +import "embed" + +// builtinAzalea is the backing directory of built-in azalea-based [Artifact] +// implementations. +// +//go:embed package +var builtinAzalea embed.FS diff --git a/internal/rosa/builtins_env.go b/internal/rosa/builtins_env.go new file mode 100644 index 00000000..a125e25f --- /dev/null +++ b/internal/rosa/builtins_env.go @@ -0,0 +1,28 @@ +//go:build penv + +package rosa + +import ( + "io/fs" + "os" +) + +// builtinAzalea is the backing directory of built-in azalea-based [Artifact] +// implementations. +var builtinAzalea = func() fs.FS { + const name = "ROSA_SOURCE" + + pathname, ok := os.LookupEnv(name) + if !ok { + println(name + " not set") + os.Exit(1) + } + + root, err := os.OpenRoot(pathname) + if err != nil { + println(err.Error()) + os.Exit(1) + } + + return root.FS() +}() diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go index 1089ffa1..2a7cd777 100644 --- a/internal/rosa/rosa.go +++ b/internal/rosa/rosa.go @@ -2,14 +2,11 @@ package rosa import ( - "embed" - "io/fs" "os" "slices" "strconv" "strings" "sync" - "time" "unsafe" "hakurei.app/fhs" @@ -623,28 +620,3 @@ func (attr *GenericHelper) script(t Toolchain, _ string) string { script += attr.Install return script } - -// parseTime is the duration of early parsing of built-in azalea expressions. -var parseTime time.Duration - -// ParseTime returns the time taken by early parsing of built-in azalea expressions. -func ParseTime() time.Duration { return parseTime } - -// builtinAzalea is the backing directory of built-in azalea-based [Artifact] -// implementations. -// -//go:embed package -var builtinAzalea embed.FS - -func init() { - sub, err := fs.Sub(builtinAzalea, "package") - if err != nil { - panic(err) - } - t := time.Now() - if err = builtin.RegisterFS(sub); err != nil { - println(err.Error()) - os.Exit(1) - } - parseTime = time.Since(t) -}