Skip to content

Commit 6f291d4

Browse files
committed
Use buildInfo to select a docker container image with the same version as the curently running hover
1 parent fc13a7f commit 6f291d4

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

cmd/docker.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ func dockerHoverBuild(targetOS string, packagingTask packaging.Task, buildFlags
8686
// intended to be abused and may disappear at any time.
8787
dockerArgs = append(dockerArgs, "--env", "HOVER_IN_DOCKER_BUILD_VMARGS="+strings.Join(vmArguments, ","))
8888
}
89-
// TODO: Use hover container of version of the current running hover.
90-
// Use debug package to obtain Module info which contains the version.
91-
dockerImage := "goflutter/hover:latest"
89+
90+
version := hoverVersion()
91+
if version == "(devel)" {
92+
version = "latest"
93+
}
94+
dockerImage := "goflutter/hover:" + version
9295
dockerArgs = append(dockerArgs, dockerImage)
9396
targetOSAndPackaging := targetOS
9497
if packName := packagingTask.Name(); packName != "" {

cmd/doctor.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ var doctorCmd = &cobra.Command{
3535
Run: func(cmd *cobra.Command, args []string) {
3636
assertInFlutterProject()
3737

38-
log.Infof("Running on %s", runtime.GOOS)
38+
version := hoverVersion()
39+
log.Infof("Hover version %s running on %s", version, runtime.GOOS)
3940

4041
log.Infof("Sharing flutter version")
41-
cmdFlutterDoctor := exec.Command(build.FlutterBin(), "--version")
42-
cmdFlutterDoctor.Stderr = os.Stderr
43-
cmdFlutterDoctor.Stdout = os.Stdout
44-
err := cmdFlutterDoctor.Run()
42+
cmdFlutterVersion := exec.Command(build.FlutterBin(), "--version")
43+
cmdFlutterVersion.Stderr = os.Stderr
44+
cmdFlutterVersion.Stdout = os.Stdout
45+
err := cmdFlutterVersion.Run()
4546
if err != nil {
46-
log.Errorf("Flutter doctor failed: %v", err)
47+
log.Errorf("Flutter --version failed: %v", err)
4748
}
4849

4950
engineCommitHash := flutterversion.FlutterRequiredEngineVersion()

cmd/version.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"runtime/debug"
7+
"sync"
8+
9+
"github.com/go-flutter-desktop/hover/internal/log"
10+
"github.com/pkg/errors"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func init() {
15+
rootCmd.AddCommand(versionCmd)
16+
}
17+
18+
var versionCmd = &cobra.Command{
19+
Use: "version",
20+
Short: "Print Hover version information",
21+
Args: func(cmd *cobra.Command, args []string) error {
22+
if len(args) > 0 {
23+
return errors.New("No arguments allowed")
24+
}
25+
return nil
26+
},
27+
Run: func(cmd *cobra.Command, args []string) {
28+
version := hoverVersion()
29+
fmt.Printf("Hover %s\n", version)
30+
},
31+
}
32+
33+
var (
34+
hoverVersionValue string
35+
hoverVersionOnce sync.Once
36+
)
37+
38+
func hoverVersion() string {
39+
hoverVersionOnce.Do(func() {
40+
buildInfo, ok := debug.ReadBuildInfo()
41+
if !ok {
42+
log.Errorf("Cannot obtain version information from hover build. To resolve this, please go-get hover using Go 1.13 or newer.")
43+
os.Exit(1)
44+
}
45+
hoverVersionValue = buildInfo.Main.Version
46+
})
47+
return hoverVersionValue
48+
}

0 commit comments

Comments
 (0)