fixed 'go run . -r'
This commit is contained in:
parent
ad7f7bf778
commit
e99e7bf437
3 changed files with 56 additions and 34 deletions
4
main.go
4
main.go
|
@ -145,7 +145,7 @@ func main() {
|
||||||
fmt.Printf("Resolved uploadPath: %s\n", uploadPath)
|
fmt.Printf("Resolved uploadPath: %s\n", uploadPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if all || buildFlag || prePatch || postPatch || clean || update {
|
if all || buildFlag || prePatch || postPatch || clean || update || run {
|
||||||
BuildProcess()
|
BuildProcess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +217,8 @@ func BuildProcess() {
|
||||||
spitfire.RunProject(sourcePath)
|
spitfire.RunProject(sourcePath)
|
||||||
}
|
}
|
||||||
fmt.Println("Spitfire build completed successfully.")
|
fmt.Println("Spitfire build completed successfully.")
|
||||||
|
} else if run {
|
||||||
|
spitfire.RunProject(sourcePath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,17 +216,62 @@ func Build(sourcePath string) {
|
||||||
func RunProject(sourcePath string) {
|
func RunProject(sourcePath string) {
|
||||||
fmt.Println("Running the project...")
|
fmt.Println("Running the project...")
|
||||||
|
|
||||||
// Use the appropriate mach command for Windows or Unix-like systems
|
// Resolve the build directory
|
||||||
var machCmd string
|
buildDir, err := ResolveBuildDir(sourcePath)
|
||||||
if runtime.GOOS == "windows" {
|
if err != nil {
|
||||||
machCmd = ".\\mach"
|
fmt.Printf("Error resolving build directory: %v\n", err)
|
||||||
} else {
|
return
|
||||||
machCmd = "./mach"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runCommand(machCmd, "run"); err != nil {
|
// List of possible binaries
|
||||||
errors = append(errors, "Failed to run the project.")
|
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
|
// Function to print collected errors
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue