Skip to content

Commit 050cd95

Browse files
author
jld3103
authored
Merge pull request #174 from edTheGuy00/master
Initial Support for flavors
2 parents ebb585f + 9c6acfa commit 050cd95

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,19 @@ To get a list of all available packaging formats run:
124124
hover build --help
125125
```
126126

127+
### Flavors
128+
129+
Hover supports different application flavors via `--flavor MY_FLAVOR` command.
130+
If you wish to create a new flavor for you application,
131+
simply copy `go/hover.yaml` into `go/hover-MY_FLAVOR.yaml` and modify contents as needed.
132+
If no flavor is specified, Hover will always default to `hover.yaml`
133+
134+
```
135+
hover run --flavor develop || hover build --flavor develop
136+
// hover-develop.yaml
137+
```
138+
139+
127140
## Issues
128141

129142
Please report issues at the [go-flutter issue tracker](https://github.com/go-flutter-desktop/go-flutter/issues/).

cmd/build.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
buildOrRunCachePath string
3434
buildOrRunOpenGlVersion string
3535
buildOrRunEngineVersion string
36+
buildOrRunHoverFlavor string
3637
buildOrRunDocker bool
3738
buildOrRunDebug bool
3839
buildOrRunRelease bool
@@ -48,6 +49,7 @@ func initCompileFlags(cmd *cobra.Command) {
4849
cmd.PersistentFlags().StringVar(&buildOrRunCachePath, "cache-path", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll")
4950
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.")
5051
cmd.PersistentFlags().StringVar(&buildOrRunEngineVersion, "engine-version", config.BuildEngineDefault, "The flutter engine version to use.")
52+
cmd.PersistentFlags().StringVar(&buildOrRunHoverFlavor, "flavor", "", "The flavor to use, defaults to 'hover.yaml'.")
5153
cmd.PersistentFlags().BoolVar(&buildOrRunDocker, "docker", false, "Execute the go build and packaging in a docker container. The Flutter build is always run locally")
5254
cmd.PersistentFlags().BoolVar(&buildOrRunDebug, "debug", false, "Build a debug version of the app.")
5355
cmd.PersistentFlags().BoolVar(&buildOrRunRelease, "release", false, "Build a release version of the app. Currently very experimental")
@@ -261,6 +263,13 @@ func initBuildParameters(targetOS string, defaultBuildOrRunMode build.Mode) {
261263
os.Exit(1)
262264
}
263265

266+
// hover.yaml file needs to be set before accessing config.GetConfig()
267+
if buildOrRunHoverFlavor == "" {
268+
config.SetDefaultHoverYamlFile()
269+
} else {
270+
config.SetHoverFlavor(buildOrRunHoverFlavor)
271+
}
272+
264273
if buildOrRunEngineVersion == config.BuildEngineDefault && config.GetConfig().Engine != "" {
265274
log.Warnf("changing the engine version can lead to undesirable behavior")
266275
buildOrRunEngineVersion = config.GetConfig().Engine
@@ -326,6 +335,9 @@ func commonFlags() []string {
326335
if buildOrRunOpenGlVersion != config.BuildOpenGlVersionDefault {
327336
f = append(f, "--opengl", buildOrRunOpenGlVersion)
328337
}
338+
if buildOrRunHoverFlavor != "" {
339+
f = append(f, "--flavor", buildOrRunHoverFlavor)
340+
}
329341
return f
330342
}
331343

internal/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ var (
7373
func GetConfig() Config {
7474
configLoadOnce.Do(func() {
7575
var err error
76-
config, err = ReadConfigFile(filepath.Join(build.BuildPath, "hover.yaml"))
76+
hoverYaml := GetHoverFlavorYaml()
77+
config, err = ReadConfigFile(filepath.Join(build.BuildPath, hoverYaml))
7778
if err != nil {
7879
if os.IsNotExist(errors.Cause(err)) {
7980
// TODO: Add a solution for the user. Perhaps we can let `hover

internal/config/flavor.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package config
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/go-flutter-desktop/hover/internal/build"
9+
"github.com/go-flutter-desktop/hover/internal/log"
10+
)
11+
12+
var hoverYaml string
13+
14+
// GetHoverFlavorYaml returns the Hover yaml file
15+
func GetHoverFlavorYaml() string {
16+
return hoverYaml
17+
}
18+
19+
// SetDefaultFlavorFile sets the default hover.yaml
20+
func SetDefaultHoverYamlFile() {
21+
hoverYaml = "hover.yaml"
22+
}
23+
24+
// SetHoverFlavor sets the user defined hover flavor.
25+
// eg. hover-develop.yaml, hover-staging.yaml, etc.
26+
func SetHoverFlavor(flavor string) {
27+
hoverYaml = fmt.Sprintf("hover-%s.yaml", flavor)
28+
assertYamlFileExists(hoverYaml)
29+
}
30+
31+
// assertYamlFileExists checks to see if the user defined yaml file exists
32+
func assertYamlFileExists(yamlFile string) {
33+
_, err := os.Stat(filepath.Join(build.BuildPath, yamlFile))
34+
if os.IsNotExist(err) {
35+
log.Warnf("Hover Yaml file \"%s\" not found.", yamlFile)
36+
os.Exit(1)
37+
}
38+
if err != nil {
39+
log.Errorf("Failed to stat %s: %v\n", yamlFile, err)
40+
os.Exit(1)
41+
}
42+
}

0 commit comments

Comments
 (0)