chunker/Rakefile
author mahlon
Sat, 08 Nov 2008 18:59:05 +0000
branchruby-modules
changeset 1 9e127bf6e84f
child 2 e5c705047540
permissions -rw-r--r--
Initial commit of chunker, a ruby module to aid with data blocks.

#!/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 = <<EOF
  Rake is a Make-like program implemented in Ruby. Tasks
  and dependencies are specified in standard Ruby syntax.
  EOF
  end

  Rake::GemPackageTask.new(spec) do |pkg|
    pkg.need_zip = true
    pkg.need_tar = true
  end






require 'rake/packagetask'
require 'rake/gempackagetask'

### Task: gem
gemspec = Gem::Specification.new do |gem|
	pkg_build = get_svn_rev( BASEDIR ) || 0
	
	gem.name    	= PKG_NAME
	gem.version 	= "%s.%s" % [ PKG_VERSION, pkg_build ]

	gem.summary     = "ThingFish - A highly-accessable network datastore"
	gem.description = "ThingFish is a network-accessable, searchable, extensible " +
	                  "datastore. It can be used to store chunks of data on the " +
	                  "network in an application-independent way, associate the chunks " +
	                  "with other chunks through metadata, and then search for the chunk " +
	                  "you need later and fetch it again, all through a REST API over HTTP."	

	gem.authors  	= "Michael Granger and Mahlon E. Smith"
	gem.email  		= "mgranger@laika.com, mahlon@laika.com"
	gem.homepage 	= "http://opensource.laika.com/wiki/ThingFish"

	gem.rubyforge_project = 'laika'

	gem.has_rdoc 	= true

	gem.files      	= RELEASE_FILES.
		collect {|f| f.relative_path_from(BASEDIR).to_s }
	gem.test_files 	= SPEC_FILES.
		collect {|f| f.relative_path_from(BASEDIR).to_s }
	gem.executables = BIN_FILES	.
		collect {|f| f.relative_path_from(BINDIR).to_s }

  	gem.add_dependency( 'uuidtools', '>= 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