luikore/triez

View on GitHub
rakefile

Summary

Maintainability
Test Coverage
require "rbconfig"
require "fileutils"
include FileUtils

so_file = "ext/triez.#{RbConfig::CONFIG['DLEXT']}"
src_files = Dir.glob('ext/*.{h,c,cc}')
vendor_files = %w[hat-trie]
extconf = 'ext/extconf.rb'
vendor_lib = 'ext/build/libtries.a'

desc "glob src for gem redist"
task :glob_src => vendor_files + [:clean] do
  Dir.chdir 'hat-trie' do
    sh *%w"git fetch"
    sh *%w"git rebase FETCH_HEAD master"
  end
  rm Dir.glob 'ext/hat-trie/*.{h,c}'
  hat_files = Dir.glob('hat-trie/src/*.{h,c}').select do |f|
    !(%w[common.h].include? File.basename(f))
  end
  cp hat_files, 'ext/hat-trie'
  cp 'hat-trie/COPYING', 'ext/hat-trie'
end

desc "download hat source"
file 'hat-trie' do
  sh 'git', 'clone', 'git://github.com/luikore/hat-trie.git'
end

desc "run tests"
task :default => so_file do
  sh 'ruby', "test/triez_test.rb"
end

desc "build ext"
file so_file => src_files + [extconf, vendor_lib] do
  Dir.chdir 'ext' do
    sh 'ruby', 'extconf.rb'
    sh 'make'
  end
end

file extconf
file vendor_lib

desc "clean ext"
task :clean do
  Dir.chdir 'ext' do
    if File.exist?('Makefile')
      sh 'make', 'clean'
    end
    rm Dir.glob 'build/*.{o,a}'
  end
end