forked from therecipe/qt
/
deploy.go
executable file
·1686 lines (1462 loc) · 64.8 KB
/
deploy.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package deploy
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
"golang.org/x/crypto/ssh"
"github.com/therecipe/qt/internal/binding/parser"
"github.com/therecipe/qt/internal/binding/templater"
"github.com/therecipe/qt/internal/cmd"
"github.com/therecipe/qt/internal/cmd/minimal"
"github.com/therecipe/qt/internal/cmd/moc"
"github.com/therecipe/qt/internal/cmd/rcc"
"github.com/therecipe/qt/internal/utils"
)
var (
appPath, appName string
depPath string
buildMode, buildTarget string
ending string
buildDocker bool
gLdFlags string
)
type State struct {
AppPath string
BuildMode, BuildTarget string
BuildDocker bool
LdFlags string
}
func Deploy(s *State) {
buildMode = s.BuildMode
buildTarget = s.BuildTarget
appPath = filepath.Clean(s.AppPath)
buildDocker = s.BuildDocker
gLdFlags = s.LdFlags
if !filepath.IsAbs(appPath) {
appPath, _ = utils.Abs(appPath)
}
appName = filepath.Base(appPath)
switch buildTarget {
case "android", "ios", "ios-simulator", "sailfish", "sailfish-emulator", "rpi1", "rpi2", "rpi3", "windows", "darwin", "linux":
{
if buildTarget == runtime.GOOS && !buildDocker {
depPath = filepath.Join(appPath, "deploy", runtime.GOOS)
}
depPath = filepath.Join(appPath, "deploy", buildTarget)
}
case "desktop":
{
depPath = filepath.Join(appPath, "deploy", runtime.GOOS)
}
}
switch buildMode {
case "build", "test":
{
utils.RemoveAll(depPath)
utils.MkdirAll(depPath)
}
}
if runtime.GOOS == "windows" && buildTarget == "desktop" || buildTarget == "windows" {
ending = ".exe"
}
switch buildMode {
case "build", "test":
{
if buildDocker {
if gLdFlags != "" {
cmd.Docker([]string{"qtdeploy", "-debug", fmt.Sprintf("-ldflags=%v", gLdFlags), "build", buildTarget}, buildTarget, appPath)
} else {
cmd.Docker([]string{"qtdeploy", "-debug", "build", buildTarget}, buildTarget, appPath)
}
} else {
//rcc
utils.Log.Debug("qtrcc - start")
var qtrcc_cwd string = appPath
if env_cwd := os.Getenv("QTRCC_CWD"); env_cwd != "" {
qtrcc_cwd = env_cwd
}
var qtrcc_output *string
if env_output_dir := os.Getenv("QTRCC_OUTPUT_DIR"); env_output_dir != "" {
qtrcc_output = &env_output_dir
}
rcc.Rcc(qtrcc_cwd, buildTarget, qtrcc_output)
utils.Log.Debug("qtrcc - done")
//moc
utils.Log.Debug("qtmoc - start")
moc.MocTree(appPath, buildTarget)
parser.State.Moc = false
parser.State.Module = ""
utils.Log.Debug("qtmoc - done")
//minimal
utils.Log.Debug("qtminimal - start")
minimal.Minimal(appPath, buildTarget)
parser.State.Minimal = false
parser.State.Module = ""
for _, c := range parser.State.ClassMap {
c.Export = false
for _, f := range c.Functions {
f.Export = false
}
}
utils.Log.Debug("qtminimal - done")
utils.Log.Debug("build - start")
build()
utils.Log.Debug("build - done")
utils.Log.Debug("deploy - start")
predeploy()
deployInternal()
pastdeploy()
utils.Log.Debug("deploy - done")
cleanup()
}
}
}
switch buildMode {
case "run", "test":
{
run()
}
}
}
func build() {
var (
ldFlags []string
tagFlags = []string{"minimal"}
outputFile string
env map[string]string
)
if gLdFlags != "" {
ldFlags = strings.Split(gLdFlags, " ")
}
if strings.ToLower(os.Getenv("QT_DOCKER")) == "true" {
tagFlags = append(tagFlags, "docker")
}
switch buildTarget {
case "android":
{
ldFlags = append(ldFlags, []string{"-s", "-w"}...)
tagFlags = append(tagFlags, buildTarget)
outputFile = filepath.Join(depPath, "libgo_base.so")
switch runtime.GOOS {
case "darwin", "linux":
{
env = map[string]string{
"PATH": os.Getenv("PATH"),
"GOPATH": os.Getenv("GOPATH"),
"GOROOT": runtime.GOROOT(),
"GOOS": "android",
"GOARCH": "arm",
"GOARM": "7",
"CGO_ENABLED": "1",
"CC": filepath.Join(utils.ANDROID_NDK_DIR(), "toolchains", "arm-linux-androideabi-4.9", "prebuilt", runtime.GOOS+"-x86_64", "bin", "arm-linux-androideabi-gcc"),
"CXX": filepath.Join(utils.ANDROID_NDK_DIR(), "toolchains", "arm-linux-androideabi-4.9", "prebuilt", runtime.GOOS+"-x86_64", "bin", "arm-linux-androideabi-g++"),
"CGO_CPPFLAGS": fmt.Sprintf("-isystem %v", filepath.Join(utils.ANDROID_NDK_DIR(), "platforms", "android-16", "arch-arm", "usr", "include")),
"CGO_LDFLAGS": fmt.Sprintf("--sysroot=%v -llog", filepath.Join(utils.ANDROID_NDK_DIR(), "platforms", "android-16", "arch-arm")),
}
}
case "windows":
{
env = map[string]string{
"PATH": os.Getenv("PATH"),
"GOPATH": os.Getenv("GOPATH"),
"GOROOT": runtime.GOROOT(),
"TMP": os.Getenv("TMP"),
"TEMP": os.Getenv("TEMP"),
"GOOS": "android",
"GOARCH": "arm",
"GOARM": "7",
"CGO_ENABLED": "1",
"CC": filepath.Join(utils.ANDROID_NDK_DIR(), "toolchains", "arm-linux-androideabi-4.9", "prebuilt", runtime.GOOS+"-x86_64", "bin", "arm-linux-androideabi-gcc"),
"CXX": filepath.Join(utils.ANDROID_NDK_DIR(), "toolchains", "arm-linux-androideabi-4.9", "prebuilt", runtime.GOOS+"-x86_64", "bin", "arm-linux-androideabi-g++"),
"CGO_CPPFLAGS": fmt.Sprintf("-isystem %v", filepath.Join(utils.ANDROID_NDK_DIR(), "platforms", "android-16", "arch-arm", "usr", "include")),
"CGO_LDFLAGS": fmt.Sprintf("--sysroot=%v -llog", filepath.Join(utils.ANDROID_NDK_DIR(), "platforms", "android-16", "arch-arm")),
}
}
}
utils.Save(filepath.Join(appPath, "cgo_main_wrapper.go"), "package main\nimport \"C\"\n//export go_main_wrapper\nfunc go_main_wrapper() { main() }")
}
case "ios", "ios-simulator":
{
ldFlags = append(ldFlags, "-w")
tagFlags = append(tagFlags, "ios")
outputFile = filepath.Join(depPath, "libgo.a")
var (
GOARCH = func() string {
if buildTarget == "ios" {
return "arm64"
}
return "amd64"
}()
ClangDir, ClangPlatform, ClangFlag, ClangArch = func() (string, string, string, string) {
if buildTarget == "ios" {
return "iPhoneOS", utils.IPHONEOS_SDK_DIR(), "iphoneos", "arm64"
}
return "iPhoneSimulator", utils.IPHONESIMULATOR_SDK_DIR(), "ios-simulator", "x86_64"
}()
)
env = map[string]string{
"PATH": os.Getenv("PATH"),
"GOPATH": os.Getenv("GOPATH"),
"GOROOT": runtime.GOROOT(),
"GOOS": runtime.GOOS,
"GOARCH": GOARCH,
"CGO_ENABLED": "1",
"CGO_CPPFLAGS": fmt.Sprintf("-isysroot %v/Contents/Developer/Platforms/%v.platform/Developer/SDKs/%v -m%v-version-min=7.0 -arch %v", utils.XCODE_DIR(), ClangDir, ClangPlatform, ClangFlag, ClangArch),
"CGO_LDFLAGS": fmt.Sprintf("-isysroot %v/Contents/Developer/Platforms/%v.platform/Developer/SDKs/%v -m%v-version-min=7.0 -arch %v", utils.XCODE_DIR(), ClangDir, ClangPlatform, ClangFlag, ClangArch),
}
utils.Save(filepath.Join(appPath, "cgo_main_wrapper.go"), "package main\nimport \"C\"\n//export go_main_wrapper\nfunc go_main_wrapper() { main() }")
}
case "desktop":
{
switch runtime.GOOS {
case "darwin":
{
ldFlags = append(ldFlags, []string{"-w", fmt.Sprintf("-r=%v", filepath.Join(utils.QT_DARWIN_DIR(), "lib"))}...)
outputFile = filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/MacOS/%v", appName, appName))
}
case "linux":
{
ldFlags = append(ldFlags, []string{"-s", "-w"}...)
outputFile = filepath.Join(depPath, appName)
}
case "windows":
{
ldFlags = append(ldFlags, []string{"-s", "-w", "-H=windowsgui"}...)
outputFile = filepath.Join(depPath, appName)
env = map[string]string{
"PATH": os.Getenv("PATH"),
"GOPATH": os.Getenv("GOPATH"),
"GOROOT": runtime.GOROOT(),
"TMP": os.Getenv("TMP"),
"TEMP": os.Getenv("TEMP"),
"GOOS": runtime.GOOS,
"GOARCH": "386",
"CGO_ENABLED": "1",
}
if utils.UseMsys2() {
if os.Getenv("MSYSTEM") == "MINGW64" {
env["GOARCH"] = "amd64"
}
}
}
}
}
case "sailfish", "sailfish-emulator":
{
//TODO: ldflags support
if !strings.Contains(appPath, utils.MustGoPath()) {
utils.Log.Panicln("Project needs to be inside GOPATH", appPath, utils.MustGoPath())
}
utils.RunCmdOptional(exec.Command(filepath.Join(utils.VIRTUALBOX_DIR(), "vboxmanage"), "registervm", filepath.Join(utils.SAILFISH_DIR(), "mersdk", "MerSDK", "MerSDK.vbox")), fmt.Sprintf("register mersdk for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmdOptional(exec.Command(filepath.Join(utils.VIRTUALBOX_DIR(), "vboxmanage"), "sharedfolder", "add", "MerSDK", "--name", "GOROOT", "--hostpath", runtime.GOROOT(), "--automount"), fmt.Sprintf("share GOROOT dir for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmdOptional(exec.Command(filepath.Join(utils.VIRTUALBOX_DIR(), "vboxmanage"), "sharedfolder", "add", "MerSDK", "--name", "GOPATH", "--hostpath", utils.MustGoPath(), "--automount"), fmt.Sprintf("share GOPATH dir for %v on %v", buildTarget, runtime.GOOS))
if runtime.GOOS == "windows" {
utils.RunCmdOptional(exec.Command(filepath.Join(utils.VIRTUALBOX_DIR(), "vboxmanage"), "startvm", "--type", "headless", "MerSDK"), fmt.Sprintf("start vbox mersdk for %v on %v", buildTarget, runtime.GOOS))
} else {
utils.RunCmdOptional(exec.Command("nohup", filepath.Join(utils.VIRTUALBOX_DIR(), "vboxmanage"), "startvm", "--type", "headless", "MerSDK"), fmt.Sprintf("start vbox mersdk for %v on %v", buildTarget, runtime.GOOS))
}
time.Sleep(10 * time.Second)
if buildTarget == "sailfish-emulator" {
sshCommand("2222", "root", "ln", "-s", "/opt/cross/bin/i486-meego-linux-gnu-as", "/opt/cross/libexec/gcc/i486-meego-linux-gnu/4.8.3/as")
sshCommand("2222", "root", "ln", "-s", "/opt/cross/bin/i486-meego-linux-gnu-ld", "/opt/cross/libexec/gcc/i486-meego-linux-gnu/4.8.3/ld")
var errBuild = sshCommand("2222", "root", "cd", strings.Replace(strings.Replace(appPath, utils.MustGoPath(), "/media/sf_GOPATH", -1), "\\", "/", -1), "&&", "GOROOT=/media/sf_GOROOT", "GOPATH=/media/sf_GOPATH", "PATH=$PATH:$GOROOT/bin/linux_386", "GOOS=linux", "GOARCH=386", "CGO_ENABLED=1", "CC=/opt/cross/bin/i486-meego-linux-gnu-gcc", "CXX=/opt/cross/bin/i486-meego-linux-gnu-g++", "CPATH=/srv/mer/targets/SailfishOS-i486/usr/include", "LIBRARY_PATH=/srv/mer/targets/SailfishOS-i486/usr/lib:/srv/mer/targets/SailfishOS-i486/lib", "CGO_LDFLAGS=--sysroot=/srv/mer/targets/SailfishOS-i486/", "go", "build", "-ldflags=\"-s -w\"", "-tags=\"minimal sailfish_emulator\"", fmt.Sprintf("-installsuffix=%v", strings.Replace(buildTarget, "-", "_", -1)), "-o", "deploy/"+buildTarget+"/harbour-"+appName)
if errBuild != nil {
cleanup()
utils.Log.WithError(errBuild).Panicf("failed to build for %v on %v", buildTarget, runtime.GOOS)
}
} else {
sshCommand("2222", "root", "ln", "-s", "/opt/cross/bin/armv7hl-meego-linux-gnueabi-as", "/opt/cross/libexec/gcc/armv7hl-meego-linux-gnueabi/4.8.3/as")
sshCommand("2222", "root", "ln", "-s", "/opt/cross/bin/armv7hl-meego-linux-gnueabi-ld", "/opt/cross/libexec/gcc/armv7hl-meego-linux-gnueabi/4.8.3/ld")
var errBuild = sshCommand("2222", "root", "cd", strings.Replace(strings.Replace(appPath, utils.MustGoPath(), "/media/sf_GOPATH", -1), "\\", "/", -1), "&&", "GOROOT=/media/sf_GOROOT", "GOPATH=/media/sf_GOPATH", "PATH=$PATH:$GOROOT/bin/linux_386", "GOOS=linux", "GOARCH=arm", "GOARM=7", "CGO_ENABLED=1", "CC=/opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc", "CXX=/opt/cross/bin/armv7hl-meego-linux-gnueabi-g++", "CPATH=/srv/mer/targets/SailfishOS-armv7hl/usr/include", "LIBRARY_PATH=/srv/mer/targets/SailfishOS-armv7hl/usr/lib:/srv/mer/targets/SailfishOS-armv7hl/lib", "CGO_LDFLAGS=--sysroot=/srv/mer/targets/SailfishOS-armv7hl/", "go", "build", "-ldflags=\"-s -w\"", "-tags=\"minimal sailfish\"", fmt.Sprintf("-installsuffix=%v", buildTarget), "-o", "deploy/"+buildTarget+"/harbour-"+appName)
if errBuild != nil {
cleanup()
utils.Log.WithError(errBuild).Panicf("failed to build for %v on %v", buildTarget, runtime.GOOS)
}
}
return
}
case "rpi1", "rpi2", "rpi3":
{
ldFlags = append(ldFlags, []string{"-s", "-w"}...)
tagFlags = append(tagFlags, buildTarget)
outputFile = filepath.Join(depPath, appName)
env = map[string]string{
"PATH": os.Getenv("PATH"),
"GOPATH": os.Getenv("GOPATH"),
"GOROOT": runtime.GOROOT(),
"GOOS": "linux",
"GOARCH": "arm",
"GOARM": "7",
"CGO_ENABLED": "1",
"CC": fmt.Sprintf("%v/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc", utils.RPI_TOOLS_DIR()),
"CXX": fmt.Sprintf("%v/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-g++", utils.RPI_TOOLS_DIR()),
}
if buildTarget == "rpi1" {
env["GOARM"] = "6"
}
}
case "windows":
{
if runtime.GOOS == "linux" {
ldFlags = append(ldFlags, []string{"-s", "-w", "-H=windowsgui"}...)
tagFlags = append(tagFlags, "windows")
outputFile = filepath.Join(depPath, appName)
env = map[string]string{
"PATH": os.Getenv("PATH"),
"GOPATH": os.Getenv("GOPATH"),
"GOROOT": runtime.GOROOT(),
"GOOS": "windows",
"GOARCH": utils.QT_MXE_ARCH(),
"CGO_ENABLED": "1",
"CC": "/usr/lib/mxe/usr/bin/i686-w64-mingw32.shared-gcc",
"CXX": "/usr/lib/mxe/usr/bin/i686-w64-mingw32.shared-g++",
}
if utils.QT_MXE_ARCH() == "amd64" {
env["CC"] = "/usr/lib/mxe/usr/bin/x86_64-w64-mingw32.shared-gcc"
env["CXX"] = "/usr/lib/mxe/usr/bin/x86_64-w64-mingw32.shared-g++"
}
}
}
}
var cmd = exec.Command("go", "build", "-p", strconv.Itoa(runtime.GOMAXPROCS(0)), "-v", fmt.Sprintf("-ldflags=\"%v\"", strings.Join(ldFlags, "\" \"")), "-o", outputFile+ending)
cmd.Dir = appPath
cmd.Args = append(cmd.Args, fmt.Sprintf("-tags=\"%v\"", strings.Join(tagFlags, "\" \"")))
if buildTarget != "desktop" {
cmd.Args = append(cmd.Args, []string{"-i", "-installsuffix", strings.Replace(buildTarget, "-", "_", -1)}...)
cmd.Args = append(cmd.Args, []string{"-pkgdir", filepath.Join(utils.MustGoPath(), "pkg", fmt.Sprintf("%v_%v_%v", env["GOOS"], env["GOARCH"], strings.Replace(buildTarget, "-", "_", -1)))}...)
}
if buildTarget != "desktop" || (runtime.GOOS == "windows" && buildTarget == "desktop") {
if buildTarget == "android" {
cmd.Args = append(cmd.Args, "-buildmode", "c-shared")
}
if buildTarget == "ios" || buildTarget == "ios-simulator" {
cmd.Args = append(cmd.Args, "-buildmode", "c-archive")
}
for key, value := range env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%v=%v", key, value))
}
}
utils.RunCmd(cmd, fmt.Sprintf("build for %v on %v", buildTarget, runtime.GOOS))
if runtime.GOOS == "darwin" && buildTarget == "desktop" {
var strip = exec.Command("strip", outputFile)
strip.Dir = appPath
utils.RunCmd(strip, fmt.Sprintf("strip binary for %v on %v", buildTarget, runtime.GOOS))
}
//armv7
if buildTarget == "ios" && (strings.HasPrefix(runtime.Version(), "go1.7") || strings.HasPrefix(runtime.Version(), "devel")) {
var cmdiOS = exec.Command("go", "build", "-p", strconv.Itoa(runtime.GOMAXPROCS(0)), "-v", fmt.Sprintf("-ldflags=\"%v\"", strings.Join(ldFlags, "\" \"")), "-o", strings.Replace(outputFile, "libgo.a", "libgo_armv7.a", -1))
cmdiOS.Dir = appPath
cmdiOS.Args = append(cmdiOS.Args, fmt.Sprintf("-tags=\"%v\"", strings.Join(tagFlags, "\" \"")))
if buildTarget != "desktop" {
cmdiOS.Args = append(cmdiOS.Args, []string{"-i", "-installsuffix", strings.Replace(buildTarget, "-", "_", -1)}...)
cmdiOS.Args = append(cmdiOS.Args, []string{"-pkgdir", filepath.Join(utils.MustGoPath(), "pkg", fmt.Sprintf("%v_%v_%v", env["GOOS"], env["GOARCH"], strings.Replace(buildTarget, "-", "_", -1)))}...)
}
cmdiOS.Args = append(cmdiOS.Args, "-buildmode", "c-archive")
var tmp = strings.Replace(strings.Join(cmd.Env, "|"), "-arch arm64", "-arch armv7", -1)
tmp = strings.Replace(tmp, "arm64", "arm", -1)
cmdiOS.Env = append(strings.Split(tmp, "|"), "GOARM=7")
utils.RunCmd(cmdiOS, fmt.Sprintf("build for %v on %v", buildTarget, runtime.GOOS))
}
}
func predeploy() {
var copyCmd = func() string {
if runtime.GOOS == "windows" {
return "xcopy"
}
return "cp"
}()
switch buildTarget {
case "android":
{
utils.MkdirAll(filepath.Join(appPath, "android"))
var libPath = filepath.Join(depPath, "build", "libs", "armeabi-v7a")
utils.MkdirAll(libPath)
var compiler = filepath.Join(utils.ANDROID_NDK_DIR(), "toolchains", "arm-linux-androideabi-4.9", "prebuilt", runtime.GOOS+"-x86_64", "bin", "arm-linux-androideabi-g++")
//add c_main_wrappers
utils.Save(filepath.Join(depPath, "c_main_wrapper.cpp"), "#include \"libgo_base.h\"\nint main(int argc, char *argv[]) { go_main_wrapper(); }")
var cmd = exec.Command(compiler, "c_main_wrapper.cpp", "-o", filepath.Join(depPath, "libgo.so"), "-I../..", "-L.", "-lgo_base", fmt.Sprintf("--sysroot=%v", filepath.Join(utils.ANDROID_NDK_DIR(), "platforms", "android-9", "arch-arm")), "-shared")
cmd.Dir = depPath
utils.RunCmd(cmd, fmt.Sprintf("compile for %v on %v", buildTarget, runtime.GOOS))
var strip = exec.Command(filepath.Join(filepath.Dir(compiler), "arm-linux-androideabi-strip"), "libgo.so")
strip.Dir = depPath
utils.RunCmd(strip, fmt.Sprintf("strip binary for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command(copyCmd, filepath.Join(depPath, "libgo_base.so"), libPath), fmt.Sprintf("copy libgo_base for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command(copyCmd, filepath.Join(depPath, "libgo.so"), libPath), fmt.Sprintf("copy libgo for %v on %v", buildTarget, runtime.GOOS))
//trick androiddeployqt into checking dependencies from libgo_base.so
utils.RemoveAll(filepath.Join(depPath, "libgo.so"))
if runtime.GOOS == "windows" {
utils.RunCmd(exec.Command(copyCmd, filepath.Join(depPath, "libgo_base.so"), filepath.Join(depPath, "libgo.so*")), "")
} else {
utils.RunCmd(exec.Command(copyCmd, filepath.Join(depPath, "libgo_base.so"), filepath.Join(depPath, "libgo.so")), "")
}
var out, err = json.Marshal(&struct {
Qt string `json:"qt"`
Sdk string `json:"sdk"`
SdkBuildToolsRevision string `json:"sdkBuildToolsRevision"`
Ndk string `json:"ndk"`
Toolchainprefix string `json:"toolchain-prefix"`
Toolprefix string `json:"tool-prefix"`
Toolchainversion string `json:"toolchain-version"`
Ndkhost string `json:"ndk-host"`
Targetarchitecture string `json:"target-architecture"`
AndroidExtraLibs string `json:"android-extra-libs"`
AndroidPackageSourceDirectory string `json:"android-package-source-directory"`
Qmlrootpath string `json:"qml-root-path"`
Applicationbinary string `json:"application-binary"`
}{
Qt: filepath.Join(utils.QT_DIR(), utils.QT_VERSION_MAJOR(), "android_armv7"),
Sdk: utils.ANDROID_SDK_DIR(),
SdkBuildToolsRevision: "25.0.2",
Ndk: utils.ANDROID_NDK_DIR(),
Toolchainprefix: "arm-linux-androideabi",
Toolprefix: "arm-linux-androideabi",
Toolchainversion: "4.9",
Ndkhost: runtime.GOOS + "-x86_64",
Targetarchitecture: "armeabi-v7a",
AndroidExtraLibs: filepath.Join(depPath, "libgo_base.so"),
AndroidPackageSourceDirectory: filepath.Join(appPath, "android"),
Qmlrootpath: appPath,
Applicationbinary: filepath.Join(depPath, "libgo.so"),
})
if err != nil {
utils.Log.WithError(err).Panicf("failed to create json-config file for androiddeployqt on %v", runtime.GOOS)
}
utils.Save(filepath.Join(depPath, "android-libgo.so-deployment-settings.json"), strings.Replace(string(out), `\\`, `/`, -1))
}
case "ios", "ios-simulator":
{
utils.MkdirAll(filepath.Join(appPath, buildTarget))
var buildPath = filepath.Join(depPath, "build")
utils.MkdirAll(filepath.Join(buildPath, "project.xcodeproj"))
utils.MkdirAll(filepath.Join(buildPath, "Images.xcassets", "AppIcon.appiconset"))
//add c_main_wrappers
utils.Save(filepath.Join(depPath, "c_main_wrapper.cpp"), "#include \"libgo.h\"\nint main(int argc, char *argv[]) { go_main_wrapper(); }")
if buildTarget == "ios" && (strings.HasPrefix(runtime.Version(), "go1.7") || strings.HasPrefix(runtime.Version(), "devel")) {
utils.Save(filepath.Join(depPath, "c_main_wrapper_armv7.cpp"), "#include \"libgo_armv7.h\"\nint main(int argc, char *argv[]) { go_main_wrapper(); }")
}
utils.Save(filepath.Join(depPath, "gallery_plugin_import.cpp"), iosGalleryPluginImport)
utils.Save(filepath.Join(depPath, "gallery_qml_plugin_import.cpp"), iosGalleryQmlPluginImport)
utils.Save(filepath.Join(depPath, "qt.conf"), iosQtConf)
//build arm64
var cmd = exec.Command("xcrun", "clang++", "c_main_wrapper.cpp", "gallery_plugin_import.cpp", "gallery_qml_plugin_import.cpp", "-o", "build/main", "-u", "_qt_registerPlatformPlugin", "-Wl,-e,_qt_main_wrapper", "-I../..", "-L.", "-lgo")
cmd.Args = append(cmd.Args, templater.GetiOSClang(buildTarget, "")...)
cmd.Dir = depPath
utils.RunCmd(cmd, fmt.Sprintf("compile for %v on %v", buildTarget, runtime.GOOS))
var strip = exec.Command("strip", "main")
strip.Dir = filepath.Join(depPath, "build")
utils.RunCmd(strip, fmt.Sprintf("strip binary for %v on %v", buildTarget, runtime.GOOS))
if buildTarget == "ios" && (strings.HasPrefix(runtime.Version(), "go1.7") || strings.HasPrefix(runtime.Version(), "devel")) {
//build armv7
cmd = exec.Command("xcrun", "clang++", "c_main_wrapper_armv7.cpp", "gallery_plugin_import.cpp", "gallery_qml_plugin_import.cpp", "-o", "build/main_armv7", "-u", "_qt_registerPlatformPlugin", "-Wl,-e,_qt_main_wrapper", "-I../..", "-L.", "-lgo_armv7")
cmd.Args = append(cmd.Args, templater.GetiOSClang(buildTarget, "armv7")...)
cmd.Dir = depPath
utils.RunCmdOptional(cmd, fmt.Sprintf("compile for %v on %v", buildTarget, runtime.GOOS))
strip = exec.Command("strip", "main_armv7")
strip.Dir = filepath.Join(depPath, "build")
utils.RunCmdOptional(strip, fmt.Sprintf("strip binary for %v on %v", buildTarget, runtime.GOOS))
//binary size limits => https://developer.apple.com/library/ios/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/Chapters/SubmittingTheApp.html
var lipo = exec.Command("xcrun", "lipo", "-create", "-arch", "arm64", "main", "-arch", "armv7", "main_armv7", "-output", "main")
lipo.Dir = filepath.Join(depPath, "build")
utils.RunCmdOptional(lipo, fmt.Sprintf("create fat binary for %v on %v", buildTarget, runtime.GOOS))
}
//create default assets
utils.Save(filepath.Join(buildPath, "Info.plist"), iosPLIST())
utils.Save(filepath.Join(buildPath, "Images.xcassets", "AppIcon.appiconset", "Contents.json"), iosAppIcon)
utils.Save(filepath.Join(buildPath, "LaunchScreen.xib"), iosLaunchScreen())
utils.Save(filepath.Join(buildPath, "project.xcodeproj", "project.pbxproj"), iosProject())
utils.RunCmd(exec.Command(copyCmd, fmt.Sprintf("%v/%v/ios/mkspecs/macx-ios-clang/Default-568h@2x.png", utils.QT_DIR(), utils.QT_VERSION_MAJOR()), buildPath), fmt.Sprintf("copy icon for %v on %v", buildTarget, runtime.GOOS))
//copy assets from buildTarget folder
utils.RunCmd(exec.Command(copyCmd, "-R", fmt.Sprintf("%v/%v/", appPath, buildTarget), buildPath), fmt.Sprintf("copy assets for %v on %v", buildTarget, runtime.GOOS))
}
case "desktop", "rpi1", "rpi2", "rpi3":
{
switch runtime.GOOS {
case "darwin":
{
utils.MkdirAll(filepath.Join(appPath, runtime.GOOS))
utils.Save(filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/MacOS/%v_sh", appName, appName)), darwinSH())
utils.Save(filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/Info.plist", appName)), darwinPLIST())
utils.RunCmd(exec.Command(copyCmd, "-R", fmt.Sprintf("%v/%v/", appPath, runtime.GOOS), filepath.Join(depPath, fmt.Sprintf("%v.app/", appName))), fmt.Sprintf("copy assets for %v on %v", buildTarget, runtime.GOOS))
}
case "linux":
{
utils.MkdirAll(filepath.Join(appPath, runtime.GOOS))
utils.Save(filepath.Join(depPath, fmt.Sprintf("%v.sh", appName)), linuxSH())
utils.RunCmd(exec.Command(copyCmd, "-R", fmt.Sprintf("%v/%v/", appPath, runtime.GOOS), depPath), fmt.Sprintf("copy assets for %v on %v", buildTarget, runtime.GOOS))
}
case "windows":
{
//TODO: icon windres
}
}
}
case "sailfish", "sailfish-emulator":
{
utils.MkdirAll(filepath.Join(appPath, buildTarget))
//create default assets
utils.MkdirAll(filepath.Join(depPath, "rpm"))
utils.Save(filepath.Join(depPath, "rpm", appName+".spec"), sailfishSpec())
utils.Save(filepath.Join(depPath, appName+".desktop"), sailfishDesktop())
//copy assets from buildTarget folder
if runtime.GOOS == "windows" {
utils.RunCmd(exec.Command(copyCmd, filepath.Join(utils.SAILFISH_DIR(), "tutorials", "stocqt", "stocqt.png"), filepath.Join(depPath, fmt.Sprintf("harbour-%v.png*", appName))), fmt.Sprintf("copy icon for %v on %v", buildTarget, runtime.GOOS))
var cmd = exec.Command(copyCmd, buildTarget, depPath)
cmd.Dir = appPath
utils.RunCmd(cmd, fmt.Sprintf("copy assets for %v on %v", buildTarget, runtime.GOOS))
} else {
utils.RunCmd(exec.Command(copyCmd, filepath.Join(utils.SAILFISH_DIR(), "tutorials", "stocqt", "stocqt.png"), filepath.Join(depPath, fmt.Sprintf("harbour-%v.png", appName))), fmt.Sprintf("copy icon for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command(copyCmd, "-R", fmt.Sprintf("%v/%v/", appPath, buildTarget), depPath), fmt.Sprintf("copy assets for %v on %v", buildTarget, runtime.GOOS))
}
var errClean = sshCommand("2222", "mersdk", "cd", "/home/mersdk", "&&", "rm", "-R", buildTarget)
if errClean != nil {
utils.Log.WithError(errClean).Errorf("failed to cleanup for %v on %v", buildTarget, runtime.GOOS)
}
var errCopy = sshCommand("2222", "mersdk", "cd", strings.Replace(strings.Replace(appPath, utils.MustGoPath(), "/media/sf_GOPATH", -1)+"/deploy", "\\", "/", -1), "&&", "cp", "-R", buildTarget, "/home/mersdk")
if errCopy != nil {
cleanup()
utils.Log.WithError(errClean).Panicf("failed to copy project for %v on %v", buildTarget, runtime.GOOS)
}
}
}
}
func deployInternal() {
switch buildTarget {
case "android":
{
var deploy = exec.Command(filepath.Join(utils.QT_DIR(), utils.QT_VERSION_MAJOR(), "android_armv7", "bin", "androiddeployqt"))
deploy.Args = append(deploy.Args,
"--input", filepath.Join(depPath, "android-libgo.so-deployment-settings.json"),
"--output", filepath.Join(depPath, "build"),
"--deployment", "bundled",
"--android-platform", "android-25",
"--jdk", utils.JDK_DIR(),
"--gradle",
"--verbose",
)
if utils.ExistsFile(filepath.Join(appPath, "android", appName+".keystore")) {
deploy.Args = append(deploy.Args,
"--sign", filepath.Join(appPath, "android", appName+".keystore"),
strings.TrimSpace(utils.Load(filepath.Join(appPath, "android", "alias.txt"))),
"--storepass", strings.TrimSpace(utils.Load(filepath.Join(appPath, "android", "password.txt"))),
)
}
deploy.Dir = filepath.Join(utils.QT_DIR(), utils.QT_VERSION_MAJOR(), "android_armv7", "bin")
deploy.Env = append(deploy.Env, "JAVA_HOME="+utils.JDK_DIR())
if runtime.GOOS == "windows" {
utils.Save(filepath.Join(depPath, "build.bat"), fmt.Sprintf("set JAVA_HOME=%v\r\n%v", utils.JDK_DIR(), strings.Join(deploy.Args, " ")))
utils.RunCmd(exec.Command(filepath.Join(depPath, "build.bat")), fmt.Sprintf("deploy %v on %v", buildTarget, runtime.GOOS))
utils.RemoveAll(filepath.Join(depPath, "build.bat"))
} else {
utils.RunCmd(deploy, fmt.Sprintf("deploy %v on %v", buildTarget, runtime.GOOS))
}
}
case "ios", "ios-simulator":
{
utils.RunCmd(exec.Command("xcrun", "xcodebuild", "clean", "build", "CODE_SIGN_IDENTITY=", "CODE_SIGNING_REQUIRED=NO", "CONFIGURATION_BUILD_DIR="+depPath, "-configuration", "Release", "-project", filepath.Join(depPath, "build", "project.xcodeproj")), fmt.Sprintf("deploy %v on %v", buildTarget, runtime.GOOS))
}
case "desktop", "rpi1", "rpi2", "rpi3", "windows":
{
switch {
case buildTarget == "windows":
{
if runtime.GOOS == "linux" {
var libraryPath = "/usr/lib/mxe/usr/i686-w64-mingw32.shared/bin/"
if utils.QT_MXE_ARCH() == "amd64" {
libraryPath = "/usr/lib/mxe/usr/x86_64-w64-mingw32.shared/bin/"
}
for _, d := range []string{"libbz2", "libfreetype-6", "libglib-2.0-0", "libharfbuzz-0", "libiconv-2", "libintl-8", "libpcre-1", "libpcre16-0", "libpng16-16", "libstdc++-6", "libwinpthread-1", "zlib1", "libeay32", "ssleay32"} {
utils.RunCmdOptional(exec.Command("cp", filepath.Join(libraryPath, fmt.Sprintf("%v.dll", d)), depPath), fmt.Sprintf("copy %v for %v on %v", d, buildTarget, runtime.GOOS))
}
for _, d := range []string{"libjasper-1", "libjpeg-9", "libmng-2", "libtiff-5", "libwebp-5", "liblcms2-2", "liblzma-5", "libwebpdemux-1"} {
utils.RunCmdOptional(exec.Command("cp", filepath.Join(libraryPath, fmt.Sprintf("%v.dll", d)), depPath), fmt.Sprintf("copy %v for %v on %v", d, buildTarget, runtime.GOOS))
}
var gccDep string
if utils.QT_MXE_ARCH() == "386" {
gccDep = "libgcc_s_sjlj-1"
} else {
gccDep = "libgcc_s_seh-1"
}
utils.RunCmdOptional(exec.Command("cp", filepath.Join(libraryPath, fmt.Sprintf("%v.dll", gccDep)), depPath), fmt.Sprintf("copy %v for %v on %v", gccDep, buildTarget, runtime.GOOS))
libraryPath = "/usr/lib/mxe/usr/i686-w64-mingw32.shared/qt5/"
if utils.QT_MXE_ARCH() == "amd64" {
libraryPath = "/usr/lib/mxe/usr/x86_64-w64-mingw32.shared/qt5/"
}
utils.RunCmd(exec.Command("cp", "-R", filepath.Join(libraryPath, "qml/")+"/.", depPath), fmt.Sprintf("copy qml dir for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command("cp", "-R", filepath.Join(libraryPath, "plugins/")+"/.", depPath), fmt.Sprintf("copy plugins dir for %v on %v", buildTarget, runtime.GOOS))
libraryPath = "/usr/lib/mxe/usr/i686-w64-mingw32.shared/qt5/bin/"
if utils.QT_MXE_ARCH() == "amd64" {
libraryPath = "/usr/lib/mxe/usr/x86_64-w64-mingw32.shared/qt5/bin/"
}
var output string
if utils.QT_MXE_ARCH() == "amd64" {
output = utils.RunCmd(exec.Command("/usr/lib/mxe/usr/bin/x86_64-w64-mingw32.shared-objdump", "-x", filepath.Join(depPath, appName+ending)), fmt.Sprintf("objdump binary for %v on %v", buildTarget, runtime.GOOS))
} else {
output = utils.RunCmd(exec.Command("/usr/lib/mxe/usr/bin/i686-w64-mingw32.shared-objdump", "-x", filepath.Join(depPath, appName+ending)), fmt.Sprintf("objdump binary for %v on %v", buildTarget, runtime.GOOS))
}
for lib, deps := range parser.LibDeps {
if strings.Contains(output, lib) && lib != parser.MOC {
for _, lib := range append(deps, lib) {
utils.RunCmd(exec.Command("cp", filepath.Join(libraryPath, fmt.Sprintf("Qt5%v.dll", lib)), depPath), fmt.Sprintf("copy %v for %v on %v", lib, buildTarget, runtime.GOOS))
}
}
}
for _, d := range []string{"Qt5OpenGL", "Qt5Quick", "Qt5QuickControls2", "Qt5QuickTemplates2"} {
utils.RunCmdOptional(exec.Command("cp", filepath.Join(libraryPath, fmt.Sprintf("%v.dll", d)), depPath), fmt.Sprintf("copy %v for %v on %v", d, buildTarget, runtime.GOOS))
}
}
}
case utils.UseMsys2():
{
var copyCmd = "xcopy"
if os.Getenv("MSYSTEM") != "" {
copyCmd = "cp"
}
var deploy = exec.Command(filepath.Join(utils.QT_MSYS2_DIR(), "bin", "windeployqt"))
deploy.Args = append(deploy.Args,
filepath.Join(depPath, appName+ending),
fmt.Sprintf("-qmldir=%v", appPath),
"-force")
utils.RunCmd(deploy, fmt.Sprintf("depoy %v on %v", buildTarget, runtime.GOOS))
var libraryPath = filepath.Join(utils.QT_MSYS2_DIR(), "bin")
for _, d := range []string{"libbz2-1", "libfreetype-6", "libglib-2.0-0", "libharfbuzz-0", "libiconv-2", "libintl-8", "libpcre-1", "libpcre16-0", "libpng16-16", "libstdc++-6", "libwinpthread-1", "zlib1", "libgraphite2", "libicudt57", "libicuin57", "libicuuc57"} {
utils.RunCmdOptional(exec.Command(copyCmd, filepath.Join(libraryPath, fmt.Sprintf("%v.dll", d)), depPath), fmt.Sprintf("copy %v for %v on %v", d, buildTarget, runtime.GOOS))
}
var gccDep string
if os.Getenv("MSYSTEM") == "MINGW64" {
gccDep = "libgcc_s_seh-1"
} else {
gccDep = "libgcc_s_dw2-1"
}
utils.RunCmdOptional(exec.Command(copyCmd, filepath.Join(libraryPath, fmt.Sprintf("%v.dll", gccDep)), depPath), fmt.Sprintf("copy %v for %v on %v", gccDep, buildTarget, runtime.GOOS))
libraryPath = filepath.Join(utils.QT_MSYS2_DIR(), "share", "qt5")
if os.Getenv("MSYSTEM") != "" {
utils.RunCmd(exec.Command("cp", "-R", filepath.Join(libraryPath, "qml/")+"/.", depPath), fmt.Sprintf("copy qml dir for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command("cp", "-R", filepath.Join(libraryPath, "plugins/")+"/.", depPath), fmt.Sprintf("copy plugins dir for %v on %v", buildTarget, runtime.GOOS))
} else {
utils.RunCmd(exec.Command("xcopy", "/S", "/Y", filepath.Join(libraryPath, "qml/"), depPath), fmt.Sprintf("copy qml dir for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command("xcopy", "/S", "/Y", filepath.Join(libraryPath, "plugins/"), depPath), fmt.Sprintf("copy plugins dir for %v on %v", buildTarget, runtime.GOOS))
}
libraryPath = filepath.Join(utils.QT_MSYS2_DIR(), "bin")
var output = utils.RunCmd(exec.Command(filepath.Join(utils.QT_MSYS2_DIR(), "bin", "objdump"), "-x", filepath.Join(depPath, appName+ending)), fmt.Sprintf("objdump binary for %v on %v", buildTarget, runtime.GOOS))
for lib, deps := range parser.LibDeps {
if strings.Contains(output, lib) && lib != parser.MOC {
for _, lib := range append(deps, lib) {
utils.RunCmd(exec.Command(copyCmd, filepath.Join(libraryPath, fmt.Sprintf("Qt5%v.dll", lib)), depPath), fmt.Sprintf("copy %v for %v on %v", lib, buildTarget, runtime.GOOS))
}
}
}
utils.RunCmd(exec.Command(copyCmd, filepath.Join(libraryPath, "Qt5OpenGL.dll"), depPath), fmt.Sprintf("copy OpenGL for %v on %v", buildTarget, runtime.GOOS))
var walkFn = func(path string, info os.FileInfo, err error) error {
if strings.HasSuffix(info.Name(), "d.dll") {
utils.RemoveAll(path)
}
return nil
}
filepath.Walk(depPath, walkFn)
}
case runtime.GOOS == "windows":
{
var deploy = exec.Command(filepath.Join(utils.QT_DIR(), utils.QT_VERSION_MAJOR(), "mingw53_32", "bin", "windeployqt"))
deploy.Args = append(deploy.Args,
filepath.Join(depPath, appName+ending),
fmt.Sprintf("-qmldir=%v", appPath),
"-force")
utils.RunCmd(deploy, fmt.Sprintf("depoy %v on %v", buildTarget, runtime.GOOS))
}
case runtime.GOOS == "darwin":
{
if utils.UseHomeBrew() {
return
}
var deploy = exec.Command(fmt.Sprintf("%v/bin/macdeployqt", utils.QT_DARWIN_DIR()))
deploy.Args = append(deploy.Args,
filepath.Join(depPath, fmt.Sprintf("%v.app/", appName)),
fmt.Sprintf("-qmldir=%v", appPath))
deploy.Dir = fmt.Sprintf("%v/bin/", utils.QT_DARWIN_DIR())
utils.RunCmd(deploy, fmt.Sprintf("deploy %v on %v", buildTarget, runtime.GOOS))
}
case runtime.GOOS == "linux":
{
if utils.UsePkgConfig() {
return
}
utils.MkdirAll(filepath.Join(depPath, "lib"))
var (
libraryPath string
lddPath = "ldd"
lddExtra string
lddOutput string
)
if strings.HasPrefix(buildTarget, "rpi") {
libraryPath = fmt.Sprintf("%v/%v/%v/lib/", utils.QT_DIR(), utils.QT_VERSION_MAJOR(), buildTarget)
lddPath = fmt.Sprintf("%v/arm-bcm2708/arm-rpi-4.9.3-linux-gnueabihf/bin/arm-linux-gnueabihf-ldd", utils.RPI_TOOLS_DIR())
lddExtra = "--root=/"
lddOutput = utils.RunCmd(exec.Command(lddPath, lddExtra, filepath.Join(depPath, appName)), fmt.Sprintf("ldd binary for %v on %v", buildTarget, runtime.GOOS))
} else {
lddOutput = utils.RunCmd(exec.Command(lddPath, filepath.Join(depPath, appName)), fmt.Sprintf("ldd binary for %v on %v", buildTarget, runtime.GOOS))
}
for _, dep := range strings.Split(lddOutput, "\n") {
if strings.Contains(dep, "libQt5") || strings.Contains(dep, "libicu") {
var libName string
if strings.HasPrefix(buildTarget, "rpi") {
libName = strings.TrimSpace(strings.Replace(strings.Split(dep, "=>")[0], "not found", "", -1))
} else {
if libraryPath == "" {
libraryPath, libName = filepath.Split(strings.Split(dep, " ")[2])
} else {
_, libName = filepath.Split(strings.Split(dep, " ")[2])
}
}
if utils.ExistsFile(filepath.Join(libraryPath, libName)) {
utils.RunCmd(exec.Command("cp", "-L", filepath.Join(libraryPath, libName), filepath.Join(depPath, "lib", libName)), fmt.Sprintf("copy %v for %v on %v", libName, buildTarget, runtime.GOOS))
}
}
}
for _, libName := range []string{"DBus", "XcbQpa", "Quick", "Widgets", "EglDeviceIntegration", "EglFsKmsSupport", "OpenGL", "WaylandClient", "WaylandCompositor", "QuickControls2", "QuickTemplates2", "QuickWidgets", "QuickParticles", "CLucene", "Concurrent"} {
if utils.ExistsFile(filepath.Join(libraryPath, fmt.Sprintf("libQt5%v.so.5", libName))) {
utils.RunCmd(exec.Command("cp", "-L", filepath.Join(libraryPath, fmt.Sprintf("libQt5%v.so.5", libName)), filepath.Join(depPath, "lib", fmt.Sprintf("libQt5%v.so.5", libName))), fmt.Sprintf("copy %v for %v on %v", libName, buildTarget, runtime.GOOS))
}
}
if utils.ExistsFile(filepath.Join(libraryPath, "libqgsttools_p.so.1.0.0")) {
utils.RunCmd(exec.Command("cp", "-L", filepath.Join(libraryPath, "libqgsttools_p.so.1.0.0"), filepath.Join(depPath, "lib", "libqgsttools_p.so.1")), fmt.Sprintf("copy libqgsttools_p.so.1 for %v on %v", buildTarget, runtime.GOOS))
}
libraryPath = strings.TrimSuffix(libraryPath, "lib/")
utils.RunCmd(exec.Command("cp", "-R", filepath.Join(libraryPath, "qml/"), depPath), fmt.Sprintf("copy qml dir for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command("cp", "-R", filepath.Join(libraryPath, "plugins/"), depPath), fmt.Sprintf("copy plugins dir for %v on %v", buildTarget, runtime.GOOS))
}
}
}
case "sailfish", "sailfish-emulator":
{
if buildTarget == "sailfish-emulator" {
var errDeploy = sshCommand("2222", "mersdk", "cd", "/home/mersdk/"+buildTarget, "&&", "mb2", "-t", "SailfishOS-i486", "build")
if errDeploy != nil {
cleanup()
utils.Log.WithError(errDeploy).Errorf("failed to deploy for %v on %v", buildTarget, runtime.GOOS)
}
} else {
var errDeploy = sshCommand("2222", "mersdk", "cd", "/home/mersdk/"+buildTarget, "&&", "mb2", "-t", "SailfishOS-armv7hl", "build")
if errDeploy != nil {
cleanup()
utils.Log.WithError(errDeploy).Errorf("failed to deploy for %v on %v", buildTarget, runtime.GOOS)
}
}
}
}
}
func pastdeploy() {
switch buildTarget {
case "android":
{
var (
copyCmd string
apkEnding string
)
switch runtime.GOOS {
case "darwin", "linux":
{
copyCmd = "cp"
apkEnding = "apk"
}
case "windows":
{
copyCmd = "xcopy"
apkEnding = "apk*"
}
}
if utils.ExistsFile(filepath.Join(appPath, "android", appName+".keystore")) {
utils.RunCmd(exec.Command(copyCmd, filepath.Join(depPath, "build", "build", "outputs", "apk", "build-release-signed.apk"), filepath.Join(depPath, fmt.Sprintf("%v.%v", appName, apkEnding))), fmt.Sprintf("copy release apk for %v on %v", buildTarget, runtime.GOOS))
} else {
utils.RunCmd(exec.Command(copyCmd, filepath.Join(depPath, "build", "build", "outputs", "apk", "build-debug.apk"), filepath.Join(depPath, fmt.Sprintf("%v.%v", appName, apkEnding))), fmt.Sprintf("copy debug apk for %v on %v", buildTarget, runtime.GOOS))
}
//TODO: copy manifest to android folder and change mindSdkVersion >= 16
}
case "ios", "ios-simulator":
{
//TODO:
}
case "desktop":
{
switch runtime.GOOS {
case "darwin":
{
utils.RunCmd(exec.Command("mv", filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/MacOS/%v", appName, appName)), filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/MacOS/%v_app", appName, appName))), fmt.Sprintf("move binary for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command("mv", filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/MacOS/%v_sh", appName, appName)), filepath.Join(depPath, fmt.Sprintf("%v.app/Contents/MacOS/%v", appName, appName))), fmt.Sprintf("move script for %v on %v", buildTarget, runtime.GOOS))
}
}
}
case "sailfish", "sailfish-emulator":
{
var errPastDeploy = sshCommand("2222", "mersdk", "cd", "/home/mersdk/"+buildTarget+"/RPMS", "&&", "cp", "*", strings.Replace(strings.Replace(depPath, utils.MustGoPath(), "/media/sf_GOPATH", -1), "\\", "/", -1))
if errPastDeploy != nil {
cleanup()
utils.Log.WithError(errPastDeploy).Panicf("failed to receive project for %v on %v", buildTarget, runtime.GOOS)
}
}
}
}
func cleanup() error {
utils.RemoveAll(filepath.Join(appPath, "rrc.go"))
utils.RemoveAll(filepath.Join(appPath, "rrc.qrc"))
utils.RemoveAll(filepath.Join(appPath, "rrc.cpp"))
utils.RemoveAll(filepath.Join(appPath, "cgo_main_wrapper.go"))
return moc.CleanPath(appPath)
}
func run() {
switch buildTarget {
case "android":
{
if runtime.GOOS != "windows" {
utils.RunCmdOptional(exec.Command("killall", "adb"), fmt.Sprintf("run \"killall adb\" for %v on %v", buildTarget, runtime.GOOS))
}
exec.Command(filepath.Join(utils.ANDROID_SDK_DIR(), "platform-tools", "adb"), "install", "-r", filepath.Join(depPath, fmt.Sprintf("%v.apk", appName))).Start()
}
case /*"ios",*/ "ios-simulator":
{
utils.RunCmdOptional(exec.Command("xcrun", "instruments", "-w", "iPhone 7 Plus (10.2)#"), fmt.Sprintf("start simulator for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command("xcrun", "simctl", "uninstall", "booted", filepath.Join(depPath, "main.app")), fmt.Sprintf("uninstall app for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command("xcrun", "simctl", "install", "booted", filepath.Join(depPath, "main.app")), fmt.Sprintf("install app for %v on %v", buildTarget, runtime.GOOS))
utils.RunCmd(exec.Command("xcrun", "simctl", "launch", "booted", fmt.Sprintf("com.identifier.%v", appName)), fmt.Sprintf("launch app for %v on %v", buildTarget, runtime.GOOS))
}
case "windows":
{
exec.Command("wine", filepath.Join(depPath, appName+ending)).Start()
}
case "desktop":
{
switch runtime.GOOS {
case "darwin":
{
utils.RunCmdOptional(exec.Command("open", filepath.Join(depPath, fmt.Sprintf("%v.app/", appName))), fmt.Sprintf("run binary for %v on %v", buildTarget, runtime.GOOS))
}
case "linux":
{