internal/rosa: isolate patching helper

This is useful outside llvm as well.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-26 20:47:11 +09:00
parent 68b7d41c65
commit 4f17dad645
2 changed files with 43 additions and 28 deletions

View File

@@ -271,3 +271,38 @@ ln -vs ../usr/bin /work/bin
)}, paths)...,
)
}
// NewPatchedSource returns [pkg.Artifact] of source with patches applied. If
// passthrough is true, source is returned as is for zero length patches.
func (t Toolchain) NewPatchedSource(
name string,
source pkg.Artifact,
passthrough bool,
patches ...[2]string,
) pkg.Artifact {
if passthrough && len(patches) == 0 {
return source
}
paths := make([]pkg.ExecPath, len(patches)+1)
for i, p := range patches {
paths[i+1] = pkg.Path(
AbsUsrSrc.Append(name+"-patches", p[0]+".patch"), false,
pkg.NewFile(p[0]+".patch", []byte(p[1])),
)
}
paths[0] = pkg.Path(AbsUsrSrc.Append(name), false, source)
aname := name + "-src"
script := `
cp -r /usr/src/` + name + `/. /work/.
chmod -R +w /work && cd /work
`
if len(paths) > 1 {
script += `cat /usr/src/` + name + `-patches/* | patch -p 1`
aname += "-patched"
}
return t.New(aname, stage3Concat(t, []pkg.Artifact{},
t.Load(Patch),
), nil, nil, script, paths...)
}