2017-03-11 00:54:09 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2018-12-21 00:26:22 +03:00
|
|
|
"os/exec"
|
2017-03-11 00:54:09 +03:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/therecipe/qt/internal/cmd"
|
|
|
|
"github.com/therecipe/qt/internal/cmd/deploy"
|
|
|
|
|
|
|
|
"github.com/therecipe/qt/internal/utils"
|
|
|
|
)
|
|
|
|
|
2017-03-16 22:18:32 +03:00
|
|
|
func main() {
|
2019-11-02 01:45:04 +03:00
|
|
|
var non_recursive bool
|
|
|
|
if os.Args[len(os.Args)-1] == "non_recursive" {
|
|
|
|
non_recursive = true
|
|
|
|
os.Args = os.Args[:len(os.Args)-1]
|
|
|
|
}
|
|
|
|
|
2017-03-11 00:54:09 +03:00
|
|
|
flag.Usage = func() {
|
|
|
|
println("Usage: qtdeploy [-docker] [mode] [target] [path/to/project]\n")
|
|
|
|
|
|
|
|
println("Flags:\n")
|
|
|
|
flag.PrintDefaults()
|
2018-07-23 23:18:06 +03:00
|
|
|
println()
|
2017-03-11 00:54:09 +03:00
|
|
|
|
|
|
|
println("Modes:\n")
|
2018-07-23 23:18:06 +03:00
|
|
|
for _, m := range []struct{ name, desc string }{
|
2017-03-11 00:54:09 +03:00
|
|
|
{"build", "compile and bundle"},
|
|
|
|
{"run", "run the binary"},
|
|
|
|
{"test", "build and run"},
|
|
|
|
{"help", "print help"},
|
2018-07-23 23:18:06 +03:00
|
|
|
} {
|
|
|
|
fmt.Printf(" %v%v%v\n", m.name, strings.Repeat(" ", 12-len(m.name)), m.desc)
|
2017-03-11 00:54:09 +03:00
|
|
|
}
|
2018-07-23 23:18:06 +03:00
|
|
|
println()
|
2017-03-11 00:54:09 +03:00
|
|
|
|
2017-03-16 22:18:32 +03:00
|
|
|
println("Targets:\n")
|
|
|
|
//TODO:
|
2018-07-23 23:18:06 +03:00
|
|
|
println()
|
2017-03-16 22:18:32 +03:00
|
|
|
|
2017-03-11 00:54:09 +03:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
var docker bool
|
|
|
|
flag.BoolVar(&docker, "docker", false, "run command inside docker container")
|
|
|
|
|
2017-07-12 00:33:08 +03:00
|
|
|
var vagrant bool
|
|
|
|
flag.BoolVar(&vagrant, "vagrant", false, "run command inside vagrant vm")
|
|
|
|
|
2017-03-11 00:54:09 +03:00
|
|
|
var ldFlags string
|
2017-03-16 22:18:32 +03:00
|
|
|
flag.StringVar(&ldFlags, "ldflags", "", "arguments to pass on each go tool link invocation")
|
|
|
|
|
|
|
|
var fast bool
|
|
|
|
flag.BoolVar(&fast, "fast", false, "use cached moc, minimal and dependencies (works for: windows, darwin, linux)")
|
2017-03-11 00:54:09 +03:00
|
|
|
|
2017-05-03 04:16:05 +03:00
|
|
|
var tags string
|
|
|
|
flag.StringVar(&tags, "tags", "", "a list of build tags to consider satisfied during the build")
|
|
|
|
|
2017-07-01 01:29:11 +03:00
|
|
|
var device string
|
|
|
|
flag.StringVar(&device, "device", "", "a device UUID to be used by the iOS simulator")
|
|
|
|
|
2018-04-07 22:05:41 +03:00
|
|
|
var comply bool
|
|
|
|
flag.BoolVar(&comply, "comply", false, "dump object code to make it easier to comply with LGPL obligations for proprietary developments")
|
|
|
|
|
2019-05-01 03:39:02 +03:00
|
|
|
var quickcompiler bool
|
|
|
|
flag.BoolVar(&quickcompiler, "quickcompiler", false, "use the quickcompiler")
|
|
|
|
|
2019-05-07 00:55:31 +03:00
|
|
|
var uic bool
|
|
|
|
flag.BoolVar(&uic, "uic", true, "use the uic")
|
|
|
|
|
2017-03-11 00:54:09 +03:00
|
|
|
if cmd.ParseFlags() {
|
|
|
|
flag.Usage()
|
|
|
|
}
|
|
|
|
|
|
|
|
mode := "test"
|
2017-03-16 22:18:32 +03:00
|
|
|
target := runtime.GOOS
|
2017-03-11 00:54:09 +03:00
|
|
|
path, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
utils.Log.WithError(err).Debug("failed to get cwd")
|
|
|
|
}
|
|
|
|
|
|
|
|
switch flag.NArg() {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
mode = flag.Arg(0)
|
|
|
|
case 2:
|
|
|
|
mode = flag.Arg(0)
|
|
|
|
target = flag.Arg(1)
|
|
|
|
case 3:
|
|
|
|
mode = flag.Arg(0)
|
|
|
|
target = flag.Arg(1)
|
|
|
|
path = flag.Arg(2)
|
|
|
|
default:
|
|
|
|
flag.Usage()
|
|
|
|
}
|
|
|
|
|
|
|
|
if mode == "help" {
|
|
|
|
flag.Usage()
|
|
|
|
}
|
|
|
|
|
2018-07-23 23:18:06 +03:00
|
|
|
var vagrant_system string
|
|
|
|
if target_splitted := strings.Split(target, "/"); vagrant && len(target_splitted) == 2 {
|
|
|
|
vagrant_system = target_splitted[0]
|
|
|
|
target = target_splitted[1]
|
2017-07-12 00:33:08 +03:00
|
|
|
}
|
|
|
|
|
2017-03-16 22:18:32 +03:00
|
|
|
if target == "desktop" {
|
|
|
|
target = runtime.GOOS
|
2018-08-18 17:55:15 +03:00
|
|
|
}
|
2019-04-07 01:31:32 +03:00
|
|
|
utils.CheckBuildTarget(target, docker)
|
2019-10-10 20:41:53 +03:00
|
|
|
cmd.InitEnv(target, docker)
|
2018-12-21 00:26:22 +03:00
|
|
|
|
|
|
|
if !filepath.IsAbs(path) {
|
|
|
|
oPath := path
|
|
|
|
path, err = filepath.Abs(path)
|
|
|
|
if err != nil || !utils.ExistsDir(path) {
|
|
|
|
utils.Log.WithError(err).WithField("path", path).Debug("can't resolve absolute path")
|
|
|
|
dirFunc := func() (string, error) {
|
2019-05-01 03:39:02 +03:00
|
|
|
out, err := utils.RunCmdOptionalError(utils.GoList("{{.Dir}}", oPath, "-find"), "get pkg dir")
|
2018-12-21 00:26:22 +03:00
|
|
|
return strings.TrimSpace(out), err
|
|
|
|
}
|
2019-03-22 22:48:57 +03:00
|
|
|
if dir, err := dirFunc(); err != nil || len(dir) == 0 {
|
2018-12-21 00:26:22 +03:00
|
|
|
utils.RunCmd(exec.Command("go", "get", "-d", "-v", oPath), "go get pkg")
|
|
|
|
path, _ = dirFunc()
|
|
|
|
} else {
|
|
|
|
path = dir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-02 01:45:04 +03:00
|
|
|
if utils.QT_DOCKER() && utils.UseGOMOD(path) && !non_recursive {
|
|
|
|
cmd.RestartWithPinnedVersion(path)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-05-07 00:55:31 +03:00
|
|
|
if !(target == runtime.GOOS || strings.HasPrefix(target, "js") || strings.HasPrefix(target, "wasm")) {
|
2018-07-23 23:18:06 +03:00
|
|
|
fast = false
|
2017-03-11 00:54:09 +03:00
|
|
|
}
|
2019-05-07 00:55:31 +03:00
|
|
|
if (docker || vagrant) && !(strings.HasPrefix(target, "js") || strings.HasPrefix(target, "wasm")) {
|
2018-11-18 06:08:14 +03:00
|
|
|
fast = false
|
|
|
|
}
|
2017-03-11 00:54:09 +03:00
|
|
|
|
2019-05-07 00:55:31 +03:00
|
|
|
deploy.Deploy(mode, target, path, docker, ldFlags, tags, fast, device, vagrant, vagrant_system, comply, uic, quickcompiler)
|
2017-03-11 00:54:09 +03:00
|
|
|
}
|