Skip to content

Commit 36d36d4

Browse files
Merge pull request #225 from StrongMonkey/fix-golang-windows
Fix: fix golang packaging in windows
2 parents b583960 + 0ef0004 commit 36d36d4

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

pkg/engine/cmd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"os"
1010
"os/exec"
11+
"path/filepath"
1112
"runtime"
1213
"sort"
1314
"strings"
@@ -202,6 +203,17 @@ func (e *Engine) newCommand(ctx context.Context, extraEnv []string, tool types.T
202203
cmdArgs = append(cmdArgs, f.Name())
203204
}
204205

206+
// This is a workaround for Windows, where the command interpreter is constructed with unix style paths
207+
// It converts unix style paths to windows style paths
208+
if runtime.GOOS == "windows" {
209+
parts := strings.Split(args[0], "/")
210+
if parts[len(parts)-1] == "gptscript-go-tool" {
211+
parts[len(parts)-1] = "gptscript-go-tool.exe"
212+
}
213+
214+
args[0] = filepath.Join(parts...)
215+
}
216+
205217
cmd := exec.CommandContext(ctx, env.Lookup(envvars, args[0]), cmdArgs...)
206218
cmd.Env = envvars
207219
return cmd, stop, nil

pkg/engine/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (e *Engine) startDaemon(_ context.Context, tool types.Tool) (string, error)
176176
e.Ports.daemonWG.Done()
177177
})
178178

179-
for i := 0; i < 20; i++ {
179+
for i := 0; i < 120; i++ {
180180
resp, err := http.Get(url)
181181
if err == nil && resp.StatusCode == http.StatusOK {
182182
go func() {

pkg/repos/runtimes/golang/golang.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,19 @@ func stripGo(env []string) (result []string) {
7777

7878
func (r *Runtime) runBuild(ctx context.Context, toolSource, binDir string, env []string) error {
7979
log.Infof("Running go build in %s", toolSource)
80-
cmd := debugcmd.New(ctx, filepath.Join(binDir, "go"), "build", "-buildvcs=false", "-o", "bin/gptscript-go-tool")
80+
cmd := debugcmd.New(ctx, filepath.Join(binDir, "go"), "build", "-buildvcs=false", "-o", artifactName())
8181
cmd.Env = stripGo(env)
8282
cmd.Dir = toolSource
8383
return cmd.Run()
8484
}
8585

86+
func artifactName() string {
87+
if runtime.GOOS == "windows" {
88+
return filepath.Join("bin", "gptscript-go-tool.exe")
89+
}
90+
return filepath.Join("bin", "gptscript-go-tool")
91+
}
92+
8693
func (r *Runtime) binDir(rel string) string {
8794
return filepath.Join(rel, "go", "bin")
8895
}

0 commit comments

Comments
 (0)