44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package workspaceruntime
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
|
|
"inbox/internal/app/lanegit"
|
|
)
|
|
|
|
type hostInboxBinary struct {
|
|
projectRoot string
|
|
runner lanegit.Runner
|
|
}
|
|
|
|
func (b *hostInboxBinary) ensure(ctx context.Context) (string, error) {
|
|
binaryPath := filepath.Join(b.projectRoot, ".runtime", "bin", "inbox")
|
|
needsBuild, err := b.needsBuild(binaryPath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if !needsBuild {
|
|
return binaryPath, nil
|
|
}
|
|
if err := os.MkdirAll(filepath.Dir(binaryPath), 0755); err != nil {
|
|
return "", fmt.Errorf("create runtime bin dir: %w", err)
|
|
}
|
|
env := map[string]string{
|
|
"GOOS": "linux",
|
|
"GOARCH": runtime.GOARCH,
|
|
}
|
|
out, err := b.runner.Run(ctx, filepath.Join(b.projectRoot, "inbox"), env, "go", "build", "-o", binaryPath, "./cmd/inbox")
|
|
if err != nil {
|
|
return "", commandError("build inbox binary", out, err)
|
|
}
|
|
return binaryPath, nil
|
|
}
|
|
|
|
func (b *hostInboxBinary) needsBuild(binaryPath string) (bool, error) {
|
|
return sourceTreeNeedsBuild(b.projectRoot, "inbox", binaryPath)
|
|
}
|