Add wails build invocation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6b8cb07973
commit
0c48594842
2
go.mod
2
go.mod
|
|
@ -3,3 +3,5 @@ module github.com/leonmika/wails-release
|
|||
go 1.25.0
|
||||
|
||||
require golang.org/x/mod v0.35.0
|
||||
|
||||
require github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -1,2 +1,4 @@
|
|||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
|
||||
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
|
||||
|
|
|
|||
31
internal/wails/build.go
Normal file
31
internal/wails/build.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package wails
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/shlex"
|
||||
"github.com/leonmika/wails-release/internal/runner"
|
||||
)
|
||||
|
||||
// BuildOpts configures a Wails build.
|
||||
type BuildOpts struct {
|
||||
Dir string
|
||||
ExtraFlags string
|
||||
}
|
||||
|
||||
// Build runs `wails build` with our mandatory flags plus any extras.
|
||||
func Build(ctx context.Context, r runner.Runner, opts BuildOpts) error {
|
||||
args := []string{"build", "-platform", "darwin/universal", "-clean", "-trimpath"}
|
||||
if opts.ExtraFlags != "" {
|
||||
extra, err := shlex.Split(opts.ExtraFlags)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse extra-build-flags: %w", err)
|
||||
}
|
||||
args = append(args, extra...)
|
||||
}
|
||||
if _, err := r.Run(ctx, runner.Spec{Name: "wails", Args: args, Dir: opts.Dir}); err != nil {
|
||||
return fmt.Errorf("wails build: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
57
internal/wails/build_test.go
Normal file
57
internal/wails/build_test.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package wails_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/leonmika/wails-release/internal/runner"
|
||||
"github.com/leonmika/wails-release/internal/wails"
|
||||
)
|
||||
|
||||
func TestBuild_DefaultArgs(t *testing.T) {
|
||||
f := &runner.Fake{}
|
||||
f.On("wails", nil).Return(nil, nil)
|
||||
|
||||
err := wails.Build(context.Background(), f, wails.BuildOpts{Dir: "/work"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected: %v", err)
|
||||
}
|
||||
want := []string{"build", "-platform", "darwin/universal", "-clean", "-trimpath"}
|
||||
if !reflect.DeepEqual(f.Calls[0].Args, want) {
|
||||
t.Fatalf("args got %v want %v", f.Calls[0].Args, want)
|
||||
}
|
||||
if f.Calls[0].Dir != "/work" {
|
||||
t.Fatalf("dir got %q want /work", f.Calls[0].Dir)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuild_AppendsExtraFlags(t *testing.T) {
|
||||
f := &runner.Fake{}
|
||||
f.On("wails", nil).Return(nil, nil)
|
||||
|
||||
err := wails.Build(context.Background(), f, wails.BuildOpts{
|
||||
Dir: "/work",
|
||||
ExtraFlags: `-tags release -ldflags "-X main.commit=abc"`,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected: %v", err)
|
||||
}
|
||||
want := []string{
|
||||
"build", "-platform", "darwin/universal", "-clean", "-trimpath",
|
||||
"-tags", "release", "-ldflags", "-X main.commit=abc",
|
||||
}
|
||||
if !reflect.DeepEqual(f.Calls[0].Args, want) {
|
||||
t.Fatalf("args got %v want %v", f.Calls[0].Args, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuild_MalformedExtraFlagsErrors(t *testing.T) {
|
||||
err := wails.Build(context.Background(), &runner.Fake{}, wails.BuildOpts{
|
||||
Dir: "/work",
|
||||
ExtraFlags: `-foo "unterminated`,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("expected parse error")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue