#!/usr/bin/env rake # # Chunker Rakefile # require 'rubygems' require 'pathname' require 'rake' require 'rake/gempackagetask' require 'spec/rake/spectask' ###################################################################### ### P A T H S ###################################################################### BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd ) SPECDIR = BASEDIR + 'spec' LIBDIR = BASEDIR + 'lib' SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ).reject {|f| f =~ /^\.svn/ } ###################################################################### ### H E L P E R S ###################################################################### ### Given a +file+ path, find the first captured match of +pattern+, ### or the string 'UNKNOWN' if not found. (easy to notice something is wrong.) ### def find_pattern( file, pattern ) ver = nil File.open( file ) do |f| ver = f.each do |line| break $1 if line =~ pattern end end return ver.is_a?( String ) ? ver : 'UNKNOWN' end ###################################################################### ### P A C K A G E C O N S T A N T S ###################################################################### PKG_NAME = 'chunker' PKG_VERSION = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ ) PKG_REVISION = find_pattern( LIBDIR + 'chunker.rb', /SVNRev = .+Rev: (\d+)/ ) PKG_VERSION = begin ver = nil File.open( LIBDIR + 'chunker.rb' ) do |f| ver = f.each do |line| break $1 if line =~ /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ end end ver.is_a?( String ) ? ver : 'UNKNOWN' end RELEASE_NAME = "REL #{PKG_VERSION}" PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" ###################################################################### ### T A S K S ###################################################################### task :default => [:test] ### Task: run rspec tests ### desc "Run tests" Spec::Rake::SpecTask.new('test') do |task| task.spec_files = FileList['spec/**/*.rb'] task.spec_opts = %w{ -c -fs } end ### Task: generate ctags ### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway. ### desc "Generate a ctags 'tags' file from Chunker source" task :ctags do sh "ctags -R #{LIBDIR}" end ### Task: Create gem from source ### gem = Gem::Specification.new do |gem| end Rake::GemPackageTask.new( gem ) do |pkg| pkg.need_zip = true pkg.need_tar = true end __END__ spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.summary = "Ruby based make-like utility." s.name = 'rake' s.version = PKG_VERSION s.requirements << 'none' s.require_path = 'lib' s.autorequire = 'rake' s.files = PKG_FILES s.description = <= 1.0.0' ) gem.add_dependency( 'pluginfactory', '>= 1.0.3' ) end Rake::GemPackageTask.new( gemspec ) do |task| task.gem_spec = gemspec task.need_tar = false task.need_tar_gz = true task.need_tar_bz2 = true task.need_zip = true end desc "Build the ThingFish gem and gems for all the standard plugins" task :gems => [:gem] do log "Building gems for plugins in: %s" % [PLUGINS.join(', ')] PLUGINS.each do |plugindir| log plugindir.basename cp BASEDIR + 'LICENSE', plugindir Dir.chdir( plugindir ) do system 'rake', 'gem' end fail unless $?.success? pkgdir = plugindir + 'pkg' gems = Pathname.glob( pkgdir + '*.gem' ) cp gems, PKGDIR end end ### Task: install task :install_gem => [:package] do $stderr.puts installer = Gem::Installer.new( %{pkg/#{PKG_FILE_NAME}.gem} ) installer.install end ### Task: uninstall task :uninstall_gem => [:clean] do uninstaller = Gem::Uninstaller.new( PKG_FILE_NAME ) uninstaller.uninstall end