Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions newt/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,11 @@ func (gd *GenericDownloader) Checkout(repoDir string, commit string) error {
return err
}

func (gd *GenericDownloader) ApplyPatches(repoDir string, patches []string) error {
func ApplyPatch(repoDir string, patch string) error {
cmd := []string{
"am",
}
cmd = append(cmd, patches...)
cmd = append(cmd, patch)

_, err := executeGitCommand(repoDir, cmd, true)
if err != nil {
Expand All @@ -481,6 +481,77 @@ func (gd *GenericDownloader) ApplyPatches(repoDir string, patches []string) erro
return nil
}

func spatchPath() (string, error) {
spatchPath, err := exec.LookPath("spatch")
if err != nil {
return "", util.NewNewtError(fmt.Sprintf("Can't find spatch binary: %s\n",
err.Error()))
}

return filepath.ToSlash(spatchPath), nil
}

func executeSpatchCommand(dir string, cmd []string, logCmd bool) ([]byte, error) {
wd, err := os.Getwd()
if err != nil {
return nil, util.NewNewtError(err.Error())
}

sp, err := spatchPath()
if err != nil {
return nil, err
}

if err := os.Chdir(dir); err != nil {
return nil, util.ChildNewtError(err)
}

defer os.Chdir(wd)

spatchCmd := []string{sp}
spatchCmd = append(spatchCmd, cmd...)
output, err := util.ShellCommandLimitDbgOutput(spatchCmd, nil, logCmd, -1)
if err != nil {
return nil, err
}

return output, nil
}

func ApplyCocci(repoDir string, cocci string) error {
cmd := []string{
"--sp-file",
cocci,
"--in-place",
"--include-headers",
repoDir,
}

_, err := executeSpatchCommand(repoDir, cmd, true)
if err != nil {
return err
}
return nil
}

func (gd *GenericDownloader) ApplyPatches(repoDir string, patches []string) error {
for _, patch := range patches {
if strings.HasSuffix(patch, ".patch") {
err := ApplyPatch(repoDir, patch)
if err != nil {
return err
}
} else if strings.HasSuffix(patch, ".cocci") {
err := ApplyCocci(repoDir, patch)
if err != nil {
return err
}
}
}

return nil
}

// Update one submodule tree in a repo (under path)
func (gd *GenericDownloader) UpdateSubmodule(path string, submodule string) error {
cmd := []string{
Expand Down
2 changes: 1 addition & 1 deletion newt/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (proj *Project) GetPkgRepos() error {
}

for _, e := range dirEntries {
if strings.HasSuffix(e.Name(), ".patch") {
if strings.HasSuffix(e.Name(), ".patch") || strings.HasSuffix(e.Name(), ".cocci") {
r.AddPatch(pkg.BasePath() + "/" + PATCHES_DIR + "/" + r.Name() + "/" + e.Name())
}
}
Expand Down
Loading