forked from therecipe/qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
136 lines (112 loc) · 3.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package main
import (
"flag"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"github.com/ilius/qt/internal/cmd"
"github.com/ilius/qt/internal/cmd/rcc"
"github.com/ilius/qt/internal/utils"
)
func main() {
var non_recursive bool
if os.Args[len(os.Args)-1] == "non_recursive" {
non_recursive = true
os.Args = os.Args[:len(os.Args)-1]
}
flag.Usage = func() {
println("Usage: qtrcc [-docker] [target] [path/to/project]\n")
println("Flags:\n")
flag.PrintDefaults()
println()
println("Targets:\n")
//TODO:
println()
os.Exit(0)
}
var docker bool
flag.BoolVar(&docker, "docker", false, "run command inside docker container")
var vagrant bool
flag.BoolVar(&vagrant, "vagrant", false, "run command inside vagrant vm")
var output string
flag.StringVar(&output, "o", os.Getenv("QTRCC_OUTPUT_DIR"), "specify an alternative output dir")
var tags string
flag.StringVar(&tags, "tags", "", "a list of build tags to consider satisfied during the build")
var quickcompiler bool
flag.BoolVar(&quickcompiler, "quickcompiler", false, "use the quickcompiler")
var uic bool
flag.BoolVar(&uic, "uic", true, "use the uic")
if cmd.ParseFlags() {
flag.Usage()
}
target := runtime.GOOS
path, err := os.Getwd()
if err != nil {
utils.Log.WithError(err).Debug("failed to get cwd")
}
switch flag.NArg() {
case 0:
case 1:
target = flag.Arg(0)
case 2:
target = flag.Arg(0)
path = flag.Arg(1)
default:
flag.Usage()
}
var vagrant_system string
if target_splitted := strings.Split(target, "/"); vagrant && len(target_splitted) == 2 {
vagrant_system = target_splitted[0]
target = target_splitted[1]
}
if target == "desktop" {
target = runtime.GOOS
}
utils.CheckBuildTarget(target, docker)
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) {
out, err := utils.RunCmdOptionalError(utils.GoList("{{.Dir}}", oPath, "-find"), "get pkg dir")
return strings.TrimSpace(out), err
}
if dir, err := dirFunc(); err != nil || len(dir) == 0 {
utils.RunCmd(exec.Command("go", "get", "-d", "-v", oPath), "go get pkg")
path, _ = dirFunc()
} else {
path = dir
}
}
}
cmd.InitEnv(target, docker, path)
if utils.QT_DOCKER() && utils.UseGOMOD(path) && !non_recursive {
if cmd.RestartWithPinnedVersion(path) {
return
}
}
if output != "" && !filepath.IsAbs(output) {
output, err = filepath.Abs(output)
if err != nil {
utils.Log.WithError(err).WithField("output", output).Fatal("can't resolve absolute path")
}
}
dockerArgs := []string{"qtrcc", "-debug"}
if !uic {
dockerArgs = append(dockerArgs, "-uic=false")
}
if quickcompiler {
dockerArgs = append(dockerArgs, "-quickcompiler")
}
switch {
case docker:
cmd.Docker(dockerArgs, target, path, false)
case vagrant:
cmd.Vagrant(dockerArgs, target, path, false, vagrant_system)
default:
rcc.Rcc(path, target, tags, output, uic, quickcompiler, false, false)
}
}