Skip to content

Add config file #51

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

Merged
Merged
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
8 changes: 8 additions & 0 deletions assets/app/hover.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
target: lib/main_desktop.dart
# Change to "@latest" to download the latest go-flutter version on every build:
branch: ""
# https://github.com/go-flutter-desktop/go-flutter/issues/184:
# cache-path: "/home/YOURUSERNAME/.cache/"
# Uncomment this line if you have trouble with your OpenGL driver (https://github.com/go-flutter-desktop/go-flutter/issues/272):
# opengl: "none"
docker: false
24 changes: 20 additions & 4 deletions cmd/build.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import (
"github.com/go-flutter-desktop/hover/cmd/packaging"
"github.com/go-flutter-desktop/hover/internal/androidmanifest"
"github.com/go-flutter-desktop/hover/internal/build"
"github.com/go-flutter-desktop/hover/internal/config"
"github.com/go-flutter-desktop/hover/internal/enginecache"
"github.com/go-flutter-desktop/hover/internal/fileutils"
"github.com/go-flutter-desktop/hover/internal/log"
@@ -44,11 +45,11 @@ var crossCompile = false
var engineCachePath string

func init() {
buildCmd.PersistentFlags().StringVarP(&buildTarget, "target", "t", "lib/main_desktop.dart", "The main entry-point file of the application.")
buildCmd.PersistentFlags().StringVarP(&buildBranch, "branch", "b", "", "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
buildCmd.PersistentFlags().StringVarP(&buildTarget, "target", "t", config.BuildTargetDefault, "The main entry-point file of the application.")
buildCmd.PersistentFlags().StringVarP(&buildBranch, "branch", "b", config.BuildBranchDefault, "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
buildCmd.PersistentFlags().BoolVar(&buildDebug, "debug", false, "Build a debug version of the app.")
buildCmd.PersistentFlags().StringVarP(&buildCachePath, "cache-path", "", "", "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
buildCmd.PersistentFlags().StringVar(&buildOpenGlVersion, "opengl", "3.3", "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.")
buildCmd.PersistentFlags().StringVarP(&buildCachePath, "cache-path", "", config.BuildCachePathDefault, "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
buildCmd.PersistentFlags().StringVar(&buildOpenGlVersion, "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.")
buildCmd.PersistentFlags().BoolVar(&buildDocker, "docker", false, "Compile in Docker container only. No need to install go")
buildCmd.AddCommand(buildLinuxCmd)
buildCmd.AddCommand(buildLinuxSnapCmd)
@@ -304,6 +305,21 @@ func buildInDocker(targetOS string, vmArguments []string) {
}

func buildNormal(targetOS string, vmArguments []string) {
if buildTarget == config.BuildTargetDefault && config.GetConfig().Target != "" {
buildTarget = config.GetConfig().Target
}
if buildBranch == config.BuildBranchDefault && config.GetConfig().Branch != "" {
buildBranch = config.GetConfig().Branch
}
if buildCachePath == config.BuildCachePathDefault && config.GetConfig().CachePath != "" {
buildCachePath = config.GetConfig().CachePath
}
if buildOpenGlVersion == config.BuildOpenGlVersionDefault && config.GetConfig().OpenGL != "" {
buildOpenGlVersion = config.GetConfig().OpenGL
}
if !buildDocker && config.GetConfig().Docker {
buildDocker = config.GetConfig().Docker
}
checkForMainDesktop()
crossCompile = targetOS != runtime.GOOS
buildDocker = crossCompile || buildDocker
1 change: 1 addition & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ var initCmd = &cobra.Command{
fileutils.CopyAsset("app/options.go", filepath.Join(desktopCmdPath, "options.go"), fileutils.AssetsBox)
fileutils.CopyAsset("app/icon.png", filepath.Join(desktopAssetsPath, "icon.png"), fileutils.AssetsBox)
fileutils.CopyAsset("app/gitignore", filepath.Join(build.BuildPath, ".gitignore"), fileutils.AssetsBox)
fileutils.CopyAsset("app/hover.yaml", filepath.Join(build.BuildPath, "hover.yaml"), fileutils.AssetsBox)

initializeGoModule(projectPath)
log.Printf("Available plugin for this project:")
9 changes: 5 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package cmd
import (
"bufio"
"fmt"
"github.com/go-flutter-desktop/hover/internal/config"
"io"
"os"
"os/exec"
@@ -20,10 +21,10 @@ import (
var runObservatoryPort string

func init() {
runCmd.Flags().StringVarP(&buildTarget, "target", "t", "lib/main_desktop.dart", "The main entry-point file of the application.")
runCmd.Flags().StringVarP(&buildBranch, "branch", "b", "", "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
runCmd.Flags().StringVarP(&buildCachePath, "cache-path", "", "", "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
runCmd.Flags().StringVar(&buildOpenGlVersion, "opengl", "3.3", "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.")
runCmd.Flags().StringVarP(&buildTarget, "target", "t", config.BuildTargetDefault, "The main entry-point file of the application.")
runCmd.Flags().StringVarP(&buildBranch, "branch", "b", config.BuildBranchDefault, "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
runCmd.Flags().StringVarP(&buildCachePath, "cache-path", "", config.BuildCachePathDefault, "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
runCmd.Flags().StringVar(&buildOpenGlVersion, "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.")
runCmd.Flags().StringVarP(&runObservatoryPort, "observatory-port", "", "50300", "The observatory port used to connect hover to VM services (hot-reload/debug/..)")
runCmd.Flags().BoolVar(&buildOmitEmbedder, "omit-embedder", false, "Don't (re)compile 'go-flutter' source code, useful when only working with Dart code")
runCmd.Flags().BoolVar(&buildOmitFlutterBundle, "omit-flutter", false, "Don't (re)compile the current Flutter project, useful when only working with Golang code (plugin)")
61 changes: 61 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package config

import (
"os"
"path/filepath"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"

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

const BuildTargetDefault = "lib/main_desktop.dart"
const BuildBranchDefault = ""
const BuildCachePathDefault = ""
const BuildOpenGlVersionDefault = "3.3"

// Config contains the parsed contents of hover.yaml
type Config struct {
loaded bool
Target string
Branch string
CachePath string `yaml:"cache-path"`
OpenGL string
Docker bool
}

var config = Config{}

// GetConfig returns the working directory hover.yaml as a Config
func GetConfig() Config {
if !config.loaded {
c, err := ReadConfigFile(filepath.Join(build.BuildPath, "hover.yaml"))
if err != nil {
return config
}
config = *c
config.loaded = true
}
return config
}

// ReadConfigFile reads a .yaml file at a path and return a correspond
// Config struct
func ReadConfigFile(configPath string) (*Config, error) {
file, err := os.Open(configPath)
if err != nil {
if os.IsNotExist(err) {
return nil, errors.Wrap(err, "Error: No hover.yaml file found")
}
return nil, errors.Wrap(err, "Failed to open hover.yaml")
}
defer file.Close()

var config Config
err = yaml.NewDecoder(file).Decode(&config)
if err != nil {
return nil, errors.Wrap(err, "Failed to decode hover.yaml")
}
return &config, nil
}