Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 462 lines (392 sloc) 13.557 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
# Rakefile for RubyGems -*- ruby -*-

#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

$:.unshift 'lib'

require 'rubygems'
require 'rake/clean'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/rdoctask'

def announce(msg='')
  $stderr.puts msg
end

def generate_rubygems_version(path, version)
  open path, 'w' do |f|
    f.puts <<-EOF
# DO NOT EDIT
# This file is auto-generated by build scripts.
# See: rake update_version
module Gem
RubyGemsVersion = '#{version}'
end
EOF
  end
end

if RUBY_PLATFORM.match('mswin')
   ENV['CERT_DIR'] ||= (File.join(ENV['USERPROFILE'], '.gem'))
else
   ENV['CERT_DIR'] ||= File.expand_path(File.join('~', '.gem'))
end

PKG_NAME = 'rubygems'
def package_version
  `ruby -Ilib bin/gem environment packageversion`.chomp
end

if ENV['REL']
  PKG_VERSION = ENV['REL']
  CURRENT_VERSION = package_version
else
  PKG_VERSION = package_version
  CURRENT_VERSION = PKG_VERSION
end

CLEAN.include("COMMENTS")
CLOBBER.include(
  'InstalledFiles',
  "test/data/one/one-*0.0.1.gem",
  "test/temp",
  'test/mock/gem/doc',
  'test/mock/gem/cache',
  'test/data/gemhome',
  'test/data/[a-z]*.gem',
  'scripts/*.hieraki',
  'data__',
  'html',
  'pkgs/sources/sources*.gem',
  '.config',
  '**/debug.log',
  'logs',
  '*.out'
  )
CLOBBER.exclude('test/data/broken-1.0.0.gem')

desc "Run all tests"
task :default => [:test]

desc "Run unit tests (functionals fail on win32)"
task :test => [:test_units]

desc "Run just the unit tests"
Rake::TestTask.new(:test_units) do |t|
  t.test_files = FileList['test/test*.rb']
  t.warning = true
end

desc "Run just the functional tests"
Rake::TestTask.new(:test_functional) do |t|
  t.test_files = FileList['test/functional*.rb']
  t.warning = true
end

desc "Run the unit and functional tests"
Rake::TestTask.new(:test_all) do |t|
  t.test_files = FileList['test/{test,functional}*.rb']
  t.warning = true
end

desc "Run the tests for a build"
task :build_tests do
  html_dir = ENV['TESTRESULTS'] || 'html/tests'
  ruby %{-Ilib scripts/buildtests.rb #{html_dir}}
  open("#{html_dir}/summary.html") do |inf|
    open("#{html_dir}/summary.new", "w") do |outf|
      inf.each do |line|
        if line =~ /td align/
          line = " <td align=\"left\">#{Time.now}</td><td align=\"right\">"
        end
        outf.puts line
      end
    end
  end
  mv "#{html_dir}/summary.html", "#{html_dir}/summary.old"
  mv "#{html_dir}/summary.new", "#{html_dir}/summary.html"
end

# Shortcuts for test targets
task :tf => [:test_functional]
task :tu => [:test_units]
task :ta => [:test_all]

task :gemtest do
  ruby %{-Ilib -rscripts/runtest -e 'run_tests("test/test_gempaths.rb", true)'}
end

# --------------------------------------------------------------------
# Creating a release

desc "Make a new release"
task :release => [
  :prerelease,
  :clobber,
  :test_all,
  :update_version,
  :package,
  :tag] do

  announce
  announce "**************************************************************"
  announce "* Release #{PKG_VERSION} Complete."
  announce "* Packages ready to upload."
  announce "**************************************************************"
  announce
end

desc "Validate that everything is ready to go for a release."
task :prerelease do
  announce
  announce "**************************************************************"
  announce "* Making RubyGem Release #{PKG_VERSION}"
  announce "* (current version #{CURRENT_VERSION})"
  announce "**************************************************************"
  announce

  # Is a release number supplied?
  raise "Usage: rake release REL=x.y.z [REUSE=tag_suffix]" unless ENV['REL']

  # Is the release different than the current release.
  # (or is REUSE set?)
  if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
    raise "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
  end

  # Are all source files checked in?
  if ENV['RELTEST']
    announce "Release Task Testing, skipping checked-in file test"
  else
    announce "Checking for unchecked-in files..."
    data = `svn st`
    unless data =~ /^$/
      abort "svn status is not clean ... do you have unchecked-in files?"
    end
    announce "No outstanding checkins found ... OK"
  end
end

task :update_version => [:prerelease] do
  if PKG_VERSION == CURRENT_VERSION
    announce "No version change ... skipping version update"
  else
    announce "Updating RubyGem version to #{PKG_VERSION}"

    generate_rubygems_version 'lib/rubygems/rubygems_version.rb', PKG_VERSION

    if ENV['RELTEST']
      announce "Release Task Testing, skipping commiting of new version"
    else
      sh %{svn commit -m "Updated to version #{PKG_VERSION}" lib/rubygems/rubygems_version.rb} # "
    end
  end
end

task :tag => [:prerelease] do
  reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}"
  reltag = "REL_#{ENV['REUSE'].gsub(/\./, '_')}" if ENV['REUSE']
  announce "Tagging SVN with [#{reltag}]"
  software_dir = File.basename(Dir.pwd)
  if ENV['RELTEST']
    announce "Release Task Testing, skipping SVN tagging (in dir #{software_dir})"
  else
    sh %{svn copy svn+ssh://rubyforge.org/var/svn/rubygems/trunk svn+ssh://rubyforge.org/var/svn/rubygems/tags/#{reltag}}
  end
end

# --------------------------------------------------------------------

begin # rcov
  require 'rcov/rcovtask'

  Rcov::RcovTask.new do |t|
    t.libs << "test"
    t.rcov_opts = ['-xRakefile', '-xrakefile', '-xpublish.rf', '--text-report']
    t.test_files = FileList[
      'test/{functional,test}*.rb'
    ]
    t.verbose = true
  end
rescue LoadError
end

# --------------------------------------------------------------------
# Create a task to build the RDOC documentation tree.

desc "Create the RDOC html files"
Rake::RDocTask.new("rdoc") { |rdoc|
  rdoc.rdoc_dir = 'html'
  rdoc.title = "RubyGems"
  rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
  rdoc.rdoc_files.include('README', 'TODO', 'LICENSE.txt', 'GPL.txt')
  rdoc.rdoc_files.include('lib/**/*.rb')
  rdoc.rdoc_files.include('doc/**/*.rdoc')
}

desc "Publish the RDOCs on RubyForge"
task :publish_rdoc => ["html/index.html"] do
  # NOTE: This task assumes that you have an SSH alias setup for rubyforge.
  mkdir_p "emptydir"
  sh "scp -rq emptydir rubyforge:/var/www/gforge-projects/rubygems/rdoc"
  sh "scp -rq html/* rubyforge:/var/www/gforge-projects/rubygems/rdoc"
  rm_r "emptydir"
end

# Wiki Doc Targets

desc "Upload the Hieraki Data"
task :upload => [:upload_gemdoc]

task :upload_gemdoc => ['scripts/gemdoc.hieraki'] do
  ruby %{scripts/upload_gemdoc.rb}
end

desc "Build the Hieraki documentation"
task :hieraki => ['scripts/gemdoc.hieraki', 'scripts/specdoc.hieraki']

file 'scripts/gemdoc.hieraki' => ['scripts/gemdoc.rb', 'scripts/gemdoc.data'] do
  chdir('scripts') do
    ruby %{-I../lib gemdoc.rb <gemdoc.data >gemdoc.hieraki}
  end
end

file 'scripts/specdoc.hieraki' =>
  ['scripts/specdoc.rb', 'scripts/specdoc.data', 'scripts/specdoc.yaml'] do
  chdir('scripts') do
    ruby %{-I../lib specdoc.rb >specdoc.hieraki}
  end
end

# Package tasks

PKG_FILES = FileList[
  ".document",
  "ChangeLog",
  "GPL.txt",
  "LICENSE.txt",
  "README",
  "Rakefile",
  "TODO",
  "bin/*",
  "doc/release_notes/*",
  "lib/**/*.rb",
  "pkgs/**/*",
  "scripts/*.rb",
  "setup.rb",
  "test/**/*"
]

PKG_FILES.exclude %r(^test/temp(/|$))
PKG_FILES.exclude %r(\*\.rbc$)

task :package_files do
  puts PKG_FILES.join("\n")
end

Rake::PackageTask.new("package") do |p|
  p.name = PKG_NAME
  p.version = PKG_VERSION
  p.need_tar = true
  p.need_zip = true
  p.package_files = PKG_FILES
end

warn_unsigned = true

Spec = Gem::Specification.new do |s|
  s.name = PKG_NAME + "-update"
  s.version = PKG_VERSION
  s.required_ruby_version = Gem::Requirement.new '> 1.8.3'
  s.summary = "RubyGems Update GEM"
  s.description = %{RubyGems is a package management framework for Ruby. This Gem
is a update for the base RubyGems software. You must have a base
installation of RubyGems before this update can be applied.
}
  s.files = PKG_FILES.to_a
  s.require_path = 'lib'
  s.authors = ['Jim Weirich', 'Chad Fowler', 'Eric Hodel']
  s.email = "rubygems-developers@rubyforge.org"
  s.homepage = "http://rubygems.rubyforge.org"
  s.rubyforge_project = "rubygems"
  s.bindir = "bin" # Use these for applications.
  s.executables = ["update_rubygems"]
  certdir = ENV['CERT_DIR']
  if certdir then
    key = File.join certdir, 'gem-private_key.pem'
    cert = File.join certdir, 'gem-public_cert.pem'

    if File.exist? key and File.exist? cert then
      s.signing_key = File.join(certdir, 'gem-private_key.pem')
      s.cert_chain = [File.join(certdir, 'gem-public_cert.pem')]
      warn_unsigned = false
    else
      warn_unsigned = true
    end
  end
end

# Add console output about signing the Gem
file "pkg/#{Spec.full_name}.gem" do
  if warn_unsigned then
    warn "WARNING: gem will not be signed, no key or certificate found in #{ENV['CERT_DIR']}"
  else
    puts "Signed with certificates in '#{ENV['CERT_DIR']}'"
  end
end

Rake::GemPackageTask.new(Spec) do |p| end

desc "Build the Gem spec file for the rubygems-update package"
task :gemspec => "pkg/rubygems-update.gemspec"
file "pkg/rubygems-update.gemspec" => ["pkg", "Rakefile"] do |t|
  open(t.name, "w") do |f| f.puts Spec.to_yaml end
end

desc "Install RubyGems"
task :install do
  opts = ENV['SETUP_OPTIONS']
  ruby "setup.rb #{opts}".strip

  svnversion = `svnversion`.split(':').last.sub(/[^\d]/, '').strip

  unless svnversion.empty? then
    File.read('lib/rubygems/rubygems_version.rb') =~ /RubyGemsVersion = '(.*)'/
    current_version = $1.split '.', 4
    rubygems_version = (current_version[0, 3] << svnversion).join '.'
    rubygems_version_file = File.join Gem::ConfigMap[:sitelibdir], 'rubygems',
                                      'rubygems_version.rb'

    generate_rubygems_version rubygems_version_file, rubygems_version
  end
end

desc "Run local 'gem' e.g. rake rungem -- install -i ~/tmp/gems"
task :rungem do
  ARGV.shift
  exec(Gem.ruby, '-Ilib', 'bin/gem', *ARGV)
end

# Misc Tasks ---------------------------------------------------------

def egrep(pattern)
  Dir['{bin,lib,test,util}/**/*.rb'].each do |fn|
    count = 0
    open(fn) do |f|
      while line = f.gets
        count += 1
        if line =~ pattern
          puts "#{fn}:#{count}:#{line}"
        end
      end
    end
  end
end

desc "Look for TODO and FIXME tags in the code"
task :todo do
  egrep /#.*(FIXME|TODO|TBD)/
end

desc "Look for Debugging print lines"
task :dbg do
  egrep /\bDBG|\bbreakpoint\b/
end

desc "List all ruby files"
task :rubyfiles do
  puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ }
  puts Dir['bin/*'].reject { |fn| fn =~ /CVS|(~$)|(\.rb$)/ }
end

task :rf => :rubyfiles

# These tasks expect to have the following directory structure:
#
# git/git.rubini.us/code # Rubinius git HEAD checkout
# svn/ruby/trunk # ruby subversion HEAD checkout
# svn/rubygems/trunk # RubyGems subversion HEAD checkout
#
# If you don't have this directory structure, set RUBY_PATH and/or
# RUBINIUS_PATH.

diff_options = "-urpN --exclude '*svn*' --exclude '*swp' --exclude '*rbc'"
rsync_options = "-avP --exclude '*svn*' --exclude '*swp' --exclude '*rbc' --exclude '*.rej' --exclude '*.orig' --exclude 'lib/rubygems/defaults/*'"

rubinius_dir = ENV['RUBINIUS_PATH'] || '../../../git/git.rubini.us/code'
ruby_dir = ENV['RUBY_PATH'] || '../../ruby/trunk'

desc "Updates Ruby HEAD with the currently checked-out copy of RubyGems."
task :update_ruby do
  sh "rsync #{rsync_options} bin/gem #{ruby_dir}/bin/gem"
  sh "rsync #{rsync_options} lib/ #{ruby_dir}/lib"
  sh "rsync #{rsync_options} test/ #{ruby_dir}/test/rubygems"
  sh "rsync #{rsync_options} util/gem_prelude.rb #{ruby_dir}/gem_prelude.rb"
end

desc "Diffs Ruby HEAD with the currently checked-out copy of RubyGems."
task :diff_ruby do
  options = "-urpN --exclude '*svn*' --exclude '*swp' --exclude '*rbc'"

  sh "diff #{diff_options} bin/gem #{ruby_dir}/bin/gem; true"
  sh "diff #{diff_options} lib/ubygems.rb #{ruby_dir}/lib/ubygems.rb; true"
  sh "diff #{diff_options} lib/rubygems.rb #{ruby_dir}/lib/rubygems.rb; true"
  sh "diff #{diff_options} lib/rubygems #{ruby_dir}/lib/rubygems; true"
  sh "diff #{diff_options} lib/rbconfig #{ruby_dir}/lib/rbconfig; true"
  sh "diff #{diff_options} test #{ruby_dir}/test/rubygems; true"
  sh "diff #{diff_options} util/gem_prelude.rb #{ruby_dir}/gem_prelude.rb; true"
end

desc "Updates Rubinius HEAD with the currently checked-out copy of RubyGems."
task :update_rubinius do
  sh "rsync #{rsync_options} bin/gem #{rubinius_dir}/lib/bin/gem"
  sh "rsync #{rsync_options} lib/ #{rubinius_dir}/lib"
  sh "rsync #{rsync_options} test/ #{rubinius_dir}/test/rubygems"
  sh "rsync #{rsync_options} util/gem_prelude.rb #{rubinius_dir}/kernel/core/gem_prelude.rb"
end

desc "Diffs Rubinius HEAD with the currently checked-out copy of RubyGems."
task :diff_rubinius do
  sh "diff #{diff_options} bin/gem #{rubinius_dir}/lib/bin/gem; true"
  sh "diff #{diff_options} lib/ubygems.rb #{rubinius_dir}/lib/ubygems.rb; true"
  sh "diff #{diff_options} lib/rubygems.rb #{rubinius_dir}/lib/rubygems.rb; true"
  sh "diff #{diff_options} lib/rubygems #{rubinius_dir}/lib/rubygems; true"
  sh "diff #{diff_options} test #{rubinius_dir}/test/rubygems; true"
  sh "diff #{diff_options} util/gem_prelude.rb #{rubinius_dir}/kernel/core/gem_prelude.rb; true"
end
Something went wrong with that request. Please try again.