windows patch
This commit is contained in:
parent
dfbecf7f98
commit
8d6f46c4ca
1 changed files with 45 additions and 2 deletions
|
@ -5,13 +5,46 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Array to store errors
|
// Array to store errors
|
||||||
var errors []string
|
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
|
// Run an external command like scp or rsync
|
||||||
func runCommand(command string, args ...string) error {
|
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 := exec.Command(command, args...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
@ -117,9 +150,19 @@ func UpdatePatches(patchesDir, patchesRepo, sourcePath string) {
|
||||||
errors = append(errors, "Failed to clone patches repository.")
|
errors = append(errors, "Failed to clone patches repository.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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" {
|
||||||
|
// 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 {
|
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).")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue