Rakefile 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. # Rakefile for rake -*- ruby -*-
  2. # Copyright 2003, 2004, 2005 by Jim Weirich (jim@weirichhouse.org)
  3. # All rights reserved.
  4. # This file may be distributed under an MIT style license. See
  5. # MIT-LICENSE for details.
  6. require 'rbconfig'
  7. require 'rubygems'
  8. system_rake = File.join RbConfig::CONFIG['rubylibdir'], 'rake.rb'
  9. # Use our rake, not the installed rake from system
  10. if $".include? system_rake or $".grep(/rake\/name_space\.rb$/).empty? then
  11. exec Gem.ruby, '-Ilib', 'bin/rake', *ARGV
  12. end
  13. require 'rubygems/package_task'
  14. require 'rake/clean'
  15. require 'rake/testtask'
  16. begin
  17. gem 'rdoc'
  18. require 'rdoc/task'
  19. rescue Gem::LoadError
  20. end
  21. CLEAN.include('**/*.o', '*.dot', '**/*.rbc')
  22. CLOBBER.include('doc/example/main')
  23. CLOBBER.include('TAGS')
  24. CLOBBER.include('coverage', 'rcov_aggregate')
  25. # Prevent OS X from including extended attribute junk in the tar output
  26. ENV['COPY_EXTENDED_ATTRIBUTES_DISABLE'] = 'true'
  27. def announce(msg='')
  28. STDERR.puts msg
  29. end
  30. # Determine the current version of the software
  31. if `ruby -Ilib ./bin/rake --version` =~ /rake, version ([0-9a-z.]+)$/
  32. CURRENT_VERSION = $1
  33. else
  34. CURRENT_VERSION = "0.0.0"
  35. end
  36. $package_version = CURRENT_VERSION
  37. SRC_RB = FileList['lib/**/*.rb']
  38. # The default task is run if rake is given no explicit arguments.
  39. desc "Default Task"
  40. task :default => :test
  41. # Test Tasks ---------------------------------------------------------
  42. Rake::TestTask.new do |t|
  43. files = FileList['test/helper.rb', 'test/test_*.rb']
  44. t.test_files = files
  45. t.libs << "."
  46. t.warning = true
  47. end
  48. begin
  49. require 'rcov/rcovtask'
  50. IGNORE_COVERAGE_IN = FileList[
  51. 'lib/rake/rdoctask.rb',
  52. 'lib/rake/testtask.rb',
  53. 'lib/rake/packagetask.rb',
  54. 'lib/rake/clean.rb',
  55. ]
  56. unless File::ALT_SEPARATOR
  57. IGNORE_COVERAGE_IN.include(
  58. 'lib/rake/alt_system.rb',
  59. 'lib/rake/win32.rb')
  60. end
  61. Rcov::RcovTask.new do |t|
  62. t.libs << "test"
  63. t.rcov_opts = [
  64. '-xRakefile', '-xrakefile', '-xpublish.rf',
  65. '-xlib/rake/contrib', '-x/Library', '-x.rvm',
  66. '--text-report',
  67. '--sort coverage'
  68. ] + FileList['rakelib/*.rake'].pathmap("-x%p") +
  69. IGNORE_COVERAGE_IN.map { |fn| "-x#{fn}" }
  70. t.test_files = FileList[
  71. 'test/lib/*_test.rb',
  72. 'test/contrib/*_test.rb',
  73. 'test/functional/*_test.rb'
  74. ]
  75. t.output_dir = 'coverage'
  76. t.verbose = true
  77. end
  78. rescue LoadError
  79. task :rcov do
  80. puts "RCov is not available"
  81. end
  82. end
  83. # CVS Tasks ----------------------------------------------------------
  84. # Install rake using the standard install.rb script.
  85. desc "Install the application"
  86. task :install do
  87. ruby "install.rb"
  88. end
  89. # Create a task to build the RDOC documentation tree.
  90. BASE_RDOC_OPTIONS = [
  91. '--line-numbers', '--show-hash',
  92. '--main', 'README.rdoc',
  93. '--title', 'Rake -- Ruby Make'
  94. ]
  95. if defined?(RDoc::Task) then
  96. RDoc::Task.new do |rdoc|
  97. rdoc.rdoc_dir = 'html'
  98. rdoc.title = "Rake -- Ruby Make"
  99. rdoc.options = BASE_RDOC_OPTIONS.dup
  100. rdoc.rdoc_files.include('README.rdoc', 'MIT-LICENSE', 'TODO', 'CHANGES')
  101. rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
  102. rdoc.rdoc_files.exclude(/\bcontrib\b/)
  103. end
  104. else
  105. warn "RDoc 2.4.2+ is required to build documentation"
  106. end
  107. # ====================================================================
  108. # Create a task that will package the Rake software into distributable
  109. # tar, zip and gem files.
  110. PKG_FILES = FileList[
  111. '.gemtest',
  112. 'install.rb',
  113. '[A-Z]*',
  114. 'bin/rake',
  115. 'lib/**/*.rb',
  116. 'test/**/*.rb',
  117. 'doc/**/*'
  118. ]
  119. PKG_FILES.exclude('doc/example/*.o')
  120. PKG_FILES.exclude('TAGS')
  121. PKG_FILES.exclude(%r{doc/example/main$})
  122. if ! defined?(Gem)
  123. puts "Package Target requires RubyGems"
  124. else
  125. SPEC = Gem::Specification.new do |s|
  126. s.name = 'rake'
  127. s.version = $package_version
  128. s.summary = "Ruby based make-like utility."
  129. s.description = <<-EOF.delete "\n"
  130. Rake is a Make-like program implemented in Ruby. Tasks and dependencies are
  131. specified in standard Ruby syntax.
  132. EOF
  133. s.required_ruby_version = '>= 1.8.6'
  134. s.required_rubygems_version = '>= 1.3.2'
  135. s.add_development_dependency 'minitest', '~> 2.1'
  136. s.files = PKG_FILES.to_a
  137. s.executables = ["rake"]
  138. s.extra_rdoc_files = FileList[
  139. 'README.rdoc',
  140. 'MIT-LICENSE',
  141. 'TODO',
  142. 'CHANGES',
  143. 'doc/**/*.rdoc'
  144. ]
  145. s.rdoc_options = BASE_RDOC_OPTIONS
  146. s.author = "Jim Weirich"
  147. s.email = "jim@weirichhouse.org"
  148. s.homepage = "http://rake.rubyforge.org"
  149. s.rubyforge_project = "rake"
  150. end
  151. Gem::PackageTask.new(SPEC) do |pkg|
  152. pkg.need_zip = true
  153. pkg.need_tar = true
  154. end
  155. file "rake.gemspec" => ["Rakefile", "lib/rake.rb"] do |t|
  156. require 'yaml'
  157. open(t.name, "w") { |f| f.puts SPEC.to_yaml }
  158. end
  159. desc "Create a stand-alone gemspec"
  160. task :gemspec => "rake.gemspec"
  161. end
  162. # Misc tasks =========================================================
  163. def count_lines(filename)
  164. lines = 0
  165. codelines = 0
  166. open(filename) { |f|
  167. f.each do |line|
  168. lines += 1
  169. next if line =~ /^\s*$/
  170. next if line =~ /^\s*#/
  171. codelines += 1
  172. end
  173. }
  174. [lines, codelines]
  175. end
  176. def show_line(msg, lines, loc)
  177. printf "%6s %6s %s\n", lines.to_s, loc.to_s, msg
  178. end
  179. desc "Count lines in the main rake file"
  180. task :lines do
  181. total_lines = 0
  182. total_code = 0
  183. show_line("File Name", "LINES", "LOC")
  184. SRC_RB.each do |fn|
  185. lines, codelines = count_lines(fn)
  186. show_line(fn, lines, codelines)
  187. total_lines += lines
  188. total_code += codelines
  189. end
  190. show_line("TOTAL", total_lines, total_code)
  191. end
  192. # Define an optional publish target in an external file. If the
  193. # publish.rf file is not found, the publish targets won't be defined.
  194. load "publish.rf" if File.exist? "publish.rf"
  195. # Support Tasks ------------------------------------------------------
  196. RUBY_FILES = FileList['**/*.rb'].exclude('pkg')
  197. desc "Look for TODO and FIXME tags in the code"
  198. task :todo do
  199. RUBY_FILES.egrep(/#.*(FIXME|TODO|TBD)/)
  200. end
  201. desc "List all ruby files"
  202. task :rubyfiles do
  203. puts RUBY_FILES
  204. puts FileList['bin/*'].exclude('bin/*.rb')
  205. end
  206. task :rf => :rubyfiles
  207. # --------------------------------------------------------------------
  208. # Creating a release
  209. def plugin(plugin_name)
  210. require "rake/plugins/#{plugin_name}"
  211. end
  212. task :noop
  213. #plugin "release_manager"
  214. desc "Make a new release"
  215. task :release, [:rel, :reuse, :reltest] => [
  216. :prerelease,
  217. :clobber,
  218. :test,
  219. :update_version,
  220. :package,
  221. :tag
  222. ] do
  223. announce
  224. announce "**************************************************************"
  225. announce "* Release #{$package_version} Complete."
  226. announce "* Packages ready to upload."
  227. announce "**************************************************************"
  228. announce
  229. end
  230. # Validate that everything is ready to go for a release.
  231. task :prerelease, :rel, :reuse, :reltest do |t, args|
  232. $package_version = args.rel
  233. announce
  234. announce "**************************************************************"
  235. announce "* Making RubyGem Release #{$package_version}"
  236. announce "* (current version #{CURRENT_VERSION})"
  237. announce "**************************************************************"
  238. announce
  239. # Is a release number supplied?
  240. unless args.rel
  241. fail "Usage: rake release[X.Y.Z] [REUSE=tag_suffix]"
  242. end
  243. # Is the release different than the current release.
  244. # (or is REUSE set?)
  245. if $package_version == CURRENT_VERSION && ! args.reuse
  246. fail "Current version is #{$package_version}, must specify REUSE=tag_suffix to reuse version"
  247. end
  248. # Are all source files checked in?
  249. if args.reltest
  250. announce "Release Task Testing, skipping checked-in file test"
  251. else
  252. announce "Checking for unchecked-in files..."
  253. data = `svn st`
  254. unless data =~ /^$/
  255. abort "svn status is not clean ... do you have unchecked-in files?"
  256. end
  257. announce "No outstanding checkins found ... OK"
  258. end
  259. end
  260. task :update_version, [:rel, :reuse, :reltest] => [:prerelease] do |t, args|
  261. if args.rel == CURRENT_VERSION
  262. announce "No version change ... skipping version update"
  263. else
  264. announce "Updating Rake version to #{args.rel}"
  265. open("lib/rake.rb") do |rakein|
  266. open("lib/rake.rb.new", "w") do |rakeout|
  267. rakein.each do |line|
  268. if line =~ /^RAKEVERSION\s*=\s*/
  269. rakeout.puts "RAKEVERSION = '#{args.rel}'"
  270. else
  271. rakeout.puts line
  272. end
  273. end
  274. end
  275. end
  276. mv "lib/rake.rb.new", "lib/rake.rb"
  277. if args.reltest
  278. announce "Release Task Testing, skipping commiting of new version"
  279. else
  280. sh %{svn commit -m "Updated to version #{args.rel}" lib/rake.rb} # "
  281. end
  282. end
  283. end
  284. desc "Tag all the CVS files with the latest release number (REL=x.y.z)"
  285. task :tag, [:rel, :reuse, :reltest] => [:prerelease] do |t, args|
  286. reltag = "REL_#{args.rel.gsub(/\./, '_')}"
  287. reltag << args.reuse.gsub(/\./, '_') if args.reuse
  288. announce "Tagging Repository with [#{reltag}]"
  289. if args.reltest
  290. announce "Release Task Testing, skipping CVS tagging"
  291. else
  292. sh %{svn copy svn+ssh://rubyforge.org/var/svn/rake/trunk svn+ssh://rubyforge.org/var/svn/rake/tags/#{reltag} -m 'Commiting release #{reltag}'} ###'
  293. end
  294. end
  295. # Require experimental XForge/Metaproject support.
  296. load 'xforge.rf' if File.exist?('xforge.rf')
  297. desc "Where is the current directory. This task displays\nthe current rake directory"
  298. task :where_am_i do
  299. puts Rake.original_dir
  300. end
  301. task :failure => :really_fail
  302. task :really_fail do
  303. fail "oops"
  304. end