added '--ignore-errors' flag instead of ignoring errors during build by default
This commit is contained in:
parent
df3e8e3a83
commit
e5c95924d5
3 changed files with 167 additions and 179 deletions
|
@ -59,63 +59,59 @@ func ResolvePath(path string) (string, error) {
|
|||
}
|
||||
|
||||
// Function to download Mozilla source if not present
|
||||
func DownloadSource(sourcePath string, sourceRepo string) {
|
||||
func DownloadSource(sourcePath, sourceRepo string) error {
|
||||
if _, err := os.Stat(sourcePath); os.IsNotExist(err) {
|
||||
fmt.Println("Mozilla source not found. Cloning from repository...")
|
||||
if err := runCommand("hg", "clone", sourceRepo, sourcePath); err != nil {
|
||||
errors = append(errors, "Failed to clone Mozilla repository.")
|
||||
return fmt.Errorf("failed to clone Mozilla repository: %w", err)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Mozilla source already exists.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Function to discard uncommitted changes
|
||||
func DiscardChanges(sourcePath string) {
|
||||
func DiscardChanges(sourcePath string) error {
|
||||
fmt.Println("Discarding uncommitted changes...")
|
||||
if err := runCommand("hg", "revert", "--all", "--no-backup", "-R", sourcePath); err != nil {
|
||||
errors = append(errors, "Failed to revert changes in Mozilla repository.")
|
||||
return fmt.Errorf("failed to revert changes: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Function to clean build
|
||||
func CleanBuild(sourcePath string, fullClean bool) {
|
||||
func CleanBuild(sourcePath string, fullClean bool) error {
|
||||
fmt.Println("Cleaning build...")
|
||||
|
||||
// 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("hg", "revert", "--all", "--no-backup", "-R", sourcePath); err != nil {
|
||||
return fmt.Errorf("failed to revert changes: %w", err)
|
||||
}
|
||||
|
||||
if fullClean {
|
||||
// Perform full clean or clobber if necessary
|
||||
var machCmd string
|
||||
machCmd := filepath.Join(sourcePath, "mach")
|
||||
if runtime.GOOS == "windows" {
|
||||
machCmd = ".\\mach"
|
||||
} else {
|
||||
machCmd = "./mach"
|
||||
machCmd = filepath.Join(sourcePath, "mach.bat")
|
||||
}
|
||||
|
||||
if err := runCommand(machCmd, "clobber"); err != nil {
|
||||
errors = append(errors, "Failed to clean build.")
|
||||
} else {
|
||||
fmt.Println("Build artifacts cleaned successfully.")
|
||||
cmd := exec.Command(machCmd, "clobber")
|
||||
cmd.Dir = sourcePath // Run in the source directory
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("failed to clean build: %w", err)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Skipping full clean. Build artifacts remain intact.")
|
||||
fmt.Println("Build artifacts cleaned successfully.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Function to update Mozilla repository
|
||||
func UpdateRepo(sourcePath string) {
|
||||
func UpdateRepo(sourcePath string) error {
|
||||
fmt.Println("Updating Mozilla repository...")
|
||||
if err := os.Chdir(sourcePath); err != nil {
|
||||
errors = append(errors, "Failed to navigate to source directory.")
|
||||
return
|
||||
return fmt.Errorf("failed to navigate to source directory: %w", err)
|
||||
}
|
||||
if err := runCommand("hg", "pull", "-u"); err != nil {
|
||||
errors = append(errors, "Failed to update Mozilla repository.")
|
||||
return fmt.Errorf("failed to update repository: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Function to update patches
|
||||
|
@ -174,56 +170,41 @@ func UpdatePatches(patchesDir, patchesRepo, sourcePath string) {
|
|||
}
|
||||
|
||||
// Function to configure Spitfire
|
||||
func Configure(sourcePath string) {
|
||||
func Configure(sourcePath string) error {
|
||||
fmt.Println("Configuring Spitfire...")
|
||||
if err := os.Chdir(sourcePath); err != nil {
|
||||
errors = append(errors, "Failed to navigate to source directory.")
|
||||
return
|
||||
return fmt.Errorf("failed to navigate to source directory: %w", err)
|
||||
}
|
||||
|
||||
// Use the appropriate mach command for Windows or Unix-like systems
|
||||
var machCmd string
|
||||
machCmd := "./mach"
|
||||
if runtime.GOOS == "windows" {
|
||||
machCmd = ".\\mach"
|
||||
} else {
|
||||
machCmd = "./mach"
|
||||
}
|
||||
|
||||
if err := runCommand(machCmd, "configure"); err != nil {
|
||||
errors = append(errors, "Configuration failed.")
|
||||
}
|
||||
return runCommand(machCmd, "configure")
|
||||
}
|
||||
|
||||
// Function to build Spitfire
|
||||
func Build(sourcePath string) {
|
||||
func Build(sourcePath string) error {
|
||||
fmt.Println("Building Spitfire...")
|
||||
if err := os.Chdir(sourcePath); err != nil {
|
||||
errors = append(errors, "Failed to navigate to source directory.")
|
||||
return
|
||||
return fmt.Errorf("failed to navigate to source directory: %w", err)
|
||||
}
|
||||
|
||||
// Use the appropriate mach command for Windows or Unix-like systems
|
||||
var machCmd string
|
||||
machCmd := "./mach"
|
||||
if runtime.GOOS == "windows" {
|
||||
machCmd = ".\\mach"
|
||||
} else {
|
||||
machCmd = "./mach"
|
||||
}
|
||||
|
||||
if err := runCommand(machCmd, "build"); err != nil {
|
||||
errors = append(errors, "Build failed.")
|
||||
}
|
||||
return runCommand(machCmd, "build")
|
||||
}
|
||||
|
||||
// Function to run the project after build
|
||||
func RunProject(sourcePath string) {
|
||||
func RunProject(sourcePath string) error {
|
||||
fmt.Println("Running the project...")
|
||||
|
||||
// Resolve the build directory
|
||||
buildDir, err := ResolveBuildDir(sourcePath)
|
||||
if err != nil {
|
||||
fmt.Printf("Error resolving build directory: %v\n", err)
|
||||
return
|
||||
return fmt.Errorf("error resolving build directory: %w", err)
|
||||
}
|
||||
|
||||
// List of possible binaries
|
||||
|
@ -242,15 +223,13 @@ func RunProject(sourcePath string) {
|
|||
}
|
||||
|
||||
if binaryPath == "" {
|
||||
fmt.Println("No suitable binary found to run the project.")
|
||||
return
|
||||
return fmt.Errorf("no suitable binary found to run the project")
|
||||
}
|
||||
|
||||
// Create a unique profile directory for each run
|
||||
profilePath := filepath.Join(buildDir, fmt.Sprintf("profile_%d", time.Now().UnixNano()))
|
||||
if err := os.Mkdir(profilePath, 0755); err != nil {
|
||||
fmt.Printf("Failed to create profile directory: %v\n", err)
|
||||
return
|
||||
return fmt.Errorf("failed to create profile directory: %w", err)
|
||||
}
|
||||
|
||||
// Run the binary with the new profile
|
||||
|
@ -260,19 +239,22 @@ func RunProject(sourcePath string) {
|
|||
cmd.Stdin = os.Stdin
|
||||
|
||||
fmt.Printf("Running binary: %s with new profile at %s\n", binaryPath, profilePath)
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Printf("Failed to run the project: %v\n", err)
|
||||
} else {
|
||||
fmt.Println("Binary execution finished successfully.")
|
||||
}
|
||||
runErr := cmd.Run()
|
||||
|
||||
// Delete the profile directory after execution
|
||||
fmt.Printf("Deleting profile directory: %s\n", profilePath)
|
||||
if err := os.RemoveAll(profilePath); err != nil {
|
||||
fmt.Printf("Failed to delete profile directory: %v\n", err)
|
||||
if removeErr := os.RemoveAll(profilePath); removeErr != nil {
|
||||
fmt.Printf("Warning: failed to delete profile directory: %v\n", removeErr)
|
||||
} else {
|
||||
fmt.Println("Profile directory deleted successfully.")
|
||||
}
|
||||
|
||||
if runErr != nil {
|
||||
return fmt.Errorf("failed to run the project: %w", runErr)
|
||||
}
|
||||
|
||||
fmt.Println("Binary execution finished successfully.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResolveBuildDir detects the build directory dynamically
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue