fixed 'go run . -r'
This commit is contained in:
parent
ad7f7bf778
commit
e99e7bf437
3 changed files with 56 additions and 34 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue