chunker/Rakefile
branchruby-modules
changeset 1 9e127bf6e84f
child 2 e5c705047540
equal deleted inserted replaced
0:83c0eed6db19 1:9e127bf6e84f
       
     1 #!/usr/bin/env rake
       
     2 #
       
     3 # Chunker Rakefile
       
     4 #
       
     5 
       
     6 require 'rubygems'
       
     7 require 'pathname'
       
     8 
       
     9 require 'rake'
       
    10 require 'rake/gempackagetask'
       
    11 require 'spec/rake/spectask'
       
    12 
       
    13 
       
    14 ######################################################################
       
    15 ### P A T H S
       
    16 ######################################################################
       
    17 
       
    18 BASEDIR    = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )
       
    19 SPECDIR    = BASEDIR + 'spec'
       
    20 LIBDIR     = BASEDIR + 'lib'
       
    21 SPEC_FILES = Pathname.glob( SPECDIR + '**/*_spec.rb' ).reject {|f| f =~ /^\.svn/ }
       
    22 
       
    23 ######################################################################
       
    24 ### H E L P E R S
       
    25 ######################################################################
       
    26 
       
    27 ### Given a +file+ path, find the first captured match of +pattern+,
       
    28 ### or the string 'UNKNOWN' if not found. (easy to notice something is wrong.)
       
    29 ###
       
    30 def find_pattern( file, pattern )
       
    31 	ver = nil
       
    32 	File.open( file ) do |f|
       
    33 		ver = f.each do |line|
       
    34 			break $1 if line =~ pattern
       
    35 		end
       
    36 	end
       
    37 	return ver.is_a?( String ) ? ver : 'UNKNOWN'
       
    38 end
       
    39 
       
    40 ######################################################################
       
    41 ### P A C K A G E   C O N S T A N T S
       
    42 ######################################################################
       
    43 
       
    44 PKG_NAME      = 'chunker'
       
    45 PKG_VERSION   = find_pattern( LIBDIR + 'chunker.rb', /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/ )
       
    46 PKG_REVISION  = find_pattern( LIBDIR + 'chunker.rb', /SVNRev = .+Rev: (\d+)/ )
       
    47 PKG_VERSION   = begin
       
    48 					ver = nil
       
    49 					File.open( LIBDIR + 'chunker.rb' ) do |f|
       
    50 						ver = f.each do |line|
       
    51 							break $1 if line =~ /VERSION = ['"](\d\.\d(?:\/\d)?)['"]/
       
    52 						end
       
    53 					end
       
    54 					ver.is_a?( String ) ? ver : 'UNKNOWN'
       
    55 				end
       
    56 RELEASE_NAME  = "REL #{PKG_VERSION}"
       
    57 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
       
    58 
       
    59 
       
    60 ######################################################################
       
    61 ### T A S K S
       
    62 ######################################################################
       
    63 
       
    64 task :default => [:test]
       
    65 
       
    66 
       
    67 ### Task: run rspec tests
       
    68 ###
       
    69 desc "Run tests"
       
    70 Spec::Rake::SpecTask.new('test') do |task|
       
    71 	task.spec_files = FileList['spec/**/*.rb']
       
    72 	task.spec_opts  = %w{ -c -fs }
       
    73 end
       
    74 
       
    75 
       
    76 ### Task: generate ctags
       
    77 ### This assumes exuberant ctags, since ctags 'native' doesn't support ruby anyway.
       
    78 ###
       
    79 desc "Generate a ctags 'tags' file from Chunker source"
       
    80 task :ctags do
       
    81 	sh "ctags -R #{LIBDIR}"
       
    82 end
       
    83 
       
    84 
       
    85 ### Task: Create gem from source
       
    86 ###
       
    87 gem = Gem::Specification.new do |gem|
       
    88 end
       
    89 
       
    90 Rake::GemPackageTask.new( gem ) do |pkg|
       
    91 	pkg.need_zip = true
       
    92 	pkg.need_tar = true
       
    93 end
       
    94 
       
    95 
       
    96 
       
    97 __END__
       
    98 
       
    99   spec = Gem::Specification.new do |s|
       
   100     s.platform = Gem::Platform::RUBY
       
   101     s.summary = "Ruby based make-like utility."
       
   102     s.name = 'rake'
       
   103     s.version = PKG_VERSION
       
   104     s.requirements << 'none'
       
   105     s.require_path = 'lib'
       
   106     s.autorequire = 'rake'
       
   107     s.files = PKG_FILES
       
   108     s.description = <<EOF
       
   109   Rake is a Make-like program implemented in Ruby. Tasks
       
   110   and dependencies are specified in standard Ruby syntax.
       
   111   EOF
       
   112   end
       
   113 
       
   114   Rake::GemPackageTask.new(spec) do |pkg|
       
   115     pkg.need_zip = true
       
   116     pkg.need_tar = true
       
   117   end
       
   118 
       
   119 
       
   120 
       
   121 
       
   122 
       
   123 
       
   124 require 'rake/packagetask'
       
   125 require 'rake/gempackagetask'
       
   126 
       
   127 ### Task: gem
       
   128 gemspec = Gem::Specification.new do |gem|
       
   129 	pkg_build = get_svn_rev( BASEDIR ) || 0
       
   130 	
       
   131 	gem.name    	= PKG_NAME
       
   132 	gem.version 	= "%s.%s" % [ PKG_VERSION, pkg_build ]
       
   133 
       
   134 	gem.summary     = "ThingFish - A highly-accessable network datastore"
       
   135 	gem.description = "ThingFish is a network-accessable, searchable, extensible " +
       
   136 	                  "datastore. It can be used to store chunks of data on the " +
       
   137 	                  "network in an application-independent way, associate the chunks " +
       
   138 	                  "with other chunks through metadata, and then search for the chunk " +
       
   139 	                  "you need later and fetch it again, all through a REST API over HTTP."	
       
   140 
       
   141 	gem.authors  	= "Michael Granger and Mahlon E. Smith"
       
   142 	gem.email  		= "mgranger@laika.com, mahlon@laika.com"
       
   143 	gem.homepage 	= "http://opensource.laika.com/wiki/ThingFish"
       
   144 
       
   145 	gem.rubyforge_project = 'laika'
       
   146 
       
   147 	gem.has_rdoc 	= true
       
   148 
       
   149 	gem.files      	= RELEASE_FILES.
       
   150 		collect {|f| f.relative_path_from(BASEDIR).to_s }
       
   151 	gem.test_files 	= SPEC_FILES.
       
   152 		collect {|f| f.relative_path_from(BASEDIR).to_s }
       
   153 	gem.executables = BIN_FILES	.
       
   154 		collect {|f| f.relative_path_from(BINDIR).to_s }
       
   155 
       
   156   	gem.add_dependency( 'uuidtools', '>= 1.0.0' )
       
   157   	gem.add_dependency( 'pluginfactory', '>= 1.0.3' )
       
   158 end
       
   159 Rake::GemPackageTask.new( gemspec ) do |task|
       
   160 	task.gem_spec = gemspec
       
   161 	task.need_tar = false
       
   162 	task.need_tar_gz = true
       
   163 	task.need_tar_bz2 = true
       
   164 	task.need_zip = true
       
   165 end
       
   166 
       
   167 
       
   168 desc "Build the ThingFish gem and gems for all the standard plugins"
       
   169 task :gems => [:gem] do
       
   170 	log "Building gems for plugins in: %s" % [PLUGINS.join(', ')]
       
   171 	PLUGINS.each do |plugindir|
       
   172 		log plugindir.basename
       
   173 		cp BASEDIR + 'LICENSE', plugindir
       
   174 		Dir.chdir( plugindir ) do
       
   175 			system 'rake', 'gem'
       
   176 		end
       
   177 		
       
   178 		fail unless $?.success?
       
   179 		
       
   180 		pkgdir = plugindir + 'pkg'
       
   181 		gems = Pathname.glob( pkgdir + '*.gem' )
       
   182 		cp gems, PKGDIR
       
   183 	end
       
   184 end
       
   185 
       
   186 
       
   187 ### Task: install
       
   188 task :install_gem => [:package] do
       
   189 	$stderr.puts 
       
   190 	installer = Gem::Installer.new( %{pkg/#{PKG_FILE_NAME}.gem} )
       
   191 	installer.install
       
   192 end
       
   193 
       
   194 ### Task: uninstall
       
   195 task :uninstall_gem => [:clean] do
       
   196 	uninstaller = Gem::Uninstaller.new( PKG_FILE_NAME )
       
   197 	uninstaller.uninstall
       
   198 end
       
   199 
       
   200 
       
   201 
       
   202