Rakefile
changeset 12 3cc813140c80
parent 11 7fc2d1713795
child 13 a03c08c289e9
equal deleted inserted replaced
11:7fc2d1713795 12:3cc813140c80
     1 #!rake
     1 #!/usr/bin/env rake
     2 #
     2 # vim: set nosta noet ts=4 sw=4:
     3 # Ruby-Ezmlm rakefile
       
     4 #
       
     5 # Based on various other Rakefiles, especially one by Ben Bleything
       
     6 #
       
     7 # Copyright (c) 2008 The FaerieMUD Consortium
       
     8 #
       
     9 # Authors:
       
    10 #  * LAIKA Information Systems <opensource@laika.com>
       
    11 #
       
    12 
     3 
    13 BEGIN {
     4 require 'pathname'
    14 	require 'pathname'
       
    15 	basedir = Pathname.new( __FILE__ ).dirname
       
    16 
     5 
    17 	libdir = basedir + "lib"
     6 PROJECT = 'ezmlm'
    18 	extdir = basedir + "ext"
     7 BASEDIR = Pathname.new( __FILE__ ).expand_path.dirname.relative_path_from( Pathname.getwd )
       
     8 LIBDIR  = BASEDIR + 'lib'
    19 
     9 
    20 	$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
    10 if Rake.application.options.trace
    21 	$LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
    11     $trace = true
    22 }
    12     $stderr.puts '$trace is enabled'
       
    13 end
       
    14 
       
    15 # parse the current library version
       
    16 $version = ( LIBDIR + "#{PROJECT}.rb" ).read.split(/\n/).
       
    17 	select{|line| line =~ /VERSION =/}.first.match(/([\d|.]+)/)[1]
       
    18 
       
    19 task :default => [ :spec, :docs, :package ]
    23 
    20 
    24 
    21 
    25 require 'rbconfig'
    22 ########################################################################
       
    23 ### P A C K A G I N G
       
    24 ########################################################################
       
    25 
    26 require 'rubygems'
    26 require 'rubygems'
    27 require 'rake'
    27 require 'rubygems/package_task'
    28 require 'rake/rdoctask'
    28 spec = Gem::Specification.new do |s|
    29 require 'rake/testtask'
    29 	s.email        = 'mahlon@martini.nu'
    30 require 'rake/packagetask'
    30 	s.homepage     = 'https://bitbucket.org/mahlon/Ruby-Ezmlm'
    31 require 'rake/clean'
    31 	s.authors      = [
       
    32 		'Mahlon E. Smith <mahlon@martini.nu>',
       
    33 		'Michael Granger <ged@faeriemud.org>',
       
    34 		'Jeremiah Jordan <jjordan@laika.com>'
       
    35 	]
       
    36 	s.platform     = Gem::Platform::RUBY
       
    37 	s.summary      = "Interact with Ezmlm-IDX mailing lists."
       
    38 	s.name         = PROJECT
       
    39 	s.version      = $version
       
    40 	s.license      = 'BSD-3-Clause'
       
    41 	s.has_rdoc     = true
       
    42 	s.require_path = 'lib'
       
    43 	s.bindir       = 'bin'
       
    44 	s.files        = File.read( __FILE__ ).split( /^__END__/, 2 ).last.split
       
    45 	# s.executables  = %w[]
       
    46 	s.description  = <<-EOF
       
    47 This is a ruby interface for interacting with ezmlm-idx, an email list
       
    48 manager for use with the Qmail MTA.  (The -idx provides an extended
       
    49 feature set over the initial ezmlm environment.)
       
    50 	EOF
       
    51 	s.required_ruby_version = '>= 2'
    32 
    52 
    33 $dryrun = false
    53 	s.add_dependency 'loggability', "~> 0.13"
    34 
    54 	s.add_dependency 'mail', "~> 2.6"
    35 ### Config constants
       
    36 BASEDIR       = Pathname.new( __FILE__ ).dirname.relative_path_from( Pathname.getwd )
       
    37 BINDIR        = BASEDIR + 'bin'
       
    38 LIBDIR        = BASEDIR + 'lib'
       
    39 EXTDIR        = BASEDIR + 'ext'
       
    40 DOCSDIR       = BASEDIR + 'docs'
       
    41 PKGDIR        = BASEDIR + 'pkg'
       
    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 
       
    66 RAKE_TASKDIR  = BASEDIR + 'rake'
       
    67 RAKE_TASKLIBS = Pathname.glob( RAKE_TASKDIR + '*.rb' )
       
    68 
       
    69 LOCAL_RAKEFILE = BASEDIR + 'Rakefile.local'
       
    70 
       
    71 EXTRA_PKGFILES = []
       
    72 
       
    73 RELEASE_FILES = TEXT_FILES + 
       
    74 	SPEC_FILES + 
       
    75 	TEST_FILES + 
       
    76 	BIN_FILES +
       
    77 	LIB_FILES + 
       
    78 	EXT_FILES + 
       
    79 	RAKE_TASKLIBS +
       
    80 	EXTRA_PKGFILES
       
    81 
       
    82 RELEASE_FILES << LOCAL_RAKEFILE if LOCAL_RAKEFILE.exist?
       
    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
       
   106 require RAKE_TASKDIR + 'helpers.rb'
       
   107 require RAKE_TASKDIR + 'svn.rb'
       
   108 require RAKE_TASKDIR + 'verifytask.rb'
       
   109 
       
   110 # Define some constants that depend on the 'svn' tasklib
       
   111 PKG_BUILD = get_svn_rev( BASEDIR ) || 0
       
   112 SNAPSHOT_PKG_NAME = "#{PKG_FILE_NAME}.#{PKG_BUILD}"
       
   113 SNAPSHOT_GEM_NAME = "#{SNAPSHOT_PKG_NAME}.gem"
       
   114 
       
   115 # Documentation constants
       
   116 RDOCDIR = DOCSDIR + 'api'
       
   117 RDOC_OPTIONS = [
       
   118 	'-w', '4',
       
   119 	'-SHN',
       
   120 	'-i', '.',
       
   121 	'-m', 'README',
       
   122 	'-W', 'http://opensource.laika.com/wiki/ruby-ezmlm/browser/trunk/'
       
   123   ]
       
   124 
       
   125 # Release constants
       
   126 SMTP_HOST = 'mail.faeriemud.org'
       
   127 SMTP_PORT = 465 # SMTP + SSL
       
   128 
       
   129 # Project constants
       
   130 PROJECT_HOST = 'deveiate.org'
       
   131 PROJECT_PUBDIR = "/usr/local/www/public/code"
       
   132 PROJECT_DOCDIR = "#{PROJECT_PUBDIR}/#{PKG_NAME}"
       
   133 PROJECT_SCPPUBURL = "#{PROJECT_HOST}:#{PROJECT_PUBDIR}"
       
   134 PROJECT_SCPDOCURL = "#{PROJECT_HOST}:#{PROJECT_DOCDIR}"
       
   135 
       
   136 # Rubyforge stuff
       
   137 RUBYFORGE_GROUP = 'laika'
       
   138 RUBYFORGE_PROJECT = 'ezmlm'
       
   139 
       
   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.
       
   190 		collect {|f| f.relative_path_from(BASEDIR).to_s }
       
   191 	gem.test_files        = SPEC_FILES.
       
   192 		collect {|f| f.relative_path_from(BASEDIR).to_s }
       
   193 		
       
   194 	DEPENDENCIES.each do |name, version|
       
   195 		version = '>= 0' if version.length.zero?
       
   196 		gem.add_runtime_dependency( name, version )
       
   197 	end
       
   198 	
       
   199 	DEVELOPMENT_DEPENDENCIES.each do |name, version|
       
   200 		version = '>= 0' if version.length.zero?
       
   201 		gem.add_development_dependency( name, version )
       
   202 	end
       
   203 	
       
   204 	REQUIREMENTS.each do |name, version|
       
   205 		gem.requirements << [ name, version ].compact.join(' ')
       
   206 	end
       
   207 end
    55 end
   208 
    56 
   209 # Manual-generation config
    57 Gem::PackageTask.new( spec ) do |pkg|
   210 MANUALDIR = DOCSDIR + 'manual'
    58 	pkg.need_zip = true
   211 
    59 	pkg.need_tar = true
   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 #####################################################################
       
   239 
       
   240 ### Default task
       
   241 task :default  => [:clean, :local, :spec, :rdoc, :package]
       
   242 
       
   243 ### Task the local Rakefile can append to -- no-op by default
       
   244 task :local
       
   245 
       
   246 
       
   247 ### Task: clean
       
   248 CLEAN.include 'coverage'
       
   249 CLOBBER.include 'artifacts', 'coverage.info', PKGDIR
       
   250 
       
   251 # Target to hinge on ChangeLog updates
       
   252 file SVN_ENTRIES
       
   253 
       
   254 ### Task: changelog
       
   255 file 'ChangeLog' => SVN_ENTRIES.to_s do |task|
       
   256 	log "Updating #{task.name}"
       
   257 
       
   258 	changelog = make_svn_changelog()
       
   259 	File.open( task.name, 'w' ) do |fh|
       
   260 		fh.print( changelog )
       
   261 	end
       
   262 end
    60 end
   263 
    61 
   264 
    62 
   265 ### Task: cruise (Cruisecontrol task)
    63 ########################################################################
   266 desc "Cruisecontrol build"
    64 ### D O C U M E N T A T I O N
   267 task :cruise => [:clean, :spec, :package] do |task|
    65 ########################################################################
   268 	raise "Artifacts dir not set." if ARTIFACTS_DIR.to_s.empty?
    66 
   269 	artifact_dir = ARTIFACTS_DIR.cleanpath
    67 begin
   270 	artifact_dir.mkpath
    68 	require 'rdoc/task'
   271 	
    69 
   272 	coverage = BASEDIR + 'coverage'
    70 	desc 'Generate rdoc documentation'
   273 	if coverage.exist? && coverage.directory?
    71 	RDoc::Task.new do |rdoc|
   274 		$stderr.puts "Copying coverage stats..."
    72 		rdoc.name       = :docs
   275 		FileUtils.cp_r( 'coverage', artifact_dir )
    73 		rdoc.rdoc_dir   = 'docs'
       
    74 		rdoc.main       = "README.rdoc"
       
    75 		# rdoc.options    = [ '-f', 'fivefish' ]
       
    76 		rdoc.rdoc_files = [ 'lib', *FileList['*.rdoc'] ]
   276 	end
    77 	end
   277 	
    78 
   278 	$stderr.puts "Copying packages..."
    79 	RDoc::Task.new do |rdoc|
   279 	FileUtils.cp_r( FileList['pkg/*'].to_a, artifact_dir )
    80 		rdoc.name       = :doc_coverage
       
    81 		rdoc.options    = [ '-C1' ]
       
    82 	end
       
    83 
       
    84 rescue LoadError
       
    85 	$stderr.puts "Omitting 'docs' tasks, rdoc doesn't seem to be installed."
   280 end
    86 end
   281 
    87 
   282 
    88 
   283 desc "Update the build system to the latest version"
    89 ########################################################################
   284 task :update_build do
    90 ### T E S T I N G
   285 	log "Updating the build system"
    91 ########################################################################
   286 	sh 'svn', 'up', RAKE_TASKDIR
    92 
   287 	log "Updating the Rakefile"
    93 begin
   288 	sh 'rake', '-f', RAKE_TASKDIR + 'Metarakefile'
    94     require 'rspec/core/rake_task'
       
    95     task :test => :spec
       
    96 
       
    97     desc "Run specs"
       
    98     RSpec::Core::RakeTask.new do |t|
       
    99         t.pattern = "spec/**/*_spec.rb"
       
   100     end
       
   101 
       
   102     desc "Build a coverage report"
       
   103     task :coverage do
       
   104         ENV[ 'COVERAGE' ] = "yep"
       
   105         Rake::Task[ :spec ].invoke
       
   106     end
       
   107 
       
   108 rescue LoadError
       
   109     $stderr.puts "Omitting testing tasks, rspec doesn't seem to be installed."
   289 end
   110 end
   290 
   111 
       
   112 
       
   113 
       
   114 ########################################################################
       
   115 ### M A N I F E S T
       
   116 ########################################################################
       
   117 __END__
       
   118