-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
45 lines (35 loc) · 950 Bytes
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
func main() {
// Define the output binary name and the source directory
output := "mosql"
sourceDir := "./cmd"
// Get the absolute path to the current working directory
cwd, err := os.Getwd()
if err != nil {
fmt.Println("Error getting current working directory:", err)
os.Exit(1)
}
// Construct the full path to the output binary
outputPath := filepath.Join(cwd, output)
// Prepare the go build command
cmd := exec.Command("go", "build", "-o", outputPath, sourceDir)
// Set the working directory to the root of the workspace
cmd.Dir = cwd
// Run the command and capture any output or errors
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
fmt.Println("Building the project...")
// Execute the build command
err = cmd.Run()
if err != nil {
fmt.Println("Build failed:", err)
os.Exit(1)
}
fmt.Println("Build succeeded! Output binary:", outputPath)
}