windows patch

This commit is contained in:
partisan 2024-09-10 23:21:46 +02:00
parent 03f533bfe6
commit 67ca7555ae

View file

@ -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 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.")
errors = append(errors, "Failed to copy files (rsync).")
}
}
}