diff --git a/internal/rosa/rosa.go b/internal/rosa/rosa.go index 7c23736c..97351f10 100644 --- a/internal/rosa/rosa.go +++ b/internal/rosa/rosa.go @@ -10,6 +10,7 @@ import ( "strings" "sync" "time" + "unsafe" "hakurei.app/fhs" "hakurei.app/internal/pkg" @@ -332,7 +333,7 @@ func (s *S) HasStageEarly() (ok bool) { } // 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( name string, source pkg.Artifact, @@ -346,29 +347,34 @@ func (t Toolchain) NewPatchedSource( 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])), + fhs.AbsRoot.Append("patches", p[0]), false, + 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" - script := ` -cp -r /usr/src/` + name + `/. /work/. + var buf strings.Builder + buf.WriteString(` +cp -r /src/. /work/. chmod -R +w /work && cd /work -` +`) if len(paths) > 1 { - script += ` -cat /usr/src/` + name + `-patches/* | \ - patch \ - -p 1 \ - --ignore-whitespace -` - aname += "-patched" + buf.WriteString(` +function apply { + echo "applying $1" + patch -p 1 < "/patches/$1" +} +`) + + for _, p := range patches { + buf.WriteString("apply '") + buf.WriteString(p[0]) + buf.WriteString("'\n") + } } - return t.New(aname, 0, t.Append(nil, + return t.New(name+"-src", 0, t.Append(nil, _patch, - ), nil, nil, script, paths...) + ), nil, nil, buf.String(), paths...) } // helperInPlace is a special directory value for omitting the cd statement. diff --git a/internal/rosa/state.go b/internal/rosa/state.go index 2939057d..12a9d9e2 100644 --- a/internal/rosa/state.go +++ b/internal/rosa/state.go @@ -1053,7 +1053,7 @@ func (ctx *evalContext) pf( return } attr.Patches = append(attr.Patches, KV{ - strings.TrimSuffix(filepath.Base(pathname), ".patch"), + filepath.Base(pathname), unsafe.String(unsafe.SliceData(p), len(p)), }) }