-
Notifications
You must be signed in to change notification settings - Fork 52
/
run-boost-tests
executable file
·1176 lines (978 loc) · 35.2 KB
/
run-boost-tests
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 ruby
# Copyright (c) 2011-2016 CrystaX.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY CrystaX ''AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CrystaX OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are those of the
# authors and should not be interpreted as representing official policies, either expressed
# or implied, of CrystaX.
require 'optparse'
require 'securerandom'
require 'open3'
require 'pathname'
require_relative 'lib/log'
Encoding.default_external = Encoding::UTF_8
ENV['LANG'] = 'en_US.UTF-8'
ENV['LC_ALL'] = ENV['LANG']
module Enumerable
def deep_freeze
unless self.is_a? String
frozen = self.dup.each do |key, value|
if (value.is_a?(Enumerable) && !value.is_a?(String))
value.deep_freeze
else
value.freeze
end
end
self.replace(frozen)
end
self.freeze
end
end
class Hash
def deep_freeze
frozen = self.dup.each do |key, value|
if (value.is_a?(Enumerable) && !value.is_a?(String))
value.deep_freeze
else
value.freeze
end
end
self.replace(frozen)
self.freeze
end
end
OPTIONS = {}
OPTIONS[:testdir] = File.join(ENV['HOME'], '.crystax', 'boost')
OPTIONS[:ndk] = File.expand_path('../..', __FILE__)
OPTIONS[:stdlib] = 'gnu'
OPTIONS[:lines_num_threshold] = 5000
optparser = OptionParser.new do |o|
o.banner = <<-EOF
Test Boost libraries with CrystaX NDK.
This requires a temporary NDK installation containing toolchain binaries for all target architectures.
By default, this will try with the current NDK directory, unless you use the --ndk-dir=<path> option.
EOF
o.separator "\nCommon options:\n\n"
o.on("-h", "--help", "Show help screen and exit") do
puts optparser
exit 0
end
OPTIONS[:verbose] = false
o.on("-v", "--[no-]verbose", "Enable verbose mode [#{OPTIONS[:verbose]}]") do |v|
OPTIONS[:verbose] = v
end
begin
case RUBY_PLATFORM
when /linux/
numcpus = File.read("/proc/cpuinfo").split("\n").select { |l| l =~ /^processor\b/ }.size
when /darwin/
numcpus = `sysctl -n hw.ncpu`.chomp.to_i
end
OPTIONS[:jobs] = numcpus * 2
rescue
OPTIONS[:jobs] = 1
end
o.on("-jN", "--jobs=N", Integer, "Use specified number of build jobs") do |j|
OPTIONS[:jobs] = j
end
OPTIONS[:log] = ENV['NDK_LOGFILE'] || File.join(OPTIONS[:testdir], 'test.log')
o.on("-l", "--log=FILE", "Log file [#{OPTIONS[:log]}]") do |l|
OPTIONS[:log] = File.expand_path(l)
end
OPTIONS[:print_timestamps] = true
o.on("--[no-]print-timestamps", "Print timestamps in log [#{OPTIONS[:print_timestamps]}]") do |p|
OPTIONS[:print_timestamps] = p
end
o.separator "\nRequired parameters:\n\n"
o.on("--runner=RUNNER", "Explicit runner name") do |r|
OPTIONS[:runner] = r
end
o.separator "\nOptional parameters:\n\n"
o.on("--ndk-dir=PATH", "Specify NDK root path for the build [#{OPTIONS[:ndk]}]") do |p|
OPTIONS[:ndk] = File.expand_path(p)
end
o.on("--test-dir=PATH", "Specify test directory [#{OPTIONS[:testdir]}]") do |p|
OPTIONS[:testdir] = File.expand_path(p)
end
OPTIONS[:abis] = ['armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'x86', 'mips', 'arm64-v8a', 'x86_64', 'mips64']
o.on("--abis=LIST", Array, "Specify list of target ABIs [#{OPTIONS[:abis].join(',')}]") do |a|
OPTIONS[:abis] = a
end
OPTIONS[:adb] = 'adb'
o.on("--adb=PATH", "Specify which adb to use [#{OPTIONS[:adb]}]") do |p|
OPTIONS[:adb] = File.expand_path(p)
end
o.on("--libraries=LIST", Array, "Explicit list of libraries to test [all]") do |l|
OPTIONS[:libraries] = l
end
OPTIONS[:device_path] = "/data/local/tmp/boost-#{SecureRandom.uuid}"
o.on("--device-path=PATH", "Path on device where to push files [#{OPTIONS[:device_path]}]") do |p|
OPTIONS[:device_path] = p
end
OPTIONS[:pie] = true
o.on("--[no-]pie", "Produce PIE-enabled binaries to test [#{OPTIONS[:pie]}]") do |p|
OPTIONS[:pie] = false
end
OPTIONS[:fetch_sources] = true
o.on("--skip-fetch-sources", "Skip fetch&update of Boost sources [#{!OPTIONS[:fetch_sources]}]") do
OPTIONS[:fetch_sources] = false
end
OPTIONS[:publish] = false
o.on("--publish-results", "Publish test results, uploading them to the public FTP [#{OPTIONS[:publish]}]") do
OPTIONS[:publish] = true
end
OPTIONS[:toolchain_versions] = Dir.glob(File.join(OPTIONS[:ndk], 'build', 'core', 'toolchains', '*')).select do |e|
File.directory?(e) && File.exists?(File.join(e, 'setup.mk')) && File.exists?(File.join(e, 'config.mk'))
end.map { |e| File.basename(e) }.reject do |e|
end.reject do |e|
# Reject aaa-bbb-ccc-clang toolchains. All clang toolchains must end with version number,
# such as arm-linux-androideabi-clang3.8
File.basename(e) =~ /clang$/
end.map do |e|
e.sub(/^.*-([^-]+)$/, '\1')
end.sort.uniq.map { |e| e.sub(/^(\d.*)$/, 'gcc\1') }.select { |e| e =~ /^(gcc|clang)/ }
o.on("--toolchain-versions=LIST", Array, "Toolchain versions [#{OPTIONS[:toolchain_versions].join(',')}]") do |l|
OPTIONS[:toolchain_versions] = l
end
OPTIONS[:tag] = 'master'
o.on("--tag=TAG", "Boost tag to test ('master' or 'develop') [#{OPTIONS[:tag]}]") do |t|
OPTIONS[:tag] = t
end
OPTIONS[:timeout] = 15
o.on("--timeout=VALUE", "Timeout for one separate test in minutes [#{OPTIONS[:timeout]}]") do |t|
OPTIONS[:timeout] = t
end
o.on("--std=STD", "Use specified C++ standard to build tests") do |s|
OPTIONS[:std] = s
end
o.on("--stdlib=STDLIB", "Use specified C++ Standard Library to build tests [#{OPTIONS[:stdlib]}]") do |s|
OPTIONS[:stdlib] = s
end
o.on("--emulator-tag=TAG", "Run tests only on emulators matching specified tag") do |t|
OPTIONS[:emulator_tag] = t
end
o.on("--runner-comment-header=FILE", "Header of runner comment") do |h|
OPTIONS[:runner_comment_header] = File.expand_path(h)
end
o.on("--runner-comment-footer=FILE", "Footer of runner comment") do |f|
OPTIONS[:runner_comment_footer] = File.expand_path(f)
end
OPTIONS[:boost_url] = 'https://github.com/boostorg/boost'
o.on("--boost-url=URL", "Use alternative git URL for Boost sources [#{OPTIONS[:boost_url]}]") do |u|
OPTIONS[:boost_url] = u
end
OPTIONS[:boost_build_url] = 'https://github.com/boostorg/build.git'
o.on("--boost-build-url=URL", "Use alternative git URL for Boost.Build sources [#{OPTIONS[:boost_build_url]}]") do |u|
OPTIONS[:boost_build_url] = u
end
OPTIONS[:boost_regression_url] = 'https://github.com/boostorg/regression.git'
o.on("--boost-regression-url=URL", "Use alternative git URL for Boost.Regression sources [#{OPTIONS[:boost_regression_url]}]") do |u|
OPTIONS[:boost_regression_url] = u
end
o.on("--lines-num-threshold=N", Integer) do |n|
OPTIONS[:lines_num_threshold] = n
end
end
optparser.parse!(ARGV)
if !ARGV.empty?
$stderr.puts "ERROR: Unknown options: #{ARGV.join(" ")}"
$stderr.puts ""
$stderr.puts optparser
exit 1
end
OPTIONS.deep_freeze
if OPTIONS[:runner].nil?
$stderr.puts "ERROR: Runner name is not specified"
$stderr.puts ""
$stderr.puts optparser
exit 1
end
case OPTIONS[:tag]
when 'master', 'develop'
# OK
else
$stderr.puts "ERROR: Wrong tag value: '#{OPTIONS[:tag]}'"
exit 1
end
case OPTIONS[:stdlib]
when 'gnu', 'llvm'
# OK
else
$stderr.puts "ERROR: Wrong 'stdlib': '#{OPTIONS[:stdlib]}'"
exit 1
end
if OPTIONS[:lines_num_threshold] <= 0
$stderr.puts "ERROR: Wrong lines-num-threshold value: '#{OPTIONS[:lines_num_threshold]}'"
exit 1
end
REGRESSION_DIR = File.join(OPTIONS[:testdir], OPTIONS[:tag], 'regression')
BOOST_SRCDIR = File.join(OPTIONS[:testdir], OPTIONS[:tag], 'src', 'boost')
BOOST_BB_SRCDIR = File.join(OPTIONS[:testdir], OPTIONS[:tag], 'src', 'boost_bb')
BOOST_RR_SRCDIR = File.join(OPTIONS[:testdir], OPTIONS[:tag], 'src', 'boost_rr')
WLOG = "/tmp/wrappers-#{SecureRandom.uuid}.log"
at_exit { FileUtils.rm_f WLOG }
FileUtils.rm_f WLOG
FileUtils.touch WLOG
FileUtils.mkdir_p OPTIONS[:testdir]
Log.timestamps = OPTIONS[:print_timestamps]
Log.add StdLogger.new(OPTIONS[:verbose] ? Log::DEBUG : Log::NOTICE)
Log.add FileLogger.new(OPTIONS[:log], Log::DEBUG) if OPTIONS[:log]
def elapsed(seconds)
s = seconds % 60
m = (seconds / 60) % 60
h = seconds / 3600
"%d:%02d:%02d" % [h,m,s]
end
def run(*args, &block)
env = args.first.is_a?(Hash) ? args.shift : {}
options = args.last.is_a?(Hash) ? args.pop : {}
cmd = args.map { |a| a =~ /\s+/ ? "'#{a}'" : a }.join(' ')
Log.info "## COMMAND: #{cmd}"
Open3.popen3(env, *args, options) do |i,o,e,t|
if block_given?
yield i,o,e
else
i.close
{o => '>', e => '*'}.map do |io,s|
Thread.start do
while line = io.gets.chomp rescue nil
Log.info " #{s} #{line}"
end
end
end.each(&:join)
end
t.join
raise "'#{cmd}' failed with exit code #{t.value.to_i}" unless t.value.success?
end
end
def fetch(url, dir, branch)
Log.info "=== Fetching #{url} to #{dir} (branch #{branch})"
FileUtils.mkdir_p(dir) if !File.directory?(dir)
FileUtils.cd(dir) do
run 'git', 'init' unless File.exists?(File.join(dir, '.git'))
run 'git', 'config', 'remote.origin.url', url
run 'git', 'config', 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*'
run 'git', 'fetch', '--prune', 'origin'
run 'git', 'reset', '--hard'
run 'git', 'clean', '-ffddx'
['git reset --hard', 'git clean -ffddx'].each do |cmd|
run 'git', 'submodule', 'foreach', '--recursive', cmd
end
sha1, e, s = Open3.capture3("git rev-parse --verify origin/#{branch}")
raise e unless s.success?
sha1.chomp!
raise "Can't detect SHA1 of branch #{branch}" if sha1.empty?
run 'git', 'checkout', '-q', '-f', sha1
run 'git', 'branch', '-D', branch rescue nil
run 'git', 'checkout', '-b', branch
run 'git', 'submodule', 'init'
run 'git', 'submodule', 'sync', '--recursive'
run 'git', 'submodule', 'update', '--recursive'
end
end
def rm_rf(path)
if File.directory?(path)
run("rm -Rfv #{path}") do |i,o,e|
i.close
ot = Thread.start do
cnt = 0
total = 0
while !o.gets.nil?
cnt += 1
next if cnt < OPTIONS[:lines_num_threshold]
total += cnt
cnt = 0
Log.info "#{total} files removed"
end
Log.info "#{total + cnt} files removed" if cnt > 0
end
et = Thread.start do
while line = e.gets
Log.info " * #{line}"
end
end
ot.join
et.join
end
else
FileUtils.rm_rf path
end
end
def fetch_boost_impl(url, dir, branch, name)
max_attempts = 6
max_attempts.times do |i|
attempt = i + 1
begin
Log.notice "Fetching #{name} sources (attempt ##{attempt})"
fetch url, dir, branch
return true
rescue => err
Log.warning "Can't fetch #{url} to #{dir} (attempt ##{attempt}): #{err.message}"
rm_rf dir
sleep attempt * 30
end
end
raise "Can't fetch #{url} to #{dir} with #{max_attempts} attempts due to continuous errors"
end
def fetch_boost(dir)
fetch_boost_impl OPTIONS[:boost_url], dir, OPTIONS[:tag], "Boost"
end
def fetch_boost_bb(dir)
fetch_boost_impl OPTIONS[:boost_build_url], dir, 'develop', "Boost.Build"
end
def fetch_boost_rr(dir)
fetch_boost_impl OPTIONS[:boost_regression_url], dir, 'develop', "Boost.Regression"
end
def fetch_all
if OPTIONS[:fetch_sources]
fetch_boost BOOST_SRCDIR
fetch_boost_bb BOOST_BB_SRCDIR
fetch_boost_rr BOOST_RR_SRCDIR
else
raise "Boost sources are not fetched" unless File.directory?(BOOST_SRCDIR)
raise "Boost.Build sources are not fetched" unless File.directory?(BOOST_BB_SRCDIR)
raise "Boost.Regression sources are not fetched" unless File.directory?(BOOST_RR_SRCDIR)
end
end
def generate_toolchain(abi, type, version, dir)
apilevel = ['arm64-v8a', 'x86_64', 'mips64'].include?(abi) ? 21 : 9
tcname = case abi
when /^armeabi/
'arm-linux-androideabi'
when /^arm64/
'aarch64-linux-android'
when 'mips'
'mipsel-linux-android'
when 'mips64'
'mips64el-linux-android'
when 'x86', 'x86_64'
abi
else
raise "Unknown ABI: #{abi}"
end
tcprefix = case abi
when 'x86'
'i686-linux-android'
when 'x86_64'
'x86_64-linux-android'
else
tcname
end
llvmtripple = case abi
when 'armeabi'
'armv5te-none-linux-androideabi'
when /^armeabi-v7a/
'armv7-none-linux-androideabi'
when /^arm64/
'aarch64-none-linux-android'
when 'x86'
'i686-none-linux-android'
when 'x86_64'
'x86_64-none-linux-android'
when 'mips'
'mipsel-none-linux-android'
when 'mips64'
'mips64el-none-linux-android'
else
raise "Unknown ABI: #{abi}"
end
arch = case abi
when /^armeabi/
'arm'
when /^arm64/
'arm64'
else
abi
end
flags = []
ldflags = []
case abi
when 'armeabi'
flags += ['-march=armv5te', '-mtune=xscale', '-msoft-float']
when 'armeabi-v7a'
flags += ['-march=armv7-a', '-mfpu=vfpv3-d16', '-mfloat-abi=softfp']
ldflags << '-Wl,--fix-cortex-a8'
when 'armeabi-v7a-hard'
flags += ['-march=armv7-a', '-mfpu=vfpv3-d16', '-mhard-float']
ldflags << '-Wl,--fix-cortex-a8'
ldflags << '-Wl,--no-warn-mismatch'
when 'x86'
flags << '-m32'
when 'x86_64'
flags << '-m64'
when 'mips'
flags += ['-mabi=32', '-mips32']
when 'mips64'
flags += ['-mabi=64', '-mips64r6']
end
case RUBY_PLATFORM
when /linux/
hostos = 'linux'
when /darwin/
hostos = 'darwin'
else
raise "Unsupported host platform: #{RUBY_PLATFORM}"
end
hosttag = "%s-%s" % [hostos, `uname -m`.chomp]
case type
when :gcc
gcc_version = version
llvm_version = `/bin/bash -c 'source #{OPTIONS[:ndk]}/build/instruments/dev-defaults.sh && echo $DEFAULT_LLVM_VERSION'`.split("\n").first
gnulibcxx_version = gcc_version
llvmlibcxx_version = llvm_version
gcctcpath = File.join(OPTIONS[:ndk], 'toolchains', "#{tcname}-#{gcc_version}", 'prebuilt', hosttag)
ccs = ['gcc', 'g++']
when :clang
llvm_version = version
gcc_version = `/bin/bash -c 'source #{OPTIONS[:ndk]}/build/instruments/dev-defaults.sh && echo $DEFAULT_GCC_VERSION'`.split("\n").first
gnulibcxx_version = gcc_version
llvmlibcxx_version = llvm_version
gcctcpath = File.join(OPTIONS[:ndk], 'toolchains', "#{tcname}-#{gcc_version}", 'prebuilt', hosttag)
llvmtcpath = File.join(OPTIONS[:ndk], 'toolchains', "llvm-#{llvm_version}", 'prebuilt', hosttag)
ccs = ['clang', 'clang++']
flags << "-fno-integrated-as"
else
raise "Unknown toolchain type: #{type.inspect}"
end
sysroot = File.join(OPTIONS[:ndk], 'platforms', "android-#{apilevel}", "arch-#{arch}")
libcrystax = File.join(OPTIONS[:ndk], 'sources', 'crystax')
gnulibcxx = File.join(OPTIONS[:ndk], 'sources', 'cxx-stl', 'gnu-libstdc++', gnulibcxx_version)
llvmlibcxx = File.join(OPTIONS[:ndk], 'sources', 'cxx-stl', 'llvm-libc++', llvmlibcxx_version)
llvmlibcxxabi = File.join(OPTIONS[:ndk], 'sources', 'cxx-stl', 'llvm-libc++abi')
compilerrt = File.join(OPTIONS[:ndk], 'sources', 'android', 'compiler-rt')
flags << "--sysroot=#{sysroot}"
flags << "-fPIC"
if OPTIONS[:pie]
flags << "-fPIE"
ldflags << "-pie"
end
flags << '-g'
ldlibs = []
case OPTIONS[:stdlib]
when 'gnu'
libcxx_incdirs = [
File.join(gnulibcxx, 'include'),
File.join(gnulibcxx, 'include', 'backward'),
File.join(gnulibcxx, 'libs', abi, 'include'),
]
libcxx_libdir = File.join(gnulibcxx, 'libs', abi)
ldlibs << 'gnustl_shared'
when 'llvm'
libcxx_incdirs = [
File.join(llvmlibcxx, 'libcxx', 'include'),
File.join(llvmlibcxxabi, 'libcxxabi', 'include'),
]
libcxx_libdir = File.join(llvmlibcxx, 'libs', abi)
ldlibs << 'c++_shared'
end
ldlibs << 'compiler_rt_static' if type == :clang
ccs.each do |cc|
tool = File.join(dir, "#{cc}-#{version}")
FileUtils.mkdir_p File.dirname(tool)
File.open(tool, 'w') do |f|
f.puts <<-EOF
#!/usr/bin/env ruby
require 'fileutils'
LINKER = !ARGV.include?('-c') && !ARGV.include?('-emit-pth')
# Remove any wrong input parameters
$args = ARGV.reject { |a| ['-m32', '-m64', '-pthread', '-lpthread', '-lutil', '-lrt'].include?(a) }
$target = nil
if LINKER
next_arg_is_target = false
$args.each do |a|
$target = a if next_arg_is_target
next_arg_is_target = (a == '-o')
end
end
$flags = []
$flags += #{flags.inspect}
def add_libpath(d)
$flags << ('-L%s' % d)
File.open('%s.ldlp' % $target, 'a') do |f|
f.puts d
end unless $target.nil?
end
if LINKER
$flags += #{ldflags.inspect}
FileUtils.rm_f('%s.ldlp' % $target) unless $target.nil?
add_libpath '#{File.join(libcrystax, 'libs', abi)}'
add_libpath '#{libcxx_libdir}'
$flags << '-L#{File.join(compilerrt, 'libs', abi)}'
else
$flags += [#{libcxx_incdirs.map { |e| "'#{e}'" }.join(',')}].map { |e| '-I%s' % e }
$flags << '-Wno-long-long'
end
$args = $flags + $args
$args += #{ldlibs.map { |l| "-l#{l}" }.inspect} if LINKER && !$target.nil?
def run(*a)
File.open('#{WLOG}', 'a') do |f|
f.flock(File::LOCK_EX)
f.puts '## COMMAND: %s' % a.join(' ')
end
Kernel.exec(*a)
end
EOF
case type
when :gcc
exe = File.join(gcctcpath, 'bin', "#{tcprefix}-#{cc}")
f.puts "run('#{exe}', *$args)"
when :clang
exe = File.join(llvmtcpath, 'bin', cc)
f.puts "run('#{exe}', '-target', '#{llvmtripple}', '-gcc-toolchain', '#{gcctcpath}', *$args)"
else
raise "Wrong toolchain type: #{type.inspect}"
end
end
FileUtils.chmod "a+x", tool
end
['ar', 'as'].each do |t|
tool = File.join(dir, t)
FileUtils.mkdir_p File.dirname(tool)
File.open(tool, 'w') do |f|
f.puts <<-EOF
#!/usr/bin/env ruby
def run(*a)
File.open('#{WLOG}', 'a') do |f|
f.flock(File::LOCK_EX)
f.puts '## COMMAND: %s' % a.join(' ')
end
Kernel.exec(*a)
end
EOF
case type
when :gcc
f.puts "run '#{File.join(gcctcpath, 'bin', "#{tcprefix}-#{t}")}', *ARGV"
when :clang
f.puts "run '#{File.join(llvmtcpath, 'bin', "llvm-#{t}")}', *ARGV"
else
raise "Wrong toolchain type: #{type.inspect}"
end
end
FileUtils.chmod "a+x", tool
end
['ranlib', 'strip'].each do |t|
tool = File.join(dir, t)
FileUtils.mkdir_p File.dirname(tool)
File.open(tool, 'w') do |f|
f.puts <<-EOF
#!/usr/bin/env ruby
def run(*a)
File.open('#{WLOG}', 'a') do |f|
f.flock(File::LOCK_EX)
f.puts '## COMMAND: %s' % a.join(' ')
end
Kernel.exec(*a)
end
run '#{File.join(gcctcpath ,'bin', "#{tcprefix}-#{t}")}', *ARGV
EOF
end
FileUtils.chmod "a+x", tool
end
end
def generate_adbrunner(abi, dir, strip)
libdir = File.join(dir, 'lib')
FileUtils.rm_rf libdir
adbrunner = File.join(dir, 'adbrunner')
FileUtils.mkdir_p File.dirname(adbrunner)
File.open(adbrunner, 'w') do |f|
f.puts <<-EOF
#!/usr/bin/env ruby
skip = ['bcp-test']
exe = File.basename(ARGV.first) rescue nil
File.open('#{WLOG}', 'a') do |f|
f.flock(File::LOCK_EX)
f.puts '## COMMAND: %s' % ([$0] + ARGV).join(' ')
if skip.include?(exe)
f.puts "SKIP running %s on Android" % exe
exit 0
end
end
Kernel.exec('#{File.join(OPTIONS[:ndk], 'tools', 'adbrunner')}',
#{"'--emulator-tag=#{OPTIONS[:emulator_tag]}'," unless OPTIONS[:emulator_tag].nil?}
'--no-print-timestamps',
'--log=#{WLOG}',
'--abi=#{abi}',
'--adb=#{OPTIONS[:adb]}',
'--timeout=#{OPTIONS[:timeout]*60 - 5}',
'--strip=#{strip}',
'--strip-dir=#{libdir}',
'--#{'no-' unless OPTIONS[:pie]}pie',
'--verbose-errors',
*ARGV)
EOF
end
FileUtils.chmod "a+x", adbrunner
end
def copy_boost(dir)
# WARNING! This is intentionally just 'rm', not 'rm -rf'.
# This is needed to remove $DIR if it's symlink.
# Thus, we try to remove it and ignore any errors.
# In case it's symlink - it will be removed.
# In case it's directory - nothing will happen.
FileUtils.rm_f dir rescue nil
FileUtils.mkdir_p dir
run 'rsync', '-a', "#{BOOST_SRCDIR}/", dir
end
def copy_boost_bb(dir)
FileUtils.mkdir_p dir
run 'rsync', '-a', "#{BOOST_BB_SRCDIR}/", dir
end
def copy_boost_rr(dir)
FileUtils.mkdir_p dir
run 'rsync', '-a', "#{BOOST_RR_SRCDIR}/", dir
end
PJL = "/tmp/process_jam_log.#{SecureRandom.uuid}"
at_exit { FileUtils.rm_f PJL }
$HOST_PJL = nil
def cleanup_pjl(dir)
Dir.glob(File.join(dir, 'build', 'bin', '**', 'process_jam_log')).select do |e|
File.file?(e)
end.each do |f|
FileUtils.rm_f f
end
return if $HOST_PJL.nil?
pjl = File.join(dir, 'stage', 'bin', $HOST_PJL)
FileUtils.mkdir_p File.dirname(pjl)
FileUtils.cp PJL, pjl
end
def prepare_boost_tools(dir)
FileUtils.mkdir_p dir
runpy = File.join(dir, 'run.py')
FileUtils.rm_f runpy
FileUtils.cp File.join(BOOST_RR_SRCDIR, 'testing', 'src', 'run.py'), runpy
FileUtils.chmod 'a+x', runpy
boost_bb = File.join(dir, 'boost_bb')
copy_boost_bb boost_bb
boost_rr = File.join(dir, 'boost_regression')
copy_boost_rr boost_rr
[
'collect_and_upload_logs.py',
'process_jam_log.py',
'regression.py',
].each do |t|
FileUtils.rm_f File.join(dir, t)
FileUtils.cp File.join(boost_rr, 'testing', 'src', t), dir
end
$HOST_PJL = nil
cleanup_pjl boost_rr
FileUtils.rm_f File.join(dir, 'user-config.jam')
FileUtils.cd(dir) do
run runpy, '--use-local', "--tag=#{OPTIONS[:tag]}", "--bjam-options=-j#{OPTIONS[:jobs]}", 'setup'
end
$HOST_PJL = Dir.glob(File.join(boost_rr, 'stage', 'bin', '**', 'process_jam_log')).select do |e|
File.file?(e)
end.map do |f|
Pathname.new(f).relative_path_from(Pathname.new(File.join(boost_rr, 'stage', 'bin'))).to_s
end.first
raise "Can't find just built process_jam_log" if $HOST_PJL.nil?
FileUtils.rm_f PJL
FileUtils.cp File.join(boost_rr, 'stage', 'bin', $HOST_PJL), PJL
end
def generate_runner_comment(comment, configjam, compilers)
FileUtils.mkdir_p File.dirname(comment)
File.open(comment, 'w') do |f|
File.open(OPTIONS[:runner_comment_header], 'r') do |r|
while line = r.gets
f.puts line
end
end unless OPTIONS[:runner_comment_header].nil?
uname, e, s = Open3.capture3('uname -a')
raise e unless s.success?
f.puts <<-EOF
<p>
<pre>
$ uname -a
#{uname}
</pre>
<pre>
$ cat user-config.jam
#{File.read(configjam)}
</pre>
</p>
EOF
f.puts '<pre>'
compilers.each do |cc|
f.puts "$ #{cc} --version"
f.puts `#{cc} --version 2>&1`.split("\n").select { |l| !l.empty? }.join("\n")
f.puts ""
end
f.puts '</pre>'
File.open(OPTIONS[:runner_comment_footer], 'r') do |r|
while line = r.gets
f.puts line
end
end unless OPTIONS[:runner_comment_footer].nil?
end
end
def test_for_abi(abi, testdir)
Log.notice "Run regression testing [#{abi}]"
FileUtils.mkdir_p testdir
srcdir = File.join(testdir, 'test')
FileUtils.mkdir_p srcdir
configjam = File.join(testdir, 'config.jam')
FileUtils.rm_f configjam
File.open(configjam, "a") do |f|
f.puts "import python ;"
# This is needed for library check scripts, running on host machine
# Here we just specify "using python" and rely on usual Python auto-detecting
# technique implemented in the Boost scripts
f.puts "using python ;"
Dir.glob(File.join(OPTIONS[:ndk], 'sources/python/*')).map do |e|
File.basename(e)
end.each do |python_version|
dir = File.join(OPTIONS[:ndk], 'sources/python', python_version)
# This line needed to specify target python - i.e. Python-for-Android
# This Python implementation will be used for target tests - i.e. for Boost.Python
f.puts "using python : #{python_version} : #{dir} : #{dir}/include/python : #{dir}/libs/#{abi} : <target-os>android ;"
end
end
toolsets = []
toolsets_path = []
cxxbins = []
strip = nil
OPTIONS[:toolchain_versions].each do |tv|
if tv =~ /^clang/
ttype = :clang
tversion = tv.sub(/^clang-?/, '')
cxxbin = "clang++-#{tversion}"
else
ttype = :gcc
tversion = tv.sub(/^gcc-?/, '')
cxxbin = "g++-#{tversion}"
end
# clang toolchains don't support armeabi good
next if ttype == :clang && abi == 'armeabi'
toolset = "#{ttype}-#{tversion}"
targetbin = File.join(testdir, toolset)
FileUtils.rm_rf targetbin
# Generate toolchain wrappers
generate_toolchain abi, ttype, tversion, targetbin
toolsets << toolset
toolsets_path << targetbin
File.open(configjam, "a") do |f|
f.puts "using #{ttype} : #{tversion} : #{targetbin}/#{cxxbin} ;"
end
cxxbins << File.join(targetbin, cxxbin)
strip = File.join(targetbin, 'strip') if strip.nil? && File.executable?(File.join(targetbin, 'strip'))
end
raise "No C++ compilers detected" if cxxbins.empty?
raise "Can't detect 'strip' for #{abi}" if strip.nil?
generate_adbrunner abi, testdir, strip
copy_boost File.join(srcdir, 'boost_root')
prepare_boost_tools srcdir
comment = File.join(srcdir, 'comment.html')
generate_runner_comment comment, configjam, cxxbins
runpy = [
File.join(srcdir, 'run.py'),
'--use-local',
'--platform=Android',
"--tag=#{OPTIONS[:tag]}",
"--runner=#{OPTIONS[:runner]}",
"--toolsets=#{toolsets.join(',')}",
]
bjam_options = [
"-j#{OPTIONS[:jobs]}",
"-m64",
"variant=release",
"link=static,shared",
"runtime-link=shared",
"threading=multi",
"target-os=android",
"testing.launcher=#{File.join(testdir, 'adbrunner')}",
]
bjam_options << "cxxflags='-std=#{OPTIONS[:std]}'" unless OPTIONS[:std].nil?
bjam_options << "binary-format=elf"
case abi
when /^armeabi/, 'x86', 'mips'
bjam_options << "address-model=32"
when /^arm64/, 'x86_64', 'mips64'
bjam_options << "address-model=64"
else
raise "Can't detect address model for abi '#{abi}'"
end
case abi
when /^armeabi/, /^arm64/
bjam_options << "architecture=arm"
bjam_options << "abi=aapcs"
when 'x86', 'x86_64'
bjam_options << "architecture=x86"
bjam_options << "abi=sysv"
when 'mips'
bjam_options << "architecture=mips1"
bjam_options << "abi=o32"
when 'mips64'
bjam_options << "architecture=mips1"
bjam_options << "abi=o64"
end
resultsdir = File.join(srcdir, 'results')
if File.directory?(resultsdir)