diff --git a/main.go b/main.go index 68d7500..5ed38fb 100644 --- a/main.go +++ b/main.go @@ -159,25 +159,19 @@ func BuildProcess() { log.Fatalf("Error resolving source path: %v", err) } - // Detect the build directory dynamically - buildDir, err := spitfire.ResolveBuildDir(sourcePath) - if err != nil { - log.Fatalf("Error resolving build directory: %v", err) - } - if all { spitfire.DownloadSource(sourcePath, sourceRepo) spitfire.DiscardChanges(sourcePath) spitfire.CleanBuild(sourcePath) spitfire.UpdateRepo(sourcePath) - if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil { + + // Pass patchesRepo to ApplyPatches + if err := spitfire.ApplyPatches(sourcePath, patchesRepo); err != nil { log.Fatalf("Error during patch application: %v", err) } + spitfire.Configure(sourcePath) spitfire.Build(sourcePath) - if err := spitfire.ApplyPatches(buildDir, patchesRepo, "post-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil { - log.Fatalf("Error during patch application: %v", err) - } if run { spitfire.RunProject(sourcePath) } @@ -191,16 +185,15 @@ func BuildProcess() { fmt.Println("Mozilla repository updated.") } else if patches { spitfire.DownloadSource(sourcePath, sourceRepo) - if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil { + + // Pass patchesRepo to ApplyPatches + if err := spitfire.ApplyPatches(sourcePath, patchesRepo); err != nil { log.Fatalf("Error during patch application: %v", err) } fmt.Println("Patches updated.") } else if buildFlag { spitfire.Configure(sourcePath) spitfire.Build(sourcePath) - if err := spitfire.ApplyPatches(buildDir, patchesRepo, "post-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil { - log.Fatalf("Error during patch application: %v", err) - } if run { spitfire.RunProject(sourcePath) } diff --git a/spitfire/patch.go b/spitfire/patch.go index 371bf1e..5d2104a 100644 --- a/spitfire/patch.go +++ b/spitfire/patch.go @@ -8,14 +8,12 @@ import ( ) // ApplyPatches handles cloning, updating, and applying 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 - +func ApplyPatches(sourcePath string, patchesRepo string) error { + // Define the patches repository and clone directory + patchesCloneDir := filepath.Join(sourcePath, "patches") 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) { @@ -28,15 +26,34 @@ func ApplyPatches(sourcePath string, patchesRepo string, patchesPath string, pat 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 patches directory exists - if _, err := os.Stat(fullPatchesPath); os.IsNotExist(err) { - return fmt.Errorf("patches path not found: %s", fullPatchesPath) + // Verify the directory exists + if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) { + return fmt.Errorf("patches directory not found after update: %s", patchesCloneDir) } - // Apply the patches using `run.sh` - applyCmd := exec.Command("./run.sh", "--path", sourcePath, "--patches", fullPatchesPath) + // Apply the patches using `go run apply.go` + applyCmd := exec.Command("./run.sh", "--path", sourcePath) applyCmd.Dir = patchesCloneDir // Run from the patches directory applyCmd.Stdout = os.Stdout applyCmd.Stderr = os.Stderr diff --git a/spitfire/resolvebuilddir.go b/spitfire/resolvebuilddir.go deleted file mode 100644 index 1cc917b..0000000 --- a/spitfire/resolvebuilddir.go +++ /dev/null @@ -1,25 +0,0 @@ -package spitfire - -import ( - "fmt" - "path/filepath" -) - -// ResolveBuildDir detects the build directory dynamically -func ResolveBuildDir(sourcePath string) (string, error) { - // The expected build directory pattern - globPattern := filepath.Join(sourcePath, "obj-*") - - // Find matching directories - matches, err := filepath.Glob(globPattern) - if err != nil { - return "", fmt.Errorf("error resolving build directory: %v", err) - } - if len(matches) == 0 { - return "", fmt.Errorf("build directory not found under %s", sourcePath) - } - full := filepath.Join(matches[0], "dist", "bin") - - // Return the first match (assumes one build directory exists) - return full, nil -}