Rakefile
changeset 11 7fc2d1713795
parent 5 804e1c2b9a40
child 12 3cc813140c80
equal deleted inserted replaced
10:389e66b0d38e 11:7fc2d1713795
     1 #!rake -*- ruby -*-
     1 #!rake
     2 #
     2 #
     3 # Ruby-Ezmlm rakefile
     3 # Ruby-Ezmlm rakefile
     4 #
     4 #
     5 # Based on Ben Bleything's Rakefile for Linen (URL?)
     5 # Based on various other Rakefiles, especially one by Ben Bleything
     6 #
     6 #
     7 # Copyright (c) 2007 LAIKA, Inc.
     7 # Copyright (c) 2008 The FaerieMUD Consortium
     8 #
     8 #
     9 # Mistakes:
     9 # Authors:
    10 #  * Michael Granger <mgranger@laika.com>
    10 #  * LAIKA Information Systems <opensource@laika.com>
    11 #
    11 #
    12 
    12 
    13 BEGIN {
    13 BEGIN {
    14 	require 'pathname'
    14 	require 'pathname'
    15 	basedir = Pathname.new( __FILE__ ).dirname
    15 	basedir = Pathname.new( __FILE__ ).dirname
    16 	libdir = basedir + 'lib'
    16 
       
    17 	libdir = basedir + "lib"
       
    18 	extdir = basedir + "ext"
    17 
    19 
    18 	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
    20 	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
    19 }
    21 	$LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
    20 
    22 }
    21 
    23 
       
    24 
       
    25 require 'rbconfig'
    22 require 'rubygems'
    26 require 'rubygems'
    23 
       
    24 require 'rake'
    27 require 'rake'
    25 require 'tmpdir'
    28 require 'rake/rdoctask'
    26 require 'pathname'
    29 require 'rake/testtask'
       
    30 require 'rake/packagetask'
       
    31 require 'rake/clean'
    27 
    32 
    28 $dryrun = false
    33 $dryrun = false
    29 
    34 
    30 # Pathname constants
    35 ### Config constants
    31 BASEDIR       = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )
    36 BASEDIR       = Pathname.new( __FILE__ ).dirname.relative_path_from( Pathname.getwd )
    32 BINDIR        = BASEDIR + 'bin'
    37 BINDIR        = BASEDIR + 'bin'
    33 LIBDIR        = BASEDIR + 'lib'
    38 LIBDIR        = BASEDIR + 'lib'
       
    39 EXTDIR        = BASEDIR + 'ext'
    34 DOCSDIR       = BASEDIR + 'docs'
    40 DOCSDIR       = BASEDIR + 'docs'
    35 VARDIR        = BASEDIR + 'var'
       
    36 WWWDIR        = VARDIR  + 'www'
       
    37 MANUALDIR     = DOCSDIR + 'manual'
       
    38 RDOCDIR       = DOCSDIR + 'rdoc'
       
    39 STATICWWWDIR  = WWWDIR  + 'static'
       
    40 PKGDIR        = BASEDIR + 'pkg'
    41 PKGDIR        = BASEDIR + 'pkg'
    41 ARTIFACTS_DIR = Pathname.new( ENV['CC_BUILD_ARTIFACTS'] || '' )
    42 
       
    43 PROJECT_NAME  = 'Ruby-Ezmlm'
       
    44 PKG_NAME      = PROJECT_NAME.downcase
       
    45 PKG_SUMMARY   = 'A programmatic interface to ezmlm-idx lists'
       
    46 VERSION_FILE  = LIBDIR + 'ezmlm.rb'
       
    47 PKG_VERSION   = VERSION_FILE.read[ /VERSION = '(\d+\.\d+\.\d+)'/, 1 ]
       
    48 PKG_FILE_NAME = "#{PKG_NAME.downcase}-#{PKG_VERSION}"
       
    49 GEM_FILE_NAME = "#{PKG_FILE_NAME}.gem"
       
    50 
       
    51 ARTIFACTS_DIR = Pathname.new( ENV['CC_BUILD_ARTIFACTS'] || 'artifacts' )
       
    52 
       
    53 TEXT_FILES    = %w( Rakefile ChangeLog README LICENSE ).collect {|filename| BASEDIR + filename }
       
    54 BIN_FILES     = Pathname.glob( BINDIR + '*' ).delete_if {|item| item =~ /\.svn/ }
       
    55 LIB_FILES     = Pathname.glob( LIBDIR + '**/*.rb' ).delete_if {|item| item =~ /\.svn/ }
       
    56 EXT_FILES     = Pathname.glob( EXTDIR + '**/*.{c,h,rb}' ).delete_if {|item| item =~ /\.svn/ }
       
    57 
       
    58 SPECDIR       = BASEDIR + 'spec'
       
    59 SPECLIBDIR    = SPECDIR + 'lib'
       
    60 SPEC_FILES    = Pathname.glob( SPECDIR + '**/*_spec.rb' ).delete_if {|item| item =~ /\.svn/ } +
       
    61                 Pathname.glob( SPECLIBDIR + '**/*.rb' ).delete_if {|item| item =~ /\.svn/ }
       
    62 
       
    63 TESTDIR       = BASEDIR + 'tests'
       
    64 TEST_FILES    = Pathname.glob( TESTDIR + '**/*.tests.rb' ).delete_if {|item| item =~ /\.svn/ }
       
    65 
    42 RAKE_TASKDIR  = BASEDIR + 'rake'
    66 RAKE_TASKDIR  = BASEDIR + 'rake'
    43 
    67 RAKE_TASKLIBS = Pathname.glob( RAKE_TASKDIR + '*.rb' )
    44 TEXT_FILES    = %w( Rakefile README LICENSE ).
    68 
    45 	collect {|filename| BASEDIR + filename }
    69 LOCAL_RAKEFILE = BASEDIR + 'Rakefile.local'
    46 
    70 
    47 SPECDIR       = BASEDIR + 'spec'
    71 EXTRA_PKGFILES = []
    48 SPEC_FILES    = Pathname.glob( SPECDIR + '**/*_spec.rb' ).
    72 
    49 	delete_if {|item| item =~ /\.svn/ }
    73 RELEASE_FILES = TEXT_FILES + 
    50 # Ideally, this should be automatically generated.
    74 	SPEC_FILES + 
    51 SPEC_EXCLUDES = 'spec,monkeypatches,/Library/Ruby,/var/lib,/usr/local/lib'
    75 	TEST_FILES + 
    52 
    76 	BIN_FILES +
    53 BIN_FILES     = Pathname.glob( BINDIR + '*').
    77 	LIB_FILES + 
    54 	delete_if {|item| item =~ /\.svn/ }
    78 	EXT_FILES + 
    55 LIB_FILES     = Pathname.glob( LIBDIR + '**/*.rb').
    79 	RAKE_TASKLIBS +
    56 	delete_if {|item| item =~ /\.svn/ }
    80 	EXTRA_PKGFILES
    57 
    81 
    58 RELEASE_FILES = BIN_FILES + TEXT_FILES + LIB_FILES + SPEC_FILES
    82 RELEASE_FILES << LOCAL_RAKEFILE if LOCAL_RAKEFILE.exist?
    59 
    83 
       
    84 COVERAGE_MINIMUM = ENV['COVERAGE_MINIMUM'] ? Float( ENV['COVERAGE_MINIMUM'] ) : 85.0
       
    85 RCOV_EXCLUDES = 'spec,tests,/Library/Ruby,/var/lib,/usr/local/lib'
       
    86 RCOV_OPTS = [
       
    87 	'--exclude', RCOV_EXCLUDES,
       
    88 	'--xrefs',
       
    89 	'--save',
       
    90 	'--callsites',
       
    91 	#'--aggregate', 'coverage.data' # <- doesn't work as of 0.8.1.2.0
       
    92   ]
       
    93 
       
    94 
       
    95 # Subversion constants -- directory names for releases and tags
       
    96 SVN_TRUNK_DIR    = 'trunk'
       
    97 SVN_RELEASES_DIR = 'releases'
       
    98 SVN_BRANCHES_DIR = 'branches'
       
    99 SVN_TAGS_DIR     = 'tags'
       
   100 
       
   101 SVN_DOTDIR       = BASEDIR + '.svn'
       
   102 SVN_ENTRIES      = SVN_DOTDIR + 'entries'
       
   103 
       
   104 
       
   105 ### Load some task libraries that need to be loaded early
    60 require RAKE_TASKDIR + 'helpers.rb'
   106 require RAKE_TASKDIR + 'helpers.rb'
    61 
       
    62 ### Package constants
       
    63 PKG_NAME      = 'ruby-ezmlm'
       
    64 PKG_VERSION_FROM = LIBDIR + 'ezmlm.rb'
       
    65 PKG_VERSION   = find_pattern_in_file( /VERSION = '(\d+\.\d+\.\d+)'/, PKG_VERSION_FROM ).first
       
    66 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
       
    67 
       
    68 RELEASE_NAME  = "REL #{PKG_VERSION}"
       
    69 
       
    70 require RAKE_TASKDIR + 'svn.rb'
   107 require RAKE_TASKDIR + 'svn.rb'
    71 require RAKE_TASKDIR + 'verifytask.rb'
   108 require RAKE_TASKDIR + 'verifytask.rb'
    72 
   109 
    73 if Rake.application.options.trace
   110 # Define some constants that depend on the 'svn' tasklib
    74 	$trace = true
   111 PKG_BUILD = get_svn_rev( BASEDIR ) || 0
    75 	log "$trace is enabled"
   112 SNAPSHOT_PKG_NAME = "#{PKG_FILE_NAME}.#{PKG_BUILD}"
    76 end
   113 SNAPSHOT_GEM_NAME = "#{SNAPSHOT_PKG_NAME}.gem"
    77 
   114 
    78 if Rake.application.options.dryrun
   115 # Documentation constants
    79 	$dryrun = true
   116 RDOCDIR = DOCSDIR + 'api'
    80 	log "$dryrun is enabled"
   117 RDOC_OPTIONS = [
    81 	Rake.application.options.dryrun = false
   118 	'-w', '4',
    82 end
   119 	'-SHN',
    83 
   120 	'-i', '.',
    84 ### Project Gemspec
   121 	'-m', 'README',
    85 GEMSPEC = Gem::Specification.new do |gem|
   122 	'-W', 'http://opensource.laika.com/wiki/ruby-ezmlm/browser/trunk/'
    86 	pkg_build = get_svn_rev( BASEDIR ) || 0
   123   ]
    87 	
   124 
    88 	gem.name    	= PKG_NAME
   125 # Release constants
    89 	gem.version 	= "%s.%s" % [ PKG_VERSION, pkg_build ]
   126 SMTP_HOST = 'mail.faeriemud.org'
    90 
   127 SMTP_PORT = 465 # SMTP + SSL
    91 	gem.summary     = "A Ruby programmatic interface to ezmlm-idx"
   128 
    92 	gem.description = "Ruby-Ezmlm is a Ruby programmatic interface to ezmlm-idx " +
   129 # Project constants
    93 		"mailing lists, message archives, and command-line tools."
   130 PROJECT_HOST = 'deveiate.org'
    94 
   131 PROJECT_PUBDIR = "/usr/local/www/public/code"
    95 	gem.authors  	= "Michael Granger, Jeremiah Jordan"
   132 PROJECT_DOCDIR = "#{PROJECT_PUBDIR}/#{PKG_NAME}"
    96 	gem.email  		= "opensource@laika.com"
   133 PROJECT_SCPPUBURL = "#{PROJECT_HOST}:#{PROJECT_PUBDIR}"
    97 	gem.homepage 	= "http://opensource.laika.com/wiki/ruby-ezmlm"
   134 PROJECT_SCPDOCURL = "#{PROJECT_HOST}:#{PROJECT_DOCDIR}"
    98 
   135 
    99 	gem.rubyforge_project = 'laika'
   136 # Rubyforge stuff
   100 
   137 RUBYFORGE_GROUP = 'laika'
   101 	gem.has_rdoc 	= true
   138 RUBYFORGE_PROJECT = 'ezmlm'
   102 
   139 
   103 	gem.files      	= RELEASE_FILES.
   140 # Gem dependencies: gemname => version
       
   141 DEPENDENCIES = {
       
   142 	'tmail' => '>=1.2.3.1',
       
   143 }
       
   144 
       
   145 # Developer Gem dependencies: gemname => version
       
   146 DEVELOPMENT_DEPENDENCIES = {
       
   147 	'amatch'      => '>= 0.2.3',
       
   148 	'rake'        => '>= 0.8.1',
       
   149 	'rcodetools'  => '>= 0.7.0.0',
       
   150 	'rcov'        => '>= 0',
       
   151 	'RedCloth'    => '>= 4.0.3',
       
   152 	'rspec'       => '>= 0',
       
   153 	'rubyforge'   => '>= 0',
       
   154 	'termios'     => '>= 0',
       
   155 	'text-format' => '>= 1.0.0',
       
   156 	'tmail'       => '>= 1.2.3.1',
       
   157 	'ultraviolet' => '>= 0.10.2',
       
   158 	'libxml-ruby' => '>= 0.8.3',
       
   159 }
       
   160 
       
   161 # Non-gem requirements: packagename => version
       
   162 REQUIREMENTS = {
       
   163 	'ezmlm-idx' => '>=0',
       
   164 }
       
   165 
       
   166 # RubyGem specification
       
   167 GEMSPEC   = Gem::Specification.new do |gem|
       
   168 	gem.name              = PKG_NAME.downcase
       
   169 	gem.version           = PKG_VERSION
       
   170 
       
   171 	gem.summary           = PKG_SUMMARY
       
   172 	gem.description       = <<-EOD
       
   173 	Ruby-Ezmlm provides a programmatic interface to ezmlm-idx lists, their archives, and the command
       
   174 	line utilities that interact with them. The library is intended to provide two sets of
       
   175 	functionality: the management and setup of lists, and programmatic access to the message archive.
       
   176 	EOD
       
   177 
       
   178 	gem.authors           = 'LAIKA Information Systems'
       
   179 	gem.email             = 'opensource@laika.com'
       
   180 	gem.homepage          = 'http://opensource.laika.com/wiki/ruby-ezmlm'
       
   181 	gem.rubyforge_project = RUBYFORGE_PROJECT
       
   182 
       
   183 	gem.has_rdoc          = true
       
   184 	gem.rdoc_options      = RDOC_OPTIONS
       
   185 
       
   186 	gem.bindir            = BINDIR.relative_path_from(BASEDIR).to_s
       
   187 	
       
   188 
       
   189 	gem.files             = RELEASE_FILES.
   104 		collect {|f| f.relative_path_from(BASEDIR).to_s }
   190 		collect {|f| f.relative_path_from(BASEDIR).to_s }
   105 	gem.test_files 	= SPEC_FILES.
   191 	gem.test_files        = SPEC_FILES.
   106 		collect {|f| f.relative_path_from(BASEDIR).to_s }
   192 		collect {|f| f.relative_path_from(BASEDIR).to_s }
   107 
   193 		
   108   	gem.add_dependency( 'tmail', '>= 1.2.3.1' )
   194 	DEPENDENCIES.each do |name, version|
   109 end
   195 		version = '>= 0' if version.length.zero?
   110 
   196 		gem.add_runtime_dependency( name, version )
   111 
   197 	end
   112 # Load task plugins
   198 	
   113 Pathname.glob( RAKE_TASKDIR + '*.rb' ).each do |tasklib|
   199 	DEVELOPMENT_DEPENDENCIES.each do |name, version|
   114 	trace "Loading task lib #{tasklib}"
   200 		version = '>= 0' if version.length.zero?
   115 	require tasklib
   201 		gem.add_development_dependency( name, version )
   116 end
   202 	end
   117 
   203 	
       
   204 	REQUIREMENTS.each do |name, version|
       
   205 		gem.requirements << [ name, version ].compact.join(' ')
       
   206 	end
       
   207 end
       
   208 
       
   209 # Manual-generation config
       
   210 MANUALDIR = DOCSDIR + 'manual'
       
   211 
       
   212 $trace = Rake.application.options.trace ? true : false
       
   213 $dryrun = Rake.application.options.dryrun ? true : false
       
   214 
       
   215 
       
   216 # Load any remaining task libraries
       
   217 RAKE_TASKLIBS.each do |tasklib|
       
   218 	next if tasklib =~ %r{/(helpers|svn|verifytask)\.rb$}
       
   219 	begin
       
   220 		require tasklib
       
   221 	rescue ScriptError => err
       
   222 		fail "Task library '%s' failed to load: %s: %s" %
       
   223 			[ tasklib, err.class.name, err.message ]
       
   224 		trace "Backtrace: \n  " + err.backtrace.join( "\n  " )
       
   225 	rescue => err
       
   226 		log "Task library '%s' failed to load: %s: %s. Some tasks may not be available." %
       
   227 			[ tasklib, err.class.name, err.message ]
       
   228 		trace "Backtrace: \n  " + err.backtrace.join( "\n  " )
       
   229 	end
       
   230 end
       
   231 
       
   232 # Load any project-specific rules defined in 'Rakefile.local' if it exists
       
   233 import LOCAL_RAKEFILE if LOCAL_RAKEFILE.exist?
       
   234 
       
   235 
       
   236 #####################################################################
       
   237 ###	T A S K S 	
       
   238 #####################################################################
   118 
   239 
   119 ### Default task
   240 ### Default task
   120 task :default  => [:clean, :spec, 'coverage:verify', :package]
   241 task :default  => [:clean, :local, :spec, :rdoc, :package]
       
   242 
       
   243 ### Task the local Rakefile can append to -- no-op by default
       
   244 task :local
   121 
   245 
   122 
   246 
   123 ### Task: clean
   247 ### Task: clean
   124 desc "Clean pkg, coverage, and rdoc; remove .bak files"
   248 CLEAN.include 'coverage'
   125 task :clean => [ :clobber_rdoc, :clobber_package, :clobber_coverage ] do
   249 CLOBBER.include 'artifacts', 'coverage.info', PKGDIR
   126 	files = FileList['**/*.bak']
   250 
   127 	files.clear_exclude
   251 # Target to hinge on ChangeLog updates
   128 	File.rm( files ) unless files.empty?
   252 file SVN_ENTRIES
   129 	FileUtils.rm_rf( 'artifacts' )
   253 
   130 end
   254 ### Task: changelog
   131 
   255 file 'ChangeLog' => SVN_ENTRIES.to_s do |task|
   132 
   256 	log "Updating #{task.name}"
   133 ### Cruisecontrol task
   257 
       
   258 	changelog = make_svn_changelog()
       
   259 	File.open( task.name, 'w' ) do |fh|
       
   260 		fh.print( changelog )
       
   261 	end
       
   262 end
       
   263 
       
   264 
       
   265 ### Task: cruise (Cruisecontrol task)
   134 desc "Cruisecontrol build"
   266 desc "Cruisecontrol build"
   135 task :cruise => [:clean, :coverage, :rdoc, :package] do |task|
   267 task :cruise => [:clean, :spec, :package] do |task|
   136 	raise "Artifacts dir not set." if ARTIFACTS_DIR.to_s.empty?
   268 	raise "Artifacts dir not set." if ARTIFACTS_DIR.to_s.empty?
   137 	artifact_dir = ARTIFACTS_DIR.cleanpath
   269 	artifact_dir = ARTIFACTS_DIR.cleanpath
   138 	artifact_dir.mkpath
   270 	artifact_dir.mkpath
   139 	
   271 	
   140 	$stderr.puts "Copying coverage stats..."
   272 	coverage = BASEDIR + 'coverage'
   141 	FileUtils.cp_r( 'coverage', artifact_dir )
   273 	if coverage.exist? && coverage.directory?
   142 	
   274 		$stderr.puts "Copying coverage stats..."
   143 	$stderr.puts "Copying documentation..."
   275 		FileUtils.cp_r( 'coverage', artifact_dir )
   144 	FileUtils.cp_r( 'docs/api', artifact_dir + 'rdoc' )
   276 	end
   145 	
   277 	
   146 	$stderr.puts "Copying packages..."
   278 	$stderr.puts "Copying packages..."
   147 	FileUtils.cp_r( FileList['pkg/*'].to_a, artifact_dir )
   279 	FileUtils.cp_r( FileList['pkg/*'].to_a, artifact_dir )
   148 end
   280 end
   149 
   281 
       
   282 
       
   283 desc "Update the build system to the latest version"
       
   284 task :update_build do
       
   285 	log "Updating the build system"
       
   286 	sh 'svn', 'up', RAKE_TASKDIR
       
   287 	log "Updating the Rakefile"
       
   288 	sh 'rake', '-f', RAKE_TASKDIR + 'Metarakefile'
       
   289 end
       
   290