2024-09-09 01:25:07 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-09-10 23:02:25 +02:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime" // for detecting system architecture and platform
|
2024-12-08 14:34:31 +01:00
|
|
|
"spitfire-builder/spitfire"
|
2024-09-10 23:02:25 +02:00
|
|
|
"time"
|
|
|
|
//"errors"
|
2024-09-09 01:25:07 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-09-10 23:02:25 +02:00
|
|
|
// Define all flags as package-level variables
|
2024-12-11 17:07:08 +01:00
|
|
|
all bool
|
|
|
|
buildFlag bool
|
|
|
|
clean bool
|
2024-12-16 21:24:35 +01:00
|
|
|
fullClean bool
|
2024-12-11 17:07:08 +01:00
|
|
|
update bool
|
|
|
|
prePatch bool
|
|
|
|
postPatch bool
|
|
|
|
skipPatchUpdate bool
|
|
|
|
run bool
|
|
|
|
compress bool
|
|
|
|
target string
|
|
|
|
version string
|
|
|
|
component string
|
|
|
|
arch string
|
|
|
|
release string
|
|
|
|
platform string
|
|
|
|
upload bool
|
|
|
|
uploadPath string
|
2025-01-18 11:48:30 +01:00
|
|
|
sourceRepo = "https://hg.mozilla.org/releases/mozilla-release"
|
|
|
|
patchesRepo = "https://weforge.xyz/Spitfire/Patcher.git"
|
2024-12-11 17:07:08 +01:00
|
|
|
url = "https://spitfirebrowser.xyz/"
|
|
|
|
licence = "AGPL-3.0"
|
|
|
|
name = "Spitfire"
|
2024-12-23 11:24:42 +01:00
|
|
|
packageName = "spitfire-browser"
|
2024-12-11 17:07:08 +01:00
|
|
|
maintainer = "Internet Addict"
|
|
|
|
initialDir string
|
2024-12-29 00:58:19 +01:00
|
|
|
skipDeps bool
|
2024-09-09 01:25:07 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2024-09-10 23:02:25 +02:00
|
|
|
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")
|
2024-12-16 21:24:35 +01:00
|
|
|
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)")
|
2024-09-10 23:02:25 +02:00
|
|
|
flag.BoolVar(&update, "u", false, "Update Mozilla repository")
|
2024-12-11 17:07:08 +01:00
|
|
|
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")
|
2024-09-10 23:02:25 +02:00
|
|
|
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")
|
2024-12-29 00:58:19 +01:00
|
|
|
flag.BoolVar(&skipDeps, "skip-deps", false, "Skip checking for required system dependencies")
|
2024-09-10 23:02:25 +02:00
|
|
|
flag.Bool("h", false, "Display help message")
|
2024-09-09 01:25:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func printHelp() {
|
2024-09-10 23:09:24 +02:00
|
|
|
fmt.Println("Usage: go run . -p=<path-to-build> -t=<target> [-c|--compress] [-v|--version=<version>] [-component=<component>] [-arch=<architecture>] [-release=<release>] [-platform=<platform>]")
|
2024-09-10 23:02:25 +02:00
|
|
|
flag.PrintDefaults()
|
2025-01-18 11:48:30 +01:00
|
|
|
fmt.Println("Example: go run . --upload -c --upload-path=./mozilla-release/obj-x86_64-pc-linux-gnu/dist/bin -a")
|
2024-09-10 23:02:25 +02:00
|
|
|
os.Exit(0)
|
2024-09-09 01:25:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2024-09-10 23:30:34 +02:00
|
|
|
|
2024-09-10 23:02:25 +02:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if flag.Lookup("h").Value.(flag.Getter).Get().(bool) {
|
|
|
|
printHelp()
|
|
|
|
}
|
|
|
|
|
2024-12-29 00:58:19 +01:00
|
|
|
// Only check dependencies if NOT skipping them
|
|
|
|
if !skipDeps {
|
2025-01-11 23:11:11 +01:00
|
|
|
if err := spitfire.CheckDependencies(); err != nil {
|
2024-12-29 00:58:19 +01:00
|
|
|
log.Fatalf("System check failed: %v", err)
|
|
|
|
}
|
2024-12-08 09:05:39 +01:00
|
|
|
}
|
|
|
|
|
2024-09-10 23:02:25 +02:00
|
|
|
// 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
|
2024-09-13 12:47:30 +02:00
|
|
|
var err2 error
|
|
|
|
initialDir, err2 = os.Getwd()
|
|
|
|
if err2 != nil {
|
|
|
|
log.Fatalf("Failed to get current working directory: %v", err2)
|
2024-09-10 23:02:25 +02:00
|
|
|
}
|
|
|
|
fmt.Printf("Initial working directory: %s\n", initialDir)
|
|
|
|
|
|
|
|
if uploadPath != "" {
|
2024-09-13 12:47:30 +02:00
|
|
|
uploadPath, err2 = spitfire.ResolvePath(uploadPath)
|
|
|
|
if err2 != nil {
|
|
|
|
log.Fatalf("Failed to convert uploadPath to absolute path: %v", err2)
|
2024-09-10 23:02:25 +02:00
|
|
|
}
|
|
|
|
fmt.Printf("Resolved uploadPath: %s\n", uploadPath)
|
|
|
|
}
|
|
|
|
|
2024-12-11 17:12:00 +01:00
|
|
|
if all || buildFlag || prePatch || postPatch || clean || update || run {
|
2024-09-10 23:02:25 +02:00
|
|
|
BuildProcess()
|
|
|
|
}
|
|
|
|
|
|
|
|
if compress || upload {
|
2025-01-11 23:11:11 +01:00
|
|
|
// Resolve the build directory dynamically
|
|
|
|
fmt.Println("Resolving build directory dynamically...")
|
2025-01-18 11:48:30 +01:00
|
|
|
sourcePath, err := spitfire.ResolvePath("./mozilla-release")
|
2025-01-11 23:11:11 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error resolving source path: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
buildDir, err := spitfire.ResolveBuildDir(sourcePath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error resolving build directory dynamically: %v", err)
|
|
|
|
}
|
|
|
|
fmt.Printf("Resolved build directory: %s\n", buildDir)
|
|
|
|
|
|
|
|
// Validate that the build directory exists
|
|
|
|
stat, err := os.Stat(buildDir)
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
log.Fatalf("Error: build directory does not exist at %s\n", buildDir)
|
|
|
|
} else if err != nil {
|
|
|
|
log.Fatalf("Error accessing build directory: %v\n", err)
|
|
|
|
} else if !stat.IsDir() {
|
|
|
|
log.Fatalf("Error: path exists but is not a directory: %s\n", buildDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proceed with packaging and uploading
|
|
|
|
PackageAndUploadProcess(buildDir)
|
2024-09-10 23:02:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
spitfire.PrintErrors()
|
2024-09-09 01:25:07 +02:00
|
|
|
}
|
|
|
|
|
2024-12-08 14:34:31 +01:00
|
|
|
// Update the BuildProcess function to pass patchesRepo
|
2024-09-09 01:25:07 +02:00
|
|
|
func BuildProcess() {
|
2025-01-18 11:48:30 +01:00
|
|
|
sourcePath, err := spitfire.ResolvePath("./mozilla-release")
|
2024-09-10 23:02:25 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error resolving source path: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if all {
|
|
|
|
spitfire.DownloadSource(sourcePath, sourceRepo)
|
|
|
|
spitfire.DiscardChanges(sourcePath)
|
2024-12-16 21:24:35 +01:00
|
|
|
spitfire.CleanBuild(sourcePath, fullClean)
|
2024-09-10 23:02:25 +02:00
|
|
|
spitfire.UpdateRepo(sourcePath)
|
2024-12-11 17:07:08 +01:00
|
|
|
if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); err != nil {
|
2024-12-08 14:34:31 +01:00
|
|
|
log.Fatalf("Error during patch application: %v", err)
|
|
|
|
}
|
2024-09-10 23:02:25 +02:00
|
|
|
spitfire.Configure(sourcePath)
|
|
|
|
spitfire.Build(sourcePath)
|
2024-12-29 08:54:45 +01:00
|
|
|
// Detect the build directory dynamically
|
|
|
|
buildDir, err := spitfire.ResolveBuildDir(sourcePath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error resolving build directory: %v", err)
|
|
|
|
}
|
2024-12-11 17:07:08 +01:00
|
|
|
if err := spitfire.ApplyPatches(buildDir, patchesRepo, "post-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); err != nil {
|
2024-12-11 16:45:34 +01:00
|
|
|
log.Fatalf("Error during patch application: %v", err)
|
|
|
|
}
|
2024-09-10 23:02:25 +02:00
|
|
|
if run {
|
|
|
|
spitfire.RunProject(sourcePath)
|
|
|
|
}
|
|
|
|
fmt.Println("Spitfire build completed successfully.")
|
2024-12-13 14:31:28 +01:00
|
|
|
} else if buildFlag {
|
|
|
|
if prePatch {
|
|
|
|
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)
|
2024-12-29 08:54:45 +01:00
|
|
|
// Detect the build directory dynamically
|
|
|
|
buildDir, err := spitfire.ResolveBuildDir(sourcePath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error resolving build directory: %v", err)
|
|
|
|
}
|
2024-12-13 14:31:28 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
fmt.Println("Spitfire build completed successfully.")
|
2024-09-10 23:02:25 +02:00
|
|
|
} else if clean {
|
2024-12-16 21:24:35 +01:00
|
|
|
spitfire.CleanBuild(sourcePath, fullClean)
|
2024-09-10 23:02:25 +02:00
|
|
|
fmt.Println("Cleaned Firefox build.")
|
|
|
|
} else if update {
|
|
|
|
spitfire.DownloadSource(sourcePath, sourceRepo)
|
|
|
|
spitfire.UpdateRepo(sourcePath)
|
|
|
|
fmt.Println("Mozilla repository updated.")
|
2024-12-11 17:07:08 +01:00
|
|
|
} else if prePatch {
|
2024-09-10 23:02:25 +02:00
|
|
|
spitfire.DownloadSource(sourcePath, sourceRepo)
|
2024-12-11 17:07:08 +01:00
|
|
|
if err := spitfire.ApplyPatches(sourcePath, patchesRepo, "pre-compile-patches", filepath.Join(sourcePath, "patcher"), skipPatchUpdate); err != nil {
|
2024-12-08 14:34:31 +01:00
|
|
|
log.Fatalf("Error during patch application: %v", err)
|
|
|
|
}
|
2024-09-10 23:02:25 +02:00
|
|
|
fmt.Println("Patches updated.")
|
2024-12-11 17:07:08 +01:00
|
|
|
} else if postPatch {
|
2024-12-29 08:54:45 +01:00
|
|
|
// Detect the build directory dynamically
|
|
|
|
buildDir, err := spitfire.ResolveBuildDir(sourcePath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error resolving build directory: %v", err)
|
|
|
|
}
|
2024-12-11 17:07:08 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2024-09-10 23:02:25 +02:00
|
|
|
if run {
|
|
|
|
spitfire.RunProject(sourcePath)
|
|
|
|
}
|
2024-12-11 17:12:00 +01:00
|
|
|
} else if run {
|
|
|
|
spitfire.RunProject(sourcePath)
|
2024-09-10 23:02:25 +02:00
|
|
|
}
|
2024-09-09 01:25:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// PackageAndUploadProcess handles compressing, packaging, and uploading the build to SourceForge.
|
2025-01-11 23:11:11 +01:00
|
|
|
func PackageAndUploadProcess(buildDir string) {
|
2024-09-10 23:02:25 +02:00
|
|
|
|
|
|
|
// Restore working directory before performing SourceForge operations
|
|
|
|
restoreWorkingDirectory()
|
|
|
|
|
2025-01-11 23:11:11 +01:00
|
|
|
pathToUse := buildDir
|
2024-09-10 23:02:25 +02:00
|
|
|
if upload && uploadPath != "" {
|
|
|
|
pathToUse = uploadPath
|
|
|
|
}
|
|
|
|
|
|
|
|
if pathToUse == "" {
|
|
|
|
log.Fatalf("Error: no valid build or upload path provided.")
|
|
|
|
}
|
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// Calculate & display uncompressed size
|
2024-09-10 23:02:25 +02:00
|
|
|
uncompressedSize, err := spitfire.GetDirectorySize(pathToUse)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to calculate uncompressed size: %v", err)
|
|
|
|
}
|
2024-12-21 22:21:04 +01:00
|
|
|
fmt.Printf("Uncompressed directory size: %s\n", spitfire.BytesToHumanReadable(uncompressedSize))
|
2024-09-10 23:02:25 +02:00
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// Create the tar.gz name, e.g. "browser-amd64-nightly-linux.tar.gz"
|
|
|
|
outputCompressedFile := filepath.Join(".", fmt.Sprintf(
|
|
|
|
"%s-%s-%s-%s.tar.gz",
|
|
|
|
component, arch, release, platform,
|
|
|
|
))
|
|
|
|
|
|
|
|
// Compress if requested
|
2024-09-10 23:02:25 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// Compressed size
|
2024-09-10 23:02:25 +02:00
|
|
|
compressedSize, err := spitfire.GetFileSize(outputCompressedFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to get compressed file size: %v", err)
|
|
|
|
}
|
2024-12-21 22:21:04 +01:00
|
|
|
fmt.Printf("Compressed file size: %s\n", spitfire.BytesToHumanReadable(compressedSize))
|
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// Show compression ratio & efficiency
|
2024-12-21 22:21:04 +01:00
|
|
|
compressionRatio, efficiency := spitfire.CalculateCompressionEfficiency(uncompressedSize, compressedSize)
|
|
|
|
fmt.Printf("Compression ratio: %.2f:1\n", compressionRatio)
|
|
|
|
fmt.Printf("Compression efficiency: %.2f%%\n", efficiency)
|
2024-09-10 23:02:25 +02:00
|
|
|
|
2025-01-11 23:11:11 +01:00
|
|
|
// Display compressed directory path
|
|
|
|
fmt.Printf("Compressed dir: %s", pathToUse)
|
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// If not uploading, we're done
|
|
|
|
if !upload {
|
|
|
|
return
|
|
|
|
}
|
2024-09-10 23:02:25 +02:00
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// Load SourceForge config
|
|
|
|
config, err := spitfire.LoadConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to load SourceForge config: %v", err)
|
|
|
|
}
|
2024-09-10 23:02:25 +02:00
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// Check tarball existence
|
|
|
|
if _, err := os.Stat(outputCompressedFile); err != nil {
|
|
|
|
log.Fatalf("No compressed file found to upload: %v", err)
|
|
|
|
}
|
2024-09-10 23:02:25 +02:00
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// The subdirectory path in the SF project
|
|
|
|
// e.g. "browser/amd64/nightly/2024.12.23"
|
|
|
|
uploadDir := fmt.Sprintf("%s/%s/%s/%s", component, arch, release, version)
|
2024-09-10 23:02:25 +02:00
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// 1) Upload the file to SourceForge once
|
|
|
|
err = spitfire.Upload(config, outputCompressedFile,
|
|
|
|
"/home/frs/project/spitfire-browser/"+uploadDir+"/")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to upload compressed file: %v", err)
|
|
|
|
}
|
|
|
|
fmt.Println("Compressed file uploaded successfully.")
|
2024-09-10 23:02:25 +02:00
|
|
|
|
2024-12-23 11:24:42 +01:00
|
|
|
// 2) Download existing APPINDEX or create new
|
|
|
|
err = spitfire.DownloadAPPINDEX(config, "/home/frs/project/spitfire-browser/")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Failed to download APPINDEX. A new one will be created and uploaded.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3) Update the APPINDEX
|
|
|
|
err = spitfire.PackageAPPINDEX(
|
|
|
|
packageName, // e.g. "spitfire-browser"
|
|
|
|
release, // e.g. "nightly"
|
|
|
|
version, // e.g. "2024.12.23"
|
|
|
|
arch,
|
|
|
|
fmt.Sprintf("%d", compressedSize),
|
|
|
|
fmt.Sprintf("%d", uncompressedSize),
|
|
|
|
name, // e.g. "Spitfire"
|
|
|
|
url,
|
|
|
|
licence,
|
|
|
|
component,
|
|
|
|
maintainer,
|
|
|
|
"", // dependencies
|
|
|
|
platform,
|
|
|
|
uploadDir,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to update APPINDEX: %v", err)
|
|
|
|
}
|
|
|
|
fmt.Println("APPINDEX updated successfully.")
|
|
|
|
|
|
|
|
// 4) Clean
|
|
|
|
if err := spitfire.CleanAppIndex(); err != nil {
|
|
|
|
log.Fatalf("Failed to clean APPINDEX: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5) Upload the updated APPINDEX
|
|
|
|
err = spitfire.UploadAPPINDEX(config, "/home/frs/project/spitfire-browser/")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to upload updated APPINDEX: %v", err)
|
2024-09-10 23:02:25 +02:00
|
|
|
}
|
2024-12-23 11:24:42 +01:00
|
|
|
fmt.Println("APPINDEX uploaded successfully.")
|
2024-09-09 01:25:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// restoreWorkingDirectory restores the initial working directory after any operation that might change it.
|
|
|
|
func restoreWorkingDirectory() {
|
2024-09-10 23:02:25 +02:00
|
|
|
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)
|
|
|
|
}
|