| 50 | | SPEC_EXCLUDES = 'spec,monkeypatches,/Library/Ruby' |
| 51 | | |
| 52 | | RELEASE_FILES = TEXT_FILES + LIB_FILES + SPEC_FILES |
| 53 | | |
| 54 | | # Load some helper functions |
| 55 | | require MISCDIR + 'rake_helpers' |
| 56 | | |
| 57 | | ### Package constants |
| 58 | | PKG_NAME = 'io-reactor' |
| 59 | | PKG_TITLE = "IO::Reactor -- multiplexed asynchronous single-thread IO via the Reactor pattern" |
| 60 | | PKG_VERSION = find_pattern_in_file( /VERSION = '(\d+\.\d+\.\d+)'/, LIBDIR + 'io/reactor.rb' ).first |
| 61 | | PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" |
| 62 | | |
| 63 | | RELEASE_NAME = "REL #{PKG_VERSION}" |
| 64 | | |
| 65 | | # Load task plugins |
| 66 | | RAKE_TASKDIR = MISCDIR |
| 67 | | Pathname.glob( RAKE_TASKDIR + '*.rb' ).each do |tasklib| |
| 68 | | next if tasklib =~ %r{/rake_helpers.rb$} |
| 69 | | require tasklib |
| 70 | | end |
| 71 | | |
| 72 | | |
| 73 | | # Turn on trace/dryrun via globals like it used to |
| 74 | | if Rake.application.options.trace |
| 75 | | $trace = true |
| 76 | | log "$trace is enabled" |
| 77 | | end |
| 78 | | |
| 79 | | if Rake.application.options.dryrun |
| 80 | | $dryrun = true |
| 81 | | log "$dryrun is enabled" |
| 82 | | Rake.application.options.dryrun = false |
| 83 | | end |
| 84 | | |
| 85 | | ### Default task |
| 86 | | task :default => [:clean, :spec, :verify, :package] |
| 87 | | |
| 88 | | |
| 89 | | ### Task: clean |
| 90 | | desc "Clean pkg, coverage, and rdoc; remove .bak files" |
| 91 | | task :clean => [ :clobber_rdoc, :clobber_package, :clobber_coverage ] do |
| 92 | | files = FileList['**/*.bak'] |
| 93 | | files.clear_exclude |
| 94 | | File.rm( files ) unless files.empty? |
| 95 | | FileUtils.rm_rf( 'artifacts' ) |
| 96 | | end |
| 97 | | |
| 98 | | |
| 99 | | ### Task: docs -- Convenience task for rebuilding dynamic docs, including coverage, api |
| 100 | | ### docs, and manual |
| 101 | | task :docs => [ :coverage, :rdoc ] |
| 102 | | |
| 103 | | |
| 104 | | ### Task: rdoc |
| 105 | | Rake::RDocTask.new do |rdoc| |
| 106 | | rdoc.rdoc_dir = 'docs/api' |
| 107 | | rdoc.title = PKG_TITLE |
| 108 | | |
| 109 | | rdoc.options += [ |
| 110 | | '-w', '4', |
| 111 | | '-SHN', |
| 112 | | '-i', 'docs', |
| 113 | | '-f', 'darkfish', |
| 114 | | '-m', 'README', |
| 115 | | '-W', 'http://deveiate.org/projects/IO-Reactor/browser/trunk/' |
| 116 | | ] |
| 117 | | |
| 118 | | rdoc.rdoc_files.include 'README' |
| 119 | | rdoc.rdoc_files.include LIB_FILES.collect {|f| f.relative_path_from(BASEDIR).to_s } |
| 120 | | end |
| 121 | | |
| 122 | | |
| 123 | | ### Task: gem |
| 124 | | gemspec = Gem::Specification.new do |gem| |
| 125 | | pkg_build = get_svn_rev( BASEDIR ) || 0 |
| 126 | | |
| 127 | | gem.name = PKG_NAME |
| 128 | | gem.version = PKG_VERSION |
| 129 | | |
| 130 | | gem.summary = "Multiplexed IO Reactor class" |
| 131 | | gem.description = <<-EOD |
| 132 | | This module is a pure-Ruby implementation of an asynchronous multiplexed IO |
| | 58 | TESTDIR = BASEDIR + 'tests' |
| | 59 | TEST_FILES = Pathname.glob( TESTDIR + '**/*.tests.rb' ).delete_if {|item| item =~ /\.svn/ } |
| | 60 | |
| | 61 | RAKE_TASKDIR = BASEDIR + 'rake' |
| | 62 | RAKE_TASKLIBS = Pathname.glob( RAKE_TASKDIR + '*.rb' ) |
| | 63 | |
| | 64 | LOCAL_RAKEFILE = BASEDIR + 'Rakefile.local' |
| | 65 | |
| | 66 | EXTRA_PKGFILES = [] |
| | 67 | EXTRA_PKGFILES.concat Pathname.glob( BASEDIR + 'examples/*.rb' ).delete_if {|item| item =~ /\.svn/ } |
| | 68 | |
| | 69 | RELEASE_FILES = TEXT_FILES + |
| | 70 | SPEC_FILES + |
| | 71 | TEST_FILES + |
| | 72 | LIB_FILES + |
| | 73 | EXT_FILES + |
| | 74 | RAKE_TASKLIBS + |
| | 75 | EXTRA_PKGFILES |
| | 76 | |
| | 77 | RELEASE_FILES << LOCAL_RAKEFILE if LOCAL_RAKEFILE.exist? |
| | 78 | |
| | 79 | COVERAGE_MINIMUM = ENV['COVERAGE_MINIMUM'] ? Float( ENV['COVERAGE_MINIMUM'] ) : 85.0 |
| | 80 | RCOV_EXCLUDES = 'spec,tests,/Library/Ruby,/var/lib,/usr/local/lib' |
| | 81 | RCOV_OPTS = [ |
| | 82 | '--exclude', RCOV_EXCLUDES, |
| | 83 | '--xrefs', |
| | 84 | '--save', |
| | 85 | '--callsites', |
| | 86 | #'--aggregate', 'coverage.data' # <- doesn't work as of 0.8.1.2.0 |
| | 87 | ] |
| | 88 | |
| | 89 | |
| | 90 | # Subversion constants -- directory names for releases and tags |
| | 91 | SVN_TRUNK_DIR = 'trunk' |
| | 92 | SVN_RELEASES_DIR = 'releases' |
| | 93 | SVN_BRANCHES_DIR = 'branches' |
| | 94 | SVN_TAGS_DIR = 'tags' |
| | 95 | |
| | 96 | SVN_DOTDIR = BASEDIR + '.svn' |
| | 97 | SVN_ENTRIES = SVN_DOTDIR + 'entries' |
| | 98 | |
| | 99 | |
| | 100 | ### Load some task libraries that need to be loaded early |
| | 101 | require RAKE_TASKDIR + 'helpers.rb' |
| | 102 | require RAKE_TASKDIR + 'svn.rb' |
| | 103 | require RAKE_TASKDIR + 'verifytask.rb' |
| | 104 | |
| | 105 | # Define some constants that depend on the 'svn' tasklib |
| | 106 | PKG_BUILD = get_svn_rev( BASEDIR ) || 0 |
| | 107 | SNAPSHOT_PKG_NAME = "#{PKG_FILE_NAME}.#{PKG_BUILD}" |
| | 108 | SNAPSHOT_GEM_NAME = "#{SNAPSHOT_PKG_NAME}.gem" |
| | 109 | |
| | 110 | # Documentation constants |
| | 111 | RDOC_OPTIONS = [ |
| | 112 | '-w', '4', |
| | 113 | '-SHN', |
| | 114 | '-i', '.', |
| | 115 | '-m', 'README', |
| | 116 | '-W', 'http://deveiate.org/projects/IO-Reactor//browser/trunk/' |
| | 117 | ] |
| | 118 | |
| | 119 | # Release constants |
| | 120 | SMTP_HOST = 'mail.faeriemud.org' |
| | 121 | SMTP_PORT = 465 # SMTP + SSL |
| | 122 | |
| | 123 | # Project constants |
| | 124 | PROJECT_HOST = 'deveiate.org' |
| | 125 | PROJECT_PUBDIR = "/usr/local/www/public/code" |
| | 126 | PROJECT_DOCDIR = "#{PROJECT_PUBDIR}/#{PKG_NAME}" |
| | 127 | PROJECT_SCPPUBURL = "#{PROJECT_HOST}:#{PROJECT_PUBDIR}" |
| | 128 | PROJECT_SCPDOCURL = "#{PROJECT_HOST}:#{PROJECT_DOCDIR}" |
| | 129 | |
| | 130 | # Rubyforge stuff |
| | 131 | RUBYFORGE_GROUP = 'deveiate' |
| | 132 | RUBYFORGE_PROJECT = 'io-reactor' |
| | 133 | |
| | 134 | # Gem dependencies: gemname => version |
| | 135 | DEPENDENCIES = { |
| | 136 | } |
| | 137 | |
| | 138 | # Non-gem requirements: packagename => version |
| | 139 | REQUIREMENTS = { |
| | 140 | } |
| | 141 | |
| | 142 | # RubyGem specification |
| | 143 | GEMSPEC = Gem::Specification.new do |gem| |
| | 144 | gem.name = PKG_NAME.downcase |
| | 145 | gem.version = PKG_VERSION |
| | 146 | |
| | 147 | gem.summary = PKG_SUMMARY |
| | 148 | gem.description = <<-EOD |
| | 149 | A pure-Ruby implementation of an asynchronous multiplexed IO |
| 152 | | end |
| 153 | | Rake::GemPackageTask.new( gemspec ) do |task| |
| 154 | | task.gem_spec = gemspec |
| 155 | | task.need_tar = false |
| 156 | | task.need_tar_gz = true |
| 157 | | task.need_tar_bz2 = true |
| 158 | | task.need_zip = true |
| 159 | | end |
| 160 | | |
| 161 | | |
| 162 | | ### Task: install |
| 163 | | task :install_gem => [:package] do |
| 164 | | $stderr.puts |
| 165 | | installer = Gem::Installer.new( %{pkg/#{PKG_FILE_NAME}.gem} ) |
| 166 | | installer.install |
| 167 | | end |
| 168 | | |
| 169 | | ### Task: uninstall |
| 170 | | task :uninstall_gem => [:clean] do |
| 171 | | uninstaller = Gem::Uninstaller.new( PKG_FILE_NAME ) |
| 172 | | uninstaller.uninstall |
| 173 | | end |
| 174 | | |
| 175 | | |
| 176 | | |
| 177 | | ### Cruisecontrol task |
| | 168 | |
| | 169 | DEPENDENCIES.each do |name, version| |
| | 170 | version = '>= 0' if version.length.zero? |
| | 171 | gem.add_dependency( name, version ) |
| | 172 | end |
| | 173 | |
| | 174 | REQUIREMENTS.each do |name, version| |
| | 175 | gem.requirements << [ name, version ].compact.join(' ') |
| | 176 | end |
| | 177 | end |
| | 178 | |
| | 179 | $trace = Rake.application.options.trace ? true : false |
| | 180 | $dryrun = Rake.application.options.dryrun ? true : false |
| | 181 | |
| | 182 | |
| | 183 | # Load any remaining task libraries |
| | 184 | RAKE_TASKLIBS.each do |tasklib| |
| | 185 | next if tasklib =~ %r{/(helpers|svn|verifytask)\.rb$} |
| | 186 | begin |
| | 187 | require tasklib |
| | 188 | rescue ScriptError => err |
| | 189 | fail "Task library '%s' failed to load: %s: %s" % |
| | 190 | [ tasklib, err.class.name, err.message ] |
| | 191 | trace "Backtrace: \n " + err.backtrace.join( "\n " ) |
| | 192 | rescue => err |
| | 193 | log "Task library '%s' failed to load: %s: %s. Some tasks may not be available." % |
| | 194 | [ tasklib, err.class.name, err.message ] |
| | 195 | trace "Backtrace: \n " + err.backtrace.join( "\n " ) |
| | 196 | end |
| | 197 | end |
| | 198 | |
| | 199 | # Load any project-specific rules defined in 'Rakefile.local' if it exists |
| | 200 | import LOCAL_RAKEFILE if LOCAL_RAKEFILE.exist? |
| | 201 | |
| | 202 | |
| | 203 | ##################################################################### |
| | 204 | ### T A S K S |
| | 205 | ##################################################################### |
| | 206 | |
| | 207 | ### Default task |
| | 208 | task :default => [:clean, :local, :spec, :rdoc, :package] |
| | 209 | |
| | 210 | ### Task the local Rakefile can append to -- no-op by default |
| | 211 | task :local |
| | 212 | |
| | 213 | |
| | 214 | ### Task: clean |
| | 215 | CLEAN.include 'coverage' |
| | 216 | CLOBBER.include 'artifacts', 'coverage.info', PKGDIR |
| | 217 | |
| | 218 | # Target to hinge on ChangeLog updates |
| | 219 | file SVN_ENTRIES |
| | 220 | |
| | 221 | ### Task: changelog |
| | 222 | file 'ChangeLog' => SVN_ENTRIES.to_s do |task| |
| | 223 | log "Updating #{task.name}" |
| | 224 | |
| | 225 | changelog = make_svn_changelog() |
| | 226 | File.open( task.name, 'w' ) do |fh| |
| | 227 | fh.print( changelog ) |
| | 228 | end |
| | 229 | end |
| | 230 | |
| | 231 | |
| | 232 | ### Task: cruise (Cruisecontrol task) |
| 192 | | |
| 193 | | ### RSpec tasks |
| 194 | | begin |
| 195 | | gem 'rspec', '>= 1.1.1' |
| 196 | | require 'spec/rake/spectask' |
| 197 | | |
| 198 | | COMMON_SPEC_OPTS = ['-c', '-f', 's'] |
| 199 | | |
| 200 | | ### Task: spec |
| 201 | | Spec::Rake::SpecTask.new( :spec ) do |task| |
| 202 | | task.spec_files = SPEC_FILES |
| 203 | | task.libs += [LIBDIR] |
| 204 | | task.spec_opts = COMMON_SPEC_OPTS |
| 205 | | end |
| 206 | | task :test => [:spec] |
| 207 | | |
| 208 | | |
| 209 | | namespace :spec do |
| 210 | | desc "Run rspec every time there's a change to one of the files" |
| 211 | | task :autotest do |
| 212 | | require 'autotest/rspec' |
| 213 | | |
| 214 | | ### Mmmm... smells like monkeys |
| 215 | | class Autotest::Rspec |
| 216 | | |
| 217 | | ### Search the path for 'spec' in addition to the simple included methods |
| 218 | | ### for finding it. |
| 219 | | def spec_commands |
| 220 | | path = ENV['PATH'].split( File::PATH_SEPARATOR ) |
| 221 | | return path.collect {|dir| File.join(dir, 'spec') } + |
| 222 | | [ |
| 223 | | File.join('bin', 'spec'), |
| 224 | | File.join(Config::CONFIG['bindir'], 'spec') |
| 225 | | ] |
| 226 | | end |
| 227 | | |
| 228 | | end |
| 229 | | |
| 230 | | autotester = Autotest::Rspec.new |
| 231 | | autotester.exceptions = %r{\.svn|\.skel} |
| 232 | | autotester.run |
| 233 | | end |
| 234 | | |
| 235 | | |
| 236 | | desc "Generate HTML output for a spec run" |
| 237 | | Spec::Rake::SpecTask.new( :html ) do |task| |
| 238 | | task.spec_files = SPEC_FILES |
| 239 | | task.spec_opts = ['-f','h', '-D'] |
| 240 | | end |
| 241 | | |
| 242 | | desc "Generate plain-text output for a CruiseControl.rb build" |
| 243 | | Spec::Rake::SpecTask.new( :text ) do |task| |
| 244 | | task.spec_files = SPEC_FILES |
| 245 | | task.spec_opts = ['-f','p'] |
| 246 | | end |
| 247 | | end |
| 248 | | rescue LoadError => err |
| 249 | | task :no_rspec do |
| 250 | | $stderr.puts "Testing tasks not defined: RSpec rake tasklib not available: %s" % |
| 251 | | [ err.message ] |
| 252 | | end |
| 253 | | |
| 254 | | task :spec => :no_rspec |
| 255 | | namespace :spec do |
| 256 | | task :autotest => :no_rspec |
| 257 | | task :html => :no_rspec |
| 258 | | task :text => :no_rspec |
| 259 | | end |
| 260 | | end |
| 261 | | |
| 262 | | |
| 263 | | ### RCov (via RSpec) tasks |
| 264 | | begin |
| 265 | | gem 'rcov' |
| 266 | | gem 'rspec', '>= 1.1.1' |
| 267 | | |
| 268 | | RCOV_OPTS = ['--exclude', SPEC_EXCLUDES, '--xrefs'] |
| 269 | | |
| 270 | | ### Task: coverage (via RCov) |
| 271 | | ### Task: spec |
| 272 | | desc "Build test coverage reports" |
| 273 | | Spec::Rake::SpecTask.new( :coverage ) do |task| |
| 274 | | task.spec_files = SPEC_FILES |
| 275 | | task.libs += [LIBDIR] |
| 276 | | task.spec_opts = ['-f', 'p', '-b'] |
| 277 | | task.rcov_opts = RCOV_OPTS + ['--save'] |
| 278 | | task.rcov = true |
| 279 | | end |
| 280 | | |
| 281 | | task :rcov => [:coverage] do; end |
| 282 | | |
| 283 | | ### Other coverage tasks |
| 284 | | namespace :coverage do |
| 285 | | desc "Generate a detailed text coverage report" |
| 286 | | Spec::Rake::SpecTask.new( :text ) do |task| |
| 287 | | task.spec_files = SPEC_FILES |
| 288 | | task.rcov_opts = RCOV_OPTS + ['--text-report'] |
| 289 | | task.rcov = true |
| 290 | | end |
| 291 | | |
| 292 | | desc "Show differences in coverage from last run" |
| 293 | | Spec::Rake::SpecTask.new( :diff ) do |task| |
| 294 | | task.spec_files = SPEC_FILES |
| 295 | | task.rcov_opts = RCOV_OPTS + ['--text-coverage-diff'] |
| 296 | | task.rcov = true |
| 297 | | end |
| 298 | | |
| 299 | | ### Task: verify coverage |
| 300 | | desc "Build coverage statistics" |
| 301 | | VerifyTask.new( :verify => :rcov ) do |task| |
| 302 | | task.threshold = 85.0 |
| 303 | | end |
| 304 | | |
| 305 | | desc "Run RCov in 'spec-only' mode to check coverage from specs" |
| 306 | | Spec::Rake::SpecTask.new( :speconly ) do |task| |
| 307 | | task.spec_files = SPEC_FILES |
| 308 | | task.rcov_opts = ['--exclude', SPEC_EXCLUDES, '--text-report'] |
| 309 | | task.rcov = true |
| 310 | | end |
| 311 | | end |
| 312 | | |
| 313 | | rescue LoadError => err |
| 314 | | task :no_rcov do |
| 315 | | $stderr.puts "Coverage tasks not defined: RSpec+RCov tasklib not available: %s" % |
| 316 | | [ err.message ] |
| 317 | | end |
| 318 | | |
| 319 | | task :coverage => :no_rcov |
| 320 | | task :clobber_coverage |
| 321 | | task :rcov => :no_rcov |
| 322 | | namespace :coverage do |
| 323 | | task :text => :no_rcov |
| 324 | | task :diff => :no_rcov |
| 325 | | end |
| 326 | | task :verify => :no_rcov |
| 327 | | end |
| 328 | | |
| 329 | | |
| 330 | | |
| 331 | | ### Coding style checks and fixes |
| 332 | | namespace :style do |
| 333 | | |
| 334 | | BLANK_LINE = /^\s*$/ |
| 335 | | GOOD_INDENT = /^(\t\s*)?\S/ |
| 336 | | |
| 337 | | # A list of the files that have legitimate leading whitespace, etc. |
| 338 | | PROBLEM_FILES = [] |
| 339 | | |
| 340 | | desc "Check source files for inconsistent indent and fix them" |
| 341 | | task :fix_indent do |
| 342 | | files = LIB_FILES + SPEC_FILES |
| 343 | | |
| 344 | | badfiles = Hash.new {|h,k| h[k] = [] } |
| 345 | | |
| 346 | | trace "Checking files for indentation" |
| 347 | | files.each do |file| |
| 348 | | if PROBLEM_FILES.include?( file ) |
| 349 | | trace " skipping problem file #{file}..." |
| 350 | | next |
| 351 | | end |
| 352 | | |
| 353 | | trace " #{file}" |
| 354 | | linecount = 0 |
| 355 | | file.each_line do |line| |
| 356 | | linecount += 1 |
| 357 | | |
| 358 | | # Skip blank lines |
| 359 | | next if line =~ BLANK_LINE |
| 360 | | |
| 361 | | # If there's a line with incorrect indent, note it and skip to the |
| 362 | | # next file |
| 363 | | if line !~ GOOD_INDENT |
| 364 | | trace " Bad line %d: %p" % [ linecount, line ] |
| 365 | | badfiles[file] << [ linecount, line ] |
| 366 | | end |
| 367 | | end |
| 368 | | end |
| 369 | | |
| 370 | | if badfiles.empty? |
| 371 | | log "No indentation problems found." |
| 372 | | else |
| 373 | | log "Found incorrect indent in #{badfiles.length} files:\n " |
| 374 | | badfiles.each do |file, badlines| |
| 375 | | log " #{file}:\n" + |
| 376 | | " " + badlines.collect {|badline| "%5d: %p" % badline }.join( "\n " ) |
| 377 | | end |
| 378 | | end |
| 379 | | end |
| 380 | | |
| 381 | | end |
| 382 | | |
| 383 | | |
| | 250 | desc "Update the build system to the latest version" |
| | 251 | task :update_build do |
| | 252 | log "Updating the build system" |
| | 253 | sh 'svn', 'up', RAKE_TASKDIR |
| | 254 | log "Updating the Rakefile" |
| | 255 | sh 'rake', '-f', RAKE_TASKDIR + 'Metarakefile' |
| | 256 | end |
| | 257 | |