From f497557264d32705c80c30fa4a00de75e0fb6665 Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 10 Sep 2024 23:02:25 +0200 Subject: [PATCH 01/10] windows patch --- main.go | 399 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 208 insertions(+), 191 deletions(-) diff --git a/main.go b/main.go index b829dbd..23e3492 100644 --- a/main.go +++ b/main.go @@ -1,231 +1,248 @@ package main import ( - "flag" - "fmt" - "log" - "os" - "path/filepath" - "runtime" // for detecting system architecture and platform - "time" - "spitfire/spitfire" - //"errors" + "flag" + "fmt" + "log" + "os" + "path/filepath" + "runtime" // for detecting system architecture and platform + "spitfire/spitfire" + "time" + //"errors" ) 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://weforgecode.xyz/Spitfire/Browser.git" - url = "https://spitfirebrowser.com/" - licence = "AGPL-3.0" - name = "Spitfire" - maintainer = "Internet Addict" - initialDir string + // 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://weforgecode.xyz/Spitfire/Browser.git" + url = "https://spitfirebrowser.com/" + licence = "AGPL-3.0" + name = "Spitfire" + maintainer = "Internet Addict" + initialDir string ) func init() { - flag.StringVar(&buildPath, "p", "", "Path to the build directory") - flag.StringVar(&target, "t", "", "Target location format: component-arch-release-platform") - flag.BoolVar(&compress, "c", false, "Compress the build directory into a tar.gz file before uploading") - flag.StringVar(&version, "v", "", "Specify version for the package. For nightly, use current date if not specified.") - flag.StringVar(&component, "component", "browser", "Component name (default: browser)") - flag.StringVar(&arch, "arch", runtime.GOARCH, "Architecture (default: system architecture)") - flag.StringVar(&release, "release", "nightly", "Release type (default: nightly)") - 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(&update, "u", false, "Update Mozilla repository") - flag.BoolVar(&patches, "patches", false, "Update patches") - 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") - flag.Bool("h", false, "Display help message") + flag.StringVar(&buildPath, "p", "", "Path to the build directory") + flag.StringVar(&target, "t", "", "Target location format: component-arch-release-platform") + flag.BoolVar(&compress, "c", false, "Compress the build directory into a tar.gz file before uploading") + flag.StringVar(&version, "v", "", "Specify version for the package. For nightly, use current date if not specified.") + flag.StringVar(&component, "component", "browser", "Component name (default: browser)") + flag.StringVar(&arch, "arch", runtime.GOARCH, "Architecture (default: system architecture)") + flag.StringVar(&release, "release", "nightly", "Release type (default: nightly)") + 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(&update, "u", false, "Update Mozilla repository") + flag.BoolVar(&patches, "patches", false, "Update patches") + 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") + flag.Bool("h", false, "Display help message") } func printHelp() { - fmt.Println("Usage: ./main -p= -t= [-c|--compress] [-v|--version=] [-component=] [-arch=] [-release=] [-platform=]") - flag.PrintDefaults() - fmt.Println("Example: go run . --upload -c --upload-path=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin -a") - os.Exit(0) + fmt.Println("Usage: ./main -p= -t= [-c|--compress] [-v|--version=] [-component=] [-arch=] [-release=] [-platform=]") + flag.PrintDefaults() + fmt.Println("Example: go run . --upload -c --upload-path=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin -a") + os.Exit(0) } func main() { - flag.Parse() + flag.Parse() - if flag.Lookup("h").Value.(flag.Getter).Get().(bool) { - printHelp() - } + if flag.Lookup("h").Value.(flag.Getter).Get().(bool) { + printHelp() + } - // Set version to current date if it's empty and release is nightly - if version == "" && release == "nightly" { - version = time.Now().Format("2006.01.02") // Set version to current date if nightly - } + // Set version to current date if it's empty and release is nightly + if version == "" && release == "nightly" { + version = time.Now().Format("2006.01.02") // Set version to current date if nightly + } - // Save the initial directory - var err error - initialDir, err = os.Getwd() - if err != nil { - log.Fatalf("Failed to get current working directory: %v", err) - } - fmt.Printf("Initial working directory: %s\n", initialDir) + // Save the initial directory + var err error + initialDir, err = os.Getwd() + if err != nil { + log.Fatalf("Failed to get current working directory: %v", err) + } + fmt.Printf("Initial working directory: %s\n", initialDir) - if all || buildFlag { - BuildProcess() - } + // Convert buildPath and uploadPath to absolute paths + if buildPath != "" { + buildPath, err = spitfire.ResolvePath(buildPath) + if err != nil { + log.Fatalf("Failed to convert buildPath to absolute path: %v", err) + } + fmt.Printf("Resolved buildPath: %s\n", buildPath) + } - if compress || upload { - PackageAndUploadProcess() - } + if uploadPath != "" { + uploadPath, err = spitfire.ResolvePath(uploadPath) + if err != nil { + log.Fatalf("Failed to convert uploadPath to absolute path: %v", err) + } + fmt.Printf("Resolved uploadPath: %s\n", uploadPath) + } - spitfire.PrintErrors() + if all || buildFlag { + BuildProcess() + } + + if compress || upload { + PackageAndUploadProcess() + } + + spitfire.PrintErrors() } // BuildProcess handles the build process: downloading, cleaning, configuring, and building the project. func BuildProcess() { - sourcePath, err := spitfire.ResolvePath("./mozilla-central") - if err != nil { - log.Fatalf("Error resolving source path: %v", err) - } + sourcePath, err := spitfire.ResolvePath("./mozilla-central") + if err != nil { + log.Fatalf("Error resolving source path: %v", err) + } - patchesDir, err := spitfire.ResolvePath(filepath.Join(sourcePath, "Spitfire")) - if err != nil { - log.Fatalf("Error resolving patches directory: %v", err) - } + patchesDir, err := spitfire.ResolvePath(filepath.Join(sourcePath, "Spitfire")) + if err != nil { + log.Fatalf("Error resolving patches directory: %v", err) + } - if all { - spitfire.DownloadSource(sourcePath, sourceRepo) - spitfire.DiscardChanges(sourcePath) - spitfire.CleanBuild(sourcePath) - spitfire.UpdateRepo(sourcePath) - spitfire.UpdatePatches(patchesDir, patchesRepo, sourcePath) - spitfire.Configure(sourcePath) - spitfire.Build(sourcePath) - if run { - spitfire.RunProject(sourcePath) - } - fmt.Println("Spitfire build completed successfully.") - } else if clean { - spitfire.CleanBuild(sourcePath) - fmt.Println("Cleaned Firefox build.") - } else if update { - spitfire.DownloadSource(sourcePath, sourceRepo) - spitfire.UpdateRepo(sourcePath) - fmt.Println("Mozilla repository updated.") - } else if patches { - spitfire.DownloadSource(sourcePath, sourceRepo) - spitfire.UpdatePatches(patchesDir, patchesRepo, sourcePath) - fmt.Println("Patches updated.") - } else if buildFlag { - spitfire.Configure(sourcePath) - spitfire.Build(sourcePath) - if run { - spitfire.RunProject(sourcePath) - } - fmt.Println("Spitfire build completed successfully.") - } + if all { + spitfire.DownloadSource(sourcePath, sourceRepo) + spitfire.DiscardChanges(sourcePath) + spitfire.CleanBuild(sourcePath) + spitfire.UpdateRepo(sourcePath) + spitfire.UpdatePatches(patchesDir, patchesRepo, sourcePath) + spitfire.Configure(sourcePath) + spitfire.Build(sourcePath) + if run { + spitfire.RunProject(sourcePath) + } + fmt.Println("Spitfire build completed successfully.") + } else if clean { + spitfire.CleanBuild(sourcePath) + fmt.Println("Cleaned Firefox build.") + } else if update { + spitfire.DownloadSource(sourcePath, sourceRepo) + spitfire.UpdateRepo(sourcePath) + fmt.Println("Mozilla repository updated.") + } else if patches { + spitfire.DownloadSource(sourcePath, sourceRepo) + spitfire.UpdatePatches(patchesDir, patchesRepo, sourcePath) + fmt.Println("Patches updated.") + } else if buildFlag { + spitfire.Configure(sourcePath) + spitfire.Build(sourcePath) + if run { + spitfire.RunProject(sourcePath) + } + fmt.Println("Spitfire build completed successfully.") + } } // PackageAndUploadProcess handles compressing, packaging, and uploading the build to SourceForge. func PackageAndUploadProcess() { - - // Restore working directory before performing SourceForge operations - restoreWorkingDirectory() - pathToUse := buildPath - if upload && uploadPath != "" { - pathToUse = uploadPath - } + // Restore working directory before performing SourceForge operations + restoreWorkingDirectory() - if pathToUse == "" { - log.Fatalf("Error: no valid build or upload path provided.") - } + pathToUse := buildPath + if upload && uploadPath != "" { + pathToUse = uploadPath + } - // // This is stupid, it wait for the path to exist (up to a maximum wait time) - // err := waitForPath(pathToUse, 60, 5) // Max 60 seconds, checking every 5 seconds - // if err != nil { - // log.Fatalf("Error: Build path or upload path not found: %v", err) - // } + if pathToUse == "" { + log.Fatalf("Error: no valid build or upload path provided.") + } - uncompressedSize, err := spitfire.GetDirectorySize(pathToUse) - if err != nil { - log.Fatalf("Failed to calculate uncompressed size: %v", err) - } - fmt.Printf("Uncompressed directory size: %d bytes\n", uncompressedSize) + // // This is stupid, it wait for the path to exist (up to a maximum wait time) + // err := waitForPath(pathToUse, 60, 5) // Max 60 seconds, checking every 5 seconds + // if err != nil { + // log.Fatalf("Error: Build path or upload path not found: %v", err) + // } - outputCompressedFile := filepath.Join(".", fmt.Sprintf("%s-%s-%s-%s.tar.gz", component, arch, release, platform)) - if compress { - err := spitfire.CompressDirectory(pathToUse, outputCompressedFile) - if err != nil { - log.Fatalf("Failed to compress build directory: %v", err) - } - fmt.Printf("Build directory compressed to: %s\n", outputCompressedFile) - } + uncompressedSize, err := spitfire.GetDirectorySize(pathToUse) + if err != nil { + log.Fatalf("Failed to calculate uncompressed size: %v", err) + } + fmt.Printf("Uncompressed directory size: %d bytes\n", uncompressedSize) - compressedSize, err := spitfire.GetFileSize(outputCompressedFile) - if err != nil { - log.Fatalf("Failed to get compressed file size: %v", err) - } - fmt.Printf("Compressed file size: %d bytes\n", compressedSize) + outputCompressedFile := filepath.Join(".", fmt.Sprintf("%s-%s-%s-%s.tar.gz", component, arch, release, platform)) + if compress { + err := spitfire.CompressDirectory(pathToUse, outputCompressedFile) + if err != nil { + log.Fatalf("Failed to compress build directory: %v", err) + } + fmt.Printf("Build directory compressed to: %s\n", outputCompressedFile) + } - if upload { - config, err := spitfire.LoadConfig() - if err != nil { - log.Fatalf("Failed to load SourceForge config: %v", err) - } + compressedSize, err := spitfire.GetFileSize(outputCompressedFile) + if err != nil { + log.Fatalf("Failed to get compressed file size: %v", err) + } + fmt.Printf("Compressed file size: %d bytes\n", compressedSize) - if _, err := os.Stat(outputCompressedFile); err == nil { - err = spitfire.Upload(config, outputCompressedFile, "/home/frs/project/spitfire-browser/"+component+"/"+arch+"/"+release+"/"+version+"/") - if err != nil { - log.Fatalf("Failed to upload compressed file: %v", err) - } - fmt.Println("Compressed file uploaded successfully.") - } else { - log.Fatalf("No compressed file found to upload.") - } + if upload { + config, err := spitfire.LoadConfig() + if err != nil { + log.Fatalf("Failed to load SourceForge config: %v", err) + } - err = spitfire.DownloadAPPINDEX(config, "/home/frs/project/spitfire-browser/") - if err != nil { - fmt.Println("Failed to download APPINDEX. A new APPINDEX will be created and uploaded.") - } + if _, err := os.Stat(outputCompressedFile); err == nil { + err = spitfire.Upload(config, outputCompressedFile, "/home/frs/project/spitfire-browser/"+component+"/"+arch+"/"+release+"/"+version+"/") + if err != nil { + log.Fatalf("Failed to upload compressed file: %v", err) + } + fmt.Println("Compressed file uploaded successfully.") + } else { + log.Fatalf("No compressed file found to upload.") + } - err = spitfire.PackageAPPINDEX( - name, release, version, arch, - fmt.Sprintf("%d", compressedSize), - fmt.Sprintf("%d", uncompressedSize), - "Spitfire build", url, licence, component, maintainer, "", platform, - ) - if err != nil { - log.Fatalf("Failed to update APPINDEX: %v", err) - } - fmt.Println("APPINDEX updated successfully.") + err = spitfire.DownloadAPPINDEX(config, "/home/frs/project/spitfire-browser/") + if err != nil { + fmt.Println("Failed to download APPINDEX. A new APPINDEX will be created and uploaded.") + } - if err := spitfire.CleanAppIndex(); err != nil { - log.Fatalf("Failed to clean APPINDEX: %v", err) - } + err = spitfire.PackageAPPINDEX( + name, release, version, arch, + fmt.Sprintf("%d", compressedSize), + fmt.Sprintf("%d", uncompressedSize), + "Spitfire build", url, licence, component, maintainer, "", platform, + ) + if err != nil { + log.Fatalf("Failed to update APPINDEX: %v", err) + } + fmt.Println("APPINDEX updated successfully.") - err = spitfire.UploadAPPINDEX(config, "/home/frs/project/spitfire-browser/") - if err != nil { - log.Fatalf("Failed to upload updated APPINDEX: %v", err) - } - fmt.Println("APPINDEX uploaded successfully.") - } + if err := spitfire.CleanAppIndex(); err != nil { + log.Fatalf("Failed to clean APPINDEX: %v", err) + } + + err = spitfire.UploadAPPINDEX(config, "/home/frs/project/spitfire-browser/") + if err != nil { + log.Fatalf("Failed to upload updated APPINDEX: %v", err) + } + fmt.Println("APPINDEX uploaded successfully.") + } } // // waitForPath checks if a path exists, waiting for up to maxWait seconds and retrying every interval seconds. @@ -252,9 +269,9 @@ func PackageAndUploadProcess() { // restoreWorkingDirectory restores the initial working directory after any operation that might change it. func restoreWorkingDirectory() { - err := os.Chdir(initialDir) - if err != nil { - log.Fatalf("Failed to restore the working directory: %v", err) - } - fmt.Printf("Restored working directory to: %s\n", initialDir) -} \ No newline at end of file + err := os.Chdir(initialDir) + if err != nil { + log.Fatalf("Failed to restore the working directory: %v", err) + } + fmt.Printf("Restored working directory to: %s\n", initialDir) +} From dfbecf7f98adde49fa590dd50f51575cfa0808f8 Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 10 Sep 2024 23:09:24 +0200 Subject: [PATCH 02/10] fix windows compatability --- main.go | 2 +- spitfire/build.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 23e3492..d0729bd 100644 --- a/main.go +++ b/main.go @@ -60,7 +60,7 @@ func init() { } func printHelp() { - fmt.Println("Usage: ./main -p= -t= [-c|--compress] [-v|--version=] [-component=] [-arch=] [-release=] [-platform=]") + fmt.Println("Usage: go run . -p= -t= [-c|--compress] [-v|--version=] [-component=] [-arch=] [-release=] [-platform=]") flag.PrintDefaults() fmt.Println("Example: go run . --upload -c --upload-path=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin -a") os.Exit(0) diff --git a/spitfire/build.go b/spitfire/build.go index a35433a..ad98f10 100644 --- a/spitfire/build.go +++ b/spitfire/build.go @@ -20,9 +20,13 @@ func runCommand(command string, args ...string) error { // Function to resolve paths using absolute path func ResolvePath(path string) (string, error) { + // Convert Unix-style slashes to the platform's native slashes + path = filepath.FromSlash(path) + + // Get the absolute path absPath, err := filepath.Abs(path) if err != nil { - return "", fmt.Errorf("failed to resolve path: %s", path) + return "", fmt.Errorf("failed to resolve path: %s, error: %v", path, err) } return absPath, nil } From 8d6f46c4ca2f3c3efd342a25335b925970fbb2ca Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 10 Sep 2024 23:21:46 +0200 Subject: [PATCH 03/10] windows patch --- spitfire/build.go | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/spitfire/build.go b/spitfire/build.go index ad98f10..bee99ea 100644 --- a/spitfire/build.go +++ b/spitfire/build.go @@ -5,13 +5,46 @@ import ( "os" "os/exec" "path/filepath" + "runtime" ) // Array to store errors var errors []string +// Check and Set MOZILLABUILD environment variable automatically +func setMozillaBuildEnv() error { + // Check if MOZILLABUILD is already set + if os.Getenv("MOZILLABUILD") != "" { + fmt.Println("MOZILLABUILD environment variable is already set.") + return nil + } + + // Try to detect the MozillaBuild installation directory + defaultPaths := []string{ + "C:\\mozilla-build", + "C:\\Program Files\\mozilla-build", + "C:\\Program Files (x86)\\mozilla-build", + } + + for _, path := range defaultPaths { + if _, err := os.Stat(path); !os.IsNotExist(err) { + // Set the MOZILLABUILD environment variable + fmt.Printf("Setting MOZILLABUILD environment variable to: %s\n", path) + return os.Setenv("MOZILLABUILD", path) + } + } + + // If no directory was found, return an error + return fmt.Errorf("MozillaBuild directory not found. Please install MozillaBuild or set the MOZILLABUILD environment variable manually.") +} + // Run an external command like scp or rsync func runCommand(command string, args ...string) error { + // Make sure the MOZILLABUILD environment variable is set for the mach commands + if err := setMozillaBuildEnv(); err != nil { + return err + } + cmd := exec.Command(command, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -117,9 +150,19 @@ func UpdatePatches(patchesDir, patchesRepo, sourcePath string) { errors = append(errors, "Failed to clone patches repository.") } } + + // Handle platform-specific rsync command fmt.Println("Copying files from patches directory to Firefox source directory...") - if err := runCommand("rsync", "-av", "--exclude=.git", patchesDir+"/", sourcePath+"/"); err != nil { - errors = append(errors, "Failed to copy files.") + if runtime.GOOS == "windows" { + // Use robocopy for Windows instead of rsync + if err := runCommand("robocopy", patchesDir, sourcePath, "/MIR"); err != nil { + errors = append(errors, "Failed to copy files (Windows robocopy).") + } + } else { + // Use rsync for Unix-like systems + if err := runCommand("rsync", "-av", "--exclude=.git", patchesDir+"/", sourcePath+"/"); err != nil { + errors = append(errors, "Failed to copy files (rsync).") + } } } From 3a36e4dda58b6c14d9a7c03301b7afd4724b0c66 Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 10 Sep 2024 23:30:34 +0200 Subject: [PATCH 04/10] windows is bs --- main.go | 6 ++++++ spitfire/build.go | 43 ++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/main.go b/main.go index d0729bd..3b025dc 100644 --- a/main.go +++ b/main.go @@ -67,6 +67,12 @@ func printHelp() { } func main() { + // Check and set the MOZILLABUILD environment variable globally + err2 := spitfire.SetGlobalEnv("MOZILLABUILD", "C:\\mozilla-build", "user") // For user + if err2 != nil { + log.Fatalf("Error setting global environment variable: %v", err2) + } + flag.Parse() if flag.Lookup("h").Value.(flag.Getter).Get().(bool) { diff --git a/spitfire/build.go b/spitfire/build.go index bee99ea..929292d 100644 --- a/spitfire/build.go +++ b/spitfire/build.go @@ -11,31 +11,28 @@ import ( // Array to store errors var errors []string -// Check and Set MOZILLABUILD environment variable automatically -func setMozillaBuildEnv() error { - // Check if MOZILLABUILD is already set - if os.Getenv("MOZILLABUILD") != "" { - fmt.Println("MOZILLABUILD environment variable is already set.") - return nil - } - - // Try to detect the MozillaBuild installation directory - defaultPaths := []string{ - "C:\\mozilla-build", - "C:\\Program Files\\mozilla-build", - "C:\\Program Files (x86)\\mozilla-build", - } - - for _, path := range defaultPaths { - if _, err := os.Stat(path); !os.IsNotExist(err) { - // Set the MOZILLABUILD environment variable - fmt.Printf("Setting MOZILLABUILD environment variable to: %s\n", path) - return os.Setenv("MOZILLABUILD", path) +// SetGlobalEnv sets the MOZILLABUILD environment variable globally for the user (or system) +func SetGlobalEnv(variable, value string, scope string) error { + if runtime.GOOS == "windows" { + var cmd *exec.Cmd + if scope == "user" { + cmd = exec.Command("setx", variable, value) // Set for current user + } else if scope == "system" { + cmd = exec.Command("setx", variable, value, "/M") // Set for system (requires admin privileges) + } else { + return fmt.Errorf("unknown scope: %s", scope) } - } - // If no directory was found, return an error - return fmt.Errorf("MozillaBuild directory not found. Please install MozillaBuild or set the MOZILLABUILD environment variable manually.") + // Run the command + out, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("failed to set environment variable %s=%s: %v\nOutput: %s", variable, value, err, string(out)) + } + fmt.Printf("Successfully set %s=%s\n", variable, value) + return nil + } else { + return fmt.Errorf("global environment variable setting is not supported on non-Windows systems") + } } // Run an external command like scp or rsync From 6d2a7669a247e634c371a6c3b1ebdef08ac7a245 Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 10 Sep 2024 23:31:22 +0200 Subject: [PATCH 05/10] oopsie --- spitfire/build.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spitfire/build.go b/spitfire/build.go index 929292d..d14b60d 100644 --- a/spitfire/build.go +++ b/spitfire/build.go @@ -37,11 +37,6 @@ func SetGlobalEnv(variable, value string, scope string) error { // Run an external command like scp or rsync func runCommand(command string, args ...string) error { - // Make sure the MOZILLABUILD environment variable is set for the mach commands - if err := setMozillaBuildEnv(); err != nil { - return err - } - cmd := exec.Command(command, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr From 39a3e90c4231aae610876eea5aba3d5d5d497898 Mon Sep 17 00:00:00 2001 From: partisan Date: Tue, 10 Sep 2024 23:35:10 +0200 Subject: [PATCH 06/10] ... --- main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 3b025dc..4a96458 100644 --- a/main.go +++ b/main.go @@ -67,11 +67,16 @@ func printHelp() { } func main() { + + path, err3 := spitfire.ResolvePath("/mozilla-central") // Check and set the MOZILLABUILD environment variable globally - err2 := spitfire.SetGlobalEnv("MOZILLABUILD", "C:\\mozilla-build", "user") // For user + err2 := spitfire.SetGlobalEnv("MOZILLABUILD", path, "user") // For user if err2 != nil { log.Fatalf("Error setting global environment variable: %v", err2) } + if err3 != nil { + log.Fatalf("Error setting global environment variable: %v", err3) + } flag.Parse() From 048bbc1e3e9becf89ea5e19a84dec780314de0ae Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 11 Sep 2024 13:19:06 +0200 Subject: [PATCH 07/10] fix windows robocopy --- sourceforge_config.json | 11 +++++------ spitfire/build.go | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/sourceforge_config.json b/sourceforge_config.json index c98a8cf..c1250c3 100644 --- a/sourceforge_config.json +++ b/sourceforge_config.json @@ -1,7 +1,6 @@ { - "SFKeyPath": "~/.ssh/id_rsa.pub", - "SFUser": "internet-addict", - "SFHost": "web.sourceforge.net", - "SFProject": "spitfire-browser" - } - \ No newline at end of file + "SFKeyPath": "~/.ssh/id_rsa.pub", + "SFUser": "internet-addict", + "SFHost": "web.sourceforge.net", + "SFProject": "spitfire-browser" +} \ No newline at end of file diff --git a/spitfire/build.go b/spitfire/build.go index d14b60d..78a9efd 100644 --- a/spitfire/build.go +++ b/spitfire/build.go @@ -146,8 +146,8 @@ func UpdatePatches(patchesDir, patchesRepo, sourcePath string) { // Handle platform-specific rsync command fmt.Println("Copying files from patches directory to Firefox source directory...") if runtime.GOOS == "windows" { - // Use robocopy for Windows instead of rsync - if err := runCommand("robocopy", patchesDir, sourcePath, "/MIR"); err != nil { + // Use robocopy for Windows + if err := runCommand("robocopy", patchesDir, sourcePath, "*", "/E", "/XF", ".git"); err != nil { errors = append(errors, "Failed to copy files (Windows robocopy).") } } else { @@ -155,7 +155,7 @@ func UpdatePatches(patchesDir, patchesRepo, sourcePath string) { if err := runCommand("rsync", "-av", "--exclude=.git", patchesDir+"/", sourcePath+"/"); err != nil { errors = append(errors, "Failed to copy files (rsync).") } - } + } } // Function to configure Spitfire From 358cd7147b5bafd284143d4d357c68c263f98160 Mon Sep 17 00:00:00 2001 From: partisan Date: Fri, 13 Sep 2024 12:47:30 +0200 Subject: [PATCH 08/10] windows build compatability --- main.go | 35 +++++++++------------ spitfire/build.go | 53 +++++++++++++++++++++++++------ spitfire/checks.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 29 deletions(-) create mode 100644 spitfire/checks.go diff --git a/main.go b/main.go index 4a96458..5eefa46 100644 --- a/main.go +++ b/main.go @@ -67,16 +67,11 @@ func printHelp() { } func main() { - - path, err3 := spitfire.ResolvePath("/mozilla-central") - // Check and set the MOZILLABUILD environment variable globally - err2 := spitfire.SetGlobalEnv("MOZILLABUILD", path, "user") // For user - if err2 != nil { - log.Fatalf("Error setting global environment variable: %v", err2) - } - if err3 != nil { - log.Fatalf("Error setting global environment variable: %v", err3) - } + // // Check system dependencies + // err := spitfire.CheckSystemDependencies() + // if err != nil { + // log.Fatalf("System check failed: %v", err) + // } flag.Parse() @@ -90,26 +85,26 @@ func main() { } // Save the initial directory - var err error - initialDir, err = os.Getwd() - if err != nil { - log.Fatalf("Failed to get current working directory: %v", err) + var err2 error + initialDir, err2 = os.Getwd() + if err2 != nil { + log.Fatalf("Failed to get current working directory: %v", err2) } fmt.Printf("Initial working directory: %s\n", initialDir) // Convert buildPath and uploadPath to absolute paths if buildPath != "" { - buildPath, err = spitfire.ResolvePath(buildPath) - if err != nil { - log.Fatalf("Failed to convert buildPath to absolute path: %v", err) + buildPath, err2 = spitfire.ResolvePath(buildPath) + if err2 != nil { + log.Fatalf("Failed to convert buildPath to absolute path: %v", err2) } fmt.Printf("Resolved buildPath: %s\n", buildPath) } if uploadPath != "" { - uploadPath, err = spitfire.ResolvePath(uploadPath) - if err != nil { - log.Fatalf("Failed to convert uploadPath to absolute path: %v", err) + uploadPath, err2 = spitfire.ResolvePath(uploadPath) + if err2 != nil { + log.Fatalf("Failed to convert uploadPath to absolute path: %v", err2) } fmt.Printf("Resolved uploadPath: %s\n", uploadPath) } diff --git a/spitfire/build.go b/spitfire/build.go index 78a9efd..3f5be5d 100644 --- a/spitfire/build.go +++ b/spitfire/build.go @@ -37,6 +37,7 @@ func SetGlobalEnv(variable, value string, scope string) error { // Run an external command like scp or rsync func runCommand(command string, args ...string) error { + fmt.Printf("Running command: %s %v\n", command, args) cmd := exec.Command(command, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr @@ -83,10 +84,21 @@ func CleanBuild(sourcePath string) { 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.") } - if err := runCommand("./mach", "clobber"); err != nil { + // Clean the build + if err := runCommand(machCmd, "clobber"); err != nil { errors = append(errors, "Failed to clean build.") } } @@ -147,7 +159,7 @@ func UpdatePatches(patchesDir, patchesRepo, sourcePath string) { fmt.Println("Copying files from patches directory to Firefox source directory...") if runtime.GOOS == "windows" { // Use robocopy for Windows - if err := runCommand("robocopy", patchesDir, sourcePath, "*", "/E", "/XF", ".git"); err != nil { + if err := runCommand("robocopy", patchesDir, sourcePath, "*", "/S", "/XF", ".git", "/XD", ".git"); err != nil { errors = append(errors, "Failed to copy files (Windows robocopy).") } } else { @@ -155,7 +167,7 @@ func UpdatePatches(patchesDir, patchesRepo, sourcePath string) { if err := runCommand("rsync", "-av", "--exclude=.git", patchesDir+"/", sourcePath+"/"); err != nil { errors = append(errors, "Failed to copy files (rsync).") } - } + } } // Function to configure Spitfire @@ -165,7 +177,16 @@ func Configure(sourcePath string) { errors = append(errors, "Failed to navigate to source directory.") return } - if err := runCommand("./mach", "configure"); err != nil { + + // Use the appropriate mach command for Windows or Unix-like systems + var machCmd string + if runtime.GOOS == "windows" { + machCmd = ".\\mach" + } else { + machCmd = "./mach" + } + + if err := runCommand(machCmd, "configure"); err != nil { errors = append(errors, "Configuration failed.") } } @@ -177,7 +198,16 @@ func Build(sourcePath string) { errors = append(errors, "Failed to navigate to source directory.") return } - if err := runCommand("./mach", "build"); err != nil { + + // Use the appropriate mach command for Windows or Unix-like systems + var machCmd string + if runtime.GOOS == "windows" { + machCmd = ".\\mach" + } else { + machCmd = "./mach" + } + + if err := runCommand(machCmd, "build"); err != nil { errors = append(errors, "Build failed.") } } @@ -185,11 +215,16 @@ func Build(sourcePath string) { // Function to run the project after build func RunProject(sourcePath string) { fmt.Println("Running the project...") - 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" } - if err := runCommand("./mach", "run"); err != nil { + + if err := runCommand(machCmd, "run"); err != nil { errors = append(errors, "Failed to run the project.") } } diff --git a/spitfire/checks.go b/spitfire/checks.go new file mode 100644 index 0000000..c0bb232 --- /dev/null +++ b/spitfire/checks.go @@ -0,0 +1,78 @@ +package spitfire + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "runtime" +) + +// CheckSystemDependencies ensures that required tools for building are installed. +func CheckSystemDependencies() error { + requiredTools := map[string]string{ + "git": "https://git-scm.com/download/win", // Git + "python": "https://www.python.org/downloads/", // Python + "pip3": "https://pip.pypa.io/en/stable/installing/", // Pip3 + } + + if runtime.GOOS == "windows" { + // Check for MozillaBuild installation + mozBuildPath := os.Getenv("MOZILLABUILD") + if mozBuildPath == "" { + mozBuildPath = "C:\\mozilla-build" // Default to standard MozillaBuild path + } + + // Check if MozillaBuild exists at the specified location + if !dirExists(mozBuildPath) { + requiredTools["mozbuild"] = "https://ftp.mozilla.org/pub/mozilla/libraries/win32/MozillaBuildSetup-Latest.exe" + } + } + + missingTools := []string{} + + // Check for each required tool + for tool, downloadLink := range requiredTools { + if !isCommandAvailable(tool) { + missingTools = append(missingTools, fmt.Sprintf("%s (Download: %s)", tool, downloadLink)) + } + } + + // Special check for mach in the local source directory (mozilla-central) + machPath := filepath.Join("mozilla-central", "mach") + if !fileExists(machPath) { + missingTools = append(missingTools, fmt.Sprintf("mach (run from mozilla-central directory)")) + } + + if len(missingTools) > 0 { + fmt.Println("The following tools are missing and are required for the build:") + for _, tool := range missingTools { + fmt.Println(" - " + tool) + } + return fmt.Errorf("missing required tools") + } + + fmt.Println("All required system dependencies are installed.") + return nil +} + +// isCommandAvailable checks if a command/tool is available on the system. +func isCommandAvailable(command string) bool { + _, err := exec.LookPath(command) + return err == nil +} + +// fileExists checks if a file exists at the given path. +func fileExists(path string) bool { + _, err := os.Stat(path) + return err == nil +} + +// dirExists checks if a directory exists at the given path. +func dirExists(path string) bool { + info, err := os.Stat(path) + if os.IsNotExist(err) { + return false + } + return info.IsDir() +} From 917e9a15475be19e5f61a49c77189c8e324e37c9 Mon Sep 17 00:00:00 2001 From: partisan Date: Fri, 13 Sep 2024 12:58:37 +0200 Subject: [PATCH 09/10] added gitignore windows compressed --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 712d01c..1b36d8f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ /packages_temp.json /APKINDEX /APPINDEX -/browser-amd64-nightly-linux.tar.gz \ No newline at end of file +/browser-amd64-nightly-linux.tar.gz +/browser-amd64-nightly-windows.tar.gz \ No newline at end of file From 430357108ce04a77f92fb166d4781fbded35696c Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 20 Nov 2024 01:49:30 +0000 Subject: [PATCH 10/10] Added README.md --- README.md | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a92ad4d --- /dev/null +++ b/README.md @@ -0,0 +1,145 @@ +

+ Logo +

+ +

+ Spitfire Builder +

+ +

+This is a "simple" script for building the Spitfire Browser based on Mozilla Firefox source code. +

+ +## Dependencies + +- Mercurial (hg) +- Git +- Golang (tested with v1.21) +- Python 3.11 and pip3 + +# Example usage: + +## Build: + +```sh +go run . -a +``` + +## Upload: + +```sh +go run . --upload -c --upload-path=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin +``` + +## Build and upload: + +```sh +go run . --upload -c --upload-path=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin -a +``` + +## Display all flags: + +```sh +go run . -h +``` + +### Config file for uploading example: + +*sourceforge_config.json* + +```json +{ + "SFKeyPath": "~/.ssh/id_rsa.pub", + "SFUser": "internet-addict", + "SFHost": "web.sourceforge.net", + "SFProject": "spitfire-browser" +} +``` + +## APPINDEX example: + +``` +C:905cd0cc2dea9e400e1ecd099462b6b19188a9f1 +P:Spitfire +R:nightly +V:2024.09.08 +A:amd64 +S:788506622 +I:3324483350 +T:Spitfire build +U:https://spitfirebrowser.com/ +L:AGPL-3.0 +o:browser +m:Internet Addict +t:1725830641 +c:905cd0cc2dea9e400e1ecd099462b6b19188a9f1 +D: +p:linux +q: +Z:905cd0cc2dea9e400e1ecd099462b6b19188a9f1 +``` + +## Repositary structure + +``` +spitfire-browser/ +├── browser/ +│ ├── amd64/ +│ │ ├── stable/ +│ │ │ ├── latest/deb.tar.gz +│ │ │ ├── x.x.x/deb.tar.gz +│ │ ├── nightly/ +│ │ ├── latest/deb.tar.gz +│ │ ├── yyyy-mm-dd/deb.tar.gz +│ ├── arm/ +│ │ ├── stable/ +│ │ │ ├── latest/ +│ │ │ ├── x.x.x/ +│ │ ├── nightly/ +│ │ ├── latest/ +│ │ ├── yyyy-mm-dd/ +├── cli-package-manager/ +│ ├── stable/ +│ │ ├── latest/ +│ │ ├── x.x.x/ +│ ├── nightly/ +│ ├── latest/ +│ ├── yyyy-mm-dd/ +├── gui-installer/ +│ ├── stable/ +│ │ ├── latest/ +│ │ ├── x.x.x/ +│ ├── nightly/ +│ ├── latest/ +│ ├── yyyy-mm-dd/ +├── gui-package-manager/ +│ ├── stable/ +│ │ ├── latest/ +│ │ ├── x.x.x/ +│ ├── nightly/ +│ ├── latest/ +│ ├── yyyy-mm-dd/ +├── addons/ +│ ├── themes/ +│ │ ├── stable/ +│ │ │ ├── latest/ +│ │ │ ├── x.x.x/ +│ │ ├── nightly/ +│ │ ├── latest/ +│ │ ├── yyyy-mm-dd/ +│ ├── custom-configs/ +│ │ ├── stable/ +│ │ │ ├── latest/ +│ │ │ ├── x.x.x/ +│ │ ├── nightly/ +│ │ ├── latest/ +│ │ ├── yyyy-mm-dd/ +│ ├── search-engines/ +│ ├── stable/ +│ │ ├── latest/ +│ │ ├── x.x.x/ +│ ├── nightly/ +│ ├── latest/ +│ ├── yyyy-mm-dd/ +├── APPINDEX +``` \ No newline at end of file