From 993bf58ecd28d2ec5b05c17bcfc31dd109a604a7 Mon Sep 17 00:00:00 2001 From: partisan Date: Mon, 16 Dec 2024 21:24:35 +0100 Subject: [PATCH] added '--full-clean' flag --- main.go | 8 +++++--- spitfire/build.go | 29 +++++++++++++++++------------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 0a7614c..357fa4b 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ var ( all bool buildFlag bool clean bool + fullClean bool update bool prePatch bool postPatch bool @@ -53,7 +54,8 @@ func init() { flag.StringVar(&platform, "platform", runtime.GOOS, "Platform (default: system platform)") flag.BoolVar(&all, "a", false, "Perform all steps (build, clean, update)") flag.BoolVar(&buildFlag, "b", false, "Build Spitfire") - flag.BoolVar(&clean, "clean", false, "Clean build") + flag.BoolVar(&clean, "clean", false, "Revert uncommitted changes without removing build artifacts") + flag.BoolVar(&fullClean, "full-clean", false, "Perform a full clean by removing all build artifacts (clobber)") flag.BoolVar(&update, "u", false, "Update Mozilla repository") flag.BoolVar(&prePatch, "pre-patch", false, "Apply pre-build patches") flag.BoolVar(&postPatch, "post-patch", false, "Apply post-build patches") @@ -172,7 +174,7 @@ func BuildProcess() { if all { spitfire.DownloadSource(sourcePath, sourceRepo) spitfire.DiscardChanges(sourcePath) - spitfire.CleanBuild(sourcePath) + spitfire.CleanBuild(sourcePath, fullClean) spitfire.UpdateRepo(sourcePath) if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); err != nil { log.Fatalf("Error during patch application: %v", err) @@ -204,7 +206,7 @@ func BuildProcess() { } fmt.Println("Spitfire build completed successfully.") } else if clean { - spitfire.CleanBuild(sourcePath) + spitfire.CleanBuild(sourcePath, fullClean) fmt.Println("Cleaned Firefox build.") } else if update { spitfire.DownloadSource(sourcePath, sourceRepo) diff --git a/spitfire/build.go b/spitfire/build.go index 4dcbe96..4fc0e34 100644 --- a/spitfire/build.go +++ b/spitfire/build.go @@ -79,28 +79,33 @@ func DiscardChanges(sourcePath string) { } // Function to clean build -func CleanBuild(sourcePath string) { +func CleanBuild(sourcePath string, fullClean bool) { fmt.Println("Cleaning build...") + if err := os.Chdir(sourcePath); err != nil { errors = append(errors, "Failed to navigate to source directory.") return } - // Use the appropriate mach command for Windows or Unix-like systems - var machCmd string - if runtime.GOOS == "windows" { - machCmd = ".\\mach" - } else { - machCmd = "./mach" - } - // Revert uncommitted changes if err := runCommand("hg", "revert", "--all", "--no-backup"); err != nil { errors = append(errors, "Failed to revert changes in Mozilla repository.") } - // Clean the build - if err := runCommand(machCmd, "clobber"); err != nil { - errors = append(errors, "Failed to clean build.") + + if fullClean { + // Perform full clean if specified + var machCmd string + if runtime.GOOS == "windows" { + machCmd = ".\\mach" + } else { + machCmd = "./mach" + } + + if err := runCommand(machCmd, "clobber"); err != nil { + errors = append(errors, "Failed to clean build.") + } + } else { + fmt.Println("Skipping full clean. Build artifacts remain intact.") } }