From ad7f7bf77866854d2cf353d7c1c66e26ab0bcbae Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 11 Dec 2024 17:07:08 +0100 Subject: [PATCH] removed '--patches' flag, added '--pre-patch', '--post-patch', '--skip-patch-update' --- main.go | 74 +++++++++++++++++++++++++++-------------------- spitfire/patch.go | 23 ++++++++++++++- 2 files changed, 65 insertions(+), 32 deletions(-) diff --git a/main.go b/main.go index 68d7500..c493ea3 100644 --- a/main.go +++ b/main.go @@ -15,29 +15,31 @@ import ( var ( // Define all flags as package-level variables - all bool - buildFlag bool - clean bool - update bool - patches bool - run bool - compress bool - buildPath string - target string - version string - component string - arch string - release string - platform string - upload bool - uploadPath string - sourceRepo = "https://hg.mozilla.org/mozilla-central" - patchesRepo = "https://weforge.xyz/Spitfire/Browser.git" - url = "https://spitfirebrowser.xyz/" - licence = "AGPL-3.0" - name = "Spitfire" - maintainer = "Internet Addict" - initialDir string + all bool + buildFlag bool + clean bool + update bool + prePatch bool + postPatch bool + skipPatchUpdate bool + run bool + compress bool + buildPath string + target string + version string + component string + arch string + release string + platform string + upload bool + uploadPath string + sourceRepo = "https://hg.mozilla.org/mozilla-central" + patchesRepo = "https://weforge.xyz/Spitfire/Browser.git" + url = "https://spitfirebrowser.xyz/" + licence = "AGPL-3.0" + name = "Spitfire" + maintainer = "Internet Addict" + initialDir string ) func init() { @@ -53,7 +55,9 @@ func init() { flag.BoolVar(&buildFlag, "b", false, "Build Spitfire") flag.BoolVar(&clean, "clean", false, "Clean build") flag.BoolVar(&update, "u", false, "Update Mozilla repository") - flag.BoolVar(&patches, "patches", false, "Update patches") + flag.BoolVar(&prePatch, "pre-patch", false, "Apply pre-build patches") + flag.BoolVar(&postPatch, "post-patch", false, "Apply post-build patches") + flag.BoolVar(&skipPatchUpdate, "skip-patch-update", false, "Skip updating the patches repository") flag.BoolVar(&run, "r", false, "Run the project after build") flag.BoolVar(&upload, "upload", false, "Upload the compressed build file to SourceForge") flag.StringVar(&uploadPath, "upload-path", "", "Path to the file to upload if no build present") @@ -141,7 +145,7 @@ func main() { fmt.Printf("Resolved uploadPath: %s\n", uploadPath) } - if all || buildFlag || patches || clean || update { + if all || buildFlag || prePatch || postPatch || clean || update { BuildProcess() } @@ -170,12 +174,12 @@ func BuildProcess() { spitfire.DiscardChanges(sourcePath) spitfire.CleanBuild(sourcePath) spitfire.UpdateRepo(sourcePath) - if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil { + if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); 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 { + if err := spitfire.ApplyPatches(buildDir, patchesRepo, "post-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); err != nil { log.Fatalf("Error during patch application: %v", err) } if run { @@ -189,17 +193,25 @@ func BuildProcess() { spitfire.DownloadSource(sourcePath, sourceRepo) spitfire.UpdateRepo(sourcePath) fmt.Println("Mozilla repository updated.") - } else if patches { + } else if prePatch { spitfire.DownloadSource(sourcePath, sourceRepo) - if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher")); err != nil { + if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); err != nil { log.Fatalf("Error during patch application: %v", err) } fmt.Println("Patches updated.") + } else if postPatch { + if _, err := os.Stat(buildDir); err == nil { + if err := spitfire.ApplyPatches(buildDir, patchesRepo, "post-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); err != nil { + log.Fatalf("Error during patch application: %v", err) + } + } } 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 postPatch { + if err := spitfire.ApplyPatches(buildDir, patchesRepo, "post-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); 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..4c380a6 100644 --- a/spitfire/patch.go +++ b/spitfire/patch.go @@ -8,7 +8,7 @@ import ( ) // ApplyPatches handles cloning, updating, and applying patches -func ApplyPatches(sourcePath string, patchesRepo string, patchesPath string, patchesCloneDir string) error { +func ApplyPatches(sourcePath string, patchesRepo string, patchesPath string, patchesCloneDir string, skipUpdateRepo bool) error { // Define the full patches path fullPatchesPath := filepath.Join(patchesCloneDir, patchesPath) // Cleaned path without double slashes @@ -28,6 +28,27 @@ 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 skipUpdateRepo { + // 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