From 57c994de3ec1b0269878e6b06e3b6e47990efcbe Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 12:31:58 +0700 Subject: [PATCH 1/9] create flavor file --- internal/config/flavor.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 internal/config/flavor.go diff --git a/internal/config/flavor.go b/internal/config/flavor.go new file mode 100644 index 00000000..654fcff0 --- /dev/null +++ b/internal/config/flavor.go @@ -0,0 +1,33 @@ +package config + +import ( + "github.com/go-flutter-desktop/hover/internal/log" + "os" +) + +var hoverYaml string + +func GetHoverFlavorYaml() string { + return hoverYaml +} + +func SetDefaultFlavorFile() { + hoverYaml = "hover.yaml" +} + +func SetHoverFlavor(flavor string) { + hoverYaml = "hover-" + flavor + ".yaml" + assertYamlFileExists(hoverYaml) +} + +func assertYamlFileExists(yamlFile string) { + _, err := os.Stat(yamlFile) + if os.IsNotExist(err) { + log.Warnf("Hover Yaml file \"%s\" not found.", yamlFile) + os.Exit(1) + } + if err != nil { + log.Errorf("Failed to stat hover.yaml: %v\n", err) + os.Exit(1) + } +} From 4889b3bc6ab9318b00828f991357e669024551b7 Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 13:50:18 +0700 Subject: [PATCH 2/9] set the flavor file --- cmd/build.go | 8 ++++++++ internal/config/config.go | 3 ++- internal/config/flavor.go | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/build.go b/cmd/build.go index e213869e..e1ea3b41 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -33,6 +33,7 @@ var ( buildOrRunCachePath string buildOrRunOpenGlVersion string buildOrRunEngineVersion string + buildOrRunHoverFlavor string buildOrRunDocker bool buildOrRunDebug bool buildOrRunRelease bool @@ -48,6 +49,7 @@ func initCompileFlags(cmd *cobra.Command) { cmd.PersistentFlags().StringVar(&buildOrRunCachePath, "cache-path", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll") cmd.PersistentFlags().StringVar(&buildOrRunOpenGlVersion, "opengl", config.BuildOpenGlVersionDefault, "The OpenGL version specified here is only relevant for external texture plugin (i.e. video_plugin).\nIf 'none' is provided, texture won't be supported. Note: the Flutter Engine still needs a OpenGL compatible context.") cmd.PersistentFlags().StringVar(&buildOrRunEngineVersion, "engine-version", config.BuildEngineDefault, "The flutter engine version to use.") + cmd.PersistentFlags().StringVar(&buildOrRunHoverFlavor, "flavor", "", "The flavor to use, defaults to 'hover.yaml'.") cmd.PersistentFlags().BoolVar(&buildOrRunDocker, "docker", false, "Execute the go build and packaging in a docker container. The Flutter build is always run locally") cmd.PersistentFlags().BoolVar(&buildOrRunDebug, "debug", false, "Build a debug version of the app.") cmd.PersistentFlags().BoolVar(&buildOrRunRelease, "release", false, "Build a release version of the app. Currently very experimental") @@ -261,6 +263,12 @@ func initBuildParameters(targetOS string, defaultBuildOrRunMode build.Mode) { os.Exit(1) } + if buildOrRunHoverFlavor == "" { + config.SetDefaultFlavorFile() + } else { + config.SetHoverFlavor(buildOrRunHoverFlavor) + } + if buildOrRunEngineVersion == config.BuildEngineDefault && config.GetConfig().Engine != "" { log.Warnf("changing the engine version can lead to undesirable behavior") buildOrRunEngineVersion = config.GetConfig().Engine diff --git a/internal/config/config.go b/internal/config/config.go index 56d5bd43..b4a25eee 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -73,7 +73,8 @@ var ( func GetConfig() Config { configLoadOnce.Do(func() { var err error - config, err = ReadConfigFile(filepath.Join(build.BuildPath, "hover.yaml")) + hoverYaml := GetHoverFlavorYaml() + config, err = ReadConfigFile(filepath.Join(build.BuildPath, hoverYaml)) if err != nil { if os.IsNotExist(errors.Cause(err)) { // TODO: Add a solution for the user. Perhaps we can let `hover diff --git a/internal/config/flavor.go b/internal/config/flavor.go index 654fcff0..f04b5ef1 100644 --- a/internal/config/flavor.go +++ b/internal/config/flavor.go @@ -7,19 +7,24 @@ import ( var hoverYaml string +// GetHoverFlavorYaml returns the Hover yaml file func GetHoverFlavorYaml() string { return hoverYaml } +// SetDefaultFlavorFile sets the default hover.yaml func SetDefaultFlavorFile() { hoverYaml = "hover.yaml" } +// SetHoverFlavor sets the user defined hover flavor. +// eg. hover-develop.yaml, hover-staging.yaml, etc. func SetHoverFlavor(flavor string) { hoverYaml = "hover-" + flavor + ".yaml" assertYamlFileExists(hoverYaml) } +// assertYamlFileExists checks to see if the user defined yaml file exists func assertYamlFileExists(yamlFile string) { _, err := os.Stat(yamlFile) if os.IsNotExist(err) { From 56e4c594579385a59273e6de72e5d19d28a83527 Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 16:01:02 +0700 Subject: [PATCH 3/9] check correct file path --- internal/config/flavor.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/config/flavor.go b/internal/config/flavor.go index f04b5ef1..b91f75c1 100644 --- a/internal/config/flavor.go +++ b/internal/config/flavor.go @@ -1,8 +1,10 @@ package config import ( + "github.com/go-flutter-desktop/hover/internal/build" "github.com/go-flutter-desktop/hover/internal/log" "os" + "path/filepath" ) var hoverYaml string @@ -26,7 +28,7 @@ func SetHoverFlavor(flavor string) { // assertYamlFileExists checks to see if the user defined yaml file exists func assertYamlFileExists(yamlFile string) { - _, err := os.Stat(yamlFile) + _, err := os.Stat(filepath.Join(build.BuildPath, yamlFile)) if os.IsNotExist(err) { log.Warnf("Hover Yaml file \"%s\" not found.", yamlFile) os.Exit(1) From 9502c326899692725dfd05202cebd0ecc82fe9ef Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 16:11:12 +0700 Subject: [PATCH 4/9] rename for clearity --- cmd/build.go | 2 +- internal/config/flavor.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/build.go b/cmd/build.go index e1ea3b41..b949bc66 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -264,7 +264,7 @@ func initBuildParameters(targetOS string, defaultBuildOrRunMode build.Mode) { } if buildOrRunHoverFlavor == "" { - config.SetDefaultFlavorFile() + config.SetDefaultHoverYamlFile() } else { config.SetHoverFlavor(buildOrRunHoverFlavor) } diff --git a/internal/config/flavor.go b/internal/config/flavor.go index b91f75c1..2c7e3bf0 100644 --- a/internal/config/flavor.go +++ b/internal/config/flavor.go @@ -15,7 +15,7 @@ func GetHoverFlavorYaml() string { } // SetDefaultFlavorFile sets the default hover.yaml -func SetDefaultFlavorFile() { +func SetDefaultHoverYamlFile() { hoverYaml = "hover.yaml" } From 59356b392ff44a897616c4d2a0981feec26c1d76 Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 16:19:43 +0700 Subject: [PATCH 5/9] add in common flag for docker --- cmd/build.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/build.go b/cmd/build.go index b949bc66..3a5b85ac 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -263,6 +263,7 @@ func initBuildParameters(targetOS string, defaultBuildOrRunMode build.Mode) { os.Exit(1) } + // hover.yaml file needs to be set before accessing config.GetConfig() if buildOrRunHoverFlavor == "" { config.SetDefaultHoverYamlFile() } else { @@ -334,6 +335,9 @@ func commonFlags() []string { if buildOrRunOpenGlVersion != config.BuildOpenGlVersionDefault { f = append(f, "--opengl", buildOrRunOpenGlVersion) } + if buildOrRunHoverFlavor != "" { + f = append(f, "--flavor", buildOrRunHoverFlavor) + } return f } From d8d321f42cabcdef3801ce9e2673e2bf7ed41f4c Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 16:41:15 +0700 Subject: [PATCH 6/9] add documentation --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index d1751788..7aa61c12 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,19 @@ To get a list of all available packaging formats run: hover build --help ``` +### Flavors + +Hover supports different application flavors via `--flavor MY_FLAVOR` command. +If you wish to create a new flavor for you application, +simply copy `go/hover.yaml` into `go/hover-MY_FLAVOR.yaml` and modify contents as needed. +If no flavor is specified, Hover will always default to `hover.yaml` + +``` +hover run --flavor develop || hover build --flavor develop +// hover-develop.yaml +``` + + ## Issues Please report issues at the [go-flutter issue tracker](https://github.com/go-flutter-desktop/go-flutter/issues/). From 416ab0fba9dc464f3a5be80222e5deaba3f71f0e Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 21:48:12 +0700 Subject: [PATCH 7/9] format file --- internal/config/flavor.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/config/flavor.go b/internal/config/flavor.go index 2c7e3bf0..82591f67 100644 --- a/internal/config/flavor.go +++ b/internal/config/flavor.go @@ -1,10 +1,11 @@ package config import ( - "github.com/go-flutter-desktop/hover/internal/build" - "github.com/go-flutter-desktop/hover/internal/log" "os" "path/filepath" + + "github.com/go-flutter-desktop/hover/internal/build" + "github.com/go-flutter-desktop/hover/internal/log" ) var hoverYaml string From d8c8fcb4a082e9e8243f889529c22db0bf68d369 Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 21:49:32 +0700 Subject: [PATCH 8/9] concat with Sprintf --- internal/config/flavor.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/config/flavor.go b/internal/config/flavor.go index 82591f67..71e529fb 100644 --- a/internal/config/flavor.go +++ b/internal/config/flavor.go @@ -1,6 +1,7 @@ package config import ( + "fmt" "os" "path/filepath" @@ -23,7 +24,7 @@ func SetDefaultHoverYamlFile() { // SetHoverFlavor sets the user defined hover flavor. // eg. hover-develop.yaml, hover-staging.yaml, etc. func SetHoverFlavor(flavor string) { - hoverYaml = "hover-" + flavor + ".yaml" + hoverYaml = fmt.Sprintf("hover-%s.yaml", flavor) assertYamlFileExists(hoverYaml) } From 9c6acfa2a154caa03a0b2edf2c5c9189b517be2d Mon Sep 17 00:00:00 2001 From: Edgar Date: Sat, 31 Oct 2020 21:50:27 +0700 Subject: [PATCH 9/9] update error message --- internal/config/flavor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/config/flavor.go b/internal/config/flavor.go index 71e529fb..05cf8db5 100644 --- a/internal/config/flavor.go +++ b/internal/config/flavor.go @@ -36,7 +36,7 @@ func assertYamlFileExists(yamlFile string) { os.Exit(1) } if err != nil { - log.Errorf("Failed to stat hover.yaml: %v\n", err) + log.Errorf("Failed to stat %s: %v\n", yamlFile, err) os.Exit(1) } }