Files
hakurei/internal/rosa/make.go
Ophestra 51d3df2419
All checks were successful
Test / Create distribution (push) Successful in 59s
Test / Sandbox (push) Successful in 2m41s
Test / Hakurei (push) Successful in 3m53s
Test / ShareFS (push) Successful in 3m57s
Test / Hpkg (push) Successful in 4m28s
Test / Sandbox (race detector) (push) Successful in 5m5s
Test / Hakurei (race detector) (push) Successful in 6m9s
Test / Flake checks (push) Successful in 2m26s
internal/rosa/make: split build and check
Doing these together breaks far too many buggy makefiles.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-03-01 14:41:34 +09:00

223 lines
4.7 KiB
Go

package rosa
import (
"slices"
"strings"
"hakurei.app/internal/pkg"
)
func (t Toolchain) newMake() pkg.Artifact {
const (
version = "4.4.1"
checksum = "YS_B07ZcAy9PbaK5_vKGj64SrxO2VMpnMKfc9I0Q9IC1rn0RwOH7802pJoj2Mq4a"
)
return t.New("make-"+version, TEarly, nil, nil, nil, `
cd "$(mktemp -d)"
/usr/src/make/configure \
--prefix=/system \
--build="${ROSA_TRIPLE}" \
--disable-dependency-tracking
./build.sh
./make DESTDIR=/work install check
`, pkg.Path(AbsUsrSrc.Append("make"), false, pkg.NewHTTPGetTar(
nil, "https://ftpmirror.gnu.org/gnu/make/make-"+version+".tar.gz",
mustDecode(checksum),
pkg.TarGzip,
)))
}
func init() { artifactsF[Make] = Toolchain.newMake }
// MakeAttr holds the project-specific attributes that will be applied to a new
// [pkg.Artifact] compiled via [Make].
type MakeAttr struct {
// Mount the source tree writable.
Writable bool
// Do not include default extras.
OmitDefaults bool
// Dependencies not provided by stage0.
NonStage0 []pkg.Artifact
// Additional environment variables.
Env []string
// Runs before configure.
ScriptEarly string
// Runs after configure.
ScriptConfigured string
// Runs before check.
ScriptCheckEarly string
// Runs after install.
Script string
// Remain in working directory set up during ScriptEarly.
InPlace bool
// Whether to skip running the configure script.
SkipConfigure bool
// Alternative name for the configure script.
ConfigureName string
// Flags passed to the configure script.
Configure [][2]string
// Extra make targets.
Make []string
// Host target triple, zero value is equivalent to the Rosa OS triple.
Host string
// Target triple, zero value is equivalent to the Rosa OS triple.
Build string
// Whether to skip the check target.
SkipCheck bool
// Name of the check target, zero value is equivalent to "check".
Check []string
// Replaces the default install command.
ScriptInstall string
// Suffix appended to the source pathname.
SourceSuffix string
// Passed through to [Toolchain.New], before source.
Paths []pkg.ExecPath
// Passed through to [Toolchain.New].
Flag int
}
// NewViaMake returns a [pkg.Artifact] for compiling and installing via [Make].
func (t Toolchain) NewViaMake(
name, version string,
source pkg.Artifact,
attr *MakeAttr,
extra ...pkg.Artifact,
) pkg.Artifact {
if name == "" || version == "" {
panic("names must be non-empty")
}
if attr == nil {
attr = new(MakeAttr)
}
var configure string
if !attr.SkipConfigure {
configure = attr.ConfigureName
if configure == "" {
configure += `/usr/src/` + name + `/configure \
--prefix=/system`
host := `"${ROSA_TRIPLE}"`
if attr.Host != "" {
host = attr.Host
}
if attr.Host != `""` {
configure += ` \
--host=` + host
}
build := `"${ROSA_TRIPLE}"`
if attr.Build != "" {
build = attr.Build
}
if attr.Build != `""` {
configure += ` \
--build=` + build
}
}
if len(attr.Configure) > 0 {
const sep = " \\\n\t"
configure += sep + strings.Join(
slices.Collect(func(yield func(string) bool) {
for _, v := range attr.Configure {
s := v[0]
if v[0] != "" &&
v[0][0] >= 'a' &&
v[0][0] <= 'z' {
s = "--" + s
} else if len(v[0]) > 1 &&
v[0][0] == 'D' &&
v[0][1] >= 'a' &&
v[0][1] <= 'z' {
s = "-" + s
}
if v[1] != "" {
s += "=" + v[1]
}
if !yield(s) {
return
}
}
}),
sep,
)
}
}
scriptMake := `
make \
"-j$(nproc)"`
if len(attr.Make) > 0 {
scriptMake += " \\\n\t" + strings.Join(attr.Make, " \\\n\t")
}
scriptMake += "\n"
if !attr.SkipCheck {
scriptMake += attr.ScriptCheckEarly + `
make \
"-j$(nproc)" \
`
if len(attr.Check) > 0 {
scriptMake += strings.Join(attr.Check, " \\\n\t")
} else {
scriptMake += "check"
}
scriptMake += "\n"
}
var finalExtra []pkg.Artifact
if !t.isStage0() {
finalExtra = append(finalExtra, t.Load(Make))
}
if !attr.OmitDefaults && attr.Flag&TEarly == 0 {
finalExtra = append(finalExtra,
t.Load(Gawk),
t.Load(Coreutils),
)
}
finalExtra = append(finalExtra, extra...)
scriptEarly := attr.ScriptEarly
if !attr.InPlace {
scriptEarly += `
cd "$(mktemp -d)"
`
} else if scriptEarly == "" {
panic("cannot remain in root")
}
scriptInstall := attr.ScriptInstall
if scriptInstall == "" {
scriptInstall = "make DESTDIR=/work install"
}
scriptInstall += "\n"
return t.New(
name+"-"+version,
attr.Flag,
stage0Concat(t,
attr.NonStage0,
finalExtra...,
),
nil,
attr.Env,
scriptEarly+
configure+
attr.ScriptConfigured+
scriptMake+
scriptInstall+
attr.Script,
slices.Concat(attr.Paths, []pkg.ExecPath{
pkg.Path(AbsUsrSrc.Append(
name+attr.SourceSuffix,
), attr.Writable, source),
})...,
)
}