From e99e7bf437a1548a4a627614d0baf7ecf428a3b6 Mon Sep 17 00:00:00 2001 From: partisan Date: Wed, 11 Dec 2024 17:12:00 +0100 Subject: [PATCH] fixed 'go run . -r' --- main.go | 4 ++- spitfire/build.go | 61 ++++++++++++++++++++++++++++++++----- spitfire/resolvebuilddir.go | 25 --------------- 3 files changed, 56 insertions(+), 34 deletions(-) delete mode 100644 spitfire/resolvebuilddir.go diff --git a/main.go b/main.go index c493ea3..e23fc49 100644 --- a/main.go +++ b/main.go @@ -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) } } diff --git a/spitfire/build.go b/spitfire/build.go index 3f5be5d..89bc64d 100644 --- a/spitfire/build.go +++ b/spitfire/build.go @@ -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 diff --git a/spitfire/resolvebuilddir.go b/spitfire/resolvebuilddir.go deleted file mode 100644 index 1cc917b..0000000 --- a/spitfire/resolvebuilddir.go +++ /dev/null @@ -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 -}