added post compile patch

This commit is contained in:
partisan 2024-12-11 16:45:34 +01:00
parent bb6e62e569
commit ef936f3aab
3 changed files with 49 additions and 34 deletions

View file

@ -8,12 +8,14 @@ import (
)
// ApplyPatches handles cloning, updating, and applying patches
func ApplyPatches(sourcePath string, patchesRepo string) error {
// Define the patches repository and clone directory
patchesCloneDir := filepath.Join(sourcePath, "patches")
func ApplyPatches(sourcePath string, patchesRepo string, patchesPath string, patchesCloneDir string) error {
// Define the full patches path
fullPatchesPath := filepath.Join(patchesCloneDir, patchesPath) // Cleaned path without double slashes
fmt.Printf("Source Path: %s\n", sourcePath)
fmt.Printf("Patches Clone Directory: %s\n", patchesCloneDir)
fmt.Printf("Patches Repository URL: %s\n", patchesRepo)
fmt.Printf("Patches Path: %s\n", fullPatchesPath)
// Check if the patches directory already exists
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
@ -26,34 +28,15 @@ func ApplyPatches(sourcePath string, patchesRepo string) error {
return fmt.Errorf("failed to clone patches repository: %v", err)
}
fmt.Println("Patches repository cloned successfully.")
} else {
// If the directory exists, fetch and pull the latest changes
fmt.Println("Patches directory already exists. Fetching latest changes.")
cmdFetch := exec.Command("git", "fetch", "--all")
cmdFetch.Dir = patchesCloneDir
cmdFetch.Stdout = os.Stdout
cmdFetch.Stderr = os.Stderr
if err := cmdFetch.Run(); err != nil {
return fmt.Errorf("failed to fetch updates for patches repository: %v", err)
}
cmdReset := exec.Command("git", "reset", "--hard", "origin/main")
cmdReset.Dir = patchesCloneDir
cmdReset.Stdout = os.Stdout
cmdReset.Stderr = os.Stderr
if err := cmdReset.Run(); err != nil {
return fmt.Errorf("failed to reset patches repository to latest state: %v", err)
}
fmt.Println("Patches repository updated successfully.")
}
// Verify the directory exists
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
return fmt.Errorf("patches directory not found after update: %s", patchesCloneDir)
// Verify the patches directory exists
if _, err := os.Stat(fullPatchesPath); os.IsNotExist(err) {
return fmt.Errorf("patches path not found: %s", fullPatchesPath)
}
// Apply the patches using `go run apply.go`
applyCmd := exec.Command("run.sh", "--path "+sourcePath)
// Apply the patches using `run.sh`
applyCmd := exec.Command("./run.sh", "--path", sourcePath, "--patches", fullPatchesPath)
applyCmd.Dir = patchesCloneDir // Run from the patches directory
applyCmd.Stdout = os.Stdout
applyCmd.Stderr = os.Stderr