require_relative "generate/generate" Dir.chdir __dir__ version_re = /\d+(\.\d+)*/ version = `command grep 'VERSION =' lib/zscan.rb`[version_re] gem_files = Dir.glob('{rakefile,zscan.gemspec,readme.md,**/*.{rb,h,c,inc},ext/pack/COPYING*}') gem_package = "zscan-#{version}.gem" generate_src = [__FILE__, *Dir.glob('generate/*')] desc "generate, build and test, and pack gem" task :default => [:gen, :test, gem_package] desc "build and test" task :test => 'ext/Makefile' do sh "make -C ext" sh "rspec" end file 'ext/Makefile' do Dir.chdir 'ext' do sh "ruby extconf.rb" end end desc "pack gem" file gem_package => gem_files + Generate.files do sh "rm zscan-*.gem" new_version = false lines = File.readlines('zscan.gemspec') lines.each do |line| if line =~ /s\.version =/ and (line.sub! version_re, version) new_version = true break end end if new_version File.open('zscan.gemspec', 'w'){|f| f << lines.join } end puts "packing files:" puts '-' * 40 puts gem_files puts '-' * 40 sh "gem build zscan.gemspec" end desc "generate files" task :gen => Generate.files Generate.files.each do |name| file name => generate_src do puts "generating #{name}" r = Generate.generate(name) File.open name, 'w' do |f| f.puts "#{name.end_with?('rb') ? '#' : '//'} generated by rake gen" f << r end end end