forked from rosa/hakurei
internal/rosa: pass stage alongside state
This cleans up many function signatures. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -104,49 +104,46 @@ func (s *S) earlyLDFLAGS(static bool) string {
|
||||
return p
|
||||
}
|
||||
|
||||
// Toolchain denotes the infrastructure to compile a [pkg.Artifact] on.
|
||||
type Toolchain uint32
|
||||
|
||||
const (
|
||||
// _toolchainBusybox denotes a busybox installation from the busyboxBin
|
||||
// binary distribution. This is defined as a toolchain to make use of the
|
||||
// toolchain abstractions to preprocess toolchainGentoo and is not a real,
|
||||
// _stageBusybox denotes a busybox installation from the busyboxBin
|
||||
// binary distribution. This is defined as a [Stage] to make use of the
|
||||
// toolchain abstractions to preprocess stageGentoo and is not a real,
|
||||
// functioning toolchain. It does not contain any compilers.
|
||||
_toolchainBusybox Toolchain = iota
|
||||
_stageBusybox Stage = iota
|
||||
|
||||
// toolchainGentoo denotes the toolchain in a Gentoo stage3 tarball. Special
|
||||
// care must be taken to compile correctly against this toolchain.
|
||||
toolchainGentoo
|
||||
// stageGentoo denotes the toolchain in a Gentoo stage3 tarball. Special
|
||||
// care must be taken to compile correctly against this stage.
|
||||
stageGentoo
|
||||
|
||||
// toolchainIntermediateGentoo is like to toolchainIntermediate, but
|
||||
// compiled against toolchainGentoo.
|
||||
toolchainIntermediateGentoo
|
||||
// stageIntermediateGentoo is like stageIntermediate, but compiled against
|
||||
// stageGentoo.
|
||||
stageIntermediateGentoo
|
||||
|
||||
// toolchainStdGentoo is like Std, but bootstrapped from toolchainGentoo.
|
||||
// This toolchain creates the first [Stage0] distribution.
|
||||
toolchainStdGentoo
|
||||
// stageStdGentoo is like Std, but bootstrapped from stageGentoo. This
|
||||
// toolchain creates the first [Stage0] distribution.
|
||||
stageStdGentoo
|
||||
|
||||
// toolchainStage0 denotes the stage0 toolchain. Special care must be taken
|
||||
// stageEarly denotes the stage0 toolchain. Special care must be taken
|
||||
// to compile correctly against this toolchain.
|
||||
toolchainStage0
|
||||
stageEarly
|
||||
|
||||
// toolchainIntermediate denotes the intermediate toolchain compiled against
|
||||
// toolchainStage0. This toolchain should be functionally identical to [Std]
|
||||
// stageIntermediate denotes the intermediate toolchain compiled against
|
||||
// stageEarly. This toolchain should be functionally identical to [Std]
|
||||
// and is used to bootstrap [Std].
|
||||
toolchainIntermediate
|
||||
stageIntermediate
|
||||
|
||||
// Std denotes the standard Rosa OS toolchain.
|
||||
Std
|
||||
|
||||
// _toolchainEnd is the total number of toolchains available and does not
|
||||
// denote a valid toolchain.
|
||||
_toolchainEnd
|
||||
// _stageEnd is the total number of stages available and does not denote a
|
||||
// valid toolchain.
|
||||
_stageEnd
|
||||
)
|
||||
|
||||
// isStage0 returns whether t is a stage0 toolchain.
|
||||
func (t Toolchain) isStage0() bool {
|
||||
func (t Stage) isStage0() bool {
|
||||
switch t {
|
||||
case toolchainGentoo, toolchainStage0:
|
||||
case stageGentoo, stageEarly:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -154,9 +151,9 @@ func (t Toolchain) isStage0() bool {
|
||||
}
|
||||
|
||||
// isIntermediate returns whether t is an intermediate toolchain.
|
||||
func (t Toolchain) isIntermediate() bool {
|
||||
func (t Stage) isIntermediate() bool {
|
||||
switch t {
|
||||
case toolchainIntermediateGentoo, toolchainIntermediate:
|
||||
case stageIntermediateGentoo, stageIntermediate:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -164,9 +161,9 @@ func (t Toolchain) isIntermediate() bool {
|
||||
}
|
||||
|
||||
// isStd returns whether t is considered functionally equivalent to [Std].
|
||||
func (t Toolchain) isStd() bool {
|
||||
func (t Stage) isStd() bool {
|
||||
switch t {
|
||||
case toolchainStdGentoo, Std:
|
||||
case stageStdGentoo, Std:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -224,8 +221,7 @@ const (
|
||||
)
|
||||
|
||||
// New returns a [pkg.Artifact] based on a [Toolchain] via s.
|
||||
func (s *S) New(
|
||||
t Toolchain,
|
||||
func (t Toolchain) New(
|
||||
name string,
|
||||
flag int,
|
||||
extra []pkg.Artifact,
|
||||
@@ -238,21 +234,21 @@ func (s *S) New(
|
||||
const lcMessages = "LC_MESSAGES=C.UTF-8"
|
||||
|
||||
var support []pkg.Artifact
|
||||
switch t {
|
||||
case _toolchainBusybox:
|
||||
switch t.stage {
|
||||
case _stageBusybox:
|
||||
name += "-early"
|
||||
support = slices.Concat([]pkg.Artifact{s.newBusyboxBin()}, extra)
|
||||
support = slices.Concat([]pkg.Artifact{t.newBusyboxBin()}, extra)
|
||||
env = fixupEnviron(env, nil, "/system/bin")
|
||||
|
||||
case toolchainGentoo, toolchainStage0:
|
||||
case stageGentoo, stageEarly:
|
||||
name += "-boot"
|
||||
support = append(support, extra...)
|
||||
support = append(support, cureEtc{})
|
||||
if t == toolchainStage0 {
|
||||
a, _ := s.Load(t, stage0Dist)
|
||||
if t.stage == stageEarly {
|
||||
a, _ := t.Load(stage0Dist)
|
||||
support = append(support, a)
|
||||
} else {
|
||||
support = append(support, s.New(_toolchainBusybox, "gentoo", 0, nil, nil, nil, `
|
||||
support = append(support, t.S.New(_stageBusybox).New("gentoo", 0, nil, nil, nil, `
|
||||
tar -C /work -xf /usr/src/stage3.tar.xz
|
||||
rm -rf /work/dev/ /work/proc/
|
||||
ln -vs ../usr/bin /work/bin
|
||||
@@ -263,22 +259,22 @@ mkdir -vp /work/system/bin
|
||||
.)
|
||||
`, pkg.Path(AbsUsrSrc.Append("stage3.tar.xz"), false,
|
||||
pkg.NewHTTPGet(
|
||||
nil, s.gentooStage3,
|
||||
s.gentooStage3Checksum,
|
||||
nil, t.gentooStage3,
|
||||
t.gentooStage3Checksum,
|
||||
),
|
||||
)))
|
||||
}
|
||||
env = fixupEnviron(env, []string{
|
||||
EnvTriplet + "=" + s.triple(),
|
||||
EnvTriplet + "=" + t.triple(),
|
||||
lcMessages,
|
||||
"LDFLAGS=" + s.earlyLDFLAGS(true),
|
||||
"LDFLAGS=" + t.earlyLDFLAGS(true),
|
||||
}, "/system/bin",
|
||||
"/usr/bin",
|
||||
)
|
||||
|
||||
case toolchainIntermediateGentoo, toolchainStdGentoo,
|
||||
toolchainIntermediate, Std:
|
||||
if t.isIntermediate() {
|
||||
case stageIntermediateGentoo, stageStdGentoo,
|
||||
stageIntermediate, Std:
|
||||
if t.stage.isIntermediate() {
|
||||
name += "-std"
|
||||
}
|
||||
|
||||
@@ -292,7 +288,7 @@ mkdir -vp /work/system/bin
|
||||
base = Musl
|
||||
}
|
||||
|
||||
support = slices.Concat(extra, s.AppendPresets(t-1, []pkg.Artifact{
|
||||
support = slices.Concat(extra, t.S.New(t.stage-1).Append([]pkg.Artifact{
|
||||
cureEtc{newIANAEtc()},
|
||||
},
|
||||
base,
|
||||
@@ -300,16 +296,16 @@ mkdir -vp /work/system/bin
|
||||
toybox,
|
||||
))
|
||||
env = fixupEnviron(env, []string{
|
||||
EnvTriplet + "=" + s.triple(),
|
||||
EnvTriplet + "=" + t.triple(),
|
||||
lcMessages,
|
||||
}, "/system/bin", "/bin")
|
||||
|
||||
default:
|
||||
panic("unsupported toolchain " + strconv.Itoa(int(t)))
|
||||
panic("unsupported toolchain " + strconv.Itoa(int(t.stage)))
|
||||
}
|
||||
|
||||
return pkg.NewExec(
|
||||
name, s.arch, knownChecksum, pkg.ExecTimeoutMax,
|
||||
name, t.arch, knownChecksum, pkg.ExecTimeoutMax,
|
||||
flag&THostNet != 0,
|
||||
flag&TExclusive != 0,
|
||||
fhs.AbsRoot, env,
|
||||
@@ -328,8 +324,7 @@ mkdir -vp /work/system/bin
|
||||
|
||||
// NewPatchedSource returns [pkg.Artifact] of source with patches applied. If
|
||||
// passthrough is true, source is returned as is for zero length patches.
|
||||
func (s *S) NewPatchedSource(
|
||||
t Toolchain,
|
||||
func (t Toolchain) NewPatchedSource(
|
||||
name, version string,
|
||||
source pkg.Artifact,
|
||||
passthrough bool,
|
||||
@@ -362,7 +357,7 @@ cat /usr/src/` + name + `-patches/* | \
|
||||
`
|
||||
aname += "-patched"
|
||||
}
|
||||
return s.New(t, aname, 0, s.AppendPresets(t, nil,
|
||||
return t.New(aname, 0, t.Append(nil,
|
||||
Patch,
|
||||
), nil, nil, script, paths...)
|
||||
}
|
||||
@@ -431,42 +426,34 @@ func paGet() pa { return paPool.Get().(pa) }
|
||||
// paPut returns a pa to paPool.
|
||||
func paPut(pv pa) { clear(pv); paPool.Put(pv) }
|
||||
|
||||
// appendPreset recursively appends a [PArtifact] and its runtime dependencies.
|
||||
func (s *S) appendPreset(
|
||||
t Toolchain,
|
||||
a []pkg.Artifact,
|
||||
pv pa, p ArtifactH,
|
||||
) []pkg.Artifact {
|
||||
// appendHandle recursively appends an [Artifact] named by its handle, and its
|
||||
// runtime dependencies.
|
||||
func (t Toolchain) appendHandle(a []pkg.Artifact, pv pa, p ArtifactH) []pkg.Artifact {
|
||||
if _, ok := pv[p]; ok {
|
||||
return a
|
||||
}
|
||||
pv[p] = struct{}{}
|
||||
|
||||
for _, d := range s.Get(p).Dependencies {
|
||||
a = s.appendPreset(t, a, pv, d)
|
||||
for _, d := range t.MustGet(p).Dependencies {
|
||||
a = t.appendHandle(a, pv, d)
|
||||
}
|
||||
d, _ := s.Load(t, p)
|
||||
d, _ := t.Load(p)
|
||||
return append(a, d)
|
||||
}
|
||||
|
||||
// AppendPresets recursively appends multiple [PArtifact] and their runtime
|
||||
// dependencies.
|
||||
func (s *S) AppendPresets(
|
||||
t Toolchain,
|
||||
a []pkg.Artifact,
|
||||
presets ...ArtifactH,
|
||||
) []pkg.Artifact {
|
||||
// Append recursively appends multiple [Artifact] named by their handles, and
|
||||
// their runtime dependencies.
|
||||
func (t Toolchain) Append(a []pkg.Artifact, handles ...ArtifactH) []pkg.Artifact {
|
||||
pv := paGet()
|
||||
for _, p := range presets {
|
||||
a = s.appendPreset(t, a, pv, p)
|
||||
for _, p := range handles {
|
||||
a = t.appendHandle(a, pv, p)
|
||||
}
|
||||
paPut(pv)
|
||||
return a
|
||||
}
|
||||
|
||||
// NewPackage constructs a [pkg.Artifact] via a build system helper.
|
||||
func (s *S) NewPackage(
|
||||
t Toolchain,
|
||||
func (t Toolchain) NewPackage(
|
||||
name, version string,
|
||||
source pkg.Artifact,
|
||||
attr *PackageAttr,
|
||||
@@ -488,10 +475,10 @@ func (s *S) NewPackage(
|
||||
{
|
||||
pv := paGet()
|
||||
for _, p := range helper.extra(attr.Flag) {
|
||||
extraRes = s.appendPreset(t, extraRes, pv, p)
|
||||
extraRes = t.appendHandle(extraRes, pv, p)
|
||||
}
|
||||
for _, p := range extra {
|
||||
extraRes = s.appendPreset(t, extraRes, pv, p)
|
||||
extraRes = t.appendHandle(extraRes, pv, p)
|
||||
}
|
||||
paPut(pv)
|
||||
}
|
||||
@@ -535,19 +522,18 @@ cd '/usr/src/` + name + `/'
|
||||
panic("cannot remain in root")
|
||||
}
|
||||
|
||||
return s.New(
|
||||
t,
|
||||
return t.New(
|
||||
name+"-"+version,
|
||||
attr.Flag,
|
||||
extraRes,
|
||||
attr.KnownChecksum,
|
||||
attr.Env,
|
||||
scriptEarly+helper.script(s, name),
|
||||
scriptEarly+helper.script(t.S, name),
|
||||
slices.Concat(attr.Paths, []pkg.ExecPath{
|
||||
pkg.Path(AbsUsrSrc.Append(
|
||||
name+sourceSuffix,
|
||||
), attr.Writable || wantsWrite, s.NewPatchedSource(
|
||||
t, name, version, source, !attr.Chmod && !wantsChmod, attr.Patches...,
|
||||
), attr.Writable || wantsWrite, t.NewPatchedSource(
|
||||
name, version, source, !attr.Chmod && !wantsChmod, attr.Patches...,
|
||||
)),
|
||||
})...,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user