From 1e5d7528f624ff53e46a605c9d1f0561fdf13978 Mon Sep 17 00:00:00 2001
From: partisan
Date: Sun, 8 Dec 2024 14:34:31 +0100
Subject: [PATCH] updated patching process
---
README.md | 79 +++++++++++++++++++++++++++++++++++++++++------
go.mod | 2 +-
main.go | 46 +++++++++------------------
spitfire/patch.go | 50 ++++++++++++++++++++++++++++++
4 files changed, 134 insertions(+), 43 deletions(-)
create mode 100644 spitfire/patch.go
diff --git a/README.md b/README.md
index a92ad4d..6f3f331 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,14 @@
This is a "simple" script for building the Spitfire Browser based on Mozilla Firefox source code.
+## Project Overview
+
+Spitfire Builder script is a tool designed to automate the building, patching, packaging, and uploading of the Spitfire Browser, which is based on the Mozilla Firefox source code. It streamlines tasks like:
+- Cloning and updating the Mozilla source repository.
+- Applying patches for Spitfire.
+- Building the browser for different platforms.
+- Compressing and uploading builts to a remote server.
+
## Dependencies
- Mercurial (hg)
@@ -17,33 +25,84 @@ This is a "simple" script for building the Spitfire Browser based on Mozilla Fir
- Golang (tested with v1.21)
- Python 3.11 and pip3
-# Example usage:
+## Flags
-## Build:
+Below is a detailed description of all the flags supported by the Spitfire Builder script:
+### **General Flags**
+
+- **`-h`**:
+ Displays the help message and exits. Use this to see all available flags and their descriptions.
+
+### **Build Process Flags**
+
+- **`-a`**:
+ Perform all steps of the build process, including cleaning, updating the repository, building, and applying patches.
+- **`-b`**:
+ Compiles the source code without cleaning or updating.
+- **`--clean`**:
+ Cleans the build directory by removing temporary or cached files.
+- **`-u`**:
+ Updates the Mozilla source repository to the latest revision using Mercurial (`hg pull`).
+- **`--patches`**:
+ Applies custom patches to the source code.
+- **`-r`**:
+ Runs the built project after the build process completes successfully.
+
+### **Compression and Upload Flags**
+
+- **`-c`**:
+ Compresses the build output into a `.tar.gz` file. Use with the `--upload-path` flag to specify the directory to compress.
+- **`--upload`**:
+ Uploads the compressed build file to a remote server (e.g., SourceForge). Requires a configuration file (`sourceforge_config.json`) to define upload parameters.
+- **`--upload-path=`**:
+ Specifies the directory or file to upload. This is required for both compression and uploading.
+
+### **Customization Flags**
+
+- **`-p=`**:
+ Specifies the build directory path. If not provided, the default path is used.
+- **`-t=`**:
+ Sets the target format for the build output. The format follows `component-arch-release-platform`.
+- **`-v=`**:
+ Defines the version of the package. For nightly builds, the current date is used by default.
+- **`--component=`**:
+ Sets the name of the component being built (default: 'browser').
+- **`--arch=`**:
+ Specifies the architecture for the build (default: system architecture, e.g., `amd64`).
+- **`--release=`**:
+ Specifies the release type (`stable`, `nightly`, etc.). Default is `nightly`.
+- **`--platform=`**:
+ Sets the platform for the build (default: system platform, e.g., `linux`).
+
+## Example usage:
+
+- **All steps**:
```sh
go run . -a
```
-## Upload:
+- **Build only**:
+```sh
+go run . -b
+```
+- **Upload**:
```sh
go run . --upload -c --upload-path=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin
```
-## Build and upload:
-
+- **Build and upload**:
```sh
go run . --upload -c --upload-path=./mozilla-central/obj-x86_64-pc-linux-gnu/dist/bin -a
```
-## Display all flags:
-
+- **Display all flags**:
```sh
go run . -h
```
-### Config file for uploading example:
+## Config file for uploading example:
*sourceforge_config.json*
@@ -67,7 +126,7 @@ A:amd64
S:788506622
I:3324483350
T:Spitfire build
-U:https://spitfirebrowser.com/
+U:https://spitfirebrowser.xyz/
L:AGPL-3.0
o:browser
m:Internet Addict
@@ -79,7 +138,7 @@ q:
Z:905cd0cc2dea9e400e1ecd099462b6b19188a9f1
```
-## Repositary structure
+## Repository structure
```
spitfire-browser/
diff --git a/go.mod b/go.mod
index 447b920..c1d81fb 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,3 @@
-module spitfire
+module spitfire-builder
go 1.18
diff --git a/main.go b/main.go
index 26efadb..5ed38fb 100644
--- a/main.go
+++ b/main.go
@@ -8,7 +8,7 @@ import (
"os/exec"
"path/filepath"
"runtime" // for detecting system architecture and platform
- "spitfire/spitfire"
+ "spitfire-builder/spitfire"
"time"
//"errors"
)
@@ -141,7 +141,7 @@ func main() {
fmt.Printf("Resolved uploadPath: %s\n", uploadPath)
}
- if all || buildFlag {
+ if all || buildFlag || patches || clean || update {
BuildProcess()
}
@@ -152,24 +152,24 @@ func main() {
spitfire.PrintErrors()
}
-// BuildProcess handles the build process: downloading, cleaning, configuring, and building the project.
+// Update the BuildProcess function to pass patchesRepo
func BuildProcess() {
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)
- }
-
if all {
spitfire.DownloadSource(sourcePath, sourceRepo)
spitfire.DiscardChanges(sourcePath)
spitfire.CleanBuild(sourcePath)
spitfire.UpdateRepo(sourcePath)
- spitfire.UpdatePatches(patchesDir, patchesRepo, sourcePath)
+
+ // 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 run {
@@ -185,7 +185,11 @@ func BuildProcess() {
fmt.Println("Mozilla repository updated.")
} else if patches {
spitfire.DownloadSource(sourcePath, sourceRepo)
- spitfire.UpdatePatches(patchesDir, patchesRepo, sourcePath)
+
+ // 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)
@@ -283,28 +287,6 @@ func PackageAndUploadProcess() {
}
}
-// // waitForPath checks if a path exists, waiting for up to maxWait seconds and retrying every interval seconds.
-// func waitForPath(path string, maxWait int, interval int) error {
-// waited := 0
-// for {
-// if PathExists(path) {
-// return nil // Path exists
-// }
-// if waited >= maxWait {
-// return errors.New("path does not exist after waiting")
-// }
-// fmt.Printf("Waiting for path %s to exist...\n", path)
-// time.Sleep(time.Duration(interval) * time.Second)
-// waited += interval
-// }
-// }
-
-// // PathExists checks if the path exists
-// func PathExists(path string) bool {
-// _, err := os.Stat(path)
-// return !os.IsNotExist(err)
-// }
-
// restoreWorkingDirectory restores the initial working directory after any operation that might change it.
func restoreWorkingDirectory() {
err := os.Chdir(initialDir)
diff --git a/spitfire/patch.go b/spitfire/patch.go
new file mode 100644
index 0000000..cebe6c0
--- /dev/null
+++ b/spitfire/patch.go
@@ -0,0 +1,50 @@
+package spitfire
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+)
+
+// ApplyPatches handles cloning and applying patches
+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)
+
+ // Check if the patches directory already exists
+ if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
+ // Clone the patches repository
+ fmt.Println("Patches directory does not exist. Proceeding to clone.")
+ cmdClone := exec.Command("git", "clone", patchesRepo, patchesCloneDir)
+ cmdClone.Stdout = os.Stdout
+ cmdClone.Stderr = os.Stderr
+ if err := cmdClone.Run(); err != nil {
+ return fmt.Errorf("failed to clone patches repository: %v", err)
+ }
+ fmt.Println("Patches repository cloned successfully.")
+ } else {
+ fmt.Println("Patches directory already exists. Skipping clone.")
+ }
+
+ // Verify the directory exists
+ if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
+ return fmt.Errorf("patches directory not found after cloning: %s", patchesCloneDir)
+ }
+
+ // Apply the patches using `go run apply.go`
+ applyCmd := exec.Command("go", "run", "apply.go", "--path="+sourcePath)
+ applyCmd.Dir = patchesCloneDir // Run from the patches directory
+ applyCmd.Stdout = os.Stdout
+ applyCmd.Stderr = os.Stderr
+ fmt.Println("Applying patches...")
+ if err := applyCmd.Run(); err != nil {
+ return fmt.Errorf("failed to apply patches: %v", err)
+ }
+
+ fmt.Println("Patches applied successfully.")
+ return nil
+}