internal/rosa: expose in-place behaviour in generic helper
All checks were successful
Test / Create distribution (push) Successful in 1m5s
Test / Sandbox (push) Successful in 3m14s
Test / Hakurei (push) Successful in 4m23s
Test / ShareFS (push) Successful in 4m22s
Test / Sandbox (race detector) (push) Successful in 5m47s
Test / Hakurei (race detector) (push) Successful in 6m51s
Test / Flake checks (push) Successful in 1m29s

This change also combines the createDir and wantsDir methods, and replaces the non-inplace target of the generic helper with a deterministic path.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-05-21 16:10:55 +09:00
parent cbf18b302d
commit 6546ddc64b
13 changed files with 27 additions and 42 deletions

View File

@@ -48,11 +48,8 @@ func (*CMakeHelper) wantsWrite() bool { return false }
// scriptEarly returns the zero value. // scriptEarly returns the zero value.
func (*CMakeHelper) scriptEarly() string { return "" } func (*CMakeHelper) scriptEarly() string { return "" }
// createDir returns true.
func (*CMakeHelper) createDir() bool { return true }
// wantsDir returns a hardcoded, deterministic pathname. // wantsDir returns a hardcoded, deterministic pathname.
func (*CMakeHelper) wantsDir() string { return "/cure/" } func (*CMakeHelper) wantsDir() (string, bool) { return "/cure/", true }
// script generates the cure script. // script generates the cure script.
func (attr *CMakeHelper) script(t Toolchain, name string) string { func (attr *CMakeHelper) script(t Toolchain, name string) string {

View File

@@ -82,15 +82,12 @@ func (attr *MakeHelper) scriptEarly() string {
return generate return generate
} }
// createDir returns false.
func (*MakeHelper) createDir() bool { return false }
// wantsDir requests a new directory in TMPDIR, or omits the cd statement if InPlace. // wantsDir requests a new directory in TMPDIR, or omits the cd statement if InPlace.
func (attr *MakeHelper) wantsDir() string { func (attr *MakeHelper) wantsDir() (string, bool) {
if attr != nil && attr.InPlace { if attr != nil && attr.InPlace {
return helperInPlace return helperInPlace, false
} }
return `"$(mktemp -d)"` return `"$(mktemp -d)"`, false
} }
// script generates the cure script. // script generates the cure script.

View File

@@ -36,11 +36,8 @@ func (*MesonHelper) wantsWrite() bool { return false }
// scriptEarly returns the zero value. // scriptEarly returns the zero value.
func (*MesonHelper) scriptEarly() string { return "" } func (*MesonHelper) scriptEarly() string { return "" }
// createDir returns false.
func (*MesonHelper) createDir() bool { return false }
// wantsDir requests a new directory in TMPDIR. // wantsDir requests a new directory in TMPDIR.
func (*MesonHelper) wantsDir() string { return `"$(mktemp -d)"` } func (*MesonHelper) wantsDir() (string, bool) { return `"$(mktemp -d)"`, false }
// script generates the cure script. // script generates the cure script.
func (attr *MesonHelper) script(t Toolchain, name string) string { func (attr *MesonHelper) script(t Toolchain, name string) string {

View File

@@ -153,7 +153,9 @@ package gen_init_cpio {
description = "a program in the kernel source tree for creating initramfs archive"; description = "a program in the kernel source tree for creating initramfs archive";
source = kernel-source; source = kernel-source;
enterSource = true;
exec = generic { exec = generic {
inPlace = true;
build = ` build = `
mkdir -p /work/system/bin/ mkdir -p /work/system/bin/
cc -o /work/system/bin/gen_init_cpio usr/gen_init_cpio.c cc -o /work/system/bin/gen_init_cpio usr/gen_init_cpio.c

View File

@@ -13,7 +13,6 @@ package make {
toyboxEarly = true; toyboxEarly = true;
exec = generic { exec = generic {
mktemp = true;
build = `/usr/src/make/configure \ build = `/usr/src/make/configure \
--prefix=/system \ --prefix=/system \
--build="${ROSA_TRIPLE}" \ --build="${ROSA_TRIPLE}" \

View File

@@ -16,8 +16,6 @@ package mksh {
]; ];
exec = generic { exec = generic {
mktemp = true;
build = `sh /usr/src/mksh/Build.sh -r build = `sh /usr/src/mksh/Build.sh -r
CPPFLAGS="${CPPFLAGS} -DMKSH_BINSHPOSIX -DMKSH_BINSHREDUCED" \ CPPFLAGS="${CPPFLAGS} -DMKSH_BINSHPOSIX -DMKSH_BINSHREDUCED" \
sh /usr/src/mksh/Build.sh -r -L sh /usr/src/mksh/Build.sh -r -L

View File

@@ -78,7 +78,9 @@ package nss-cacert {
source = nss; source = nss;
enterSource = true;
exec = generic { exec = generic {
inPlace = true;
build = ` build = `
mkdir -p /work/system/etc/ssl/{certs/unbundled,certs/hashed,trust-source} mkdir -p /work/system/etc/ssl/{certs/unbundled,certs/hashed,trust-source}
buildcatrust \ buildcatrust \

View File

@@ -59,10 +59,12 @@ package perl-Module-Build {
checksum = "ZKxEFG4hE1rqZt52zBL2LRZBMkYzhjb5-cTBXcsyA52EbPeeYyVxU176yAea8-Di"; checksum = "ZKxEFG4hE1rqZt52zBL2LRZBMkYzhjb5-cTBXcsyA52EbPeeYyVxU176yAea8-Di";
}; };
enterSource = true;
writable = true; writable = true;
chmod = true; chmod = true;
exec = generic { exec = generic {
inPlace = true;
build = ` build = `
perl Build.PL --prefix=/system perl Build.PL --prefix=/system
./Build build`; ./Build build`;

View File

@@ -15,10 +15,12 @@ package unzip {
compress = gzip; compress = gzip;
}; };
enterSource = true;
writable = true; writable = true;
chmod = true; chmod = true;
exec = generic { exec = generic {
inPlace = true;
build = `unix/configure build = `unix/configure
make -f unix/Makefile generic1`; make -f unix/Makefile generic1`;
install = ` install = `

View File

@@ -26,11 +26,8 @@ func (*MakeMakerHelper) wantsWrite() bool { return true }
// scriptEarly is a noop. // scriptEarly is a noop.
func (*MakeMakerHelper) scriptEarly() string { return "" } func (*MakeMakerHelper) scriptEarly() string { return "" }
// createDir returns false. // wantsDir requests the source directory.
func (*MakeMakerHelper) createDir() bool { return false } func (*MakeMakerHelper) wantsDir() (string, bool) { return "", false }
// wantsDir returns the zero value.
func (*MakeMakerHelper) wantsDir() string { return "" }
// script generates Makefile.PL-based build and test commands. // script generates Makefile.PL-based build and test commands.
func (attr *MakeMakerHelper) script(t Toolchain, _ string) string { func (attr *MakeMakerHelper) script(t Toolchain, _ string) string {

View File

@@ -48,11 +48,8 @@ func (attr *PipHelper) wantsWrite() bool { return attr.wantsChmod() }
// scriptEarly is a noop. // scriptEarly is a noop.
func (*PipHelper) scriptEarly() string { return "" } func (*PipHelper) scriptEarly() string { return "" }
// createDir returns false.
func (*PipHelper) createDir() bool { return false }
// wantsDir requests a new directory in TMPDIR. // wantsDir requests a new directory in TMPDIR.
func (*PipHelper) wantsDir() string { return `"$(mktemp -d)"` } func (*PipHelper) wantsDir() (string, bool) { return `"$(mktemp -d)"`, false }
// script generates the pip3 install command. // script generates the pip3 install command.
func (attr *PipHelper) script(_ Toolchain, name string) string { func (attr *PipHelper) script(_ Toolchain, name string) string {

View File

@@ -397,13 +397,11 @@ type Helper interface {
// scriptEarly returns the helper-specific segment of cure script that goes // scriptEarly returns the helper-specific segment of cure script that goes
// before the cd statement. // before the cd statement.
scriptEarly() string scriptEarly() string
// createDir returns whether the path returned by wantsDir should be created.
createDir() bool
// wantsDir returns the directory to enter before script. // wantsDir returns the directory to enter before script.
// //
// The zero value implies source directory if [PackageAttr.ScriptEarly] is // The zero value implies source directory if [PackageAttr.ScriptEarly] is
// also empty. The special value helperInPlace omits the cd statement. // also empty. The special value helperInPlace omits the cd statement.
wantsDir() string wantsDir() (pathname string, create bool)
// script returns the helper-specific segment of cure script. // script returns the helper-specific segment of cure script.
script(t Toolchain, name string) string script(t Toolchain, name string) string
} }
@@ -527,7 +525,7 @@ mv '/usr/src/` + rn + `' '/usr/src/` + name + `'
` `
} }
dir := helper.wantsDir() dir, create := helper.wantsDir()
helperScriptEarly := helper.scriptEarly() helperScriptEarly := helper.scriptEarly()
if attr.EnterSource || if attr.EnterSource ||
dir == "" || dir == "" ||
@@ -539,7 +537,7 @@ cd '/usr/src/` + name + `/'
} }
scriptEarly += attr.ScriptEarly + helperScriptEarly scriptEarly += attr.ScriptEarly + helperScriptEarly
if dir != "" && dir != helperInPlace { if dir != "" && dir != helperInPlace {
if helper.createDir() { if create {
scriptEarly += "\nmkdir -p " + dir scriptEarly += "\nmkdir -p " + dir
} }
scriptEarly += "\ncd " + dir + "\n" scriptEarly += "\ncd " + dir + "\n"
@@ -568,8 +566,8 @@ cd '/usr/src/` + name + `/'
// one-off build scripts too specific to fit into any other [Helper] // one-off build scripts too specific to fit into any other [Helper]
// implementation, but can still benefit from [Toolchain.NewPackage]. // implementation, but can still benefit from [Toolchain.NewPackage].
type GenericHelper struct { type GenericHelper struct {
// Whether to create and enter a directory in TMPDIR. // Remain in current directory.
EnterTemp bool InPlace bool
// Concatenated for [Toolchain]. // Concatenated for [Toolchain].
Build, Check, Install string Build, Check, Install string
@@ -589,15 +587,12 @@ func (*GenericHelper) wantsWrite() bool { return false }
// scriptEarly returns the zero value. // scriptEarly returns the zero value.
func (*GenericHelper) scriptEarly() string { return "" } func (*GenericHelper) scriptEarly() string { return "" }
// createDir returns false. // wantsDir requests a new directory, or omits the cd statement if InPlace.
func (*GenericHelper) createDir() bool { return false } func (attr *GenericHelper) wantsDir() (string, bool) {
if attr == nil || !attr.InPlace {
// wantsDir requests a new directory in TMPDIR, or the source directory otherwise. return "/cure/", true
func (attr *GenericHelper) wantsDir() string {
if attr != nil && attr.EnterTemp {
return `"$(mktemp -d)"`
} }
return "" return helperInPlace, false
} }
// script concatenates specified segments. // script concatenates specified segments.

View File

@@ -746,7 +746,7 @@ func (s *S) getFrame() azalea.Frame {
) (v any, set bool, err error) { ) (v any, set bool, err error) {
var attr GenericHelper var attr GenericHelper
if err = args.Apply(map[unique.Handle[azalea.Ident]]any{ if err = args.Apply(map[unique.Handle[azalea.Ident]]any{
k("mktemp"): &attr.EnterTemp, k("inPlace"): &attr.InPlace,
k("build"): &attr.Build, k("build"): &attr.Build,
k("check"): &attr.Check, k("check"): &attr.Check,
k("install"): &attr.Install, k("install"): &attr.Install,