Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Pass build flags to binding generator #4023

Merged
1 change: 1 addition & 0 deletions docs/src/content/docs/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix nil menu issue when calling RegisterContextMenu by [@leaanthony](https://github.com/leaanthony)
- Fixed dependency cycles in binding generator output by [@fbbdev](https://github.com/fbbdev) in [#4001](https://github.com/wailsapp/wails/pull/4001)
- Fixed use-before-define errors in binding generator output by [@fbbdev](https://github.com/fbbdev) in [#4001](https://github.com/wailsapp/wails/pull/4001)
- Pass build flags to binding generator by [@fbbdev](https://github.com/fbbdev) in [#4023](https://github.com/wailsapp/wails/pull/4023)

### Changed

Expand Down
25 changes: 8 additions & 17 deletions v3/internal/commands/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"os"
"path/filepath"

"github.com/pterm/pterm"

"github.com/wailsapp/wails/v3/internal/flags"
"github.com/wailsapp/wails/v3/internal/generator"
"github.com/wailsapp/wails/v3/internal/generator/config"
Expand All @@ -21,8 +19,8 @@ func GenerateBindings(options *flags.GenerateBindingsOptions, patterns []string)
term.DisableOutput()
defer term.EnableOutput()
} else if options.Verbose {
pterm.EnableDebugMessages()
defer pterm.DisableDebugMessages()
term.EnableDebug()
defer term.DisableDebug()
}

term.Header("Generate Bindings")
Expand Down Expand Up @@ -52,20 +50,18 @@ func GenerateBindings(options *flags.GenerateBindingsOptions, patterns []string)
}

// Start a spinner for progress messages.
var spinner *pterm.SpinnerPrinter
if term.IsTerminal() {
spinner, _ = pterm.DefaultSpinner.Start("Initialising...")
}
spinner := term.StartSpinner("Initialising...")

// Initialise and run generator.
stats, err := generator.NewGenerator(
options,
creator,
config.DefaultPtermLogger(spinner),
spinner.Logger(),
).Generate(patterns...)

// Resolve spinner.
resultMessage := fmt.Sprintf(
// Stop spinner and print summary.
term.StopSpinner(spinner)
term.Infof(
"Processed: %s, %s, %s, %s, %s in %s.",
pluralise(stats.NumPackages, "Package"),
pluralise(stats.NumServices, "Service"),
Expand All @@ -74,14 +70,9 @@ func GenerateBindings(options *flags.GenerateBindingsOptions, patterns []string)
pluralise(stats.NumModels, "Model"),
stats.Elapsed().String(),
)
if spinner != nil {
spinner.Info(resultMessage)
} else {
term.Infofln(resultMessage)
}

// Report output directory.
term.Infofln("Output directory: %s", absPath)
term.Infof("Output directory: %s", absPath)

// Process generator error.
if err != nil {
Expand Down
16 changes: 12 additions & 4 deletions v3/internal/commands/build_assets/Taskfile.tmpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ tasks:
- npm install

build:frontend:
label: build:frontend (PRODUCTION={{ "{{.PRODUCTION}}" }})
summary: Build the frontend project
dir: frontend
sources:
- "**/*"
generates:
- dist/*
- dist/**/*
deps:
- task: install:frontend:deps
- task: generate:bindings
vars:
BUILD_FLAGS:
ref: .BUILD_FLAGS
cmds:
- npm run {{ "{{.BUILD_COMMAND}}" }} -q
env:
Expand All @@ -40,17 +44,21 @@ tasks:


generate:bindings:
label: generate:bindings (BUILD_FLAGS={{ "{{.BUILD_FLAGS}}" }})
summary: Generates bindings for the frontend
deps:
- task: go:mod:tidy
sources:
- "**/*.[jt]s"
- exclude: frontend/**/*
- frontend/bindings/**/* # Rerun when switching between dev/production mode causes changes in output
- "**/*.go"
- go.mod
- go.sum
generates:
- "frontend/bindings/**/*"
- frontend/bindings/**/*
cmds:
- wails3 generate bindings -f {{ "'{{.BUILD_FLAGS}}'" }} -clean=true {{if .Typescript}} -ts{{end}}
- wails3 generate bindings -f {{ "'{{.BUILD_FLAGS}}'" }} -clean=true {{- if .Typescript}} -ts{{end}}

generate:icons:
summary: Generates Windows `.ico` and Mac `.icns` files from an image
Expand All @@ -75,4 +83,4 @@ tasks:
summary: Updates the build assets
dir: build
cmds:
- wails3 update build-assets -name {{ "\"{{.APP_NAME}}\"" }} -binaryname {{ "\"{{.APP_NAME}}\"" }} -config config.yml -dir .
- wails3 update build-assets -name {{ "\"{{.APP_NAME}}\"" }} -binaryname {{ "\"{{.APP_NAME}}\"" }} -config config.yml -dir .
5 changes: 5 additions & 0 deletions v3/internal/commands/build_assets/darwin/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ tasks:
deps:
- task: common:go:mod:tidy
- task: common:build:frontend
vars:
BUILD_FLAGS:
ref: .BUILD_FLAGS
PRODUCTION:
ref: .PRODUCTION
- task: common:generate:icons
cmds:
- go build {{.BUILD_FLAGS}} -o {{.OUTPUT}}
Expand Down
11 changes: 8 additions & 3 deletions v3/internal/commands/build_assets/linux/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ tasks:
deps:
- task: common:go:mod:tidy
- task: common:build:frontend
vars:
BUILD_FLAGS:
ref: .BUILD_FLAGS
PRODUCTION:
ref: .PRODUCTION
- task: common:generate:icons
cmds:
- go build {{.BUILD_FLAGS}} -o {{.BIN_DIR}}/{{.APP_NAME}}
Expand Down Expand Up @@ -83,17 +88,17 @@ tasks:

generate:deb:
summary: Creates a deb package
cmds:
cmds:
- wails3 tool package -name {{.APP_NAME}} -format deb -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin

generate:rpm:
summary: Creates a rpm package
cmds:
cmds:
- wails3 tool package -name {{.APP_NAME}} -format rpm -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin

generate:aur:
summary: Creates a arch linux packager package
cmds:
cmds:
- wails3 tool package -name {{.APP_NAME}} -format archlinux -config ./build/linux/nfpm/nfpm.yaml -out {{.ROOT_DIR}}/bin

generate:dotdesktop:
Expand Down
7 changes: 5 additions & 2 deletions v3/internal/commands/build_assets/windows/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ tasks:
- task: common:go:mod:tidy
- task: common:build:frontend
vars:
PRODUCTION: '{{.PRODUCTION}}'
BUILD_FLAGS:
ref: .BUILD_FLAGS
PRODUCTION:
ref: .PRODUCTION
- task: common:generate:icons
cmds:
- task: generate:syso
Expand Down Expand Up @@ -57,4 +60,4 @@ tasks:

run:
cmds:
- '{{.BIN_DIR}}\\{{.APP_NAME}}.exe'
- '{{.BIN_DIR}}\\{{.APP_NAME}}.exe'
53 changes: 29 additions & 24 deletions v3/internal/term/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ func Header(header string) {
pterm.BgLightGreen.Println(pterm.LightWhite(" " + header + " "))
}

func Infof(format string, args ...interface{}) {
pterm.Info.Printf(format, args...)
}
func Infofln(format string, args ...interface{}) {
pterm.Info.Printfln(format, args...)
}

func IsTerminal() bool {
return term.IsTerminal(int(os.Stdout.Fd())) && (os.Getenv("CI") != "true")
}
Expand All @@ -31,50 +24,53 @@ type Spinner struct {
spinner *pterm.SpinnerPrinter
}

func (s *Spinner) Logger() config.Logger {
if s == nil {
return nil
}
func (s Spinner) Logger() config.Logger {
return config.DefaultPtermLogger(s.spinner)
}

func StartSpinner(text string) *Spinner {
func StartSpinner(text string) Spinner {
if !IsTerminal() {
return nil
return Spinner{}
}
spin, err := pterm.DefaultSpinner.Start(text)
spinner, err := pterm.DefaultSpinner.Start(text)
if err != nil {
return nil
}
return &Spinner{
spinner: spin,
return Spinner{}
}
spinner.RemoveWhenDone = true
return Spinner{spinner}
}

func StopSpinner(s *Spinner) {
if s == nil {
return
func StopSpinner(s Spinner) {
if s.spinner != nil {
_ = s.spinner.Stop()
}
_ = s.spinner.Stop()
}

func output(input any, printer pterm.PrefixPrinter, args ...any) {
switch v := input.(type) {
case string:
printer.Println(fmt.Sprintf(input.(string), args...))
printer.Printfln(input.(string), args...)
case error:
printer.Println(v.Error())
default:
printer.Printfln("%v", v)
}
}

func Info(input any) {
output(input, pterm.Info)
}

func Infof(input any, args ...interface{}) {
output(input, pterm.Info, args...)
}

func Warning(input any) {
output(input, pterm.Warning)
}

func Warningf(input any, args ...any) {
output(input, pterm.Warning, args)
output(input, pterm.Warning, args...)
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

LGTM! Critical bug fix for variadic argument handling.

The change correctly expands the variadic arguments when passing them to the output function. This fixes a potential bug where format strings expecting multiple arguments would receive the slice as a single argument instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leaanthony Here's the committable code:

func Warningf(input any, args ...any) {
	output(input, pterm.Warning, args...)
}

}

func Error(input any) {
Expand All @@ -93,6 +89,7 @@ func Section(s string) {
func DisableColor() {
pterm.DisableColor()
}

func EnableOutput() {
pterm.EnableOutput()
}
Expand All @@ -101,6 +98,14 @@ func DisableOutput() {
pterm.DisableOutput()
}

func EnableDebug() {
pterm.EnableDebugMessages()
}

func DisableDebug() {
pterm.DisableDebugMessages()
}

func Println(s string) {
pterm.Println(s)
}
Expand Down
Loading