Skip to content
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

enable users to prepare the flutter engine within docker image without building first. #214

Merged
merged 13 commits into from
Jun 20, 2021
Merged
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,7 @@ RUN go install -v ./... 2>&1

COPY docker/hover-safe.sh /usr/local/bin/hover-safe.sh

# Prepare engines
ENV CGO_LDFLAGS="-L~/.cache/hover/engine/linux-release -L~/.cache/hover/engine/linux-debug_unopt -L~/.cache/hover/engine/windows-release -L~/.cache/hover/engine/windows-debug_unopt -L~/.cache/hover/engine/darwin-debug_unopt"
cosban marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /app
99 changes: 99 additions & 0 deletions cmd/prepare-engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package cmd

import (
"os"
"runtime"

"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/log"
"github.com/spf13/cobra"
)

var (
prepareCachePath string
prepareEngineVersion string
prepareReleaseMode bool
prepareDebugMode bool
prepareProfileMode bool
prepareBuildModes []build.Mode
)

func init() {
prepareEngineCmd.PersistentFlags().StringVar(&prepareCachePath, "cache-path", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll")
prepareEngineCmd.PersistentFlags().StringVar(&prepareEngineVersion, "engine-version", config.BuildEngineDefault, "The flutter engine version to use.")
prepareEngineCmd.PersistentFlags().BoolVar(&prepareDebugMode, "debug", false, "Prepare the flutter engine for debug mode")
prepareEngineCmd.PersistentFlags().BoolVar(&prepareReleaseMode, "release", false, "Prepare the flutter engine for release mode.")
prepareEngineCmd.PersistentFlags().BoolVar(&prepareProfileMode, "profile", false, "Prepare the flutter engine for profile mode.")
prepareEngineCmd.AddCommand(prepareEngineLinuxCmd)
prepareEngineCmd.AddCommand(prepareEngineDarwinCmd)
prepareEngineCmd.AddCommand(prepareEngineWindowsCmd)
rootCmd.AddCommand(prepareEngineCmd)
}

var prepareEngineCmd = &cobra.Command{
Use: "prepare-engine",
Short: "Validates or updates the flutter engine on this machine for a given platform",
}

var prepareEngineLinuxCmd = &cobra.Command{
Use: "linux",
Short: "Validates or updates the flutter engine on this machine for a given platform",
Run: func(cmd *cobra.Command, args []string) {
initPrepareEngineParameters("linux")
subcommandPrepare("linux")
},
}

var prepareEngineDarwinCmd = &cobra.Command{
Use: "darwin",
Short: "Validates or updates the flutter engine on this machine for a given platform",
Run: func(cmd *cobra.Command, args []string) {
initPrepareEngineParameters("darwin")
subcommandPrepare("darwin")
},
}

var prepareEngineWindowsCmd = &cobra.Command{
Use: "windows",
Short: "Validates or updates the flutter engine on this machine for a given platform",
Run: func(cmd *cobra.Command, args []string) {
initPrepareEngineParameters("windows")
subcommandPrepare("windows")
},
}

func initPrepareEngineParameters(targetOS string) {
validatePrepareEngineParameters(targetOS)
if prepareDebugMode {
prepareBuildModes = append(prepareBuildModes, build.DebugMode)
}
if prepareReleaseMode {
prepareBuildModes = append(prepareBuildModes, build.ReleaseMode)
}
cosban marked this conversation as resolved.
Show resolved Hide resolved
if prepareProfileMode {
prepareBuildModes = append(prepareBuildModes, build.ProfileMode)
}
}

func validatePrepareEngineParameters(targetOS string) {
if !prepareDebugMode && !prepareReleaseMode && !prepareProfileMode {
log.Errorf("No target mode set. Please select exactly one from: debug, profile, release.")
os.Exit(1)
}
if (prepareDebugMode && prepareReleaseMode) || (prepareDebugMode && prepareProfileMode) || (prepareReleaseMode && prepareProfileMode) {
cosban marked this conversation as resolved.
Show resolved Hide resolved
log.Errorf("Multiple target modes set. Please select exactly one from: debug, profile, release.")
os.Exit(1)
}
if targetOS == "darwin" && runtime.GOOS != targetOS && prepareReleaseMode {
cosban marked this conversation as resolved.
Show resolved Hide resolved
log.Errorf("It is not possible to prepare the flutter engine in release mode for darwin using docker")
os.Exit(1)
}
}

func subcommandPrepare(targetOS string) {
for _, mode := range prepareBuildModes {
enginecache.ValidateOrUpdateEngine(targetOS, prepareCachePath, prepareEngineVersion, mode)
}
}
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down Expand Up @@ -151,8 +150,6 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/otiai10/copy v1.5.1 h1:a/cs2E1/1V0az8K5nblbl+ymEa4E11AfaOLMar8V34w=
github.com/otiai10/copy v1.5.1/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ=
github.com/otiai10/copy v1.6.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
Expand Down Expand Up @@ -201,7 +198,6 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
Expand Down Expand Up @@ -319,7 +315,6 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
Expand Down