internal/rosa/make: migrate to helper interface
All checks were successful
Test / Create distribution (push) Successful in 1m8s
Test / Sandbox (push) Successful in 2m55s
Test / Hakurei (push) Successful in 5m3s
Test / ShareFS (push) Successful in 5m13s
Test / Hpkg (push) Successful in 5m56s
Test / Hakurei (race detector) (push) Successful in 6m18s
Test / Sandbox (race detector) (push) Successful in 2m37s
Test / Flake checks (push) Successful in 1m43s
All checks were successful
Test / Create distribution (push) Successful in 1m8s
Test / Sandbox (push) Successful in 2m55s
Test / Hakurei (push) Successful in 5m3s
Test / ShareFS (push) Successful in 5m13s
Test / Hpkg (push) Successful in 5m56s
Test / Hakurei (race detector) (push) Successful in 6m18s
Test / Sandbox (race detector) (push) Successful in 2m37s
Test / Flake checks (push) Successful in 1m43s
This also updates all affected artifacts to use new behaviour. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -28,29 +28,21 @@ cd "$(mktemp -d)"
|
||||
}
|
||||
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
|
||||
|
||||
// MakeHelper is the [Make] build system helper.
|
||||
type MakeHelper struct {
|
||||
// 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
|
||||
// Command to generate the build system.
|
||||
Generate string
|
||||
// Runs before make.
|
||||
ScriptMakeEarly string
|
||||
// Runs before check.
|
||||
ScriptCheckEarly string
|
||||
// Runs after install.
|
||||
Script string
|
||||
|
||||
// Remain in working directory set up during ScriptEarly.
|
||||
// Remain in current directory.
|
||||
InPlace bool
|
||||
|
||||
// Whether to skip running the configure script.
|
||||
@@ -59,40 +51,76 @@ type MakeAttr struct {
|
||||
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
|
||||
|
||||
// Extra make targets.
|
||||
Make []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
|
||||
Install string
|
||||
}
|
||||
|
||||
// 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")
|
||||
var _ Helper = new(MakeHelper)
|
||||
|
||||
// name returns its arguments joined with '-'.
|
||||
func (*MakeHelper) name(name, version string) string {
|
||||
return name + "-" + version
|
||||
}
|
||||
|
||||
// extra returns make and other optional dependencies.
|
||||
func (attr *MakeHelper) extra(flag int) []PArtifact {
|
||||
extra := []PArtifact{Make}
|
||||
if (attr == nil || !attr.OmitDefaults) && flag&TEarly == 0 {
|
||||
extra = append(extra,
|
||||
Gawk,
|
||||
Coreutils,
|
||||
)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
// wantsChmod returns whether the build system needs to be generated.
|
||||
func (attr *MakeHelper) wantsChmod() bool {
|
||||
return attr != nil && attr.Generate != ""
|
||||
}
|
||||
|
||||
// wantsWrite is equivalent to wantsChmod.
|
||||
func (attr *MakeHelper) wantsWrite() bool { return attr.wantsChmod() }
|
||||
|
||||
// scriptEarly returns the optional build system generation segment.
|
||||
func (attr *MakeHelper) scriptEarly() string {
|
||||
if attr == nil {
|
||||
attr = new(MakeAttr)
|
||||
return ""
|
||||
}
|
||||
|
||||
generate := attr.Generate
|
||||
if len(generate) > 0 && generate[len(generate)-1] != '\n' {
|
||||
generate += "\n"
|
||||
}
|
||||
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.
|
||||
func (attr *MakeHelper) wantsDir() string {
|
||||
if attr != nil && attr.InPlace {
|
||||
return helperInPlace
|
||||
}
|
||||
return `"$(mktemp -d)"`
|
||||
}
|
||||
|
||||
// script generates the cure script.
|
||||
func (attr *MakeHelper) script(name string) string {
|
||||
if attr == nil {
|
||||
attr = new(MakeHelper)
|
||||
}
|
||||
|
||||
var configure string
|
||||
@@ -159,8 +187,7 @@ make \
|
||||
scriptMake += "\n"
|
||||
|
||||
if !attr.SkipCheck {
|
||||
scriptMake += attr.ScriptCheckEarly + `
|
||||
make \
|
||||
scriptMake += attr.ScriptCheckEarly + `make \
|
||||
"-j$(nproc)" \
|
||||
`
|
||||
if len(attr.Check) > 0 {
|
||||
@@ -171,52 +198,15 @@ make \
|
||||
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
|
||||
scriptInstall := attr.Install
|
||||
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),
|
||||
})...,
|
||||
)
|
||||
return configure +
|
||||
attr.ScriptMakeEarly +
|
||||
scriptMake +
|
||||
scriptInstall +
|
||||
attr.Script
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user