/
ruby.rb
1359 lines (1212 loc) · 48.5 KB
/
ruby.rb
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
# chkbuild/ruby.rb - ruby build module
#
# Copyright (C) 2006-2012 Tanaka Akira <akr@fsij.org>
#
# 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.
# 3. The name of the author may not be used to endorse or promote
# products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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.
module ChkBuild::Ruby
METHOD_LIST_SCRIPT = <<'End'
use_symbol = Object.instance_methods[0].is_a?(Symbol)
nummodule = nummethod = 0
mods = []
ObjectSpace.each_object(Module) {|m| mods << m if m.name }
mods = mods.sort_by {|m| m.name }
mods.each {|mod|
nummodule += 1
mc = mod.kind_of?(Class) ? "class" : "module"
puts "#{mc} #{mod.name} #{(mod.ancestors - [mod]).inspect}"
mod.singleton_methods(false).sort.each {|methname|
nummethod += 1
meth = mod.method(methname)
line = "#{mod.name}.#{methname} #{meth.arity}"
line << " not-implemented" if !mod.respond_to?(methname)
puts line
}
ms = mod.instance_methods(false)
if use_symbol
ms << :initialize if mod.private_instance_methods(false).include? :initialize
else
ms << "initialize" if mod.private_instance_methods(false).include? "initialize"
end
ms.sort.each {|methname|
nummethod += 1
meth = mod.instance_method(methname)
line = "#{mod.name}\##{methname} #{meth.arity}"
line << " not-implemented" if /\(not-implemented\)/ =~ meth.inspect
puts line
}
}
puts "#{nummodule} modules, #{nummethod} methods"
End
VERSION_LIST_SCRIPT = <<'End'
require "etc"
ary = []
if defined? Etc::CS_GNU_LIBC_VERSION
ary << ["libc", lambda { Etc.confstr(Etc::CS_GNU_LIBC_VERSION) }]
end
ary.concat [
["gmp", lambda { Bignum::GMP_VERSION }],
["dbm", lambda { require "dbm"; DBM::VERSION }],
["gdbm", lambda { require "gdbm"; GDBM::VERSION }],
["readline", lambda { require "readline"; Readline::VERSION }],
["openssl", lambda {
require "openssl"
hv = OpenSSL::OPENSSL_VERSION
lv = OpenSSL::OPENSSL_LIBRARY_VERSION rescue nil
if hv == lv || lv == nil
hv
else
"header:#{hv.dump} library:#{lv.dump}"
end
}],
["zlib", lambda {
require "zlib"
hv = Zlib::ZLIB_VERSION
lv = Zlib.zlib_version
lv == hv ? lv : "header:#{hv} library:#{lv}"
}],
["tcltklib", lambda { require "tcltklib"; TclTkLib::COMPILE_INFO }],
["curses", lambda { require "curses"; Curses::VERSION }],
]
ary.each {|name, versionproc|
begin
puts "#{name}: #{versionproc.call}"
rescue Exception
puts "#{name}: ERROR #{$!}"
end
}
End
# not strictly RFC 1034.
DOMAINLABEL = /[A-Za-z0-9-]+/
DOMAINPAT = /#{DOMAINLABEL}(\.#{DOMAINLABEL})*/
OldestMaintainedRelease = "2.3"
module_function
def ruby_branches
IO.popen("svn ls http://svn.ruby-lang.org/repos/ruby/branches") {|f|
f.readlines.map {|f| f.chomp("/\n") }
}
end
def maintained_release_branches(rbs=ruby_branches)
rbs.map {|b|
next if /\Aruby_(\d+)_(\d+)\z/ !~ b
major_minor = [$1.to_i, $2.to_i]
major_minor = nil if (major_minor <=> OldestMaintainedRelease.scan(/\d+/).map(&:to_i)) < 0
major_minor
}.compact.sort.reverse.map {|major, minor|
"#{major}.#{minor}"
}
end
def def_target(*args)
args << { :complete_options => CompleteOptions }
ChkBuild.def_target("ruby", *args)
end
def count_prefix(pat, str)
n = 0
str.scan(pat) { n += 1 }
case n
when 0
nil
when 1
""
else
n.to_s
end
end
end
module ChkBuild::Ruby::CompleteOptions
end
def (ChkBuild::Ruby::CompleteOptions).call(target_opts)
hs = []
suffixes = Util.opts2funsuffixes(target_opts)
suffixes.each {|s|
case s
when "trunk" then hs << { :ruby_branch => 'trunk' }
when "mvm" then hs << { :ruby_branch => 'branches/mvm' }
when "half-baked-1.9" then hs << { :ruby_branch => 'branches/half-baked-1.9' }
when "matzruby" then hs << { :ruby_branch => 'branches/matzruby' }
when /\A([3-9]).([0-9]\d*)\z/ then hs << { :ruby_branch => "branches/ruby_#$1_#$2" }
when /\A2.([1-9]\d*)\z/ then hs << { :ruby_branch => "branches/ruby_2_#$1" }
when "2.0.0" then hs << { :ruby_branch => 'branches/ruby_2_0_0' }
when "1.9.3" then hs << { :ruby_branch => 'branches/ruby_1_9_3' }
when "1.9.2" then hs << { :ruby_branch => 'branches/ruby_1_9_2' }
when "1.9.1" then hs << { :ruby_branch => 'branches/ruby_1_9_1' }
when "1.8" then hs << { :ruby_branch => 'branches/ruby_1_8' }
when "1.8.7" then hs << { :ruby_branch => 'branches/ruby_1_8_7' }
when "1.8.6" then hs << { :ruby_branch => 'branches/ruby_1_8_6' }
when "1.8.5" then hs << { :ruby_branch => 'branches/ruby_1_8_5' }
when "o0" then hs << { :optflags => %w[-O0] }
when "o1" then hs << { :optflags => %w[-O1] }
when "o2" then hs << { :optflags => %w[-O2] }
when "o3" then hs << { :optflags => %w[-O3] }
when "os" then hs << { :optflags => %w[-Os] }
when "pth" then hs << { :configure_args_pthread => %w[--enable-pthread] }
when "m32" then hs << { :cflags => ['-m32'], :dldflags => ['-m32'] }
when "m64" then hs << { :cflags => ['-m64'], :dldflags => ['-m64'] }
end
}
if target_opts["--with-opt-dir"]
v = target_opts["--with-opt-dir"]
hs << { :configure_args_with_opt_dir => ["--with-opt-dir=#{v}"] }
end
if Util.search_command('git')
hs << { :use_rubyspec => true }
end
hs << {
:autoconf_command => 'autoconf',
:configure_args => [],
:configure_args_valgrind => %w[--with-valgrind],
:cppflags => %w[-DRUBY_DEBUG_ENV],
:dldflags => %w[],
:make_options => {},
:force_gperf => false,
:use_rubyspec => false,
:use_rubyspec_in_tree => false,
:use_bundled_gems => false,
:inplace_build => true,
:validate_dependencies => false,
:do_test => true,
}
opts = target_opts.dup
hs.each {|h|
h.each {|k1, v1|
opts[k1] = v1 if !opts.include?(k1)
}
}
ruby_branch = opts.fetch(:ruby_branch)
if /ruby_1_9_1/ =~ ruby_branch && opts[:use_rubyspec]
opts[:use_rubyspec] = false
end
if /trunk/ =~ ruby_branch && opts[:use_rubyspec]
opts[:use_rubyspec] = false
opts[:use_rubyspec_in_tree] = true
end
if /trunk/ =~ ruby_branch && opts[:use_bundled_gems]
opts[:use_bundled_gems] = true
end
if ruby_branch == 'branches/mvm' &&
opts.fetch(:cppflags, []).include?('-DRUBY_DEBUG_ENV')
opts.fetch(:cppflags).delete '-DRUBY_DEBUG_ENV'
end
if Util.opts2aryparam(opts, :configure_args).include?("--enable-pthread")
if %r{\Abranches/ruby_1_8} !~ ruby_branch &&
%r{\Abranches/matzruby} !~ ruby_branch
return nil
end
end
if ruby_branch != "trunk"
opts[:validate_dependencies] = false
end
opts
end
def (ChkBuild::Ruby::CompleteOptions).merge_dependencies(opts, dep_dirs)
opts = opts.dup
hs = []
dep_dirs.each {|s|
case s
when /\Agcc=/ then
hs << { :configure_args_cc => "CC=#{$'}/bin/gcc",
:"make_options_ENV:LD_RUN_PATH" => "#{$'}/lib" }
when /\Aautoconf=/ then
hs << { :autoconf_command => "#{$'}/bin/autoconf" }
when /\Aopenssl=/
hs << { :configure_args_openssl => "--with-openssl-dir=#{$'}" }
hs << { :configure_args_digest => "--with-digest-dir=#{$'}" }
when /\Agdbm=/
hs << { :configure_args_gdbm => "--with-gdbm-dir=#{$'}" }
hs << { :configure_args_dbm => "--with-dbm-dir=#{$'}" }
when /\Azlib=/
hs << { :configure_args_zlib => "--with-zlib-dir=#{$'}" }
when /\Alibffi=/
hs << { :configure_args_fiddle => "--with-libffi-dir=#{$'}" }
end
}
hs.each {|h|
opts.update h
}
#pp opts
opts
end
class ChkBuild::Ruby::RubyVersion
def initialize(version_info)
@ary = []
if version_info.has_key?('RUBY_VERSION')
@ary.concat version_info['RUBY_VERSION'].scan(/\d+/).map {|s| s.to_i }
if version_info.has_key?('RUBY_PATCHLEVEL')
@ary << version_info['RUBY_PATCHLEVEL'].to_i
end
end
end
def since(major,minor=0,teeny=0,patchlevel=-1)
([major, minor, teeny, patchlevel] <=> @ary) <= 0
end
def before(major,minor=0,teeny=0,patchlevel=-1)
([major, minor, teeny, patchlevel] <=> @ary) > 0
end
end
def (ChkBuild::Ruby).build_proc(b)
bopts = b.opts
ruby_branch = bopts[:ruby_branch]
configure_args = Util.opts2aryparam(bopts, :configure_args)
cflags = Util.opts2nullablearyparam(bopts, :cflags)
cppflags = Util.opts2aryparam(bopts, :cppflags)
optflags = Util.opts2nullablearyparam(bopts, :optflags)
debugflags = Util.opts2nullablearyparam(bopts, :debugflags)
warnflags = Util.opts2nullablearyparam(bopts, :warnflags)
dldflags = Util.opts2aryparam(bopts, :dldflags)
autoconf_command = bopts[:autoconf_command]
make_options = Util.opts2hashparam(bopts, :make_options)
use_rubyspec = bopts[:use_rubyspec]
use_rubyspec_in_tree = bopts[:use_rubyspec_in_tree]
use_bundled_gems = bopts[:use_bundled_gems]
force_gperf = bopts[:force_gperf]
inplace_build = bopts[:inplace_build]
parallel = bopts[:parallel]
validate_dependencies = bopts[:validate_dependencies]
abi_check = bopts[:abi_check]
abi_check_notitle = bopts[:abi_check_notitle]
abi_check_options = Util.opts2aryparam(bopts, :abi_check_options)
do_test = bopts[:do_test]
b.run(autoconf_command, '--version', :section=>'autoconf-version')
b.run('bison', '--version', :section=>'bison-version')
if validate_dependencies
cflags ||= []
cflags += %w[-save-temps=obj]
end
ruby_build_dir = b.build_dir
objdir = ruby_build_dir+'ruby'
if !inplace_build
checkout_dir = b.target_dir
else
checkout_dir = ruby_build_dir
end
srcdir = (checkout_dir+'ruby').relative_path_from(objdir)
Dir.chdir(checkout_dir)
b.svn("http://svn.ruby-lang.org/repos/ruby", ruby_branch, 'ruby')
b.svn_info('ruby', :section=>"svn-info/ruby")
svn_info_section = b.logfile.get_section('svn-info/ruby')
ruby_svn_rev = svn_info_section[/Last Changed Rev: (\d+)/, 1].to_i
Dir.chdir("ruby")
version_data = {
'version.h' => %w[
RUBY_BRANCH_NAME
RUBY_PATCHLEVEL
RUBY_RELEASE_CODE
RUBY_RELEASE_DATE
RUBY_RELEASE_DAY
RUBY_RELEASE_MONTH
RUBY_RELEASE_YEAR
RUBY_VERSION
RUBY_VERSION_CODE
RUBY_VERSION_MAJOR
RUBY_VERSION_MINOR
RUBY_VERSION_TEENY
],
}
version_info = {}
if version_data.keys.any? {|fn| File.exist? fn }
b.logfile.start_section 'version.h'
version_data.each {|fn, version_macros|
if File.exist? fn
File.foreach(fn) {|line|
if /\A\#\s*define\s+([A-Z_]+)\s+(\S.*)\n\z/ =~ line &&
version_macros.include?($1)
puts line
version_info[$1] = $2
end
}
end
}
end
if /\A\d+-\d+-\d+\z/ !~ version_info['RUBY_RELEASE_DATE']
version_info['RUBY_RELEASE_DATE'] = '%04d-%02d-%02d' % version_info.values_at(
*%w[YEAR MONTH DAY].map{|s|"RUBY_RELEASE_#{s}"}
).map(&:to_i)
puts %<#define RUBY_RELEASE_DATE "#{version_info['RUBY_RELEASE_DATE']}">
end
ruby_version = ChkBuild::Ruby::RubyVersion.new(version_info)
if force_gperf
b.run('gperf', '--version', :section=>'gperf-version')
if File.exist?('defs/lex.c.src') && File.exist?('lex.c.blt')
b.run('rm', 'defs/lex.c.src', 'lex.c.blt', :section=>'force-gperf')
elsif File.exist?('lex.c.src') && File.exist?('lex.c.blt')
b.run('rm', 'lex.c.src', 'lex.c.blt', :section=>'force-gperf')
elsif File.exist?('lex.c')
b.run('rm', 'lex.c', :section=>'force-gperf')
else
b.run('echo', 'lex.c related files not found', :section=>'force-gperf')
end
end
b.run(autoconf_command)
Dir.chdir(ruby_build_dir)
use_rubyspec &&= b.catch_error {
b.git('https://github.com/ruby/mspec.git', 'mspec', bopts)
}
use_rubyspec &&= b.catch_error {
b.git('https://github.com/ruby/rubyspec.git', 'rubyspec', bopts)
}
large_cflags = nil
if ruby_version.before(1,8,8)
large_cflags = []
large_cflags.concat cppflags
large_cflags.concat optflags if optflags
large_cflags.concat debugflags if debugflags
large_cflags.concat warnflags if warnflags
cppflags = nil
optflags = nil
debugflags = nil
warnflags = nil
end
b.mkcd("ruby")
args = []
args << "--prefix=#{ruby_build_dir}"
args << "CFLAGS=#{large_cflags.join(' ')}" if large_cflags
args << "cflags=#{cflags.join(' ')}" if cflags
args << "CPPFLAGS=#{cppflags.join(' ')}" if cppflags && !cppflags.empty?
args << "optflags=#{optflags.join(' ')}" if optflags
args << "debugflags=#{debugflags.join(' ')}" if debugflags
args << "warnflags=#{warnflags.join(' ')}" if warnflags
args << "DLDFLAGS=#{dldflags.join(' ')}" unless dldflags.empty?
args.concat configure_args
b.run("#{srcdir}/configure", *args)
b.logfile.start_section 'config-files'
%w[
tool/config.guess
tool/config.sub
config.guess
config.sub
].each {|fn|
begin
contents = File.read(fn)
rescue SystemCallError
next
end
if /^timestamp=(\S*)/ =~ contents
fn = File.basename(fn)
timestamp = $1
timestamp.sub!(/\A'/, '')
timestamp.sub!(/'\z/, '')
puts "#{fn}: #{timestamp}"
end
}
verconf_list = [
'verconf.h',
'config.h',
*Dir.glob(".ext/include/*/ruby/config.h")
]
if verconf_list.any? {|fn| File.exist? fn }
b.logfile.start_section 'verconf.h'
verconf_list.each {|fn|
if File.exist? fn
File.foreach(fn) {|line|
if /\A\#\s*define\s+([A-Z_]+)\s+(\S.*)\n\z/ =~ line &&
$1 == 'RUBY_PLATFORM'
puts line
end
}
end
}
end
if /^CC[ \t]*=[ \t](\S*)/ =~ File.read('Makefile')
cc = $1
b.cc_version(cc)
end
make_args = ["miniruby", make_options]
make_args.unshift "-j#{parallel}" if parallel
b.make(*make_args)
if Util.search_command('file')
b.catch_error {
b.run("file", "miniruby", :section=>'miniruby-file')
}
end
if Util.search_command('ldd')
b.catch_error {
b.run("ldd", "./miniruby", :section=>'miniruby-shlibs')
}
end
if /-gnu|-linux/ =~ RUBY_PLATFORM && /kfreebsd/ !~ RUBY_PLATFORM
# glibc shared library (libc.so) is executable on
# GNU/Linux and GNU/Hurd but not on GNU/kFreeBSD.
# Several examples of RUBY_PLATFORM:
# GNU/Linux: "x86_64-linux"
# GNU/Hurd: "i486-gnu"
# GNU/kFreeBSD: "x86_64-kfreebsd-gnu"
ldd_miniruby = `ldd ./miniruby`
libc_path = ldd_miniruby[%r{libc\.so.* => (/\S*)}, 1]
if libc_path && File.executable?(libc_path)
b.catch_error {
b.run(libc_path, :section=>'miniruby-libc')
}
end
end
b.catch_error { b.run("./miniruby", "-v", :section=>"miniversion") }
if do_test
if File.directory? "#{srcdir}/bootstraptest"
b.catch_error { b.make("btest", "OPTS=-v -q", make_options.merge(:section=>"btest")) }
end
b.catch_error {
testfile = if File.exist?("#{srcdir+'basictest/test.rb'}")
"#{srcdir+'basictest/test.rb'}" # Ruby 2.4 or later.
else
"#{srcdir+'sample/test.rb'}"
end
b.run("./miniruby", testfile, :section=>"test.rb")
if /^end of test/ !~ b.logfile.get_section('test.rb')
raise ChkBuild::Build::CommandError.new(0, "test.rb")
end
}
end
b.catch_error { b.run("./miniruby", '-e', ChkBuild::Ruby::METHOD_LIST_SCRIPT, :section=>"method-list") }
# Ruby 1.9 provides 'main' target to build ruby excluding documents.
makefile_lines = IO.readlines('Makefile')
makefile_lines.concat IO.readlines('uncommon.mk') if File.file?('GNUmakefile') && File.file?('uncommon.mk')
do_rdoc = true
make_docs = nil
if makefile_lines.grep(/\Aall:.*\S/).sort == ["all: showflags main docs\n"]
b.make('showflags', make_options)
make_args = ['main', make_options]
make_args.unshift "-j#{parallel}" if parallel
b.make(*make_args)
make_docs = lambda {
do_rdoc &&= b.catch_error {
make_args = ['docs', make_options]
make_args.unshift "-j#{parallel}" if parallel
b.make(*make_args)
}
}
else
make_args = [make_options]
make_args.unshift "-j#{parallel}" if parallel
b.make(*make_args)
end
b.make("install-nodoc", make_options)
if Util.search_command('file')
b.catch_error {
b.run("file", "ruby", :section=>'ruby-file')
}
end
if Util.search_command('ldd')
b.catch_error {
b.logfile.start_section 'ruby-shlibs'
b.run("ldd", "./ruby", :section=>nil)
Dir.glob(".ext/**/*.so").sort.each {|solib|
b.run("ldd", solib, :section=>nil)
}
}
end
b.catch_error { b.run("./ruby", "-v", :section=>"version") }
make_docs.call if make_docs
do_rdoc &&= b.catch_error { b.make("install-doc", make_options) }
b.catch_error { b.run("./ruby", '-e', ChkBuild::Ruby::VERSION_LIST_SCRIPT, :section=>"version-list") }
if validate_dependencies
b.catch_error {
b.make("golf")
b.run("./ruby", "tool/update-deps", :section=>"update-deps")
}
end
abi_reference_dir = abi_check || abi_check_notitle
if abi_reference_dir
secname = abi_check ? 'abi-check' : 'abi-check-notitle'
b.catch_error {
Dir.chdir(ruby_build_dir) {
args = ["bin/ruby", "#{ChkBuild::TOP_DIRECTORY}/abi-checker.rb"]
args.concat abi_check_options.map {|e| e.to_s }
args.concat [abi_reference_dir, ruby_build_dir.to_s]
args << {:section=>secname}
b.run(*args)
b.run("w3m", "-cols", "132", "-ON", "-dump",
"compat_reports/libruby/unspecified_to_unspecified/abi_compat_report.html",
:section=>nil)
}
}
end
if do_test
if File.file? "#{srcdir}/KNOWNBUGS.rb"
b.catch_error { b.make("test-knownbug", "OPTS=-v -q", make_options) }
end
hide_skip_option = ''
if ruby_version.since(1,9,3)
hide_skip_option = '--hide-skip '
end
b.catch_error {
parallel_option = ''
parallel_option = "j#{parallel}" if parallel
b.make("test-all", "TESTS=#{hide_skip_option}-v#{parallel_option}", "RUBYOPT=-w", make_options.merge(:section=>"test-all"))
}
b.catch_error {
if /^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors/ !~ b.logfile.get_section('test-all')
ts = Dir.entries(srcdir+"test").sort
ts.each {|t|
next if %r{\A\.} =~ t
s = File.lstat(srcdir+"test/#{t}")
if s.directory? || (s.file? && /\Atest_/ =~ t)
b.catch_error {
if /\A-/ =~ t
testpath = srcdir+"test/#{t}" # prevent to interpret -ext- as an option
else
testpath = t # "TESTS=-v test/foo" doesn't work on Ruby 1.8
end
b.make("test-all", "TESTS=#{hide_skip_option}-v #{testpath}", "RUBYOPT=-w", make_options.merge(:section=>"test/#{t}"))
}
end
}
end
}
Dir.chdir(ruby_build_dir)
if use_rubyspec
rubybin = ruby_build_dir + "bin/ruby"
b.catch_error {
FileUtils.rmtree "rubyspec_temp"
config = Dir.pwd + "/rubyspec/default.mspec"
command = %W[bin/ruby mspec/bin/mspec -B #{config} -V -f s -t #{rubybin}]
command << "rubyspec"
command << {
:section=>"rubyspec"
}
b.run(*command)
}
if /^Finished/ !~ b.logfile.get_section('rubyspec')
Pathname("rubyspec").children.reject {|f| !f.directory? }.sort.each {|d|
d.stable_find {|f|
Find.prune if %w[.git fixtures nbproject shared tags].include? f.basename.to_s
next if /_spec\.rb\z/ !~ f.basename.to_s
s = f.lstat
next if !s.file?
b.catch_error {
FileUtils.rmtree "rubyspec_temp"
config = ruby_build_dir + "rubyspec/default.mspec"
command = %W[bin/ruby mspec/bin/mspec -B #{config} -V -f s -t #{rubybin}]
command << f.to_s
command << {
:section=>f.to_s
}
b.run(*command)
}
}
}
end
end
if use_rubyspec_in_tree
b.mkcd("ruby")
b.catch_error {
FileUtils.rmtree "rubyspec_temp"
b.make("yes-test-rubyspec", "MSPECOPT=-Vfs", make_options.merge(:section=>"rubyspec"))
}
end
if use_bundled_gems
b.catch_error {
b.make("yes-test-bundled-gems", make_options.merge(:section => "test-bundled-gems"))
}
end
end
Dir.chdir(ruby_build_dir)
Dir.chdir('ruby') {
relname = nil
if ruby_version.before(1,9,3)
# "make dist" doesn't support BRANCH@rev.
relname = nil
else
# "make dist" support BRANCH@rev since Ruby 1.9.3.
relname = "#{ruby_branch}@#{ruby_svn_rev}"
end
if relname
b.make("dist", "RELNAME=#{relname}", "AUTOCONF=#{autoconf_command}")
end
}
end
ChkBuild.define_build_proc('ruby') {|b|
ChkBuild::Ruby.build_proc(b)
}
ChkBuild.define_title_hook('ruby', %w[svn-info/ruby version.h verconf.h]) {|title, logs|
log = logs.join('')
lastrev = /^Last Changed Rev: (\d+)$/.match(log)
version = /^#\s*define RUBY_VERSION "(\S+)"/.match(log)
reldate = /^#\s*define RUBY_RELEASE_DATE "(\S+)"/.match(log)
relyear = /^#\s*define RUBY_RELEASE_YEAR (\d+)/.match(log)
relmonth = /^#\s*define RUBY_RELEASE_MONTH (\d+)/.match(log)
relday = /^#\s*define RUBY_RELEASE_DAY (\d+)/.match(log)
patchlev = /^#\s*define RUBY_PATCHLEVEL (\S+)/.match(log)
platform = /^#\s*define RUBY_PLATFORM "(\S+)"/.match(log)
if lastrev
str = ''
if lastrev
str << "r#{lastrev[1]} "
end
str << 'ruby '
if reldate
reldate = reldate[1]
elsif relyear && relmonth && relday
reldate = "#{relyear[1]}-#{relmonth[1]}-#{relday[1]}"
end
if version && reldate
str << version[1]
str << (patchlev[1] == '-1' ? 'dev' : "p#{patchlev[1]}") if patchlev
str << " (" << reldate << ")"
str << " [" << platform[1] << "]" if platform
ss = title.suffixed_name.split(/-/)[1..-1].reject {|s|
/\A(trunk|1\.8)\z/ =~ s ||
version[1] == s
}
str << " [#{ss.join(',')}]" if !ss.empty?
end
str.sub!(/ \z/, '')
title.update_title(:version, str)
end
}
ChkBuild.define_title_hook('ruby', 'svn-info/ruby') {|title, log|
lastrev = /^Last Changed Rev: (\d+)$/.match(log)
if lastrev
title.update_hidden_title(:ruby_rev, "r#{lastrev[1]}")
end
}
#ChkBuild.define_title_hook('ruby', "configure") {|title, log|
# if /^checking target system type\.\.\. (\S+)$/ =~ log
# title.update_title(:version, "#{title.suffixed_name} [#{$1}]")
# end
#}
#ChkBuild.define_title_hook('ruby', "miniversion") {|title, log|
# if /^ruby [0-9].*$/ =~ log
# ver = $&
# ss = title.suffixed_name.split(/-/)[1..-1].reject {|s| /\A(trunk|1\.8)\z/ =~ s }
# ver << " [#{ss.join(',')}]" if !ss.empty?
# title.update_title(:version, ver)
# end
#}
#ChkBuild.define_title_hook('ruby', "version") {|title, log|
# if /^ruby [0-9].*$/ =~ log
# ver = $&
# ss = title.suffixed_name.split(/-/)[1..-1].reject {|s| /\A(trunk|1\.8)\z/ =~ s }
# ver << " [#{ss.join(',')}]" if !ss.empty?
# title.update_title(:version, ver)
# end
#}
ChkBuild.define_failure_hook('ruby', "btest") {|log|
if /^FAIL (\d+)\/\d+ tests failed/ =~ log
"#{$1}BFail"
end
}
ChkBuild.define_failure_hook('ruby', "test-knownbug") {|log|
if /^FAIL (\d+)\/\d+ tests failed/ =~ log
"#{$1}KB"
elsif /^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors$/ =~ log
failures = $1.to_i
errors = $2.to_i
if failures != 0 || errors != 0
"KB#{failures}F#{errors}E"
end
end
}
ChkBuild.define_failure_hook('ruby', "test.rb") {|log|
if /^end of test/ !~ log
if /^test: \d+ failed (\d+)/ =~ log || %r{^not ok/test: \d+ failed (\d+)} =~ log
"#{$1}NotOK"
end
end
}
ChkBuild.define_failure_hook('ruby', "test-all") {|log|
# 5422 tests, 1924652 assertions, 11 failures, 5 errors
# 16162 tests, 2235446 assertions, 1 failures, 0 errors, 39 skips
if /.*^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors/m =~ log
failures = $1.to_i
errors = $2.to_i
if failures != 0 || errors != 0
"#{failures}F#{errors}E"
end
end
}
ChkBuild.define_failure_hook('ruby', "rubyspec") {|log|
# 3604 files, 24079 examples, 173399 expectations, 0 failures, 0 errors
# 3455 files, 24098 examples, 173444 expectations, 0 failures, 0 errors, 0 tagged
if /.*^\d+ files?, \d+ examples?, \d+ expectations?, (\d+) failures?, (\d+) errors?/m =~ log
failures = $1.to_i
errors = $2.to_i
if failures != 0 || errors != 0
"rubyspec:#{failures}F#{errors}E"
end
end
}
ChkBuild.define_title_hook('ruby', "abi-check") {|title, log|
high = 0
log.scan(/ High +([0-9])+ *$/) { high += $1.to_i }
medium = 0
log.scan(/ Medium +([0-9])+ *$/) { medium += $1.to_i }
#low = 0
#log.scan(/ Low +([0-9])+ *$/) { low += $1.to_i }
if high != 0 || medium != 0 # || low != 0
str = "ABI:"
str << "#{high}H" if high != 0
str << "#{medium}M" if medium != 0
#str << "#{low}L" if low != 0
title.update_title(:status, str)
end
}
ChkBuild.define_title_hook('ruby', nil) {|title, logfile|
numbugs = numsegv = numsigbus = numsigill = numsigabrt = numfatal = 0
logfile.each_line {|line|
line = line.gsub(/^LASTLOG .*/, '') # skip commit message.
line = line.sub(/combination may cause frequent hang or segmentation fault|hangs or segmentation faults/, '') # skip tk message.
numbugs += line.scan(/\[BUG\]/i).length
numsegv += line.scan(/segmentation fault|signal segv/i).length
numsigbus += line.scan(/chkbuild: signal SIGBUS/i).length
numsigill += line.scan(/chkbuild: signal SIGILL/i).length
numsigabrt += line.scan(/chkbuild: signal SIGABRT/i).length
numfatal += line.scan(/\[FATAL\]/i).length
}
mark = ''
mark << " #{numbugs == 1 ? '' : numbugs}[BUG]" if 0 < numbugs
mark << " #{numsegv == 1 ? '' : numsegv}[SEGV]" if 0 < numsegv
mark << " #{numsigbus == 1 ? '' : numsigbus}[SIGBUS]" if 0 < numsigbus
mark << " #{numsigill == 1 ? '' : numsigill}[SIGILL]" if 0 < numsigill
mark << " #{numsigabrt == 1 ? '' : numsigabrt}[SIGABRT]" if 0 < numsigabrt
mark << " #{numfatal == 1 ? '' : numfatal}[FATAL]" if 0 < numfatal
mark.sub!(/\A /, '')
title.update_title(:mark, mark)
}
# ps -o blocked : 0000000000000000
# ps -o blocked : fffffffe7dfbfaff
# ps -o caught : 0000000182006e47
# ps -o ignored : 0000000000000000
# ps -o pending : 0000000000000000
ChkBuild.define_diff_preprocess_gsub('ruby', /^ps -o (blocked|caught|ignored|pending) : [0-9a-f]+/) {|match|
"ps -o #{match[1]} : <hex>"
}
# #define RUBY_RELEASE_DATE "2013-04-06"
ChkBuild.define_diff_preprocess_gsub('ruby', /^\#define RUBY_RELEASE_DATE ".*"/) {|match|
'#define RUBY_RELEASE_DATE "<year>-<mm>-<dd>"'
}
# #define RUBY_RELEASE_YEAR 2013
# #define RUBY_RELEASE_MONTH 4
# #define RUBY_RELEASE_DAY 6
ChkBuild.define_diff_preprocess_gsub('ruby', /^\#define RUBY_RELEASE_(YEAR|MONTH|DAY) \d+/) {|match|
"\#define RUBY_RELEASE_#{match[1]} <num>"
}
# ruby 1.9.2dev (2009-12-07 trunk 26037) [i686-linux]
# ruby 1.9.1p376 (2009-12-07 revision 26040) [i686-linux]
# | ruby 1.9.2dev (2010-02-18 trunk 26704) [x86_64-linux]
ChkBuild.define_diff_preprocess_gsub('ruby', /ruby [0-9.a-z]+ \(.*\) \[.*\]$/) {|match|
"ruby <version>"
}
# tcltklib: tcltklib 2010-08-25 :: Ruby2.0.0 (2012-02-20) with pthread :: Tcl8.5.10(without stub)/Tk8.5.10(without stub) with tcl_threads
ChkBuild.define_diff_preprocess_gsub('ruby', /^tcltklib: (.*)Ruby[\d.]+ \([\d-]+\)/) {|match|
"tcltklib: #{match[1]}Ruby<version> (<release-date>)"
}
# + file miniruby
# miniruby: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0xd5a7c589cce09467a49e1792bc822ae48f75b5ee, not stripped
ChkBuild.define_diff_preprocess_gsub('ruby', /BuildID\[sha1\]=(?:0x)?[0-9a-f]+,/) {|match|
"BuildID[sha1]=<hex>"
}
# file.c:884: warning: comparison between signed and unsigned
# vm.c:2012:5: warning: "OPT_BASIC_OPERATIONS" is not defined
#
# Doxygen:
# /home/akr/chkbuild/tmp/build/ruby-trunk/20100816T014700Z/ruby/ext/ripper/ripper.y:18: Warning: include file ruby/ruby.h not found, perhaps you forgot to add its directory to INCLUDE_PATH?
# /home/akr/chkbuild/tmp/build/ruby-trunk/20100816T014700Z/ruby/pack.c:89: Problem during constant expression evaluation: syntax error
# from /extdisk/chkbuild/chkbuild/tmp/build/ruby-trunk/<buildtime>/ruby/test/ruby/test_autoload.rb:82:in `block (2 levels) in test_threaded_accessing_constant'
ChkBuild.define_diff_preprocess_gsub_state('ruby', /\A([^:]*:)(\d+)(:((?:\d+:)? (?:[Ww]arning: |Problem )|in `.*').*)/) {|match, state|
pre, linenum, post = match[1], match[2], match[3]
warnhash = state[:warnhash] ||= {}
key = "#{pre}<linenum>#{post}"
id_next, warnhash2 = warnhash[key] ||= ["a", {}]
if warnhash2[linenum]
id = warnhash2[linenum]
else
warnhash2[linenum] = id = id_next.dup
id_next.succ!
end
"#{pre}<line_#{id}>#{post}"
}
# Doxygen:
# Running dot for graph 1/405
ChkBuild.define_diff_preprocess_gsub('ruby', %r{Running dot for graph \d+/\d+}) {|match|
'Running dot for graph <num>/<num>'
}
# Doxygen:
# Inserting map/figure 1/342
ChkBuild.define_diff_preprocess_gsub('ruby', %r{Inserting map/figure \d+/\d+}) {|match|
'Inserting map/figure <num>/<num>'
}
# gcc ... -DRUBY_RELEASE_DATE=\"2010-05-04\" ... tcltklib.c
ChkBuild.define_diff_preprocess_gsub('ruby', /-DRUBY_RELEASE_DATE=\\"\d+-\d\d-\d\d\\"/) {|match|
'-DRUBY_RELEASE_DATE=\"YYYY-MM-DD\"'
}
# done. (0.07user 0.01system 0.05elapsed)
ChkBuild.define_diff_preprocess_gsub('ruby', /^done\. \(\d+\.\d\duser \d+\.\d\dsystem \d+\.\d\delapsed\)/) {|match|
"done. (X.XXuser X.XXsystem X.XXelapsed)"
}
# rdoc:
# 0% [ 1/513] eval.c
# 0% [ 2/513] prelude.c
# 2% [19/949] ...chkbuild/tmp/build/20160406T053229Z/ruby/doc/contributing.rdoc
# ...
# 99% [512/513] ext/zlib/zlib.c
# 100% [513/513] doc/re.rdoc
ChkBuild.define_diff_preprocess_gsub('ruby', %r{^\s*\d+%\s+\[\s*\d+/\d+\] (\S*/)?([^/]+)$}) {|match|
"XXX% [XXX/XXX] #{match[1] ? '<dir>/' : ''}#{match[2]}"
}
# ldd
# libpthread.so.0 => /lib/libpthread.so.0 (0x00007f3dcb6c6000)
# /lib64/ld-linux-x86-64.so.2 (0x00007f3dcbd49000)
ChkBuild.define_diff_preprocess_gsub('ruby', /(\.so\b.*) \(0x[0-9A-Fa-f]+\)/) {|match|
"#{match[1]} (<address>)"
}
# Generated on Thu Jun 6 10:17:43 2013 for libruby by ABI Compliance Checker 1.99
ChkBuild.define_diff_preprocess_gsub('ruby', /^ *Generated on .* for libruby by ABI Compliance Checker/) {|match|
"Generated on <date> for libruby by ABI Compliance Checker"
}
# A tool for checking backward compatibility of a C/C++ library API
ChkBuild.define_diff_preprocess_gsub('ruby', %r{^ *A tool for checking backward compatibility of a C/C\+\+ library API}) {|match|
"A tool for checking backward compatibility of a C/C++ library API"
}
# btest since 2014-06-08
# test_attr.rb
# #1 test_attr.rb:1:in `<top (required)>' F 0.006
# stderr output is not empty
# bootstraptest.tmp.rb:2:in `<main>': undefined local variable or method `x' for main:Object (NameError)
# #2 test_attr.rb:28:in `<top (required)>' . 0.006
ChkBuild.define_diff_preprocess_gsub('ruby', /\#\d+ (test_.* [F.]) [0-9]+\.[0-9]+/) {|match|
"#<n> #{match[1]} <elapsed>"
}
# test_exception.rb #2 test_exception.rb:1
# .#3 test_exception.rb:8
# .#4 test_exception.rb:20
# .#5 test_exception.rb:37
ChkBuild.define_diff_preprocess_gsub('ruby', /\#\d+ test_/) {|match|
"#<n> test_"
}
# test/unit:
# 28) Error:
# 33) Failure:
# 2) Skipped:
# rubyspec:
# 61)
ChkBuild.define_diff_preprocess_gsub('ruby', /^ *\d+\)( Error:| Failure:| Skipped:|$)/) {|match|
" <n>)#{match[1]}"
}