Skip to content

Commit fdb3749

Browse files
committed
Merge branch 'master' into cleanup-packaging-variables
2 parents f5a3caf + b51a1d2 commit fdb3749

File tree

5 files changed

+70
-72
lines changed

5 files changed

+70
-72
lines changed

cmd/build.go

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@ var dotSlash = string([]byte{'.', filepath.Separator})
2828

2929
var (
3030
// common build flages (shared with `hover run`)
31-
buildTarget string
32-
buildGoFlutterBranch string
33-
buildCachePath string
34-
buildOpenGlVersion string
35-
buildEngineVersion string
36-
// TODO(GeertJohan): Separate the init code for the common build flags (run
37-
// and build) into a function that's used for both buildCmd and runCmd. Also
38-
// rename those to `compileFooBar`.
31+
buildOrRunFlutterTarget string
32+
buildOrRunGoFlutterBranch string
33+
buildOrRunCachePath string
34+
buildOrRunOpenGlVersion string
35+
buildOrRunEngineVersion string
36+
buildOrRunDocker bool
37+
)
38+
39+
func initCompileFlags(cmd *cobra.Command) {
40+
cmd.PersistentFlags().StringVarP(&buildOrRunFlutterTarget, "target", "t", config.BuildTargetDefault, "The main entry-point file of the application.")
41+
cmd.PersistentFlags().StringVarP(&buildOrRunGoFlutterBranch, "branch", "b", config.BuildBranchDefault, "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
42+
cmd.PersistentFlags().StringVar(&buildOrRunCachePath, "cache-path", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll")
43+
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.")
44+
cmd.PersistentFlags().StringVar(&buildOrRunEngineVersion, "engine-version", config.BuildEngineDefault, "The flutter engine version to use.")
45+
cmd.PersistentFlags().BoolVar(&buildOrRunDocker, "docker", false, "Execute the go build and packaging in a docker container. The Flutter build is always run locally")
46+
}
3947

48+
var (
4049
// `hover build`-only build flags
41-
buildDocker bool
4250
buildDebug bool
4351
buildVersionNumber string
4452
buildSkipEngineDownload bool
@@ -51,14 +59,10 @@ const clangBinName = "o32-clang"
5159
var engineCachePath string
5260

5361
func init() {
54-
buildCmd.PersistentFlags().StringVarP(&buildTarget, "target", "t", config.BuildTargetDefault, "The main entry-point file of the application.")
55-
buildCmd.PersistentFlags().StringVarP(&buildGoFlutterBranch, "branch", "b", config.BuildBranchDefault, "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
56-
buildCmd.PersistentFlags().StringVar(&buildEngineVersion, "engine-version", config.BuildEngineDefault, "The flutter engine version to use.")
57-
buildCmd.PersistentFlags().StringVar(&buildCachePath, "cache-path", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll")
58-
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.")
62+
initCompileFlags(buildCmd)
63+
5964
buildCmd.PersistentFlags().StringVar(&buildVersionNumber, "version-number", "", "Override the version number used in build and packaging. You may use it with $(git describe --tags)")
6065
buildCmd.PersistentFlags().BoolVar(&buildDebug, "debug", false, "Build a debug version of the app.")
61-
buildCmd.PersistentFlags().BoolVar(&buildDocker, "docker", false, "Execute the go build and packaging in a docker container. The Flutter build is always run locally.")
6266
buildCmd.PersistentFlags().BoolVar(&buildSkipEngineDownload, "skip-engine-download", false, "Skip donwloading the Flutter Engine and artifacts.")
6367
buildCmd.PersistentFlags().BoolVar(&buildSkipFlutterBuildBundle, "skip-flutter-build-bundle", false, "Skip the 'flutter build bundle' step.")
6468
buildCmd.AddCommand(buildLinuxCmd)
@@ -181,15 +185,15 @@ var buildWindowsMsiCmd = &cobra.Command{
181185
func subcommandBuild(targetOS string, packagingTask packaging.Task) {
182186
assertHoverInitialized()
183187
packagingTask.AssertInitialized()
184-
if !buildDocker {
188+
if !buildOrRunDocker {
185189
packagingTask.AssertSupported()
186190
}
187191

188192
if !buildSkipFlutterBuildBundle {
189193
cleanBuildOutputsDir(targetOS)
190194
buildFlutterBundle(targetOS)
191195
}
192-
if buildDocker {
196+
if buildOrRunDocker {
193197
var buildFlags []string
194198
buildFlags = append(buildFlags, commonFlags()...)
195199
buildFlags = append(buildFlags, "--skip-flutter-build-bundle")
@@ -211,18 +215,18 @@ func subcommandBuild(targetOS string, packagingTask packaging.Task) {
211215
// fallback values based on config or defaults for values that have not
212216
// explicitly been set through flags.
213217
func initBuildParameters(targetOS string) {
214-
if buildGoFlutterBranch == config.BuildBranchDefault && config.GetConfig().Branch != "" {
215-
buildGoFlutterBranch = config.GetConfig().Branch
218+
if buildOrRunGoFlutterBranch == config.BuildBranchDefault && config.GetConfig().Branch != "" {
219+
buildOrRunGoFlutterBranch = config.GetConfig().Branch
216220
}
217221

218-
if buildCachePath == "" {
222+
if buildOrRunCachePath == "" {
219223
log.Errorf("Missing cache path, cannot continue. Please see previous warning.")
220224
os.Exit(1)
221225
}
222226

223-
if buildEngineVersion == config.BuildEngineDefault && config.GetConfig().Engine != "" {
227+
if buildOrRunEngineVersion == config.BuildEngineDefault && config.GetConfig().Engine != "" {
224228
log.Warnf("changing the engine version can lead to undesirable behavior")
225-
buildEngineVersion = config.GetConfig().Engine
229+
buildOrRunEngineVersion = config.GetConfig().Engine
226230
}
227231

228232
// TODO: This override doesn't work properly when the config specifies a
@@ -231,32 +235,30 @@ func initBuildParameters(targetOS string) {
231235
//
232236
// The comment on (*FlagSet).Lookup(..).Changed isn't very clear, but we
233237
// could test how that behaves and switch to it.
234-
if buildOpenGlVersion == config.BuildOpenGlVersionDefault && config.GetConfig().OpenGL != "" {
235-
buildOpenGlVersion = config.GetConfig().OpenGL
238+
if buildOrRunOpenGlVersion == config.BuildOpenGlVersionDefault && config.GetConfig().OpenGL != "" {
239+
buildOrRunOpenGlVersion = config.GetConfig().OpenGL
236240
}
237241

238242
if buildVersionNumber == "" {
239243
buildVersionNumber = pubspec.GetPubSpec().GetVersion()
240244
}
241245

242-
// TODO(GeertJohan): This is complicated to read and can be simplified.
243-
if buildSkipEngineDownload {
244-
engineCachePath = enginecache.EngineCachePath(targetOS, buildCachePath)
245-
} else {
246-
engineCachePath = enginecache.ValidateOrUpdateEngineAtPath(targetOS, buildCachePath, buildEngineVersion)
246+
engineCachePath = enginecache.EngineCachePath(targetOS, buildOrRunCachePath)
247+
if !buildSkipEngineDownload {
248+
enginecache.ValidateOrUpdateEngine(targetOS, buildOrRunCachePath, buildOrRunEngineVersion)
247249
}
248250
}
249251

250252
func commonFlags() []string {
251253
f := []string{}
252-
if buildTarget != config.BuildTargetDefault {
253-
f = append(f, "--target", buildTarget)
254+
if buildOrRunFlutterTarget != config.BuildTargetDefault {
255+
f = append(f, "--target", buildOrRunFlutterTarget)
254256
}
255-
if buildGoFlutterBranch != config.BuildBranchDefault {
256-
f = append(f, "--branch", buildGoFlutterBranch)
257+
if buildOrRunGoFlutterBranch != config.BuildBranchDefault {
258+
f = append(f, "--branch", buildOrRunGoFlutterBranch)
257259
}
258-
if buildOpenGlVersion != config.BuildOpenGlVersionDefault {
259-
f = append(f, "--opengl", buildOpenGlVersion)
260+
if buildOrRunOpenGlVersion != config.BuildOpenGlVersionDefault {
261+
f = append(f, "--opengl", buildOrRunOpenGlVersion)
260262
}
261263
return f
262264
}
@@ -300,10 +302,10 @@ func cleanBuildOutputsDir(targetOS string) {
300302
}
301303

302304
func buildFlutterBundle(targetOS string) {
303-
if buildTarget == config.BuildTargetDefault && config.GetConfig().Target != "" {
304-
buildTarget = config.GetConfig().Target
305+
if buildOrRunFlutterTarget == config.BuildTargetDefault && config.GetConfig().Target != "" {
306+
buildOrRunFlutterTarget = config.GetConfig().Target
305307
}
306-
assertTargetFileExists(buildTarget)
308+
assertTargetFileExists(buildOrRunFlutterTarget)
307309

308310
runPluginGet, err := shouldRunPluginGet()
309311
if err != nil {
@@ -323,7 +325,7 @@ func buildFlutterBundle(targetOS string) {
323325
var flutterBuildBundleArgs = []string{
324326
"build", "bundle",
325327
"--asset-dir", filepath.Join(build.OutputDirectoryPath(targetOS), "flutter_assets"),
326-
"--target", buildTarget,
328+
"--target", buildOrRunFlutterTarget,
327329
}
328330
if buildDebug {
329331
flutterBuildBundleArgs = append(flutterBuildBundleArgs, "--track-widget-creation")
@@ -378,7 +380,7 @@ func buildGoBinary(targetOS string, vmArguments []string) {
378380
os.Exit(1)
379381
}
380382

381-
if buildGoFlutterBranch == "" {
383+
if buildOrRunGoFlutterBranch == "" {
382384
currentTag, err := versioncheck.CurrentGoFlutterTag(filepath.Join(wd, build.BuildPath))
383385
if err != nil {
384386
log.Errorf("%v", err)
@@ -395,7 +397,7 @@ func buildGoBinary(targetOS string, vmArguments []string) {
395397
log.Infof("Upgrading 'go-flutter' to the latest release")
396398
// no buildBranch provided and currentTag isn't a release,
397399
// force update. (same behaviour as previous version of hover).
398-
err = upgradeGoFlutter(targetOS, engineCachePath)
400+
err = upgradeGoFlutter(targetOS)
399401
if err != nil {
400402
// the upgrade can fail silently
401403
log.Warnf("Upgrade ignored, current 'go-flutter' version: %s", currentTag)
@@ -407,18 +409,18 @@ func buildGoBinary(targetOS string, vmArguments []string) {
407409
}
408410

409411
} else {
410-
log.Printf("Downloading 'go-flutter' %s", buildGoFlutterBranch)
412+
log.Printf("Downloading 'go-flutter' %s", buildOrRunGoFlutterBranch)
411413

412414
// when the buildBranch is set, fetch the go-flutter branch version.
413-
err = upgradeGoFlutter(targetOS, engineCachePath)
415+
err = upgradeGoFlutter(targetOS)
414416
if err != nil {
415417
os.Exit(1)
416418
}
417419
}
418420

419421
versioncheck.CheckForHoverUpdate(hoverVersion())
420422

421-
if buildOpenGlVersion == "none" {
423+
if buildOrRunOpenGlVersion == "none" {
422424
log.Warnf("The '--opengl=none' flag makes go-flutter incompatible with texture plugins!")
423425
}
424426

@@ -451,13 +453,16 @@ func buildGoBinary(targetOS string, vmArguments []string) {
451453

452454
func buildEnv(targetOS string, engineCachePath string) []string {
453455
var cgoLdflags string
456+
var cgoCflags string
454457

455458
outputDirPath := filepath.Join("build", "outputs", targetOS)
456459

457460
switch targetOS {
458461
case "darwin":
459462
cgoLdflags = fmt.Sprintf("-F%s -Wl,-rpath,@executable_path", engineCachePath)
460-
cgoLdflags = fmt.Sprintf("%s -F%s -L%s", cgoLdflags, outputDirPath, outputDirPath)
463+
cgoLdflags += fmt.Sprintf(" -F%s -L%s", outputDirPath, outputDirPath)
464+
cgoLdflags += " -mmacosx-version-min=10.10"
465+
cgoCflags = "-mmacosx-version-min=10.10"
461466
case "linux":
462467
cgoLdflags = fmt.Sprintf("-L%s -L%s", engineCachePath, outputDirPath)
463468
case "windows":
@@ -469,6 +474,7 @@ func buildEnv(targetOS string, engineCachePath string) []string {
469474
env := []string{
470475
"GO111MODULE=on",
471476
"CGO_LDFLAGS=" + cgoLdflags,
477+
"CGO_CFLAGS=" + cgoCflags,
472478
"GOOS=" + targetOS,
473479
"GOARCH=amd64",
474480
"CGO_ENABLED=1",
@@ -527,7 +533,7 @@ func buildCommand(targetOS string, vmArguments []string, outputBinaryPath string
527533
outputCommand := []string{
528534
"go",
529535
"build",
530-
"-tags=opengl" + buildOpenGlVersion,
536+
"-tags=opengl" + buildOrRunOpenGlVersion,
531537
"-o", outputBinaryPath,
532538
"-v",
533539
}

cmd/bumpversion.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
func init() {
19-
upgradeCmd.Flags().StringVarP(&buildCachePath, "cache-path", "", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
19+
upgradeCmd.Flags().StringVarP(&buildOrRunCachePath, "cache-path", "", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
2020
upgradeCmd.Flags().MarkHidden("branch")
2121
rootCmd.AddCommand(upgradeCmd)
2222
}
@@ -37,10 +37,12 @@ var upgradeCmd = &cobra.Command{
3737
}
3838

3939
func upgrade(targetOS string) (err error) {
40-
return upgradeGoFlutter(targetOS, enginecache.ValidateOrUpdateEngineAtPath(targetOS, buildCachePath, ""))
40+
enginecache.ValidateOrUpdateEngine(targetOS, buildOrRunCachePath, "")
41+
return upgradeGoFlutter(targetOS)
4142
}
4243

43-
func upgradeGoFlutter(targetOS string, engineCachePath string) (err error) {
44+
func upgradeGoFlutter(targetOS string) (err error) {
45+
engineCachePath := enginecache.EngineCachePath(targetOS, buildOrRunCachePath)
4446
wd, err := os.Getwd()
4547
if err != nil {
4648
log.Errorf("Failed to get working dir: %v", err)
@@ -60,11 +62,11 @@ func upgradeGoFlutter(targetOS string, engineCachePath string) (err error) {
6062
return
6163
}
6264

63-
if buildGoFlutterBranch == "" {
64-
buildGoFlutterBranch = "@latest"
65+
if buildOrRunGoFlutterBranch == "" {
66+
buildOrRunGoFlutterBranch = "@latest"
6567
}
6668

67-
cmdGoGetU := exec.Command(build.GoBin(), "get", "-u", "github.com/go-flutter-desktop/go-flutter"+buildGoFlutterBranch)
69+
cmdGoGetU := exec.Command(build.GoBin(), "get", "-u", "github.com/go-flutter-desktop/go-flutter"+buildOrRunGoFlutterBranch)
6870
cmdGoGetU.Dir = filepath.Join(wd, build.BuildPath)
6971
cmdGoGetU.Env = append(os.Environ(),
7072
"GOPROXY=direct", // github.com/golang/go/issues/32955 (allows '/' in branch name)
@@ -77,7 +79,7 @@ func upgradeGoFlutter(targetOS string, engineCachePath string) (err error) {
7779
err = cmdGoGetU.Run()
7880
// When cross-compiling the command fails, but that is not an error
7981
if err != nil {
80-
log.Errorf("Updating go-flutter to %s version failed: %v", buildGoFlutterBranch, err)
82+
log.Errorf("Updating go-flutter to %s version failed: %v", buildOrRunGoFlutterBranch, err)
8183
return
8284
}
8385

cmd/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func dockerHoverBuild(targetOS string, packagingTask packaging.Task, buildFlags
2020
var err error
2121
dockerBin := build.DockerBin()
2222

23-
hoverCacheDir := filepath.Join(buildCachePath, "hover")
23+
hoverCacheDir := filepath.Join(buildOrRunCachePath, "hover")
2424

2525
engineCacheDir := filepath.Join(hoverCacheDir, "engine")
2626
err = os.MkdirAll(engineCacheDir, 0755)

cmd/run.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/go-flutter-desktop/hover/cmd/packaging"
1616
"github.com/go-flutter-desktop/hover/internal/build"
1717
"github.com/go-flutter-desktop/hover/internal/config"
18-
"github.com/go-flutter-desktop/hover/internal/enginecache"
1918
"github.com/go-flutter-desktop/hover/internal/log"
2019
"github.com/go-flutter-desktop/hover/internal/pubspec"
2120
)
@@ -25,24 +24,15 @@ var (
2524
runInitialRoute string
2625
runOmitEmbedder bool
2726
runOmitFlutterBundle bool
28-
runDocker bool
2927
)
3028

3129
func init() {
32-
runCmd.Flags().StringVarP(&buildTarget, "target", "t", config.BuildTargetDefault, "The main entry-point file of the application.")
33-
runCmd.Flags().StringVarP(&buildGoFlutterBranch, "branch", "b", config.BuildBranchDefault, "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
34-
// TODO: The variable buildCachePath is set twice, once during the setup of
35-
// buildCmd, and once during the setup of runCmd. The last of the two will
36-
// override the value with it's default, which leads to strange problems.
37-
runCmd.Flags().StringVar(&buildCachePath, "cache-path", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
38-
runCmd.PersistentFlags().StringVar(&buildEngineVersion, "engine-version", "", "The flutter engine version to use.")
39-
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.")
30+
initCompileFlags(runCmd)
4031

4132
runCmd.Flags().StringVar(&runInitialRoute, "route", "", "Which route to load when running the app.")
4233
runCmd.Flags().StringVarP(&runObservatoryPort, "observatory-port", "", "50300", "The observatory port used to connect hover to VM services (hot-reload/debug/..)")
4334
runCmd.Flags().BoolVar(&runOmitFlutterBundle, "omit-flutter", false, "Don't (re)compile the current Flutter project, useful when only working with Golang code (plugin)")
4435
runCmd.Flags().BoolVar(&runOmitEmbedder, "omit-embedder", false, "Don't (re)compile 'go-flutter' source code, useful when only working with Dart code")
45-
runCmd.Flags().BoolVar(&runDocker, "docker", false, "Execute the go build in a docker container. The Flutter build is always run locally")
4636
rootCmd.AddCommand(runCmd)
4737
}
4838

@@ -76,7 +66,7 @@ var runCmd = &cobra.Command{
7666
log.Infof("Omiting build the embedder")
7767
} else {
7868
vmArguments := []string{"--observatory-port=" + runObservatoryPort, "--enable-service-port-fallback", "--disable-service-auth-codes"}
79-
if runDocker {
69+
if buildOrRunDocker {
8070
var buildFlags []string
8171
buildFlags = append(buildFlags, commonFlags()...)
8272
buildFlags = append(buildFlags, []string{
@@ -122,7 +112,7 @@ func runAndAttach(projectName string, targetOS string) {
122112
match := regexObservatory.FindStringSubmatch(text)
123113
if len(match) == 2 {
124114
log.Infof("Connecting hover to '%s' for hot reload", projectName)
125-
startHotReloadProcess(cmdFlutterAttach, buildTarget, match[1])
115+
startHotReloadProcess(cmdFlutterAttach, buildOrRunFlutterTarget, match[1])
126116
break
127117
}
128118
}

internal/enginecache/cache.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ func EngineCachePath(targetOS, cachePath string) string {
199199
return filepath.Join(cachePath, "hover", "engine", targetOS)
200200
}
201201

202-
// ValidateOrUpdateEngineAtPath validates the engine we have cached matches the
202+
// ValidateOrUpdateEngine validates the engine we have cached matches the
203203
// flutter version, or otherwise downloads a new engine. The engine cache
204204
// location is set by the the user.
205-
func ValidateOrUpdateEngineAtPath(targetOS, cachePath, requiredEngineVersion string) (engineCachePath string) {
206-
engineCachePath = EngineCachePath(targetOS, cachePath)
205+
func ValidateOrUpdateEngine(targetOS, cachePath, requiredEngineVersion string) {
206+
engineCachePath := EngineCachePath(targetOS, cachePath)
207207

208208
if strings.Contains(engineCachePath, " ") {
209209
log.Errorf("Cannot save the engine to '%s', engine cache is not compatible with path containing spaces.", cachePath)
@@ -227,7 +227,7 @@ func ValidateOrUpdateEngineAtPath(targetOS, cachePath, requiredEngineVersion str
227227
if cachedEngineVersion != "" {
228228
if cachedEngineVersion == requiredEngineVersion {
229229
log.Printf("Using engine from cache")
230-
return engineCachePath
230+
return
231231
}
232232

233233
// Engine is outdated, we remove the old engine and continue to download
@@ -356,5 +356,5 @@ func ValidateOrUpdateEngineAtPath(targetOS, cachePath, requiredEngineVersion str
356356
os.Exit(1)
357357
}
358358

359-
return engineCachePath
359+
return
360360
}

0 commit comments

Comments
 (0)