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
4 changed files with 92 additions and 0 deletions
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…
Add table
Add a link
Reference in a new issue