Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
12 changes: 12 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
buildOrRunCachePath string
buildOrRunOpenGlVersion string
buildOrRunEngineVersion string
buildOrRunHoverFlavor string
buildOrRunDocker bool
buildOrRunDebug bool
buildOrRunRelease bool
Expand All @@ -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")
Expand Down Expand Up @@ -261,6 +263,13 @@ 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 {
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
Expand Down Expand Up @@ -326,6 +335,9 @@ func commonFlags() []string {
if buildOrRunOpenGlVersion != config.BuildOpenGlVersionDefault {
f = append(f, "--opengl", buildOrRunOpenGlVersion)
}
if buildOrRunHoverFlavor != "" {
f = append(f, "--flavor", buildOrRunHoverFlavor)
}
return f
}

Expand Down
3 changes: 2 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions internal/config/flavor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package config

import (
"fmt"
"os"
"path/filepath"

"github.com/go-flutter-desktop/hover/internal/build"
"github.com/go-flutter-desktop/hover/internal/log"
)

var hoverYaml string

// GetHoverFlavorYaml returns the Hover yaml file
func GetHoverFlavorYaml() string {
return hoverYaml
}

// SetDefaultFlavorFile sets the default hover.yaml
func SetDefaultHoverYamlFile() {
hoverYaml = "hover.yaml"
}

// SetHoverFlavor sets the user defined hover flavor.
// eg. hover-develop.yaml, hover-staging.yaml, etc.
func SetHoverFlavor(flavor string) {
hoverYaml = fmt.Sprintf("hover-%s.yaml", flavor)
assertYamlFileExists(hoverYaml)
}

// assertYamlFileExists checks to see if the user defined yaml file exists
func assertYamlFileExists(yamlFile string) {
_, err := os.Stat(filepath.Join(build.BuildPath, 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 %s: %v\n", yamlFile, err)
os.Exit(1)
}
}