Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 291 lines (235 sloc) 8.378 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
# NOTE! When updating this file, also update INSTALL, if necessary.
# NOTE! Please keep your tasks grouped together.

include Rake::DSL if Rake.const_defined? :DSL

if ENV["RUBYLIB"]
  STDERR.puts <<-EOM
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING
WARNING You have the RUBYLIB environment variable set. This can WARNING
WARNING cause serious problems building Rubinius, including but WARNING
WARNING not limited to causing the build to fail or specs to fail WARNING
WARNING or your computer to randomly emit strange beeping sounds WARNING
WARNING or burst into flames. Not all these possible catastrophic WARNING
WARNING effects have been observed in the wild, but you have been WARNING
WARNING warned. We recommend unsetting this environment variable WARNING
WARNING and running the build again. WARNING
WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
EOM
end

# Wipe out CDPATH, it interferes with building in some cases,
# see http://github.com/rubinius/rubinius/issues#issue/555
if ENV["CDPATH"]
  ENV.delete("CDPATH")
end

$trace ||= false
$VERBOSE = true
$verbose = Rake.application.options.trace || ARGV.delete("-v")

if !$verbose and respond_to?(:verbose)
  verbose(false) if verbose() == :default
end

$:.unshift File.expand_path("../", __FILE__)

BUILD_CONFIG = {} unless Object.const_defined? :BUILD_CONFIG

def load_configuration
  config_rb = File.expand_path "../config.rb", __FILE__
  config_h = File.expand_path "../vm/gen/config.h", __FILE__

  unless File.exists?(config_rb) and File.exists?(config_h)
    STDERR.puts "Please run ./configure first"
    exit 1
  end

  load config_rb
  BUILD_CONFIG.replace Rubinius::BUILD_CONFIG
end

load_configuration

unless BUILD_CONFIG[:config_version] == 162
  STDERR.puts "Your configuration is outdated, please run ./configure first"
  exit 1
end

# Yes, this is duplicated from the configure script for now.
unless BUILD_CONFIG[:which_ruby] == :ruby or BUILD_CONFIG[:which_ruby] == :rbx
  STDERR.puts "Sorry, building Rubinius requires MRI or Rubinius"
  exit 1
end

def libprefixdir
  if BUILD_CONFIG[:stagingdir]
    "#{BUILD_CONFIG[:stagingdir]}#{BUILD_CONFIG[:libdir]}"
  else
    "#{BUILD_CONFIG[:sourcedir]}/lib"
  end
end

# Records the full path to the ruby executable that runs this configure
# script. That path will be made available to the rest of the build system
# so the same version of ruby is invoked as needed.
#
# This is duplicated from the configure script for now.
@build_ruby = nil

def build_ruby
  unless @build_ruby
    bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"]
    bin += (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
    @build_ruby = File.join(RbConfig::CONFIG['bindir'], bin)
  end
  @build_ruby
end

unless BUILD_CONFIG[:build_ruby] == build_ruby
  STDERR.puts "\nUnable to build using the running Ruby executable.\n\n"

  STDERR.puts "To resolve this issue:"
  if ENV['PATH'] =~ /#{BUILD_CONFIG[:bindir]}/
    STDERR.puts " * Remove '#{BUILD_CONFIG[:bindir]}' from your PATH."
  elsif build_ruby == File.join(BUILD_CONFIG[:bindir], BUILD_CONFIG[:program_name])
    # This may occur using rbx from the build directory to build a version
    # of rbx to install. The rbx in the build directory will pick up the
    # lib/rubinius/build_config.rb that was just written by configure.
    # Obviously, this chewing gum, duct tape, bailing wire, and toilet paper
    # system needs fixing.
    STDERR.puts " * Configure using a Ruby executable other than the one in your build directory."
  else
    STDERR.puts " * Use '#{BUILD_CONFIG[:build_ruby]}' to build."
  end

  exit 1
end

# Set the build compiler to the configured compiler unless
# the compiler is set via CC environment variable.
ENV['CC'] = BUILD_CONFIG[:cc] unless ENV['CC']
ENV['CXX'] = BUILD_CONFIG[:cxx] unless ENV['CXX']

$dlext = RbConfig::CONFIG["DLEXT"]
$CC = ENV['CC']

class SpecRunner

  @at_exit_handler_set = false
  @at_exit_status = 0

  def self.at_exit_status
    @at_exit_status
  end

  def self.set_at_exit_handler
    return if @at_exit_handler_set

    at_exit { exit SpecRunner.at_exit_status }
    @at_exit_handler_set = true
  end

  def self.set_at_exit_status(status)
    @at_exit_status = status
  end

  def initialize
    unless File.directory? BUILD_CONFIG[:runtimedir]
      # Setting these enables the specs to run when rbx has been configured
      # to be installed, but rake install has not been run yet.
      ENV["RBX_RUNTIME"] = File.expand_path "../runtime", __FILE__
      ENV["RBX_LIB"] = File.expand_path "../lib", __FILE__
      ENV["CFLAGS"] = "-Ivm/capi"
    end

    ENV.delete("RUBYOPT")

    @handler = lambda do |ok, status|
      self.class.set_at_exit_status(status.exitstatus) unless ok
    end
  end

  def run(flags=nil)
    self.class.set_at_exit_handler

    sh("bin/mspec ci #{ENV['CI_MODE_FLAG'] || flags} -d --agent --background", &@handler)
  end
end

if BUILD_CONFIG[:stagingdir]
  task :default => [:spec, :check_status, :install]
else
  task :default => :spec
end

task :check_status do
  exit unless SpecRunner.at_exit_status == 0
end

task :github do
  cur = `git config remote.origin.url`.strip
  if cur == "git://github.com/evanphx/rubinius.git"
    sh "git config remote.origin.url git://github.com/rubinius/rubinius.git"
    puts "\nSwitch to git://github.com/rubinius/rubinius.git"
  else
    sh "git config remote.origin.url git@github.com:rubinius/rubinius.git"
    puts "\nSwitch to github.com:rubinius/rubinius.git"
  end
end

# See vm.rake for more information
desc "Build Rubinius"
task :build => %w[build:build gems:install]

desc "Recompile all ruby system files"
task :rebuild => %w[clean build]

def run_ci
  unless system("rake -q")
    puts "<< ERROR IN CI, CLEANING AND RERUNNING >>"
    system "rake -q clean"
    system "find . -name *.rbc -delete"
    sh "rake -q"
  end
end

desc "Run CI in default (configured) mode"
task :ci => %w[build vm:test] do
  run_ci
end

# These tasks run the specs in the specified mode regardless of
# the default mode with which Rubinius was configured.
desc "Run CI in 1.8 mode"
task :ci18 => %w[build vm:test] do
  ENV['CI_MODE_FLAG'] = "-T -X18"
  run_ci
end

desc "Run CI in 1.9 mode"
task :ci19 => %w[build vm:test] do
  ENV['CI_MODE_FLAG'] = "-T -X19"
  run_ci
end

desc "Run CI in 2.0 mode"
task :ci20 => %w[build vm:test] do
  ENV['CI_MODE_FLAG'] = "-T -X20"
  run_ci
end

desc 'Remove rubinius build files'
task :clean => %w[
vm:clean
kernel:clean
clean:crap
extensions:clean
]

desc 'Remove rubinius build files and external library build files'
task :distclean => %w[
clean
vm:distclean
]

namespace :clean do
  desc "Cleans up editor files and other misc crap"
  task :crap do
    files = (Dir["*~"] + Dir["**/*~"]).uniq

    rm_f files, :verbose => $verbose unless files.empty?
  end
end

desc "Run the Rubinius documentation website"
task :docs do
  require 'kernel/delta/options'
  require 'rbconfig'
  require 'webrick'
  require 'lib/rubinius/documentation'

  Rubinius::Documentation.main
end

spec_runner = SpecRunner.new

desc "Run the CI specs in 1.8 mode but do not rebuild on failure"
task :spec18 => %w[build vm:test] do
  spec_runner.run "-T -X18"
end

desc "Run the CI specs in 1.9 mode but do not rebuild on failure"
task :spec19 => %w[build vm:test] do
  spec_runner.run "-T -X19"
end

desc "Run the CI specs in 2.0 mode but do not rebuild on failure"
task :spec20 => %w[build vm:test] do
  spec_runner.run "-T -X20"
end

desc "Run CI in default (configured) mode but do not rebuild on failure"
task :spec => BUILD_CONFIG[:version_list].map { |v| "spec#{v}" }

desc "Print list of items marked to-do in kernel/ (@todo|TODO)"
task :todos do

  # create array with files to be checked
  filesA = Dir['kernel/**/*.*']

  # search for @todo or TODO
  filesA.sort!.each do |filename|
    File.open(filename) do |file|
      file.each do |line|
        puts "#{filename} #{file.lineno.to_s}:\t#{line.strip}" if line.include?("@todo") or line.include?("TODO")
      end
    end
  end
end
Something went wrong with that request. Please try again.