rakefile in nyara-0.0.1.pre vs rakefile in nyara-0.0.1.pre.1
- old
+ new
@@ -2,10 +2,12 @@
Dir.chdir __dir__
status_file = "ext/inc/status_codes.inc"
version_file = "ext/inc/version.inc"
+makefile = "ext/Makefile"
+extconf = "ext/extconf.rb"
desc "code generate"
task :gen => [status_file, version_file]
desc "generate #{status_file}"
@@ -40,27 +42,73 @@
File.open version_file, 'w' do |f|
f.puts %Q{#define NYARA_VERSION "#{version}"}
end
end
+desc "generate makefile"
+file makefile => extconf do
+ Dir.chdir 'ext' do
+ sh 'ruby extconf.rb'
+ end
+end
+
desc "build ext"
-task :build do
+task :build => makefile do
Dir.chdir 'ext' do
sh 'make'
end
end
+def term_color n
+ print "\e[38;5;#{n}m"
+end
+
+def reset_color
+ print "\e[00m"
+end
+
+desc "check arity of rb_define_method/rb_define_singleton_method"
+task :check_arity do
+ Dir.glob 'ext/*.{c,cc}' do |f|
+ puts "validatign #{f}"
+ arities = {}
+ data = File.read f
+ data.scan /^(?:static )?VALUE (\w+)\((.+)\)/ do |func, params|
+ arities[func] = params.count(',')
+ puts " scan: #{func}/#{arities[func]}"
+ end
+ data.scan /rb_define(?:_singleton)?_method\(.*?(\w+)\s*\,\s*(\d+)\)/ do |func, arity|
+ print " check: #{func}/#{arity} "
+ if arities[func].nil?
+ term_color 5
+ print "UNSCANNED"
+ reset_color
+ puts
+ elsif arities[func] != arity.to_i
+ term_color 9
+ print "MISMATCH #{arities[func]}"
+ reset_color
+ puts
+ else
+ puts "OK"
+ end
+ end
+ end
+end
+
desc "test"
task :test => :build do
sh 'rspec', '-c'
end
desc "build and test"
task :default => :test
desc "build and install gem"
-task :gem do
- sh 'rm', '-f', '*.gem'
+task :gem => 'gen' do
+ Dir.glob('*.gem') do |f|
+ sh 'rm', f
+ end
sh 'gem', 'build', 'nyara.gemspec'
gem_package = Dir.glob('*.gem').first
sh 'gem', 'install', '--no-rdoc', '--no-ri', gem_package
end