aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-01-26 20:47:11 +0900
committerOphestra <cat@gensokyo.uk>2026-01-26 21:00:29 +0900
commit4f17dad645a31e7971b956267aee8f983c59e1ec (patch)
treeb4be07fef13caa467621d53bacf3aff6fe1ab8ea
parent68b7d41c65bcec698a4c80fbfee2a359c6c593c3 (diff)
internal/rosa: isolate patching helper
This is useful outside llvm as well. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--internal/rosa/llvm.go36
-rw-r--r--internal/rosa/rosa.go35
2 files changed, 43 insertions, 28 deletions
diff --git a/internal/rosa/llvm.go b/internal/rosa/llvm.go
index c990e538..6e413bd5 100644
--- a/internal/rosa/llvm.go
+++ b/internal/rosa/llvm.go
@@ -170,34 +170,14 @@ cp -r /system/include /usr/include && rm -rf /system/include
)
}
- source := pkg.NewHTTPGetTar(
- nil, "https://github.com/llvm/llvm-project/archive/refs/tags/"+
- "llvmorg-"+version+".tar.gz",
- mustDecode(checksum),
- pkg.TarGzip,
- )
-
- patches := make([]pkg.ExecPath, len(attr.patches)+1)
- for i, p := range attr.patches {
- patches[i+1] = pkg.Path(
- AbsUsrSrc.Append("llvm-patches", p[0]+".patch"), false,
- pkg.NewFile(p[0], []byte(p[1])),
- )
- }
- patches[0] = pkg.Path(AbsUsrSrc.Append("llvmorg"), false, source)
- if len(patches) > 1 {
- source = t.New(
- "llvmorg-patched", stage3Concat(t, []pkg.Artifact{},
- t.Load(Patch),
- ), nil, nil, `
-cp -r /usr/src/llvmorg/. /work/.
-chmod -R +w /work && cd /work
-cat /usr/src/llvm-patches/* | patch -p 1
-`, patches...,
- )
- }
-
- return t.NewViaCMake("llvm", version, variant, source, &CMakeAttr{
+ return t.NewViaCMake("llvm", version, variant, t.NewPatchedSource(
+ "llvmorg", pkg.NewHTTPGetTar(
+ nil, "https://github.com/llvm/llvm-project/archive/refs/tags/"+
+ "llvmorg-"+version+".tar.gz",
+ mustDecode(checksum),
+ pkg.TarGzip,
+ ), true, attr.patches...,
+ ), &CMakeAttr{
Cache: slices.Concat(cache, attr.cmake),
Append: cmakeAppend,
Extra: stage3Concat(t, attr.extra,
diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go
index dfb75eee..312e16b1 100644
--- a/internal/rosa/rosa.go
+++ b/internal/rosa/rosa.go
@@ -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...)
+}