internal/rosa: apply patches in specified order
Test / Create distribution (push) Successful in 1m1s
Test / Sandbox (push) Successful in 2m59s
Test / ShareFS (push) Successful in 4m4s
Test / Hakurei (push) Successful in 4m15s
Test / Sandbox (race detector) (push) Successful in 5m40s
Test / Hakurei (race detector) (push) Successful in 6m45s
Test / Flake checks (push) Successful in 1m30s

This seems more intuitive than letting the filesystem decide, and having to use awkward names.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-07-10 15:31:58 +09:00
parent 8e9b3a2ed1
commit e1f16e7720
2 changed files with 24 additions and 18 deletions
+23 -17
View File
@@ -10,6 +10,7 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"unsafe"
"hakurei.app/fhs" "hakurei.app/fhs"
"hakurei.app/internal/pkg" "hakurei.app/internal/pkg"
@@ -332,7 +333,7 @@ func (s *S) HasStageEarly() (ok bool) {
} }
// NewPatchedSource returns [pkg.Artifact] of source with patches applied. If // NewPatchedSource returns [pkg.Artifact] of source with patches applied. If
// passthrough is true, source is returned as is for zero length patches. // passthrough is true, source is returned as is for zero-length patches.
func (t Toolchain) NewPatchedSource( func (t Toolchain) NewPatchedSource(
name string, name string,
source pkg.Artifact, source pkg.Artifact,
@@ -346,29 +347,34 @@ func (t Toolchain) NewPatchedSource(
paths := make([]pkg.ExecPath, len(patches)+1) paths := make([]pkg.ExecPath, len(patches)+1)
for i, p := range patches { for i, p := range patches {
paths[i+1] = pkg.Path( paths[i+1] = pkg.Path(
AbsUsrSrc.Append(name+"-patches", p[0]+".patch"), false, fhs.AbsRoot.Append("patches", p[0]), false,
pkg.NewFile(p[0]+".patch", []byte(p[1])), pkg.NewFile(p[0], unsafe.Slice(unsafe.StringData(p[1]), len(p[1]))),
) )
} }
paths[0] = pkg.Path(AbsUsrSrc.Append(name), false, source) paths[0] = pkg.Path(fhs.AbsRoot.Append("src"), false, source)
aname := name + "-src" var buf strings.Builder
script := ` buf.WriteString(`
cp -r /usr/src/` + name + `/. /work/. cp -r /src/. /work/.
chmod -R +w /work && cd /work chmod -R +w /work && cd /work
` `)
if len(paths) > 1 { if len(paths) > 1 {
script += ` buf.WriteString(`
cat /usr/src/` + name + `-patches/* | \ function apply {
patch \ echo "applying $1"
-p 1 \ patch -p 1 < "/patches/$1"
--ignore-whitespace
`
aname += "-patched"
} }
return t.New(aname, 0, t.Append(nil, `)
for _, p := range patches {
buf.WriteString("apply '")
buf.WriteString(p[0])
buf.WriteString("'\n")
}
}
return t.New(name+"-src", 0, t.Append(nil,
_patch, _patch,
), nil, nil, script, paths...) ), nil, nil, buf.String(), paths...)
} }
// helperInPlace is a special directory value for omitting the cd statement. // helperInPlace is a special directory value for omitting the cd statement.
+1 -1
View File
@@ -1053,7 +1053,7 @@ func (ctx *evalContext) pf(
return return
} }
attr.Patches = append(attr.Patches, KV{ attr.Patches = append(attr.Patches, KV{
strings.TrimSuffix(filepath.Base(pathname), ".patch"), filepath.Base(pathname),
unsafe.String(unsafe.SliceData(p), len(p)), unsafe.String(unsafe.SliceData(p), len(p)),
}) })
} }