windows build compatability

This commit is contained in:
partisan 2024-09-13 12:47:30 +02:00
parent 048bbc1e3e
commit 358cd7147b
3 changed files with 137 additions and 29 deletions

View file

@ -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.")
}
}

78
spitfire/checks.go Normal file
View 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()
}