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

Added possibility to specify platform for dev command #3245

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions v2/cmd/wails/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,44 +207,43 @@ func buildApplication(f *flags.Build) error {
pterm.Warning.Println("obfuscated flag overrides skipbindings flag.")
buildOptions.SkipBindings = false
}
}

if !f.DryRun {
// Start Time
start := time.Now()

compiledBinary, err := build.Build(buildOptions)
if err != nil {
pterm.Error.Println(err.Error())
return err
if !f.DryRun {
// Start Time
start := time.Now()

compiledBinary, err := build.Build(buildOptions)
if err != nil {
pterm.Error.Println(err.Error())
return err
}

buildOptions.IgnoreFrontend = true
buildOptions.CleanBinDirectory = false

// Output stats
buildOptions.Logger.Println(fmt.Sprintf("Built '%s' in %s.\n", compiledBinary, time.Since(start).Round(time.Millisecond).String()))

outputBinaries[buildOptions.Platform+"/"+buildOptions.Arch] = compiledBinary
} else {
pterm.Info.Println("Dry run: skipped build.")
}

buildOptions.IgnoreFrontend = true
buildOptions.CleanBinDirectory = false

// Output stats
buildOptions.Logger.Println(fmt.Sprintf("Built '%s' in %s.\n", compiledBinary, time.Since(start).Round(time.Millisecond).String()))

outputBinaries[buildOptions.Platform+"/"+buildOptions.Arch] = compiledBinary
} else {
pterm.Info.Println("Dry run: skipped build.")
}

if f.DryRun {
return nil
}

if f.NSIS {
amd64Binary := outputBinaries["windows/amd64"]
arm64Binary := outputBinaries["windows/arm64"]
if amd64Binary == "" && arm64Binary == "" {
return fmt.Errorf("cannot build nsis installer - no windows targets")

if f.DryRun {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation of the DryRun flag correctly skips the build process when set. However, consider moving the check for DryRun to an earlier stage in the function to avoid unnecessary processing before deciding not to perform the build.

}

if err := build.GenerateNSISInstaller(buildOptions, amd64Binary, arm64Binary); err != nil {
return err

if f.NSIS {
amd64Binary := outputBinaries["windows/amd64"]
arm64Binary := outputBinaries["windows/arm64"]
if amd64Binary == "" && arm64Binary == "" {
return fmt.Errorf("cannot build nsis installer - no windows targets")
}

if err := build.GenerateNSISInstaller(buildOptions, amd64Binary, arm64Binary); err != nil {
return err
}
}
}

return nil
}
51 changes: 15 additions & 36 deletions v2/cmd/wails/flags/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,21 @@ func (t Target) String() string {
return t.Platform
}

func parseTargets(platform string) TargetsCollection {
allowedPlatforms := map[string]bool{
"windows": true,
"linux": true,
"darwin": true,
}

if !allowedPlatforms[platform] {
pterm.Error.Println("platform argument must be one of 'windows', 'linux', or 'darwin'")
os.Exit(1)
}

var result []Target
var targets slicer.StringSlicer

targets.AddSlice(strings.Split(platform, ","))
targets.Deduplicate()

targets.Each(func(platform string) {
target := Target{
Platform: "",
Arch: "",
}

platformSplit := strings.Split(platform, "/")

target.Platform = platformSplit[0]

if len(platformSplit) > 1 {
target.Arch = platformSplit[1]
} else {
target.Arch = defaultTarget().Arch
func parseTargets(platforms string) TargetsCollection {
platformList := strings.Split(platforms, ",")

var targets []Target

for _, platform := range platformList {
parts := strings.Split(platform, "/")
if len(parts) == 1 {
architecture := defaultTarget().Arch
targets = append(targets, Target{Platform: parts[0], Arch: architecture})
} else if len(parts) == 2 {
targets = append(targets, Target{Platform: parts[0], Arch: parts[1]})
}
}

result = append(result, target)
})

return result
return targets
Copy link
Contributor

Choose a reason for hiding this comment

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

The refactoring of parseTargets improves readability and maintainability. However, consider handling unexpected formats more robustly, such as entries with more than one '/' character, which could lead to incorrect parsing without any error or warning.

}

Loading