fixed 'go run . -r'

This commit is contained in:
partisan 2024-12-11 17:12:00 +01:00
parent ad7f7bf778
commit e99e7bf437
3 changed files with 56 additions and 34 deletions

View file

@ -145,7 +145,7 @@ func main() {
fmt.Printf("Resolved uploadPath: %s\n", uploadPath)
}
if all || buildFlag || prePatch || postPatch || clean || update {
if all || buildFlag || prePatch || postPatch || clean || update || run {
BuildProcess()
}
@ -217,6 +217,8 @@ func BuildProcess() {
spitfire.RunProject(sourcePath)
}
fmt.Println("Spitfire build completed successfully.")
} else if run {
spitfire.RunProject(sourcePath)
}
}

View file

@ -216,17 +216,62 @@ func Build(sourcePath string) {
func RunProject(sourcePath string) {
fmt.Println("Running the project...")
// Use the appropriate mach command for Windows or Unix-like systems
var machCmd string
if runtime.GOOS == "windows" {
machCmd = ".\\mach"
} else {
machCmd = "./mach"
// Resolve the build directory
buildDir, err := ResolveBuildDir(sourcePath)
if err != nil {
fmt.Printf("Error resolving build directory: %v\n", err)
return
}
if err := runCommand(machCmd, "run"); err != nil {
errors = append(errors, "Failed to run the project.")
// List of possible binaries
binaries := []string{"firefox", "Firefox", "spitfire", "Spitfire"}
var binaryPath string
// Check for the existence of binaries
for _, binary := range binaries {
binaryPath = filepath.Join(buildDir, binary)
if _, err := os.Stat(binaryPath); err == nil {
fmt.Printf("Found binary: %s\n", binaryPath)
break
}
binaryPath = ""
}
if binaryPath == "" {
fmt.Println("No suitable binary found to run the project.")
return
}
// Run the binary
cmd := exec.Command(binaryPath)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
fmt.Printf("Running binary: %s\n", binaryPath)
if err := cmd.Run(); err != nil {
fmt.Printf("Failed to run the project: %v\n", err)
}
}
// ResolveBuildDir detects the build directory dynamically
func ResolveBuildDir(sourcePath string) (string, error) {
// The expected build directory pattern
globPattern := filepath.Join(sourcePath, "obj-*")
// Find matching directories
matches, err := filepath.Glob(globPattern)
if err != nil {
return "", fmt.Errorf("error resolving build directory: %v", err)
}
if len(matches) == 0 {
return "", fmt.Errorf("build directory not found under %s", sourcePath)
}
full := filepath.Join(matches[0], "dist", "bin")
// Return the first match (assumes one build directory exists)
return full, nil
}
// Function to print collected errors

View file

@ -1,25 +0,0 @@
package spitfire
import (
"fmt"
"path/filepath"
)
// ResolveBuildDir detects the build directory dynamically
func ResolveBuildDir(sourcePath string) (string, error) {
// The expected build directory pattern
globPattern := filepath.Join(sourcePath, "obj-*")
// Find matching directories
matches, err := filepath.Glob(globPattern)
if err != nil {
return "", fmt.Errorf("error resolving build directory: %v", err)
}
if len(matches) == 0 {
return "", fmt.Errorf("build directory not found under %s", sourcePath)
}
full := filepath.Join(matches[0], "dist", "bin")
// Return the first match (assumes one build directory exists)
return full, nil
}