class L::C::TargetGeneratedHeader
Public Class Methods
new(opt, name, h, c, values)
click to toggle source
Calls superclass method
R::TargetSmart::new
# 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
Public Instance Methods
build_self()
click to toggle source
# 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] # @TODO: make this quote for C rather then ruby. 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
hash_input()
click to toggle source
# File lib/rub/l/c.rb, line 382 def hash_input Digest::SHA1.digest(@val.inspect) end
hash_output(t)
click to toggle source
# File lib/rub/l/c.rb, line 386 def hash_output(t) Digest::SHA1.digest(t.readlines.drop(2).join('\n')) end