Module: ChkBuild::Ruby

Defined in:
lib/chkbuild/targets/ruby.rb

Constant Summary collapse

METHOD_LIST_SCRIPT =
"use_symbol = Object.instance_methods[0].is_a?(Symbol)\nnummodule = nummethod = 0\nmods = []\nObjectSpace.each_object(Module) {|m| mods << m if m.name }\nmods = mods.sort_by {|m| m.name }\nmods.each {|mod|\n  nummodule += 1\n  puts \"\#{mod.name} \#{(mod.ancestors - [mod]).inspect}\"\n  mod.singleton_methods(false).sort.each {|methname|\n    nummethod += 1\n    meth = mod.method(methname)\n    line = \"\#{mod.name}.\#{methname} \#{meth.arity}\"\n    line << \" not-implemented\" if !mod.respond_to?(methname)\n    puts line\n  }\n  ms = mod.instance_methods(false)\n  if use_symbol\n    ms << :initialize if mod.private_instance_methods(false).include? :initialize\n  else\n    ms << \"initialize\" if mod.private_instance_methods(false).include? \"initialize\"\n  end\n  ms.sort.each {|methname|\n    nummethod += 1\n    meth = mod.instance_method(methname)\n    line = \"\#{mod.name}\\#\#{methname} \#{meth.arity}\"\n    line << \" not-implemented\" if /\\(not-implemented\\)/ =~ meth.inspect\n    puts line\n  }\n}\nputs \"\#{nummodule} modules, \#{nummethod} methods\"\n"
DOMAINLABEL =

not strictly RFC 1034.

/[A-Za-z0-9-]+/
DOMAINPAT =
/#{DOMAINLABEL}(\.#{DOMAINLABEL})*/
MaintainedBranches =
%w[trunk 1.9.1 1.8 1.8.7 1.8.6]

Class Method Summary collapse

Class Method Details

.count_prefix(pat, str) ⇒ Object



443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/chkbuild/targets/ruby.rb', line 443

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

.def_target(*args) ⇒ Object



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
# File 'lib/chkbuild/targets/ruby.rb', line 77

def def_target(*args)
  opts = Hash === args.last ? args.pop : {}
  default_opts = {:separated_srcdir=>false, :shared_gitdir=>ChkBuild.build_top}
  opts = default_opts.merge(opts)
  opts[:limit_combination] = method(:limit_combination)
  args.push opts
  opts = Hash === args.last ? args.last : {}
  separated_srcdir = opts[:separated_srcdir]
  t = ChkBuild.def_target("ruby", *args) {|b, *suffixes|
    ruby_build_dir = b.build_dir

    ruby_branch = nil
    configure_flags = %w[--with-valgrind]
    cflags = %w[]
    cppflags = %w[-DRUBY_DEBUG_ENV]
    optflags = %w[-O2]
    debugflags = %w[-g]
  warnflags = %w[-W -Wall -Wformat=2 -Wundef -Wno-parentheses -Wno-unused-parameter]
  dldflags = %w[]
    gcc_dir = nil
    autoconf_command = 'autoconf'
    make_options = {}
    suffixes.each {|s|
      case s
      when "trunk" then ruby_branch = 'trunk'
      when "mvm" then ruby_branch = 'branches/mvm'
        cppflags.delete '-DRUBY_DEBUG_ENV'
      when "half-baked-1.9" then ruby_branch = 'branches/half-baked-1.9'
      when "matzruby" then ruby_branch = 'branches/matzruby'
      when "1.9.1" then ruby_branch = 'branches/ruby_1_9_1'
      when "1.8" then ruby_branch = 'branches/ruby_1_8'
      when "1.8.5" then ruby_branch = 'branches/ruby_1_8_5'
      when "1.8.6" then ruby_branch = 'branches/ruby_1_8_6'
      when "1.8.7" then ruby_branch = 'branches/ruby_1_8_7'
      when "o0"
        optflags.delete_if {|arg| /\A-O\d\z/ =~ arg }
        optflags << '-O0'
      when "o1"
        optflags.delete_if {|arg| /\A-O\d\z/ =~ arg }
        optflags << '-O1'
      when "o3"
        optflags.delete_if {|arg| /\A-O\d\z/ =~ arg }
        optflags << '-O3'
      when "pth" then configure_flags << '--enable-pthread'
      when "m32"
        cflags.delete_if {|arg| /\A-m(32|64)\z/ =~ arg }
        cflags << '-m32'
        dldflags.delete_if {|arg| /\A-m(32|64)\z/ =~ arg }
        dldflags << '-m32'
      when "m64"
        cflags.delete_if {|arg| /\A-m(32|64)\z/ =~ arg }
        cflags << '-m64'
        dldflags.delete_if {|arg| /\A-m(32|64)\z/ =~ arg }
        dldflags << '-m64'
      when /\Agcc=/
        configure_flags << "CC=#{$'}/bin/gcc"
        make_options["ENV:LD_RUN_PATH"] = "#{$'}/lib"
      when /\Aautoconf=/
        autoconf_command = "#{$'}/bin/autoconf"
      else
        raise "unexpected suffix: #{s.inspect}"
      end
    }

  if opts["--with-opt-dir"]
    configure_flags << "--with-opt-dir=#{opts['--with-opt-dir']}"
  end

  if %r{branches/ruby_1_8_} =~ ruby_branch && $' < "8"
    cflags.concat cppflags
    cflags.concat optflags
    cflags.concat debugflags
    cflags.concat warnflags
      cppflags = nil
    optflags = nil
    debugflags = nil
    warnflags = nil
  end

    use_rubyspec = false
    if ENV['PATH'].split(/:/).any? {|d| File.executable?("#{d}/git") }
      use_rubyspec = true
    end

    objdir = ruby_build_dir+'ruby'
    if separated_srcdir
      checkout_dir = ruby_build_dir.dirname
    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',
      :viewvc=>'http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?diff_format=u')
    Dir.chdir("ruby")
    b.run(autoconf_command)

    Dir.chdir(ruby_build_dir)

    use_rubyspec &&= b.catch_error {
      opts2 = opts.dup
      opts2[:section] = "git-mspec"
      b.github("rubyspec", "mspec", "mspec", opts2)
    }
    use_rubyspec &&= b.catch_error {
      opts2 = opts.dup
      opts2[:section] = "git-rubyspec"
      b.github("rubyspec", "rubyspec", "rubyspec", opts2)
    }

    b.mkcd("ruby")
  args = []
  args << "--prefix=#{ruby_build_dir}"
  args << "CFLAGS=#{cflags.join(' ')}" if cflags && !cflags.empty?
  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_flags
    b.run("#{srcdir}/configure", *args)
    b.make("miniruby", make_options)
    b.catch_error { b.run("./miniruby", "-v", :section=>"miniversion") }
    if File.directory? "#{srcdir}/bootstraptest"
      b.catch_error { b.make("btest", "OPTS=-v -q", :section=>"btest") }
    end
    b.catch_error {
      b.run("./miniruby", "#{srcdir+'sample/test.rb'}", :section=>"test.rb")
      if /^end of test/ !~ b.logfile.get_section('test.rb')
        raise ChkBuild::Build::CommandError.new(0, "test.rb")
      end
    }
    b.catch_error { b.run("./miniruby", '-e', METHOD_LIST_SCRIPT, :section=>"method-list") }
    b.make(make_options)
    b.catch_error { b.run("./ruby", "-v", :section=>"version") }
    b.make("install-nodoc")
    b.catch_error { b.make("install-doc") }
    if File.file? "#{srcdir}/KNOWNBUGS.rb"
      b.catch_error { b.make("test-knownbug", "OPTS=-v -q") }
    end
    #b.catch_error { b.run("./ruby", "#{srcdir+'test/runner.rb'}", "-v", :section=>"test-all") }
    b.catch_error { b.make("test-all", "TESTS=-v", :section=>"test-all") }

    Dir.chdir(ruby_build_dir)
    use_rubyspec &&= b.catch_error {
      if %r{branches/ruby_1_8} =~ ruby_branch
        config = Dir.pwd + "/rubyspec/ruby.1.8.mspec"
        command = %W[bin/ruby mspec/bin/mspec -V -f s -B #{config} -t bin/ruby -G critical rubyspec]
      else
        config = Dir.pwd + "/rubyspec/ruby.1.9.mspec"
        command = %W[bin/ruby mspec/bin/mspec ci -V -f s -B #{config} -t bin/ruby rubyspec]
      end
      command << { :section=>"rubyspec" }
      b.run(*command)
    }
  }

  t.add_title_hook("configure") {|title, log|
    if /^checking target system type\.\.\. (\S+)$/ =~ log
      title.update_title(:version, "#{title.suffixed_name} [#{$1}]")
    end
  }

  t.add_title_hook("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
  }

  t.add_title_hook("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
  }

  t.add_failure_hook("btest") {|log|
    if /^FAIL (\d+)\/\d+ tests failed/ =~ log
      "#{$1}BFail"
    end
  }

  t.add_failure_hook("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
  }

  t.add_failure_hook("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
  }

  t.add_failure_hook("test-all") {|log|
    if /^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors$/ =~ log
      failures = $1.to_i
      errors = $2.to_i
      if failures != 0 || errors != 0
        "#{failures}F#{errors}E"
      end
    elsif /^\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors, (\d+) skips$/ =~ log
      failures = $1.to_i
      errors = $2.to_i
      skips = $3.to_i
      if failures != 0 || errors != 0 || skips != 0
 if skips == 0
   "#{failures}F#{errors}E"
 else
   "#{failures}F#{errors}E#{skips}S"
 end
      end
    end
  }

  t.add_failure_hook("rubyspec") {|log|
    if /^\d+ files?, \d+ examples?, \d+ expectations?, (\d+) failures?, (\d+) errors?$/ =~ log
      failures = $1.to_i
      errors = $2.to_i
      if failures != 0 || errors != 0
        "rubyspec:#{failures}F#{errors}E"
      end
    end
  }

  t.add_title_hook(nil) {|title, log|
    mark = ''
    numbugs = count_prefix(/\[BUG\]/i, log) and mark << " #{numbugs}[BUG]"
    numsegv = count_prefix(
      /segmentation fault|signal segv/i,
      log.sub(/combination may cause frequent hang or segmentation fault|hangs or segmentation faults/, '')) and # skip tk message.
      mark << " #{numsegv}[SEGV]"
    numsigbus = count_prefix(/signal SIGBUS/i, log) and mark << " #{numsigbus}[SIGBUS]"
    numsigill = count_prefix(/signal SIGILL/i, log) and mark << " #{numsigill}[SIGILL]"
    numsigabrt = count_prefix(/signal SIGABRT/i, log) and mark << " #{numsigabrt}[SIGABRT]"
    numfatal = count_prefix(/\[FATAL\]/i, log) and mark << " #{numfatal}[FATAL]" 
    mark.sub!(/\A /, '')
    title.update_title(:mark, mark)
  }

  # delete trailing spaces.
  t.add_diff_preprocess_gsub(/[ \t]*$/) {|match|
    ""
  }

  # test_exception.rb #1 test_exception.rb:1
  t.add_diff_preprocess_gsub(/\#\d+ test_/) {|match|
    "#<n> test_"
  }

  # test/unit:
  #  28) Error:
  #  33) Failure:
  # rubyspec:
  # 61)
  t.add_diff_preprocess_gsub(/^ *\d+\)( Error:| Failure:|$)/) {|match|
    " <n>) #{match[1]}"
  }

  # rubyspec
  # -- reports aborting on a killed thread (FAILED - 9)
  # -- flattens self (ERROR - 21)
  t.add_diff_preprocess_gsub(/\((FAILED|ERROR) - \d+\)$/) {|match|
    "(#{match[1]} - <n>)"
  }

  t.add_diff_preprocess_gsub(%r{\((druby|drbssl)://(#{DOMAINPAT}):\d+\)}o) {|match|
    "(#{match[1]}://#{match[2]}:<port>)"
  }

  # [2006-09-24T12:48:49.245737 #6902] ERROR -- : undefined method `each' for #<String:0x447fc5e4> (NoMethodError)
  t.add_diff_preprocess_gsub(%r{\[\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+) \#(\d+)\]}o) {|match|
    "[YYYY-MM-DDThh:mm:ss" + match[1].gsub(/\d/, 's') + " #<pid>]"
  }

  # #<String:0x4455ae94
  t.add_diff_preprocess_gsub(%r{\#<[A-Z][A-Za-z0-9_]*(?:::[A-Z][A-Za-z0-9_]*)*:0x[0-9a-f]+}o) {|match|
    match[0].sub(/[0-9a-f]+\z/) { 'X' * $&.length }
  }

  # #<#<Class:0xXXXXXXX>:0x0e87dd00
  # order sensitive.  this should be applied after the above.
  t.add_diff_preprocess_gsub(%r{(\#<\#<Class:0xX+>:0x)([0-9a-f]+)}o) {|match|
    match[1] + 'X' * match[2].length
  }

  # #<BigDecimal:403070d8,
  t.add_diff_preprocess_gsub(%r{\#<BigDecimal:[0-9a-f]+}) {|match|
    match[0].sub(/[0-9a-f]+\z/) { 'X' * $&.length }
  }

  # but got ThreadError (uncaught throw `blah' in thread 0x23f0660)
  t.add_diff_preprocess_gsub(%r{thread 0x[0-9a-f]+}o) {|match|
    match[0].sub(/[0-9a-f]+\z/) { 'X' * $&.length }
  }

  # XSD::ValueSpaceError: {http://www.w3.org/2001/XMLSchema}dateTime: cannot accept '2007-02-01T23:44:2682967.846399999994901+09:00'.
  t.add_diff_preprocess_gsub(%r{\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\d+\.\d+}o) {|match|
    s = match[0]
    chars = %w[Y M D h m s s]
    s.gsub!(/\d+/) { "<#{chars.shift}>" }
    s
  }

  # mkdir -p /home/akr/chkbuild/tmp/build/ruby-trunk/<buildtime>/tmp/fileutils.rb.23661/tmpdir/dir/
  t.add_diff_preprocess_gsub(%r{/tmp/fileutils.rb.\d+/tmpdir/}o) {|match|
    '/tmp/fileutils.rb.<n>/tmpdir/'
  }

  # connect to #<Addrinfo: [::1]:54046 TCP>.
  t.add_diff_preprocess_gsub(%r{\#<Addrinfo: \[::1\]:\d+}o) {|match|
    '#<Addrinfo: [::1]:<port>'
  }

  t.add_diff_preprocess_gsub(/^Elapsed: [0-9.]+s/) {|match|
    "Elapsed: <t>s"
  }

  # test/unit:
  # Finished in 139.785699 seconds.
  # rubyspec:
  # Finished in 31.648244 seconds
  t.add_diff_preprocess_gsub(/^Finished in [0-9.]+ seconds/) {|match|
    "Finished in <t> seconds"
  }

  # /tmp/test_rubygems_18634
  t.add_diff_preprocess_gsub(%r{/tmp/test_rubygems_\d+}o) {|match|
    '/tmp/test_rubygems_<pid>'
  }

  # <buildtime>/mspec/lib/mspec/mocks/mock.rb:128:in `__ms_70044980_respond_to?__'
  t.add_diff_preprocess_gsub(%r{__ms_-?\d+_}) {|match|
  '__ms_<object_id>_'
  }

  # miniunit:
  # Complex_Test#test_parse: 0.01 s: .
  t.add_diff_preprocess_gsub(%r{\d+\.\d\d s: }) {|match|
  '<elapsed> s: '
  }

  # MinitestSpec#test_needs_to_verify_nil: <elapsed> s: .
  # RUNIT::TestAssert#test_assert_send: .
  t.add_diff_preprocess_sort(/\A[A-Z][A-Za-z0-9_]+(::[A-Z][A-Za-z0-9_]+)*\#/)

  # - returns self as a symbol literal for :$*
  t.add_diff_preprocess_sort(/\A- returns self as a symbol literal for :/)

  t
end

.limit_combination(*suffixes) ⇒ Object



68
69
70
71
72
73
# File 'lib/chkbuild/targets/ruby.rb', line 68

def limit_combination(*suffixes)
  if suffixes.include?("pth")
    return false if suffixes.grep(/\A1\.8/).empty? && !suffixes.include?("matzruby")
  end
  true
end