From 50c219307fff9e1cfb57fa7c4c012c65ad59db1e Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 26 Mar 2021 14:10:25 +1100 Subject: [PATCH] Add clean flag --- v2/cmd/wails/internal/commands/build/build.go | 26 +++++++++------ v2/pkg/commands/build/base.go | 10 +++--- v2/pkg/commands/build/build.go | 33 ++++++++++--------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/v2/cmd/wails/internal/commands/build/build.go b/v2/cmd/wails/internal/commands/build/build.go index a5716bbc..390ba459 100644 --- a/v2/cmd/wails/internal/commands/build/build.go +++ b/v2/cmd/wails/internal/commands/build/build.go @@ -63,6 +63,10 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { outputFilename := "" command.StringFlag("o", "Output filename", &outputFilename) + // Clean build directory + cleanBuildDirectory := false + command.BoolFlag("clean", "Clean the build directory before building", &cleanBuildDirectory) + appleIdentity := "" if runtime.GOOS == "darwin" { command.StringFlag("sign", "Signs your app with the given identity.", &appleIdentity) @@ -112,16 +116,17 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { // Create BuildOptions buildOptions := &build.Options{ - Logger: logger, - OutputType: outputType, - OutputFile: outputFilename, - Mode: mode, - Pack: pack, - LDFlags: ldflags, - Compiler: compilerCommand, - KeepAssets: keepAssets, - AppleIdentity: appleIdentity, - Verbosity: verbosity, + Logger: logger, + OutputType: outputType, + OutputFile: outputFilename, + CleanBuildDirectory: cleanBuildDirectory, + Mode: mode, + Pack: pack, + LDFlags: ldflags, + Compiler: compilerCommand, + KeepAssets: keepAssets, + AppleIdentity: appleIdentity, + Verbosity: verbosity, } // Calculate platform and arch @@ -148,6 +153,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { fmt.Fprintf(w, "Compiler: \t%s\n", buildOptions.Compiler) fmt.Fprintf(w, "Build Mode: \t%s\n", buildModeText) fmt.Fprintf(w, "Package: \t%t\n", buildOptions.Pack) + fmt.Fprintf(w, "Clean Build Dir: \t%t\n", buildOptions.CleanBuildDirectory) fmt.Fprintf(w, "KeepAssets: \t%t\n", buildOptions.KeepAssets) fmt.Fprintf(w, "LDFlags: \t\"%s\"\n", buildOptions.LDFlags) if len(buildOptions.OutputFile) > 0 { diff --git a/v2/pkg/commands/build/base.go b/v2/pkg/commands/build/base.go index 91e6c3cd..f17b5183 100644 --- a/v2/pkg/commands/build/base.go +++ b/v2/pkg/commands/build/base.go @@ -212,10 +212,12 @@ func (b *BaseBuilder) CompileProject(options *Options) error { // Get application build directory appDir := options.BuildDirectory - //err = cleanBuildDirectory(options) - //if err != nil { - // return err - //} + if options.CleanBuildDirectory { + err = cleanBuildDirectory(options) + if err != nil { + return err + } + } if options.LDFlags != "" { commands.Add("-ldflags") diff --git a/v2/pkg/commands/build/build.go b/v2/pkg/commands/build/build.go index 0396699c..222dbf9d 100644 --- a/v2/pkg/commands/build/build.go +++ b/v2/pkg/commands/build/build.go @@ -28,22 +28,23 @@ var modeMap = []string{"Debug", "Production"} // Options contains all the build options as well as the project data type Options struct { - LDFlags string // Optional flags to pass to linker - Logger *clilogger.CLILogger // All output to the logger - OutputType string // EG: desktop, server.... - Mode Mode // release or debug - ProjectData *project.Project // The project data - Pack bool // Create a package for the app after building - Platform string // The platform to build for - Arch string // The architecture to build for - Compiler string // The compiler command to use - IgnoreFrontend bool // Indicates if the frontend does not need building - OutputFile string // Override the output filename - BuildDirectory string // Directory to use for building the application - CompiledBinary string // Fully qualified path to the compiled binary - KeepAssets bool // /Keep the generated assets/files - Verbosity int // Verbosity level (0 - silent, 1 - default, 2 - verbose) - AppleIdentity string + LDFlags string // Optional flags to pass to linker + Logger *clilogger.CLILogger // All output to the logger + OutputType string // EG: desktop, server.... + Mode Mode // release or debug + ProjectData *project.Project // The project data + Pack bool // Create a package for the app after building + Platform string // The platform to build for + Arch string // The architecture to build for + Compiler string // The compiler command to use + IgnoreFrontend bool // Indicates if the frontend does not need building + OutputFile string // Override the output filename + BuildDirectory string // Directory to use for building the application + CleanBuildDirectory bool // Indicates if the build directory should be cleaned before building + CompiledBinary string // Fully qualified path to the compiled binary + KeepAssets bool // /Keep the generated assets/files + Verbosity int // Verbosity level (0 - silent, 1 - default, 2 - verbose) + AppleIdentity string } // GetModeAsString returns the current mode as a string