Compare commits
2 commits
610a5abae1
...
fa6fdd6ba0
Author | SHA1 | Date | |
---|---|---|---|
|
fa6fdd6ba0 | ||
|
221317be93 |
5 changed files with 145 additions and 36 deletions
|
@ -12,10 +12,12 @@ This is a "simple" script for building the Spitfire Browser based on Mozilla Fir
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
- Mercurial (hg)
|
|
||||||
- Git
|
- Git
|
||||||
- Golang (tested with v1.21)
|
- Golang (tested with v1.21)
|
||||||
- Python 3.11 and pip3
|
- Python 3.11 and pip3
|
||||||
|
- Mercurial (hg)
|
||||||
|
|
||||||
|
*Python 3.11, pip3, and Mercurial (hg) are dependencies needed to build Firefox, and they might change in the future or based on your operating system. For Windows, you need to install MozillaBuild. Please ensure you have all the dependencies to build Firefox by following the instructions on Mozilla Firefox's website!*
|
||||||
|
|
||||||
# Example usage:
|
# Example usage:
|
||||||
|
|
||||||
|
|
35
main.go
35
main.go
|
@ -67,16 +67,11 @@ func printHelp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// // Check system dependencies
|
||||||
path, err3 := spitfire.ResolvePath("/mozilla-central")
|
// err := spitfire.CheckSystemDependencies()
|
||||||
// Check and set the MOZILLABUILD environment variable globally
|
// if err != nil {
|
||||||
err2 := spitfire.SetGlobalEnv("MOZILLABUILD", path, "user") // For user
|
// log.Fatalf("System check failed: %v", err)
|
||||||
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()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -90,26 +85,26 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the initial directory
|
// Save the initial directory
|
||||||
var err error
|
var err2 error
|
||||||
initialDir, err = os.Getwd()
|
initialDir, err2 = os.Getwd()
|
||||||
if err != nil {
|
if err2 != nil {
|
||||||
log.Fatalf("Failed to get current working directory: %v", err)
|
log.Fatalf("Failed to get current working directory: %v", err2)
|
||||||
}
|
}
|
||||||
fmt.Printf("Initial working directory: %s\n", initialDir)
|
fmt.Printf("Initial working directory: %s\n", initialDir)
|
||||||
|
|
||||||
// Convert buildPath and uploadPath to absolute paths
|
// Convert buildPath and uploadPath to absolute paths
|
||||||
if buildPath != "" {
|
if buildPath != "" {
|
||||||
buildPath, err = spitfire.ResolvePath(buildPath)
|
buildPath, err2 = spitfire.ResolvePath(buildPath)
|
||||||
if err != nil {
|
if err2 != nil {
|
||||||
log.Fatalf("Failed to convert buildPath to absolute path: %v", err)
|
log.Fatalf("Failed to convert buildPath to absolute path: %v", err2)
|
||||||
}
|
}
|
||||||
fmt.Printf("Resolved buildPath: %s\n", buildPath)
|
fmt.Printf("Resolved buildPath: %s\n", buildPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if uploadPath != "" {
|
if uploadPath != "" {
|
||||||
uploadPath, err = spitfire.ResolvePath(uploadPath)
|
uploadPath, err2 = spitfire.ResolvePath(uploadPath)
|
||||||
if err != nil {
|
if err2 != nil {
|
||||||
log.Fatalf("Failed to convert uploadPath to absolute path: %v", err)
|
log.Fatalf("Failed to convert uploadPath to absolute path: %v", err2)
|
||||||
}
|
}
|
||||||
fmt.Printf("Resolved uploadPath: %s\n", uploadPath)
|
fmt.Printf("Resolved uploadPath: %s\n", uploadPath)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"SFKeyPath": "~/.ssh/id_rsa.pub",
|
"SFKeyPath": "~/.ssh/id_rsa.pub",
|
||||||
"SFUser": "internet-addict",
|
"SFUser": "internet-addict",
|
||||||
"SFHost": "web.sourceforge.net",
|
"SFHost": "web.sourceforge.net",
|
||||||
"SFProject": "spitfire-browser"
|
"SFProject": "spitfire-browser"
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ func SetGlobalEnv(variable, value string, scope string) error {
|
||||||
|
|
||||||
// Run an external command like scp or rsync
|
// Run an external command like scp or rsync
|
||||||
func runCommand(command string, args ...string) error {
|
func runCommand(command string, args ...string) error {
|
||||||
|
fmt.Printf("Running command: %s %v\n", command, args)
|
||||||
cmd := exec.Command(command, args...)
|
cmd := exec.Command(command, args...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
@ -83,10 +84,21 @@ func CleanBuild(sourcePath string) {
|
||||||
errors = append(errors, "Failed to navigate to source directory.")
|
errors = append(errors, "Failed to navigate to source directory.")
|
||||||
return
|
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 {
|
if err := runCommand("hg", "revert", "--all", "--no-backup"); err != nil {
|
||||||
errors = append(errors, "Failed to revert changes in Mozilla repository.")
|
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.")
|
errors = append(errors, "Failed to clean build.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,8 +158,8 @@ func UpdatePatches(patchesDir, patchesRepo, sourcePath string) {
|
||||||
// Handle platform-specific rsync command
|
// Handle platform-specific rsync command
|
||||||
fmt.Println("Copying files from patches directory to Firefox source directory...")
|
fmt.Println("Copying files from patches directory to Firefox source directory...")
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
// Use robocopy for Windows instead of rsync
|
// Use robocopy for Windows
|
||||||
if err := runCommand("robocopy", patchesDir, sourcePath, "/MIR"); err != nil {
|
if err := runCommand("robocopy", patchesDir, sourcePath, "*", "/S", "/XF", ".git", "/XD", ".git"); err != nil {
|
||||||
errors = append(errors, "Failed to copy files (Windows robocopy).")
|
errors = append(errors, "Failed to copy files (Windows robocopy).")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,7 +177,16 @@ func Configure(sourcePath string) {
|
||||||
errors = append(errors, "Failed to navigate to source directory.")
|
errors = append(errors, "Failed to navigate to source directory.")
|
||||||
return
|
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.")
|
errors = append(errors, "Configuration failed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +198,16 @@ func Build(sourcePath string) {
|
||||||
errors = append(errors, "Failed to navigate to source directory.")
|
errors = append(errors, "Failed to navigate to source directory.")
|
||||||
return
|
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.")
|
errors = append(errors, "Build failed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,11 +215,16 @@ func Build(sourcePath string) {
|
||||||
// Function to run the project after build
|
// Function to run the project after build
|
||||||
func RunProject(sourcePath string) {
|
func RunProject(sourcePath string) {
|
||||||
fmt.Println("Running the project...")
|
fmt.Println("Running the project...")
|
||||||
if err := os.Chdir(sourcePath); err != nil {
|
|
||||||
errors = append(errors, "Failed to navigate to source directory.")
|
// Use the appropriate mach command for Windows or Unix-like systems
|
||||||
return
|
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.")
|
errors = append(errors, "Failed to run the project.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
78
spitfire/checks.go
Normal file
78
spitfire/checks.go
Normal file
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in a new issue