Class: L::C::TargetGeneratedHeader
Instance Attribute Summary
#input, #output
Instance Method Summary
collapse
#build, #clean, #clean?
Methods inherited from R::Target
#build, #clean?, #description, #hash_outputs, #hash_self, #input, #output, #register
Constructor Details
Returns a new instance of TargetGeneratedHeader.
370
371
372
373
374
375
376
377
378
379
380
|
# File 'lib/rub/l/c.rb', line 370
def initialize(opt, name, h, c, values)
super()
@n = name
@h = h
@c = c
@val = values
output << @h << @c
end
|
Instance Method Details
#build_self ⇒ Object
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
|
# File 'lib/rub/l/c.rb', line 390
def build_self
@h.dirname.mkpath
@c.dirname.mkpath
h = @h.open('w')
c = @c.open('w')
notice = <<"EOS"
/* THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT! */
/* This file was generated by Rub on #{DateTime.now.iso8601} */
EOS
h.print notice
c.print notice
hname = L::C.to_c_identifier(@h.basename.to_s).upcase
h.puts "#ifndef RUB_L_C_GENERATE_HEADER___#{hname}"
h.puts "#define RUB_L_C_GENERATE_HEADER___#{hname}"
h.puts ''
c.puts %|#include "#{@n}.h"|
c.puts ''
@val.each do |k, v|
type, v = if v.is_a?(Array)
[v[0], v[1]]
elsif v.is_a? Numeric
['int', v.to_s]
elsif v.equal?(true) || v.equal?(false)
['short unsigned int', v ? 1 : 0]
elsif v.respond_to? :to_s
['const char *', v.to_s.inspect] end
h.puts "extern #{type} #{k};"
c.puts "#{type} #{k} = #{v};"
end
h.puts ''
h.puts "#endif /* RUB_L_C_GENERATE_HEADER___#{hname} */"
h.close
c.close
bs = R::BuildStep.new
bs.desc = "Generating #{@h} and #{@c}"
bs.print
end
|
382
383
384
|
# File 'lib/rub/l/c.rb', line 382
def hash_input
Digest::SHA1.digest(@val.inspect)
end
|
#hash_output(t) ⇒ Object
386
387
388
|
# File 'lib/rub/l/c.rb', line 386
def hash_output(t)
Digest::SHA1.digest(t.readlines.drop(2).join('\n'))
end
|