forked from therecipe/qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.go
76 lines (63 loc) · 2.48 KB
/
generate.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
package setup
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"github.com/akiyosi/qt/internal/binding/parser"
"github.com/akiyosi/qt/internal/binding/templater"
"github.com/akiyosi/qt/internal/cmd"
"github.com/akiyosi/qt/internal/cmd/moc"
"github.com/akiyosi/qt/internal/utils"
)
func Generate(target string, docker, vagrant bool) {
utils.Log.Infof("running: 'qtsetup generate %v' [docker=%v] [vagrant=%v]", target, docker, vagrant)
if docker {
cmd.Docker([]string{"/home/user/work/bin/qtsetup", "-debug", "generate"}, "linux", "", true)
return
}
parser.LoadModules(target)
mode := "full"
switch {
case target == "js", target == "wasm":
case target != runtime.GOOS:
mode = "cgo"
case utils.QT_STUB():
mode = "stub"
}
if target == "windows" && runtime.GOOS == target && os.Getenv("QT_DEBUG_CONSOLE") != "false" {
os.Setenv("QT_DEBUG_CONSOLE", "true")
}
for _, module := range parser.GetLibs() {
if !parser.ShouldBuildForTarget(module, target) {
utils.Log.Debugf("skipping generation of %v for %v", module, target)
continue
}
var license string
switch module {
case "Charts", "DataVisualization", "VirtualKeyboard":
license = strings.Repeat(" ", 21-len(module)) + "[GPLv3]"
}
utils.Log.Infof("generating %v qt/%v%v", mode, strings.ToLower(module), license)
if target == runtime.GOOS || utils.QT_FAT() || (mode == "full" && (target == "js" || target == "wasm")) { //TODO: REVIEW
templater.GenModule(module, target, templater.NONE)
} else {
templater.CgoTemplate(module, "", target, templater.MINIMAL, "", "") //TODO: collect errors
}
if utils.QT_DYNAMIC_SETUP() && mode == "full" && (target != "js" && target != "wasm") {
cc, _ := templater.ParseCgo(strings.ToLower(module), target)
if cc != "" {
cmd := exec.Command("go", "tool", "cgo", utils.GoQtPkgPath(strings.ToLower(module), strings.ToLower(module)+".go"))
cmd.Dir = utils.GoQtPkgPath(strings.ToLower(module))
utils.RunCmdOptional(cmd, fmt.Sprintf("failed to run cgo for %v (%v) on %v", target, strings.ToLower(module), runtime.GOOS))
}
}
}
runtimePath := utils.GoQtPkgPath("internal/binding/runtime")
utils.RemoveAll(runtimePath)
utils.MkdirAll(runtimePath)
utils.Save(filepath.Join(runtimePath, "utils-runtime.go"), utils.Load(filepath.Join(strings.TrimSpace(utils.GoListOptional("{{.Dir}}", "github.com/akiyosi/qt/internal", "-find", "get files dir")), "/binding/files/utils-runtime.go")))
moc.Moc(runtimePath, target, "", true, false, false, true)
}