forked from overte-org/overte-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverte-builder
executable file
·2411 lines (1896 loc) · 67.6 KB
/
overte-builder
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
#!/usr/bin/env perl
use warnings;
use strict;
use FindBin;
use lib "$FindBin::Bin/lib";
use Getopt::Long;
use Term::ANSIColor;
use IO::Select;
use IPC::Open3;
use File::Find;
use File::Spec;
use File::Copy qw(cp);
use File::Basename;
use Cwd qw(abs_path);
use VircadiaBuilder::Common;
use VircadiaBuilder::Package;
use VircadiaBuilder::Package::Archive;
use POSIX ();
$| = 1;
my $prev_len = 0;
my $inst_copied = 0;
my $inst_skipped = 0;
my $inst_deleted = 0;
my %installed;
my $data;
# Valid build targets for the makefile
my $all_targets = {
'domain-server' => { service => 1, service_desc => "Vircadia Domain Server" , service_args => [] },
'assignment-client' => { service => 1, service_desc => "Vircadia Assignment Client", service_args => ["-n", "6"] },
'ice-server' => { service => 1, service_desc => "Vircadia ICE Server" , service_args => [] },
'interface' => { service => 0 },
'atp-client' => { service => 0 },
'oven' => { service => 0 },
'nitpick' => { service => 0 },
'skeleton-dump' => { service => 0 },
'ac-client' => { service => 0 },
'ktx-tool' => { service => 0 },
'ice-client' => { service => 0 },
'gpu-frame-player' => { service => 0 },
'vhacd-util' => { service => 0 }
};
# Libraries that don't go into an AppImage.
# Taken from https://github.com/AppImage/pkg2appimage/blob/master/excludelist
# Trimmed down a bit, as I want a minimum of requirements for installation.
#
# libnss3.so and libnssutil3.so weren't part of the original list and added
# to fix "Error initializing NSS with a persistent database"
my @excluded_system_libs = (
qr/^ld-linux\.so\.2/,
qr/^ld-linux-x86-64\.so\.2/,
# qr/^libanl\.so\.1/,
# qr/^libasound\.so\.2/,
# qr/^libBrokenLocale\.so\.1/,
# qr/^libcidn\.so\.1/,
# qr/^libcom_err\.so\.2/,
qr/^libc\.so\.6/,
qr/^libdl\.so\.2/,
qr/^libdrm\.so\.2/,
qr/^libEGL\.so\.1/,
# qr/^libexpat\.so\.1/,
qr/^libfontconfig\.so\.1/,
qr/^libfreetype\.so\.6/,
qr/^libfribidi\.so\.0/,
# qr/^libgbm\.so\.1/,
qr/^libgcc_s\.so\.1/,
# qr/^libgdk_pixbuf-2\.0\.so\.0/,
# qr/^libgio-2\.0\.so\.0/,
qr/^libglapi\.so\.0/,
qr/^libGLdispatch\.so\.0/,
# qr/^libglib-2\.0\.so\.0/,
qr/^libGL\.so\.1/,
qr/^libGLX\.so\.0/,
# qr/^libgmp\.so\.10/,
# qr/^libgobject-2\.0\.so\.0/,
# qr/^libgpg-error\.so\.0/,
qr/^libharfbuzz\.so\.0/, #fixes crash with freetype 2.11 system libraries
# qr/^libICE\.so\.6/,
# qr/^libjack\.so\.0/,
qr/^libm\.so\.6/,
qr/^libmvec\.so\.1/,
qr/^libnss_compat\.so\.2/,
qr/^libnss_dns\.so\.2/,
qr/^libnss_files\.so\.2/,
qr/^libnss_hesiod\.so\.2/,
qr/^libnss_nisplus\.so\.2/,
qr/^libnss_nis\.so\.2/,
qr/^libnss3\.so/, #added - fixes crash in libsoftokn3.so
qr/^libnssutil3\.so/, #added
qr/^libOpenGL\.so\.0/, #fixes GLVND on different vendor systems
# qr/^libp11-kit\.so\.0/,
# qr/^libpango-1\.0\.so\.0/,
# qr/^libpangocairo-1\.0\.so\.0/,
# qr/^libpangoft2-1\.0\.so\.0/,
qr/^libpthread\.so\.0/,
qr/^libresolv\.so\.2/,
qr/^librt\.so\.1/,
# qr/^libSM\.so\.6/,
qr/^libstdc\+\+\.so\.6/,
# qr/^libthai\.so\.0/,
qr/^libthread_db\.so\.1/,
# qr/^libusb-1\.0\.so\.0/,
qr/^libutil\.so\.1/,
# qr/^libuuid\.so\.1/,
# qr/^libX11\.so\.6/,
# qr/^libxcb-dri2\.so\.0/,
# qr/^libxcb-dri3\.so\.0/,
# qr/^libxcb\.so\.1/,
# qr/^libz\.so\.1/
);
my $optimization_presets = {
native => {
description => "Build code optimized for this specific machine. Not suitable for packaging or copying to other systems.",
flags => '-march=native -mtune=native',
},
compatible => {
description => "Build code optimized for SSE3. This should work on almost anything.",
flags => '-msse3'
},
none => {
description => "Do not perform any CPU-specific optimizations. Suitable for any hardware.",
flags => '-march=x86-64'
}
};
my $appimagetool_release = 13;
my $appimagetool_url = "https://github.com/AppImage/AppImageKit/releases/download/${appimagetool_release}/appimagetool-x86_64.AppImage";
my @x11_lib_paths = ("/usr/lib64", "/usr/X11R6/lib64", "/usr/lib/x86_64-linux-gnu", "/usr/lib");
my @system_qt_paths = ('/usr/lib64/cmake', '/usr/lib/x86_64-linux-gnu/cmake');
# Amount of RAM needed to build Vircadia, per compiler process.
my $mem_per_core_vircadia = 1 * 1024 * 1024;
# Qt has a build stage that consumes a huge amount of RAM. Be a bit conservative here.
my $mem_per_core_qt = 1.2 * 1024 * 1024;
my $repo;
my $qt_repo = "git://code.qt.io/qt/qt5.git";
my $repo_tag;
my $root_dir = "$ENV{HOME}/Vircadia";
my $inst_dir = "$root_dir/install"; # Where files will be installed
my $binary_dir = $inst_dir; # Where the final binaries are found
my $rel_type = "DEV"; # DEV by default.
my $rel_no = "";
my $build_no = "";
my $build_cores;
my $build_cores_qt;
my $optimization_level;
my $desktop;
my $distro;
my $using_system_qt;
my ($opt_keep_source, $opt_auto, $opt_build_qt, $opt_build, $opt_skip_build, $opt_skip_systemd_restart, $opt_no_modify_rpath, $opt_skip_install, $opt_make_appimage, $opt_install_deps_only, $opt_verbose);
my ($opt_qt_debug, $opt_qt_debug_info, $cmd_get_install_dir, $cmd_get_archive_name, $cmd_make_archive, $opt_debug);
my ($cmd_help, $cmd_get_supported, $cmd_get_source_deps, $cmd_get_qt_deps, $cmd_get_system_qt_deps, $cmd_get_qt_version, $cmd_get_qt_patches, $cmd_make_pkglist);
my ($opt_fork, $opt_pr);
$opt_build = "client";
my @build_list;
GetOptions(
"keep-source|K" => \$opt_keep_source,
"help|h" => \$cmd_help,
"auto|y" => \$opt_auto,
"repo|r=s" => \$repo,
"tag|t=s" => \$repo_tag,
"release-type=s" => \$rel_type,
"release-number=s" => \$rel_no,
"build-number=s" => \$build_no,
"destdir|d=s" => \$root_dir,
"cores|j=i" => \$build_cores,
"qt-cores|J=i" => \$build_cores_qt,
"collect-info|C" => \$VircadiaBuilder::Common::collect_system_info,
"distro|D=s" => \$distro,
"build-qt|B" => \$opt_build_qt,
"build|U=s" => \$opt_build,
"get-supported" => \$cmd_get_supported,
"get-source-deps=s" => \$cmd_get_source_deps,
"get-qt-deps=s" => \$cmd_get_qt_deps,
"get-system-qt-deps=s" => \$cmd_get_system_qt_deps,
"get-qt-version=s" => \$cmd_get_qt_version,
"get-qt-patches=s" => \$cmd_get_qt_patches,
"get-install-dir" => \$cmd_get_install_dir,
"get-archive" => \$cmd_get_archive_name,
"make-pkglist" => \$cmd_make_pkglist,
"make-appimage|A" => \$opt_make_appimage,
"make-archive" => \$cmd_make_archive,
"skip-build" => \$opt_skip_build,
"skip-install" => \$opt_skip_install,
"skip-systemd-restart" => \$opt_skip_systemd_restart,
"no-modify-rpath" => \$opt_no_modify_rpath,
"qt-debug" => \$opt_qt_debug,
"qt-debug-info" => \$opt_qt_debug_info,
"install-deps-only" => \$opt_install_deps_only,
"verbose|v" => \$opt_verbose,
"debug" => \$opt_debug,
"optimization-level=s" => \$optimization_level,
"fork|F=s" => \$opt_fork,
"pr|P=s" => \$opt_pr,
) or help(1);
@build_list = parse_build_option($opt_build);
if ( $opt_make_appimage ) {
# If we're building an AppImage, and no level has been manually specified, default to 'compatible'
$optimization_level //= "compatible";
} else {
# Otherwise we build for the local system specifically
$optimization_level //= "native";
}
if (!optimization_preset_is_valid($optimization_level)) {
list_optimization_presets();
exit(1);
}
load_data();
my $custom_fork;
my $fork_name;
if ( $opt_pr ) {
if ( $opt_pr =~ m#https://github.com/vircadia/vircadia/pulls/(\d+)# ) {
$opt_pr = $1;
$opt_fork = "vircadia";
} elsif ( $opt_pr =~ m#https://github.com/overte-org/overte/pull/(\d+)# ) {
$opt_pr = $1;
$opt_fork = "overte";
} elsif ( $opt_pr =~ m#https://github.com/tivolicloud/interface/pull/(\d+)# ) {
$opt_pr = $1;
$opt_fork = "tivoli";
} elsif ( $opt_pr =~ m#https://github.com/(\w+)/(\w+)/pull/(\d+)# ) {
$opt_fork = $1;
$repo = "https://github.com/$1/$2";
$opt_pr = $3;
# This ensures we don't fail due to an unrecognized fork name later.
$custom_fork = 1;
} elsif ( $opt_pr =~ /^(\d+)/ ) {
# Nothing, PR number specified as-is
} else {
die "Invalid argument to --pr. Either pass a PR number, or a full URL to the PR on github";
}
}
if ( !$opt_fork) {
my $exe = basename($0);
if ( $exe =~ /vircadia/i ) {
$opt_fork = "vircadia";
} elsif ( $exe =~ /overte/i ) {
$opt_fork = "overte";
} elsif ( $exe =~ /tivoli/ ) {
$opt_fork = "tivoli";
} else {
warn "--fork not specified, and can't determine fork from filename. Defaulting to vircadia";
$opt_fork = "vircadia";
}
debug("Selected fork $opt_fork based on our filename $0\n");
}
$opt_fork = lc($opt_fork);
if ( $opt_fork eq "vircadia" ) {
$fork_name = "Vircadia";
$repo //= "https://github.com/vircadia/vircadia";
$repo_tag //= "master";
} elsif ( $opt_fork eq "overte" ) {
$fork_name = "Overte";
$repo //= "https://github.com/overte-org/overte";
$repo_tag //= "master";
} elsif ( $opt_fork eq "tivoli" ) {
$fork_name = "Tivoli";
$repo //= "https://github.com/tivolicloud/interface";
$repo_tag //= "main";
} else {
die "Unrecognized fork: $opt_fork" unless ($custom_fork);
}
debug("Fork is $fork_name, repo $repo\n");
$root_dir = "$ENV{HOME}/$fork_name";
$inst_dir = "$root_dir/install"; # Where files will be installed
$binary_dir = $inst_dir; # Where the final binaries are found
help(1) if ($cmd_help);
get_supported() if ( $cmd_get_supported );
get_conf( 'source_dependencies', $cmd_get_source_deps ) if ( $cmd_get_source_deps );
get_conf( 'qt_source_dependencies', $cmd_get_qt_deps ) if ( $cmd_get_qt_deps );
get_conf( 'system_qt_dependencies', $cmd_get_system_qt_deps ) if ( $cmd_get_system_qt_deps );
get_conf( 'qt_version', $cmd_get_qt_version ) if ( $cmd_get_qt_version );
get_conf( 'qt_patches', $cmd_get_qt_patches ) if ( $cmd_get_qt_patches );
make_pkglist() if ( $cmd_make_pkglist );
init_log();
$build_cores //= calculate_cores($fork_name, $mem_per_core_vircadia);
$build_cores_qt //= calculate_cores("Qt", $mem_per_core_qt);
$desktop //= get_desktop();
$distro //= detect_distro();
if ( !exists $data->{$distro} ) {
fatal("No configuration for $distro, distribution unsupported.");
}
my $DD = $data->{$distro};
my %PACKAGES = get_package_list();
set_environment();
# We need to build Qt if:
# A. The user explicitly wants to build it
# B. Both of these are the case:
# * There's no binary package
# * System Qt is not supported.
my $need_to_build_qt = $opt_build_qt || (!$DD->{has_binary_qt_package} && !$DD->{system_qt_dependencies});
install_missing_packages();
exit(0) if ( $opt_install_deps_only );
import_nvm_environment();
collect_info();
unless($opt_skip_build) {
get_source();
$inst_dir = get_install_dir_path();
$binary_dir = $opt_skip_install ? "$root_dir/build" : $inst_dir;
install_qt() if ($need_to_build_qt);
build();
}
# Ensure the paths are set if we didn't build
$inst_dir = get_install_dir_path();
$binary_dir = $opt_skip_install ? "$root_dir/build" : $inst_dir;
setup_qt() if ($need_to_build_qt);
adjust_library_paths() unless ($opt_no_modify_rpath);
if ( $opt_make_appimage ) {
download_appimage_tool();
install_into_appimage();
} elsif ($cmd_make_archive) {
install();
setup_scripts();
create_archive();
} else {
install() unless ($opt_skip_install);
setup_scripts();
setup_services();
setup_desktop();
}
sub load_data {
my $confpath = "$FindBin::Bin/distros";
opendir(my $dfh, $confpath) or die "Can't find distros directory at $confpath";
while(my $filename = readdir($dfh)) {
next if ( -d "$confpath/$filename" );
if ( $filename =~ /.cfg$/ ) {
my $distro_name = basename($filename, ".cfg");
$data->{$distro_name} = do("$confpath/$filename");
}
}
}
sub detect_distro {
info("Detecting distribution... ");
if ( -f "/etc/os-release" ) {
my @release_info = readfile("/etc/os-release");
my %release_data;
debug("Parsing /etc/os-release...\n");
foreach my $line (@release_info) {
my ($k, $v) = $line =~ /^(\w+)=(.*?)$/;
$v =~ s/^"//;
$v =~ s/"$//;
$release_data{$k} = $v;
debug("\t$k => '$v'\n");
}
my $id = $release_data{ID} . "-" . $release_data{VERSION_ID};
my $pretty_name = $release_data{PRETTY_NAME} // ( $release_data{NAME} . " " . $release_data{VERSION} );
if ( $release_data{ID} eq "opensuse-tumbleweed" || $release_data{ID} eq "manjaro" || $release_data{ID} eq "manjaro-arm" ||
$release_data{ID} eq "arch" ) {
$id = $release_data{ID};
# Opensuse Tumbleweed is a rolling release, and VERSION_ID is a timestamp, so it changes
# far too often. For now we're just going to assume that people stay up to date and only
# supporting the latest is needed.
# Manjaro and Arch are rolling release, and VERSION_ID does not exist.
}
if ( $release_data{ID} eq "debian" && $release_data{PRETTY_NAME} =~ m/bookworm/ ) {
$id = "debian-bookworm";
# Debian Bookworm is in testing and therefore doesn't have a VERSION_ID yet.
# While the VERSION_ID will change to "12" in the future, we are using "bookworm"
# here to emphasize that bookworm has not been released yet.
}
info_ok("$pretty_name ($id)\n");
return $id;
}
fatal("Failed to detect distribution! Couldn't find /etc/os-release.");
}
sub get_package_list {
info("Getting the package list... ");
my @packages;
if ( $DD->{package_manager} eq "dnf" || $DD->{package_manager} eq "yum" || $DD->{package_manager} eq "zypper" ) {
@packages = read_from_cmd("rpm", "-qa", "--qf", "%{NAME}\\n");
} elsif ( $DD->{package_manager} eq "apt" ) {
@packages = read_from_cmd("dpkg-query", "--show", "-f", "\${Package}\n");
} elsif ( $DD->{package_manager} eq "pacman" ) {
@packages = read_from_cmd("pacman", "-Qq");
} elsif ( $DD->{package_manager} eq "none" ) {
# Nothing
} else {
fatal("Internal error: unknown package manager " . $DD->{package_manager});
}
chomp @packages;
info_ok("done.\n");
return map { $_ => 1 } @packages;
}
sub set_environment {
if ( exists $DD->{environment} ) {
info("Setting environment... ");
foreach my $var ( keys %{ $DD->{environment} } ) {
$ENV{$var} = $DD->{environment}->{$var};
info_ok("$var ");
}
info_ok("\n");
}
}
sub install_missing_packages {
my @required_packages = @{$DD->{source_dependencies}};
info("Checking Qt availability... ");
if ( $DD->{system_qt_dependencies} && !$need_to_build_qt ) {
info_ok(" system Qt available.\n");
push @required_packages, @{ $DD->{system_qt_dependencies}};
} elsif ( $DD->{has_binary_qt_package} && !$need_to_build_qt) {
info_ok(" binary Qt package available.\n");
} else {
push @required_packages, @{ $DD->{qt_source_dependencies}};
warning(" no system Qt support, nor binary package\n\n");
warning("System Qt is not supported on your system, and there is no binary\n");
warning("Qt package available either.\n\n");
warning("This script will build it for you, but it can take a long time,\n");
warning("up to several hours, depending on hardware capabilities.\n\n");
warning("Fortunately, it only needs to be built once.\n\n");
}
if ( $opt_make_appimage ) {
push @required_packages, @{ $DD->{appimage_dependencies} };
}
info("Checking if any packages need installing... ");
my @missing = grep { !exists $PACKAGES{$_} } @required_packages;
my $failed;
if ( @missing ) {
print scalar(@missing) . " additional packages needed: " . join(", ", @missing) . "\n";
if ( $DD->{package_manager} eq "dnf" ) {
sudo_run("dnf", "install", "-y", @missing);
} elsif ( $DD->{package_manager} eq "yum" ) {
sudo_run("yum", "install", "-y", @missing);
} elsif ( $DD->{package_manager} eq "apt" ) {
$ENV{DEBIAN_FRONTEND} = 'noninteractive';
sudo_run("apt-get", "update");
my $ret = sudo_run({ fail_ok => 1, get_retval => 1 }, "--preserve-env=DEBIAN_FRONTEND", "apt-get", "install", "-y", "--no-remove", @missing);
if ( $ret->{retval} > 0 ) {
$failed = 1;
}
} elsif ( $DD->{package_manager} eq "pacman" ) {
sudo_run("pacman", "-S", "--noconfirm", @missing);
} elsif ( $DD->{package_manager} eq "zypper" ) {
sudo_run("zypper", "--non-interactive", "install", @missing);
} elsif ( $DD->{package_manager} eq "none" ) {
# Nothing
} else {
fatal("Internal error: unknown package manager " . $DD->{package_manager});
}
if ( $failed ) {
warning("\nFailed to install packages\n");
diagnose_package_install_error(@missing);
exit(1);
} else {
info_ok("\nPackages have been installed, please run $0 again.\n\n");
exit(0);
}
} else {
info_ok("no, all " . scalar(@required_packages) . " required packages are present.\n");
}
}
sub diagnose_package_install_error {
my (@packages) = @_;
info("Trying to diagnose package install problem. Please wait, this may take a while.\n");
info("Checking: ");
my @would_remove;
my @other_errors;
foreach my $pkg ( @packages ) {
if ( $DD->{package_manager} eq "dnf" ) {
# TODO
} elsif ( $DD->{package_manager} eq "yum" ) {
# TODO
} elsif ( $DD->{package_manager} eq "apt" ) {
info("$pkg ");
$ENV{DEBIAN_FRONTEND} = 'noninteractive';
my $ret_norem = run({ fail_ok => 1, get_retval => 1, quiet => 1 }, "apt-get", "install", "-y", "--no-remove", "-s", $pkg);
my $ret = run({ fail_ok => 1, get_retval => 1, quiet => 1 }, "apt-get", "install", "-y", "-s", $pkg);
info("(" . $ret_norem->{retval} . "/" . $ret->{retval} . "), ");
if ( $ret_norem->{retval} > 0 && $ret->{retval} == 0 ) {
push @would_remove, $pkg;
} elsif ( $ret->{retval} > 0 ) {
push @other_errors, $pkg;
}
} elsif ( $DD->{package_manager} eq "pacman" ) {
# TODO
} elsif ( $DD->{package_manager} eq "zypper" ) {
# TODO
} elsif ( $DD->{package_manager} eq "none" ) {
# Nothing
} else {
fatal("Internal error: unknown package manager " . $DD->{package_manager});
}
}
info_ok("done\n\n");
if ( @would_remove ) {
warning("Installing these packages would require uninstalling packages from your system: " . join(', ', @would_remove) . "\n");
}
if ( @other_errors ) {
warning("These packages can't be installed in your system: " . join(', ', @other_errors) . "\n");
}
fatal("$0 failed to install required dependencies. Please look at the output above, there may be some clues as to what is the problem.\n".
"Also, try to install any updates to your Linux distribution");
}
sub import_nvm_environment {
# Amazon Linux 2 is a huge pain to deal with. The official instructions as per:
# https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html
# require running a random shell script off the web, and sourcing a script to get the environment vars.
#
# For the sake of user friendliness we'd like to avoid making the user modify their profile.
#
# So we're counting on that install_amazon_linux_deps.sh did the installation work, and then we'll try
# and import the environment into our process by calling nvm.sh, env, and parsing that.
info("Checking for NPM... ");
if (!-x "/usr/bin/npm" && !-x "/usr/local/bin/npm") {
if ( -f "$ENV{HOME}/.nvm/nvm.sh" ) {
info_ok("NVM found, importing environment... ");
my $shell;
my $var_data;
# On Ubuntu 18.04, /bin/sh is dash, which doesn't recognize the source command.
# We try and force using bash if at all possible. If that doesn't work, we'll
# try whatever Perl wants to invoke, but that might not work.
foreach my $sh (qw(/bin/bash /usr/bin/bash)) {
if ( -x "$sh") {
$shell = $sh;
info_ok("Found bash in $sh; ");
}
}
if ( $shell ) {
$var_data = run({keep_buf => 1}, $shell, "-c", "source \"$ENV{HOME}/.nvm/nvm.sh\" && env --null");
} else {
warning("Failed to find bash, this might fail;");
$var_data = run({keep_buf => 1}, "source \"$ENV{HOME}/.nvm/nvm.sh\" && env --null");
}
foreach my $var_line (split(/\0/, $var_data)) {
chomp $var_line;
my ($k, $v) = split(/=/, $var_line);
if ( $k =~ /^NVM/ || $k eq "PATH" ) {
# Import NVM_* and PATH variables to our local environment
info_ok("$k ");
debug("$k => $v");
$ENV{$k} = $v;
}
}
if ( $ENV{PATH} =~ /\.nvm/ ) {
# Sanity check
info_ok("imported, looks good.\n");
} else {
warning("imported, may not have worked.\n");
}
} else {
warning("Not found installed, NPM not found. Build may fail.\n");
}
} else {
info_ok("Found installed, all good.\n");
}
}
sub collect_info {
require Term::ReadLine;
info("\n");
important("Everything seems to be in order. I am going to ask you some questions now.\n");
important("The defaults should be just fine. Simply press ENTER to accept the suggested\n");
important("value.\n\n");
important("By default, the code will be compiled to target your specific hardware.\n");
important("If you are going to deploy this build on another machine, choose the 'compatible'\n");
important("optimization level. It will be automatically selected by default for AppImage builds.\n\n");
my $opt_levels = "";
foreach my $lvl ( sort keys %$optimization_presets ) {
$opt_levels .= ", " if ($opt_levels);
$opt_levels .= $lvl;
}
$opt_levels .= "or help";
my $rl = Term::ReadLine->new('vircadia_setup');
my $ok = $opt_auto ? "yes" : "no";
while($ok ne "yes") {
$repo = $rl->readline("Git repository : ", $repo);
$repo_tag = $rl->readline("Git tag : ", $repo_tag);
$rel_type = $rl->readline("Release type : ", $rel_type);
$rel_no = $rl->readline("Release number : ", $rel_no);
$build_no = $rl->readline("Build number : ", $build_no);
$root_dir = $rl->readline("Installation dir : ", $root_dir);
$build_cores = $rl->readline("CPU cores to use for $fork_name: ", $build_cores);
$build_cores_qt = $rl->readline("CPU cores to use for Qt5 : ", $build_cores_qt);
my $first_time=1;
while( $first_time || !optimization_preset_is_valid($optimization_level)) {
$optimization_level = $rl->readline("Optimization level ($opt_levels): ", $optimization_level);
if (!optimization_preset_is_valid($optimization_level)) {
list_optimization_presets();
}
undef $first_time;
}
info("\n");
$ok = $rl->readline("If the above is okay, say 'yes' to begin installation: ", "yes");
}
if ( defined $rel_no ) {
$ENV{RELEASE_NUMBER} = $rel_no;
}
if ( defined $build_no ) {
$ENV{BUILD_NUMBER} = $build_no;
}
if ( lc($rel_type) eq "production" ) {
$ENV{RELEASE_TYPE} = 'PRODUCTION';
$ENV{PRODUCTION_BUILD} = 1;
$ENV{USE_STABLE_GLOBAL_SERVICES} = 1;
$ENV{BUILD_GLOBAL_SERVICES} = 'STABLE';
}
if ( lc($rel_type) eq "pr" ) {
$ENV{RELEASE_TYPE} = 'PR';
$ENV{PR_BUILD} = 1;
}
if ( lc($rel_type) eq "dev" ) {
$ENV{RELEASE_TYPE} = 'DEV';
$ENV{DEV_BUILD} = 1;
$ENV{BUILD_GLOBAL_SERVICES} = 'DEVELOPMENT';
}
}
sub get_source {
info("\n\n");
important("############################################################\n");
important("# Starting installation\n");
important("############################################################\n");
info("\n");
mkdir($root_dir);
get_source_from_git($repo, "source", $repo_tag, no_submodules => 0, pr => $opt_pr);
}
sub build {
info("\n\n");
important("############################################################\n");
important("# Building\n");
important("############################################################\n");
info("\n");
if ( $DD->{system_qt_dependencies} ) {
important("Using system Qt\n");
$ENV{VIRCADIA_USE_SYSTEM_QT} = 1;
$ENV{OVERTE_USE_SYSTEM_QT} = 1;
$using_system_qt = 1;
} elsif ( check_qt_install() ) {
important("Using compiled Qt\n");
$ENV{QT_CMAKE_PREFIX_PATH}="$root_dir/qt5-install/lib/cmake";
# hifi_qt.py in the master merge branch looks for Qt in:
# $HIFI_QT_BASE/$VIRCADIA_USE_QT_VERSION/qt5-install
#
# We do a horrid hack here, where $VIRCADIA_USE_QT_VERSION is
# an empty string, but still has a value, and $HIFI_QT_BASE
# points to the root dir, where a qt5-install directory happens
# to exist.
#
# This will be redone later, once the merge is complete and a
# less ugly way of specifying an external Qt can be introduced.
$ENV{VIRCADIA_USE_PREBUILT_QT}=1;
$ENV{VIRCADIA_USE_QT_VERSION}="";
$ENV{OVERTE_USE_PREBUILT_QT}=1;
$ENV{OVERTE_USE_QT_VERSION}="";
$ENV{HIFI_QT_BASE} = "$root_dir";
# Finally, the single, clean solution to the issue, after PR #936
# The above is obsolete, and can be removed after a while.
# Suggested cleanup date: Jan 1, 2022.
$ENV{VIRCADIA_QT_PATH} = "$root_dir/qt5-install";
$ENV{OVERTE_QT_PATH} = "$root_dir/qt5-install";
}
$ENV{HIFI_VCPKG_BASE} = "$root_dir/vcpkg";
if ( -d "$root_dir/build" ) {
run("rm", "-rf", "$root_dir/build");
}
mkdir("$root_dir/build");
chdir("$root_dir/build");
my @cmake_extra_opts;
if ( $opt_debug ) {
push @cmake_extra_opts, "-DVIRCADIA_OPTIMIZE=0";
} else {
if ( exists $optimization_presets->{$optimization_level} ) {
push @cmake_extra_opts, "-DVIRCADIA_CPU_ARCHITECTURE=" . $optimization_presets->{$optimization_level}->{flags};
}
}
run($DD->{cmake}, "../source", @cmake_extra_opts);
my @make_extra_opts;
if ( $opt_verbose ) {
push @make_extra_opts,"VERBOSE=1"
}
foreach my $target (@build_list) {
important("Building target $target\n");
run("make", $target, "-j${build_cores}", @make_extra_opts);
}
if (!$using_system_qt) {
# The one in lib/ doesn't have a rpath, which causes quazip to link against system Qt, which causes interface to link against
# both system Qt and custom Qt. This leads to problems.
#
# This probably needs a cmake fix. See https://github.com/vircadia/vircadia/issues/308
info("Checking for libquazip linking issue... ");
my ($quazip_in_lib) = grep { -f $_ && ! -l $_ } glob("$root_dir/build/ext/makefiles/quazip/project/lib/libquazip5.so*");
my ($quazip_in_build) = grep { -f $_ && ! -l $_ } glob("$root_dir/build/ext/makefiles/quazip/project/build/libquazip5.so*");
if ( $quazip_in_lib && $quazip_in_build ) {
my $lib_rpath = read_from_cmd("patchelf", "--print-rpath", $quazip_in_lib); chomp $lib_rpath;
my $build_rpath = read_from_cmd("patchelf", "--print-rpath", $quazip_in_build); chomp $build_rpath;
if ( $lib_rpath eq "" && $build_rpath ne "" ) {
cp($quazip_in_build, $quazip_in_lib) or fatal("Can't copy $quazip_in_build to $quazip_in_lib");
info_ok("issue found, corrected\n");
} else {
info_ok("everything looks okay\n");
}
} else {
warning("lib/libquazip5.so* not found; ") unless ($quazip_in_lib);
warning("build/libquazip5.so* not found; ") unless ($quazip_in_build);
info_ok("skipping\n");
}
}
}
sub adjust_library_paths {
info("\n\n");
important("############################################################\n");
important("# Adjusting library paths\n");
important("############################################################\n");
info("\n");
chdir("$root_dir/build");
find(\&adjust_libs_search_func, "$root_dir/build");
}
sub install {
info("\n\n");
important("############################################################\n");
important("# Installing\n");
important("############################################################\n");
info("\n");
info("Copying files to install directory...\n");
find({ follow => 1,
follow_skip => 2,
wanted => sub { install_search_func("$root_dir/build", $inst_dir, "link") }},
"$root_dir/build");
#find({ follow => 1, follow_skip => 2, wanted => \&install_search_func }, "$root_dir/build");
# Clear line
info( "\r" . (" " x $prev_len) . "\r");
info("Cleaning up install directory...");
find(\&install_clean_func, $inst_dir);
info_ok("done\n");
info("Copied : "); info_ok("$inst_copied\n");
info("Skipped: "); info_ok("$inst_skipped\n");
info("Deleted: "); info_ok("$inst_deleted\n");
}
sub create_archive {
info("\n\n");
important("############################################################\n");
important("# Creating achive\n");
important("############################################################\n");
info("\n");
if (!exists $DD->{packaging}) {
fatal("Packaging not implemented for this distribution");
}
my $archive = VircadiaBuilder::Package::Archive->new();
$archive->set_version( get_source_version() );
$archive->set_install_dir( $inst_dir );
$archive->set_packaging_data( $DD->{packaging} );
$archive->set_targets( @build_list );
my $dest_file = $archive->get_output_file();
info("Writing into $dest_file... ");
if ( $archive->build() ) {
my $size = int((-s $dest_file) / (1024*1024));
info_ok("done, $size MiB written.\n");
} else {
error("Failed!");
}
}
sub install_search_func {
my ($source, $destination, $method) = @_;
my $abspath = $File::Find::name;
my $relpath = File::Spec->abs2rel($abspath, $source);
my $file = $_;
info( "\r" . (" " x $prev_len) . "\r". $relpath );
$prev_len = length($relpath);
my $keep;
my $skip;
# All libraries are to be kept
$keep = 1 if ( $file =~ /\.so$/ || $file =~ /\.so\.\d+$/ || $file =~ /\.so\.\d+\.\d+/ || $file =~ /\.so\.\d+\.\d+\.\d+/ );
# Otherwise, nothing from the ext directory is to be kept
$skip = 1 if ( $relpath =~ /^ext\// );
$skip = 1 if ( $relpath =~ /.cmake$/ || $relpath =~ /CMake/ || $relpath =~ /_CPack_Packages/ );
$skip = 1 if ( $relpath =~ "Makefile" );
$skip = 1 if ( $relpath =~ /_autogen/ );
$skip = 1 if ( $relpath =~ /\.h$/ || $relpath =~ /\.cpp$/ );
$skip = 1 if ( $relpath =~ /_env/ );
$skip = 1 if ( $relpath =~ /interface_manifest.txt/ );
if ( $keep || !$skip) {
if ( -f $abspath ) {
my $reldir = dirname($relpath);
debug("COPY: '$abspath' => '$destination/$relpath'\n");
mkdir_path("$destination/$reldir");
unlink("$destination/$relpath") if ( -e "$destination/$relpath" );
if ( -l $abspath ) {
# Turns out that trying to make a hardlink of a symlink copies the symlink
if ( $method eq "copy" ) {
symlink(readlink($abspath), "$destination/$relpath");
} elsif ( $method eq "link" ) {
link(readlink($abspath), "$destination/$relpath") or die "Can't link " . readlink($abspath) . " to $destination/$relpath: $!";
} else {
fatal("Unrecognized install method: $method");
}
} else {
if ( $method eq "copy" ) {
cp($abspath, "$destination/$relpath") or die "Can't copy $abspath to $destination/$relpath: $!";
} elsif ( $method eq "link" ) {
link($abspath, "$destination/$relpath") or die "Can't link $abspath to $destination/$relpath: $!";
} else {
fatal("Unrecognized install method: $method");
}
}
$installed{$relpath} = 1;
$inst_copied++;
}
} else {
debug("SKIP: '$abspath'\n");
$inst_skipped++;
}
}