diff --git a/internal/deploy/deploy.go b/internal/deploy/deploy.go index dc0e42c4..892b7ab7 100755 --- a/internal/deploy/deploy.go +++ b/internal/deploy/deploy.go @@ -26,6 +26,7 @@ var ( buildMode, buildTarget string ending string buildMinimal bool + buildDocker bool ) func main() { @@ -35,13 +36,17 @@ func main() { switch buildMode { case "build", "test": { - moc() - qrc() - build() - predeploy() - deploy() - pastdeploy() - cleanup() + if buildDocker { + deployDocker() + } else { + moc() + qrc() + build() + predeploy() + deploy() + pastdeploy() + cleanup() + } } } @@ -93,7 +98,7 @@ func args() { buildMode = os.Args[1] buildTarget = os.Args[2] appPath = os.Args[3] - buildMinimal = true + buildDocker = true } } @@ -107,14 +112,48 @@ func args() { case "build", "run", "test": { switch buildTarget { - case "desktop", "android", "ios", "ios-simulator", "sailfish", "sailfish-emulator", "rpi1", "rpi2", "rpi3", "windows": + case "desktop", "android", "ios", "ios-simulator", "sailfish", "sailfish-emulator", "rpi1", "rpi2", "rpi3", "windows", "darwin", "linux": { + switch buildTarget { + case "windows": + { + if runtime.GOOS == "windows" && !buildDocker { + buildTarget = "desktop" + } else if runtime.GOOS == "linux" || buildDocker { + buildTarget = "windows" + } else { + fmt.Printf("%v is currently not supported as a deploy target on %v\n", buildTarget, runtime.GOOS) + os.Exit(1) + } + } + case "darwin": + { + if runtime.GOOS == "darwin" && !buildDocker { + buildTarget = "desktop" + } else { + fmt.Printf("%v is currently not supported as a deploy target on %v (not even with docker)", buildTarget, runtime.GOOS) + os.Exit(1) + } + } + + case "linux": + { + if runtime.GOOS == "linux" && !buildDocker { + buildTarget = "desktop" + } else if buildDocker { + buildTarget = "linux" + } else { + fmt.Printf("%v is currently not supported as a deploy target on %v\n", buildTarget, runtime.GOOS) + os.Exit(1) + } + } + } } default: { - fmt.Println("usage:", "qtdeploy", "[ build | run | test ]", "[ desktop | android | ios | ios-simulator | sailfish | sailfish-emulator | rpi1 | rpi2 | rpi3 | windows ]", fmt.Sprintf("[ %v ]", filepath.Join("path", "to", "project"))) + fmt.Println("usage:", "qtdeploy", "[ build | run | test ]", "[ desktop | android | ios | ios-simulator | sailfish | sailfish-emulator | rpi1 | rpi2 | rpi3 | windows ]", fmt.Sprintf("[ %v ]", filepath.Join("path", "to", "project")), "[ docker ]") os.Exit(1) } } @@ -122,7 +161,7 @@ func args() { default: { - fmt.Println("usage:", "qtdeploy", "[ build | run | test ]", "[ desktop | android | ios | ios-simulator | sailfish | sailfish-emulator | rpi1 | rpi2 | rpi3 | windows ]", fmt.Sprintf("[ %v ]", filepath.Join("path", "to", "project"))) + fmt.Println("usage:", "qtdeploy", "[ build | run | test ]", "[ desktop | android | ios | ios-simulator | sailfish | sailfish-emulator | rpi1 | rpi2 | rpi3 | windows ]", fmt.Sprintf("[ %v ]", filepath.Join("path", "to", "project")), "[ docker ]") os.Exit(1) } } @@ -1007,6 +1046,68 @@ func cleanup() { utils.RemoveAll(filepath.Join(appPath, "cleanup.json")) } +func deployDocker() { + + var dockerImage string + + switch buildTarget { + case "desktop": + { + switch runtime.GOOS { + case "windows": + { + dockerImage = "base_windows" + } + + case "darwin": + { + fmt.Printf("%v is currently not supported as a deploy target by docker", runtime.GOOS) + os.Exit(1) + } + + case "linux": + { + dockerImage = "base" + } + } + } + + case "windows": + { + dockerImage = "base_windows" + } + + case "darwin": + { + fmt.Printf("%v is currently not supported as a deploy target by docker", runtime.GOOS) + os.Exit(1) + } + + case "linux": + { + dockerImage = "base" + } + + case "android": + { + dockerImage = "base_android" + } + + default: + { + fmt.Printf("%v is currently not supported as a deploy target by docker", runtime.GOOS) + os.Exit(1) + } + } + + if !strings.Contains(appPath, utils.MustGoPath()) { + fmt.Println("Project needs to be inside GOPATH", appPath, utils.MustGoPath()) + os.Exit(1) + } + + utils.RunCmd(exec.Command("docker", "run", "--rm", "-v", fmt.Sprintf("%v:/media/sf_GOPATH", utils.MustGoPath()), "-i", fmt.Sprintf("therecipe/qt:%v", dockerImage), "qtdeploy", "build", buildTarget, strings.Replace(strings.Replace(appPath, utils.MustGoPath(), "/media/sf_GOPATH", -1), "\\", "/", -1)), "deployDocker") +} + func run() { switch buildTarget { diff --git a/internal/docker/Dockerfile b/internal/docker/Dockerfile index 3c4a192f..6ce07f7d 100644 --- a/internal/docker/Dockerfile +++ b/internal/docker/Dockerfile @@ -28,8 +28,8 @@ ENV GOPATH $HOME/work RUN go get -d github.com/therecipe/qt RUN go get -d golang.org/x/crypto/ssh RUN go get -d github.com/emirpasic/gods/lists/arraylist -RUN go build -o /usr/local/bin/qtdeploy $GOPATH/src/github.com/therecipe/qt/internal/deploy/deploy.go -RUN go build -o /usr/local/bin/qtmoc $GOPATH/src/github.com/therecipe/qt/internal/moc/moc.go +RUN go build -o $HOME/work/bin/qtdeploy $GOPATH/src/github.com/therecipe/qt/internal/deploy/deploy.go && ln -s $HOME/work/bin/qtdeploy /usr/local/bin/qtdeploy +RUN go build -o $HOME/work/bin/qtmoc $GOPATH/src/github.com/therecipe/qt/internal/moc/moc.go && ln -s $HOME/work/bin/qtmoc /usr/local/bin/qtmoc ENV QT_DIR /opt/Qt5.7.0