aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/make.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/rosa/make.go')
-rw-r--r--internal/rosa/make.go148
1 files changed, 69 insertions, 79 deletions
diff --git a/internal/rosa/make.go b/internal/rosa/make.go
index fb74039c..891f6077 100644
--- a/internal/rosa/make.go
+++ b/internal/rosa/make.go
@@ -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
+ Install string
+}
+
+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 != ""
+}
- // Suffix appended to the source pathname.
- SourceSuffix string
+// wantsWrite is equivalent to wantsChmod.
+func (attr *MakeHelper) wantsWrite() bool { return attr.wantsChmod() }
- // Passed through to [Toolchain.New], before source.
- Paths []pkg.ExecPath
- // Passed through to [Toolchain.New].
- Flag int
+// scriptEarly returns the optional build system generation segment.
+func (attr *MakeHelper) scriptEarly() string {
+ if attr == nil {
+ return ""
+ }
+
+ generate := attr.Generate
+ if len(generate) > 0 && generate[len(generate)-1] != '\n' {
+ generate += "\n"
+ }
+ return generate
}
-// 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")
+// 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(MakeAttr)
+ 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
}