1
0
Fork 0

Add support for applying patches

timestamps
dump_stack() 2023-02-16 10:21:44 +00:00
parent cc1261b0b0
commit 2d6db97b43
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
3 changed files with 69 additions and 0 deletions

View File

@ -115,6 +115,12 @@ type FileTransfer struct {
Remote string
}
type Patch struct {
Path string
Source string
Script string
}
// Artifact is for .out-of-tree.toml
type Artifact struct {
Name string
@ -140,6 +146,8 @@ type Artifact struct {
DisableKpti bool
}
Patches []Patch
Make struct {
Target string
}

3
gen.go
View File

@ -39,6 +39,9 @@ func genConfig(at config.ArtifactType) (err error) {
a.Preload = append(a.Preload, config.PreloadModule{
Repo: "Repo name (e.g. https://github.com/openwall/lkrg)",
})
a.Patches = append(a.Patches, config.Patch{
Path: "/path/to/profiling.patch",
})
buf, err := toml.Marshal(&a)
if err != nil {

58
pew.go
View File

@ -157,6 +157,59 @@ func dockerRun(timeout time.Duration, container, workdir, command string) (
return
}
func sh(workdir, cmd string) (output string, err error) {
command := exec.Command("sh", "-c", "cd "+workdir+" && "+cmd)
raw, err := command.CombinedOutput()
output = string(raw)
if err != nil {
e := fmt.Sprintf("%v %v output: %v", cmd, err, output)
err = errors.New(e)
}
return
}
func applyPatches(src string, ka config.Artifact) (err error) {
for i, patch := range ka.Patches {
name := fmt.Sprintf("patch_%02d", i)
path := src + "/" + name + ".diff"
if patch.Source != "" && patch.Path != "" {
err = errors.New("path and source are mutually exclusive")
return
} else if patch.Source != "" {
err = os.WriteFile(path, []byte(patch.Source), 0644)
if err != nil {
return
}
} else if patch.Path != "" {
err = copy.Copy(patch.Path, path)
if err != nil {
return
}
}
if patch.Source != "" || patch.Path != "" {
_, err = sh(src, "patch < "+path)
if err != nil {
return
}
}
if patch.Script != "" {
script := src + "/" + name + ".sh"
err = os.WriteFile(script, []byte(patch.Script), 0755)
if err != nil {
return
}
_, err = sh(src, script)
if err != nil {
return
}
}
}
return
}
func build(tmp string, ka config.Artifact, ki config.KernelInfo,
dockerTimeout time.Duration) (outPath, output string, err error) {
@ -169,6 +222,11 @@ func build(tmp string, ka config.Artifact, ki config.KernelInfo,
return
}
err = applyPatches(tmpSourcePath, ka)
if err != nil {
return
}
outPath = tmpSourcePath + "/" + target
if ka.Type == config.KernelModule {
outPath += ".ko"