Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Build Rubinius file system location independent.

  • Loading branch information...
commit 7862130ba9a2a54306587330f18f76268e77656c 1 parent d0b1d0f
@brixen brixen authored
View
2  .gitignore
@@ -48,6 +48,7 @@ tmtags
/lib/site
/share
/work
+/staging
# ignore gems and commands installed by gems
/gems/*
@@ -63,7 +64,6 @@ tmtags
!/bin/mkspec
!/bin/mspec
!/bin/prof.rb
-!/bin/rbx
# don't ignore spec/tags
!/spec/tags
View
54 Rakefile
@@ -33,7 +33,7 @@ end
require config_rb
BUILD_CONFIG = Rubinius::BUILD_CONFIG
-unless BUILD_CONFIG[:config_version] == 158
+unless BUILD_CONFIG[:config_version] == 159
STDERR.puts "Your configuration is outdated, please run ./configure first"
exit 1
end
@@ -44,6 +44,14 @@ unless BUILD_CONFIG[:which_ruby] == :ruby or BUILD_CONFIG[:which_ruby] == :rbx
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.
@@ -93,6 +101,10 @@ 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
@@ -105,7 +117,7 @@ class SpecRunner
end
def initialize
- unless File.directory? BUILD_CONFIG[:runtime]
+ 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__
@@ -127,7 +139,15 @@ class SpecRunner
end
end
-task :default => :spec
+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
@@ -141,8 +161,8 @@ task :github do
end
# See vm.rake for more information
-desc "Build everything that needs to be built at default level."
-task :build => ["build:build", "gem_bootstrap"]
+desc "Build Rubinius"
+task :build => %w[build:build gems:install]
desc "Recompile all ruby system files"
task :rebuild => %w[clean build]
@@ -204,30 +224,6 @@ namespace :clean do
end
end
-desc 'Install the pre-installed gems'
-task :gem_bootstrap do
- STDOUT.puts "Installing pre-installed gems..."
- ENV['GEM_HOME'] = ENV['GEM_PATH'] = nil
-
- rbx = "#{BUILD_CONFIG[:bindir]}/#{BUILD_CONFIG[:program_name]}"
- gems = Dir["preinstalled-gems/*.gem"]
- options = "--local --conservative --ignore-dependencies --no-rdoc --no-ri"
-
- BUILD_CONFIG[:version_list].each do |ver|
- gems.each do |gem|
- parts = File.basename(gem, ".gem").split "-"
- gem_name = parts[0..-2].join "-"
- gem_version = parts[-1]
-
- system "#{rbx} -X#{ver} -S gem query --name-matches #{gem_name} --installed --version #{gem_version} > #{DEV_NULL}"
-
- unless $?.success?
- sh "#{rbx} -X#{ver} -S gem install #{options} #{gem}"
- end
- end
- end
-end
-
desc "Run the Rubinius documentation website"
task :docs do
require 'kernel/delta/options'
View
1  bin/gem
View
1  bin/irb
View
1  bin/rake
View
1  bin/rbx
View
10 bin/rbx-build
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-BIN_DIR=$(dirname $0)
-BASE_DIR=$(dirname $BIN_DIR)
-
-export RBX_RUNTIME="$BASE_DIR/runtime"
-export RBX_LIB="$BASE_DIR/lib"
-export RBX_CAPI_DIR=$BASE_DIR
-
-exec $BIN_DIR/../vm/vm "$*"
View
1  bin/rdoc
View
1  bin/ri
View
1  bin/ruby
View
199 configure
@@ -19,6 +19,9 @@ class Configure
def initialize(root)
@log = Logger.new "configure.log"
+ @command_line = ARGV.dup
+ @log.log "Command line: #{@command_line.join(" ").inspect}"
+
@defines = []
@config = File.join(root, "config.rb")
@@ -49,7 +52,6 @@ class Configure
@rake = ENV['RAKE'] || 'rake'
@tar = ENV['TAR'] || (@windows ? 'bsdtar' : 'tar')
@perl = ENV['PERL'] || 'perl'
- @install = false
@default_version = "18"
@version_list = ["18", "19"]
@supported_versions = ["18", "19", "20"]
@@ -98,20 +100,21 @@ class Configure
@lib_dirs = []
# File system paths
- @bindir = root + "/bin"
- @include18dir = root + "/vm/capi/18/include"
- @include19dir = root + "/vm/capi/19/include"
- @include20dir = root + "/vm/capi/19/include"
- @libdir = root
- @runtime = @libdir + "/runtime"
- @kernel_path = @libdir + "/kernel"
- @lib_path = @libdir + "/lib"
- @mandir = root + "/man"
- @gemsdir = root + "/gems"
-
- # Some simple defaults for when running directly out of the build dir
- @sitedir = @lib_path + "/site"
- @vendordir = @lib_path + "/vendor"
+ @sourcedir = root
+ @prefixdir = nil
+ @bindir = nil
+ @libdir = nil
+ @runtimedir = nil
+ @kerneldir = nil
+ @sitedir = nil
+ @vendordir = nil
+ @mandir = nil
+ @gemsdir = nil
+
+ # TODO: fix this
+ @include18dir = nil # root + "/vm/capi/18/include"
+ @include19dir = nil # root + "/vm/capi/19/include"
+ @include20dir = nil # root + "/vm/capi/19/include"
@program_name = "rbx"
@@ -123,7 +126,7 @@ class Configure
@libversion = "2.0"
@version = "#{@libversion}.0dev"
@release_date = "yyyy-mm-dd"
- @config_version = 158
+ @config_version = 159
# TODO: add conditionals for platforms
if RbConfig::CONFIG["build_os"] =~ /darwin/
@@ -159,6 +162,54 @@ class Configure
File.expand_path(path)
end
+ def expand_install_dir(dir)
+ dir = expand dir
+ if File.directory?(dir) and dir !~ /(rubinius|rbx).*\/?$/
+ original = dir
+ dir + "/rubinius/#{@libversion}"
+ @log.write "The directory #{original} already exists, installing to #{dir}"
+ end
+ dir
+ end
+
+ def set_filesystem_paths
+ @prefixdir = @sourcedir unless @prefixdir
+ @bindir = @prefixdir + "/bin" unless @bindir
+ @libdir = @prefixdir + "/lib" unless @libdir
+ @runtimedir = @prefixdir + "/runtime" unless @runtimedir
+ @kerneldir = @prefixdir + "/kernel" unless @kerneldir
+ @sitedir = @prefixdir + "/site" unless @sitedir
+ @vendordir = @prefixdir + "/vendor" unless @vendordir
+ @mandir = @prefixdir + "/man" unless @mandir
+ @gemsdir = @prefixdir + "/gems" unless @gemsdir
+ @include18dir = @prefixdir + "/vm/capi/18/include" unless @include18dir
+ @include19dir = @prefixdir + "/vm/capi/19/include" unless @include19dir
+ @include20dir = @prefixdir + "/vm/capi/19/include" unless @include20dir
+
+ dirs = [@bindir, @libdir, @runtimedir, @kerneldir, @sitedir, @vendordir,
+ @mandir, @gemsdir, @include18dir, @include19dir, @include20dir]
+
+ parts = dirs.map { |d| d.split "/" }
+
+ i = 0
+ total = parts[0].size
+ prefix = []
+
+ while i < total
+ part = parts[0][i]
+ break unless parts.all? { |p| p[i] == part }
+ prefix << part
+ i += 1
+ end
+
+ @prefixdir = prefix.join "/"
+ size = @prefixdir.size
+
+ dirs.each { |d| d.replace d[size..-1] }
+
+ @stagingdir = "#{@sourcedir}/staging" unless @prefixdir == @sourcedir
+ end
+
def options
o = Rubinius::Options.new "Usage: configure [options]", 30
o.left_align
@@ -272,71 +323,44 @@ class Configure
o.doc "\n File system paths for installing Rubinius"
o.on "-P", "--prefix", "PATH", "Install Rubinius in subdirectories of PATH" do |dir|
- @install = true
- dir = File.expand_path dir
-
- if !ENV['RELEASE'] and File.directory? dir and dir !~ /(rubinius|rbx).*\/?$/
- old = dir
- dir += "/rubinius/#{@libversion}"
- @log.write "The directory #{old} already exists, installing to #{dir}"
- end
-
- @bindir = dir + "/bin"
- @include18dir = dir + "/18/include"
- @include19dir = dir + "/19/include"
- @include20dir = dir + "/19/include"
- @libdir = dir
- @runtime = @libdir + "/runtime"
- @kernel_path = @libdir + "/kernel"
- @lib_path = @libdir + "/lib"
- @mandir = dir + "/man"
- @gemsdir = dir + "/gems"
-
- @sitedir = dir + "/site"
- @vendordir = dir + "/vendor"
+ @prefixdir = expand_install_dir dir
end
o.on "-B", "--bindir", "PATH", "Install Rubinius executable in PATH" do |dir|
- @install = true
@bindir = expand dir
end
o.on "-I", "--includedir", "PATH", "Install Rubinius C-API include files in PATH" do |dir|
- @install = true
- path = expand dir
- @include18dir = path + "/18"
- @include19dir = path + "/19"
- @include20dir = path + "/20"
+ dir = expand dir
+ @include18dir = dir + "/18"
+ @include19dir = dir + "/19"
+ @include20dir = dir + "/20"
end
o.on "-L", "--libdir", "PATH", "Install Ruby library in PATH" do |dir|
- @install = true
- @libdir = expand(dir) + "/rubinius/#{@libversion}"
- @runtime = @libdir + "/runtime"
- @kernel_path = @libdir + "/kernel"
- @lib_path = @libdir + "/lib"
+ dir = expand_install_dir dir
- @sitedir = @libdir + "/site"
- @vendordir = @libdir + "/vendor"
+ @libdir = dir
+ @runtime = dir + "/runtime"
+ @kernel_path = dir + "/kernel"
+ @lib_path = dir + "/lib"
+ @sitedir = dir + "/site"
+ @vendordir = dir + "/vendor"
end
o.on "-M", "--mandir", "PATH", "Install man pages in PATH" do |dir|
- @install = true
@mandir = expand dir
end
o.on "-G", "--gemsdir", "PATH", "Install gems in PATH" do |dir|
- @install = true
@gemsdir = expand dir
end
o.on "--sitedir", "PATH", "Install site-specific Ruby code in PATH" do |dir|
- @install = true
@sitedir = expand dir
end
o.on "--vendordir", "PATH", "Install vendor-specific Ruby code in PATH" do |dir|
- @install = true
@vendordir = expand dir
end
@@ -1268,6 +1292,7 @@ int main() { return tgetnum(""); }
f.puts <<-EOC
module Rubinius
BUILD_CONFIG = {
+ :command_line => #{@command_line.join(" ").inspect},
:which_ruby => :#{which_ruby},
:build_ruby => "#{build_ruby}",
:build_rake => "#{@rake}",
@@ -1292,18 +1317,20 @@ module Rubinius
:x86_32 => #{@x86_32},
:x86_64 => #{@x86_64},
:fibers => #{@fibers},
+ :sourcedir => "#{@sourcedir}",
+ :stagingdir => #{@stagingdir.inspect},
+ :prefixdir => "#{@prefixdir}",
:bindir => "#{@bindir}",
:libdir => "#{@libdir}",
- :runtime => "#{@runtime}",
- :kernel_path => "#{@kernel_path}",
- :lib_path => "#{@lib_path}",
+ :runtimedir => "#{@runtimedir}",
+ :kerneldir => "#{@kerneldir}",
+ :sitedir => "#{@sitedir}",
+ :vendordir => "#{@vendordir}",
:include18dir => "#{@include18dir}",
:include19dir => "#{@include19dir}",
:include20dir => "#{@include20dir}",
:mandir => "#{@mandir}",
:gemsdir => "#{@gemsdir}",
- :sitedir => "#{@sitedir}",
- :vendordir => "#{@vendordir}",
:program_name => "#{@program_name}",
:version => "#{@version}",
:libversion => "#{@libversion}",
@@ -1335,11 +1362,12 @@ end
#define RBX_CPU "#{@cpu}"
#define RBX_VENDOR "#{@vendor}"
#define RBX_OS "#{@os}"
+#define RBX_PREFIX_PATH "#{@prefixdir}"
#define RBX_BIN_PATH "#{@bindir}"
#define RBX_GEMS_PATH "#{@gemsdir}"
-#define RBX_RUNTIME "#{@runtime}"
-#define RBX_KERNEL_PATH "#{@kernel_path}"
-#define RBX_LIB_PATH "#{@lib_path}"
+#define RBX_RUNTIME_PATH "#{@runtimedir}"
+#define RBX_KERNEL_PATH "#{@kerneldir}"
+#define RBX_LIB_PATH "#{@libdir}"
#define RBX_HDR18_PATH "#{@include18dir}"
#define RBX_HDR19_PATH "#{@include19dir}"
#define RBX_HDR20_PATH "#{@include20dir}"
@@ -1355,7 +1383,7 @@ end
EOC
if @vendor_zlib
- f.puts %[#define RBX_ZLIB_PATH "#{@lib_path}/zlib/"]
+ f.puts %[#define RBX_ZLIB_PATH "#{@libdir}/zlib/"]
else
f.puts %[#define RBX_ZLIB_PATH ""]
end
@@ -1594,6 +1622,8 @@ end
options
parse ARGV
+ set_filesystem_paths
+
if File.join(@bindir, @program_name) == build_ruby
@log.error "\nYou are attempting to build using the instance of Rubinius that you are building.\n\n"
@@ -1630,19 +1660,46 @@ irc.freenode.net and provide the following system information:
EOM
end
- if @install
- @log.write "\nConfigured. Run 'rake install' to install Rubinius."
+ unless @stagingdir
+ build_msg = <<-EOM
+Rubinius has been configured.
+
+Run 'rake' to build and test Rubinius.
+ EOM
else
- @log.write <<-EOM
+ build_msg = <<-EOM
+Rubinius has been configured for the following paths:
+
+prefix: #{@prefixdir}
+bin: #{@bindir}
+lib: #{@libdir}
+runtime: #{@runtimedir}
+kernel: #{@kerneldir}
+site: #{@sitedir}
+vendor: #{@vendordir}
+man: #{@mandir}
+gems: #{@gemsdir}
+
+Run 'rake' to build, test and install Rubinius.
+ EOM
+ end
+
+ @log.write <<-EOM
+------------------------------------------------------------------
-Configured. Run 'rake' to build and run VM tests and rubyspecs.
+#{build_msg}
+After building, you may add
-After building, you may add '#{@bindir}' to your PATH or run commands directly from that directory. Available commands are:
+'#{@prefixdir}#{@bindir}'
+
+to your PATH or run commands directly from that directory.
+
+Available commands are:
#{@program_name}, ruby, rake, gem, irb, rdoc, ri
- EOM
- end
+------------------------------------------------------------------
+ EOM
end
# Handles user output and logging while running configure.
View
20 kernel/loader.rb
@@ -77,25 +77,7 @@ def preamble
def system_load_path
@stage = "setting up system load path"
- if env_lib = ENV['RBX_LIB'] and File.exists?(env_lib)
- @main_lib = File.expand_path(env_lib)
- else
- # use configured library path and check its existence
- @main_lib = Rubinius::LIB_PATH
-
- unless File.exists?(@main_lib)
- STDERR.puts <<-EOM
-Rubinius was configured to find standard library files at:
-
- #{@main_lib}
-
-but that directory does not exist.
-
-Set the environment variable RBX_LIB to the directory
-containing the Rubinius standard library files.
- EOM
- end
- end
+ @main_lib = Rubinius::LIB_PATH
@main_lib_bin = File.join @main_lib, "bin"
Rubinius.const_set :PARSER_EXT_PATH, "#{@main_lib}/ext/melbourne/rbx/melbourne20"
View
8 lib/rbconfig.rb
@@ -5,18 +5,16 @@ module RbConfig
raise "Looks like you loaded the Rubinius rbconfig, but this is not Rubinius."
end
- prefix = File.dirname(File.dirname(__FILE__))
-
CONFIG = {}
- CONFIG["prefix"] = prefix
+ CONFIG["prefix"] = Rubinius::PREFIX_PATH
CONFIG["install_prefix"] = ''
CONFIG["DLEXT"] = Rubinius::LIBSUFFIX[1..-1]
CONFIG["EXEEXT"] = ""
CONFIG["ruby_install_name"] = RUBY_ENGINE.dup
CONFIG["RUBY_INSTALL_NAME"] = RUBY_ENGINE.dup
CONFIG["exec_prefix"] = "$(prefix)"
- CONFIG["bindir"] = Rubinius::BUILD_CONFIG[:bindir]
+ CONFIG["bindir"] = Rubinius::BIN_PATH
CONFIG["sbindir"] = "$(exec_prefix)/sbin"
CONFIG["libexecdir"] = "$(exec_prefix)/libexec"
CONFIG["datarootdir"] = "$(prefix)/share"
@@ -218,7 +216,7 @@ def RbConfig.ruby
RbConfig::CONFIG["bindir"],
RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"]
)
- end
+ end
# Adapted from MRI's' rbconfig.rb
MAKEFILE_CONFIG = {}
View
80 rakelib/extensions.rake
@@ -27,8 +27,11 @@ namespace :extensions do
end
def rbx_build
- # rbx-build can run even if prefix is used
- File.expand_path "../bin/rbx-build", File.dirname(__FILE__)
+ if BUILD_CONFIG[:stagingdir]
+ "#{BUILD_CONFIG[:stagingdir]}#{BUILD_CONFIG[:bindir]}/#{BUILD_CONFIG[:program_name]}"
+ else
+ "#{BUILD_CONFIG[:sourcedir]}/vm/vm"
+ end
end
def build_extconf(name, opts)
@@ -44,10 +47,10 @@ def build_extconf(name, opts)
ENV["BUILD_RUBY"] = BUILD_CONFIG[:build_ruby]
- include18_dir = File.expand_path("../../vm/capi/18/include", __FILE__)
- include19_dir = File.expand_path("../../vm/capi/19/include", __FILE__)
+ include18_dir = "#{BUILD_CONFIG[:sourcedir]}/vm/capi/18/include"
+ include19_dir = "#{BUILD_CONFIG[:sourcedir]}/vm/capi/19/include"
- unless File.directory? BUILD_CONFIG[:runtime]
+ unless File.directory? BUILD_CONFIG[:runtimedir]
if opts[:env] == "-X18"
ENV["CFLAGS"] = "-I#{include18_dir}"
else
@@ -69,7 +72,7 @@ end
def compile_ext(name, opts={})
names = name.split ":"
name = names.last
- ext_dir = opts[:dir] || File.join("lib/ext", names)
+ ext_dir = opts[:dir] || File.join("#{libprefixdir}/ext", names)
if t = opts[:task]
ext_task_name = "build:#{t}"
@@ -131,21 +134,21 @@ compile_ext "melbourne", :task => "rbx",
:env => melbourne_env,
:doc => "for Rubinius"
-compile_ext "digest", :dir => "lib/digest/ext"
-compile_ext "digest:md5", :dir => "lib/digest/ext/md5"
-compile_ext "digest:rmd160", :dir => "lib/digest/ext/rmd160"
-compile_ext "digest:sha1", :dir => "lib/digest/ext/sha1"
-compile_ext "digest:sha2", :dir => "lib/digest/ext/sha2"
-compile_ext "digest:bubblebabble", :dir => "lib/digest/ext/bubblebabble"
+compile_ext "digest", :dir => "#{libprefixdir}/digest/ext"
+compile_ext "digest:md5", :dir => "#{libprefixdir}/digest/ext/md5"
+compile_ext "digest:rmd160", :dir => "#{libprefixdir}/digest/ext/rmd160"
+compile_ext "digest:sha1", :dir => "#{libprefixdir}/digest/ext/sha1"
+compile_ext "digest:sha2", :dir => "#{libprefixdir}/digest/ext/sha2"
+compile_ext "digest:bubblebabble", :dir => "#{libprefixdir}/digest/ext/bubblebabble"
if enabled_18
- compile_ext "18/bigdecimal", :dir => "lib/18/bigdecimal/ext", :env => "-X18"
+ compile_ext "18/bigdecimal", :dir => "#{libprefixdir}/18/bigdecimal/ext", :env => "-X18"
- compile_ext "18/syck", :dir => "lib/18/syck/ext"
- compile_ext "18/nkf", :dir => "lib/18/nkf/ext", :env => "-X18"
+ compile_ext "18/syck", :dir => "#{libprefixdir}/18/syck/ext"
+ compile_ext "18/nkf", :dir => "#{libprefixdir}/18/nkf/ext", :env => "-X18"
if BUILD_CONFIG[:readline] == :c_readline
- compile_ext "18/readline", :dir => "lib/18/readline/ext",
+ compile_ext "18/readline", :dir => "#{libprefixdir}/18/readline/ext",
:deps => ["Makefile", "extconf.rb"],
:env => "-X18"
end
@@ -153,58 +156,67 @@ if enabled_18
# rbx must be able to run to build these because they use
# extconf.rb, so they must be after melbourne for Rubinius.
compile_ext "18/openssl", :deps => ["Makefile", "extconf.h"],
- :dir => "lib/18/openssl/ext",
+ :dir => "#{libprefixdir}/18/openssl/ext",
:env => "-X18"
compile_ext "18/dl", :deps => ["Makefile", "dlconfig.h"],
- :dir => "lib/18/dl/ext", :env => "-X18"
+ :dir => "#{libprefixdir}/18/dl/ext", :env => "-X18"
compile_ext "18/pty", :deps => ["Makefile"],
- :dir => "lib/18/pty/ext",
+ :dir => "#{libprefixdir}/18/pty/ext",
:env => "-X18"
compile_ext "18/zlib", :deps => ["Makefile", "extconf.rb"],
- :dir => "lib/18/zlib/ext",
+ :dir => "#{libprefixdir}/18/zlib/ext",
:env => "-X18"
end
if enabled_19
- compile_ext "19/bigdecimal", :dir => "lib/19/bigdecimal/ext",
+ compile_ext "19/bigdecimal", :dir => "#{libprefixdir}/19/bigdecimal/ext",
:deps => ["Makefile", "extconf.rb"],
:env => "-X19"
- compile_ext "19/nkf", :dir => "lib/19/nkf/ext",
+ compile_ext "19/nkf", :dir => "#{libprefixdir}/19/nkf/ext",
:deps => ["Makefile", "extconf.rb"],
:env => "-X19"
if BUILD_CONFIG[:readline] == :c_readline
- compile_ext "19/readline", :dir => "lib/19/readline/ext",
+ compile_ext "19/readline", :dir => "#{libprefixdir}/19/readline/ext",
:deps => ["Makefile", "extconf.rb"],
:env => "-X19"
end
- compile_ext "19/psych", :deps => ["Makefile"], :dir => "lib/19/psych/ext", :env => "-X19"
+ compile_ext "19/psych", :deps => ["Makefile"],
+ :dir => "#{libprefixdir}/19/psych/ext",
+ :env => "-X19"
- compile_ext "19/syck", :deps => ["Makefile"], :dir => "lib/19/syck/ext", :env => "-X19"
+ compile_ext "19/syck", :deps => ["Makefile"],
+ :dir => "#{libprefixdir}/19/syck/ext",
+ :env => "-X19"
compile_ext "json/parser", :deps => ["Makefile", "extconf.rb"],
- :dir => "lib/19/json/ext/parser",
+ :dir => "#{libprefixdir}/19/json/ext/parser",
:env => "-X19"
compile_ext "json/generator", :deps => ["Makefile", "extconf.rb"],
- :dir => "lib/19/json/ext/generator",
+ :dir => "#{libprefixdir}/19/json/ext/generator",
:env => "-X19"
compile_ext "19/openssl", :deps => ["Makefile", "extconf.h"],
- :dir => "lib/19/openssl/ext",
+ :dir => "#{libprefixdir}/19/openssl/ext",
:env => "-X19"
compile_ext "19/pty", :deps => ["Makefile"],
- :dir => "lib/19/pty/ext",
+ :dir => "#{libprefixdir}/19/pty/ext",
:env => "-X19"
compile_ext "19/zlib", :deps => ["Makefile", "extconf.rb"],
- :dir => "lib/19/zlib/ext",
+ :dir => "#{libprefixdir}/19/zlib/ext",
:env => "-X19"
end
-compile_ext "dbm", :ignore_fail => true, :deps => ["Makefile"], :dir => "lib/dbm/ext"
-compile_ext "gdbm", :ignore_fail => true, :deps => ["Makefile"], :dir => "lib/gdbm/ext"
-compile_ext "sdbm", :deps => ["Makefile"], :dir => "lib/sdbm/ext"
+compile_ext "dbm", :deps => ["Makefile"],
+ :dir => "#{libprefixdir}/dbm/ext",
+ :ignore_fail => true
+compile_ext "gdbm", :deps => ["Makefile"],
+ :dir => "#{libprefixdir}/gdbm/ext",
+ :ignore_fail => true
+compile_ext "sdbm", :deps => ["Makefile"],
+ :dir => "#{libprefixdir}/sdbm/ext"
-compile_ext "profiler", :dir => "lib/tooling/profiler",
+compile_ext "profiler", :dir => "#{libprefixdir}/tooling/profiler",
:deps => ["Makefile"]
View
29 rakelib/gems.rake
@@ -0,0 +1,29 @@
+namespace :gems do
+ desc 'Install the pre-installed gems'
+ task :install do
+ STDOUT.puts "Installing pre-installed gems..."
+ ENV['GEM_HOME'] = ENV['GEM_PATH'] = nil
+
+ if BUILD_CONFIG[:stagingdir]
+ rbx = "#{BUILD_CONFIG[:stagingdir]}#{BUILD_CONFIG[:bindir]}/#{BUILD_CONFIG[:program_name]}"
+ else
+ rbx = "#{BUILD_CONFIG[:sourcedir]}/bin/rbx"
+ end
+ gems = Dir["preinstalled-gems/*.gem"]
+ options = "--local --conservative --ignore-dependencies --no-rdoc --no-ri"
+
+ BUILD_CONFIG[:version_list].each do |ver|
+ gems.each do |gem|
+ parts = File.basename(gem, ".gem").split "-"
+ gem_name = parts[0..-2].join "-"
+ gem_version = parts[-1]
+
+ system "#{rbx} -X#{ver} -S gem query --name-matches #{gem_name} --installed --version #{gem_version} > #{DEV_NULL}"
+
+ unless $?.success?
+ sh "#{rbx} -X#{ver} -S gem install #{options} #{gem}"
+ end
+ end
+ end
+ end
+end
View
294 rakelib/install.rake
@@ -5,23 +5,8 @@
# and install the files with the 'install' command
#
-def install_dir(lib)
- if fr = ENV['FAKEROOT']
- return File.join(fr, lib)
- end
-
- lib
-end
-
-install_dirs = [
- BUILD_CONFIG[:bindir],
- BUILD_CONFIG[:libdir],
- BUILD_CONFIG[:include18dir],
- BUILD_CONFIG[:include19dir],
- BUILD_CONFIG[:include20dir],
- BUILD_CONFIG[:mandir],
- BUILD_CONFIG[:gemsdir]
-]
+desc "Install Rubinius"
+task :install => %w[build:build gems:install install:files install:done]
# What the hell does this code do? We want to avoid sudo whenever
# possible. This code is based on the assumption that if A is a
@@ -30,9 +15,9 @@ install_dirs = [
# at a time from the right-hand side. That path is checked for
# whether it is a directory. If it is and it is writable, we can
# create A. Otherwise, we can't create A and sudo is required.
-def need_sudo?(dirs)
- dirs.each do |name|
- dir = install_dir(File.expand_path(name))
+def need_sudo?
+ FileList["#{BUILD_CONFIG[:stagingdir]}/*"].each do |name|
+ dir = File.expand_path "#{BUILD_CONFIG[:prefixdir]}/#{name}"
until dir == "/"
if File.directory? dir
@@ -47,118 +32,201 @@ def need_sudo?(dirs)
return false
end
-def need_install?
- File.expand_path(Dir.pwd) != install_dir(BUILD_CONFIG[:libdir])
+def install_file(source, prefix, dest, name=nil, options={})
+ return if File.directory? source
+
+ dest_name = File.join(dest, source[prefix.size..-1])
+ dir = File.dirname dest_name
+ mkdir_p dir, :verbose => $verbose unless File.directory? dir
+
+ options[:mode] ||= 0644
+ options[:verbose] ||= $verbose
+
+ install source, dest_name, options
end
-def install_file(source, pattern, dest)
- return if File.directory? source
+def install_bin(source, target)
+ bin = "#{target}#{BUILD_CONFIG[:bindir]}/#{BUILD_CONFIG[:program_name]}"
+ dir = File.dirname bin
+ mkdir_p dir, :verbose => $verbose unless File.directory? dir
- dest_name = install_dir File.join(dest, source.sub(pattern, ""))
- dir = File.dirname(dest_name)
- mkdir_p dir unless File.directory? dir
+ install source, bin, :mode => 0755, :verbose => $verbose
- install source, dest_name, :mode => 0644, :verbose => true
+ # Create symlinks for common commands
+ begin
+ ["ruby", "rake", "gem", "irb", "rdoc", "ri"].each do |command|
+ name = "#{target}/#{BUILD_CONFIG[:bindir]}/#{command}"
+ File.delete name if File.exists? name
+ File.symlink BUILD_CONFIG[:program_name], name
+ end
+ rescue NotImplementedError
+ # ignore
+ end
end
-desc "Install Rubinius"
-task :install => %w[ build:build install:files gem_bootstrap install:done]
+def install_runtime(prefix, target)
+ FileList[
+ "#{prefix}/platform.conf",
+ "#{prefix}/**/index",
+ "#{prefix}/**/signature",
+ "#{prefix}/**/*.rb{a,c}",
+ "#{prefix}/**/load_order*.txt"
+ ].each do |name|
+ install_file name, prefix, "#{target}#{BUILD_CONFIG[:runtimedir]}"
+ end
+end
+
+def install_kernel(prefix, target)
+ FileList["#{prefix}/**/*.rb"].each do |name|
+ install_file name, prefix, "#{target}#{BUILD_CONFIG[:kerneldir]}"
+ end
+end
+
+def install_capi_include(prefix, destination)
+ FileList["#{prefix}/**/*.h", "#{prefix}/**/*.hpp"].each do |name|
+ install_file name, prefix, destination
+ end
+end
+
+def install_build_lib(prefix, target)
+ FileList["#{prefix}/**/*.*", "#{prefix}/**/*"].each do |name|
+ install_file name, prefix, "#{target}#{BUILD_CONFIG[:libdir]}"
+ end
+end
+
+def install_lib(prefix, target)
+ FileList["#{prefix}/**/*.rb"].each do |name|
+ install_file name, prefix, "#{target}#{BUILD_CONFIG[:libdir]}"
+ end
+end
+
+def install_tooling(prefix, target)
+ FileList["#{prefix}/tooling/**/*.#{$dlext}"].each do |name|
+ install_file name, prefix, "#{target}#{BUILD_CONFIG[:libdir]}"
+ end
+end
+
+def install_cext(prefix, target)
+ FileList["#{prefix}/**/ext/**/*.#{$dlext}"].each do |name|
+ install_file name, prefix, "#{target}#{BUILD_CONFIG[:libdir]}"
+ end
+end
+
+def install_documentation(prefix, target)
+ FileList["#{prefix}/rubinius/documentation/**/*"].each do |name|
+ install_file name, prefix, "#{target}#{BUILD_CONFIG[:libdir]}"
+ end
+end
+
+def install_gems(prefix, target)
+ FileList["#{prefix}/**/*.*", "#{prefix}/**/*"].each do |name|
+ install_file name, prefix, "#{target}#{BUILD_CONFIG[:gemsdir]}"
+ end
+end
+
+namespace :stage do
+ task :bin do
+ install_bin "#{BUILD_CONFIG[:sourcedir]}/vm/vm", BUILD_CONFIG[:sourcedir]
+
+ if BUILD_CONFIG[:stagingdir]
+ install_bin "#{BUILD_CONFIG[:sourcedir]}/vm/vm", BUILD_CONFIG[:stagingdir]
+
+ mode = File::CREAT | File::TRUNC | File::WRONLY
+ File.open("#{BUILD_CONFIG[:sourcedir]}/bin/rbx", mode, 0755) do |f|
+ f.puts <<-EOS
+#!/bin/sh
+#
+# Rubinius has been configured to be installed. This convenience
+# wrapper enables running Rubinius from the staging directories.
+
+export RBX_PREFIX_PATH=#{BUILD_CONFIG[:stagingdir]}
+EXE=$(basename $0)
+
+exec #{BUILD_CONFIG[:stagingdir]}#{BUILD_CONFIG[:bindir]}/$EXE "$@"
+ EOS
+ end
+ end
+ end
+
+ task :capi_include do
+ if BUILD_CONFIG[:stagingdir]
+ install_capi_include "#{BUILD_CONFIG[:sourcedir]}/vm/capi/18/include",
+ "#{BUILD_CONFIG[:stagingdir]}#{BUILD_CONFIG[:include18dir]}"
+ install_capi_include "#{BUILD_CONFIG[:sourcedir]}/vm/capi/19/include",
+ "#{BUILD_CONFIG[:stagingdir]}#{BUILD_CONFIG[:include19dir]}"
+ install_capi_include "#{BUILD_CONFIG[:sourcedir]}/vm/capi/20/include",
+ "#{BUILD_CONFIG[:stagingdir]}#{BUILD_CONFIG[:include20dir]}"
+ end
+ end
+
+ task :lib do
+ if BUILD_CONFIG[:stagingdir]
+ install_build_lib "#{BUILD_CONFIG[:sourcedir]}/lib", BUILD_CONFIG[:stagingdir]
+ end
+ end
+
+ task :tooling do
+ if BUILD_CONFIG[:stagingdir]
+ install_tooling "#{BUILD_CONFIG[:sourcedir]}/lib/tooling", BUILD_CONFIG[:stagingdir]
+ end
+ end
+
+ task :runtime do
+ if BUILD_CONFIG[:stagingdir]
+ install_runtime "#{BUILD_CONFIG[:sourcedir]}/runtime", BUILD_CONFIG[:stagingdir]
+ end
+ end
+
+ task :kernel do
+ if BUILD_CONFIG[:stagingdir]
+ install_kernel "#{BUILD_CONFIG[:sourcedir]}/kernel", BUILD_CONFIG[:stagingdir]
+ end
+ end
+
+ task :documentation do
+ if BUILD_CONFIG[:stagingdir]
+ install_documentation "#{BUILD_CONFIG[:sourcedir]}/lib", BUILD_CONFIG[:stagingdir]
+ end
+ end
+end
namespace :install do
desc "Install all the Rubinius files"
task :files do
- if need_sudo? install_dirs
- sh "sudo #{BUILD_CONFIG[:build_ruby]} -S #{BUILD_CONFIG[:build_rake]} install:files", :verbose => true
- elsif !need_install?
- puts "Install directory is the same as build directory, nothing to install"
- else
- install_dirs.each { |name| mkdir_p install_dir(name), :verbose => $verbose }
-
- [["18", "18"], ["19", "19"], ["19", "20"]].each do |a, b|
- FileList["vm/capi/#{a}/include/**/*.h"].each do |name|
- install_file name, %r[^vm/capi/#{a}/include], BUILD_CONFIG[:"include#{b}dir"]
- end
- end
+ if BUILD_CONFIG[:stagingdir]
+ if need_sudo?
+ sh "sudo #{BUILD_CONFIG[:build_ruby]} -S #{BUILD_CONFIG[:build_rake]} install:files", :verbose => true
+ else
+ stagingdir = BUILD_CONFIG[:stagingdir]
+ prefixdir = BUILD_CONFIG[:prefixdir]
- FileList[
- 'runtime/platform.conf',
- 'runtime/**/index',
- 'runtime/**/signature',
- 'runtime/**/*.rb{a,c}',
- 'runtime/**/load_order*.txt'
- ].each do |name|
- install_file name, /^runtime/, BUILD_CONFIG[:runtime]
- end
+ install_capi_include "#{stagingdir}/vm/capi/18/include",
+ "#{prefixdir}#{BUILD_CONFIG[:include18dir]}"
+ install_capi_include "#{stagingdir}/vm/capi/19/include",
+ "#{prefixdir}#{BUILD_CONFIG[:include19dir]}"
+ install_capi_include "#{stagingdir}/vm/capi/20/include",
+ "#{prefixdir}#{BUILD_CONFIG[:include20dir]}"
- # Install the .rb files for the core library (kernel).
- FileList['kernel/**/*.rb'].each do |name|
- install_file name, /^kernel/, BUILD_CONFIG[:kernel_path]
- end
+ install_runtime "#{stagingdir}#{BUILD_CONFIG[:runtimedir]}", prefixdir
- # Install the .rb files for the standard library. This is a
- # separate block from the .rbc files so that the .rb files
- # have an older timestamp and do not trigger recompiling.
- FileList['lib/**/*.rb'].each do |name|
- install_file name, /^lib/, BUILD_CONFIG[:lib_path]
- end
+ install_kernel "#{stagingdir}#{BUILD_CONFIG[:kerneldir]}", prefixdir
- FileList['lib/**/*.rbc'].each do |name|
- install_file name, /^lib/, BUILD_CONFIG[:lib_path]
- end
+ install_lib "#{stagingdir}#{BUILD_CONFIG[:libdir]}", prefixdir
- # Install C++ extensions. Since we permit configuring where
- # to install the C extensions separately from the lib files,
- # we have to be more restrictive with the globbing.
- #
- # TODO: handle this better in daedalus.
- FileList["lib/tooling/**/*.#{$dlext}"].each do |name|
- install_file name, /^lib/, BUILD_CONFIG[:lib_path]
- end
+ install_tooling "#{stagingdir}#{BUILD_CONFIG[:libdir]}", prefixdir
- if Rubinius::BUILD_CONFIG[:vendor_zlib]
- # Install the zlib library files
- FileList["lib/zlib/*"].each do |name|
- install_file name, /^lib/, BUILD_CONFIG[:lib_path]
- end
- end
+ install_documentation "#{stagingdir}#{BUILD_CONFIG[:libdir]}", prefixdir
- # Install the documentation site
- FileList['lib/rubinius/documentation/**/*'].each do |name|
- install_file name, /^lib/, BUILD_CONFIG[:lib_path]
- end
+ install_cext "#{stagingdir}#{BUILD_CONFIG[:libdir]}", prefixdir
- # Install the C extensions for the standard library.
- FileList["lib/**/ext/**/*.#{$dlext}"].each do |name|
- install_file name, /^lib/, BUILD_CONFIG[:lib_path]
- end
-
- # Install pre-installed gems
- gems_dest = "#{BUILD_CONFIG[:gemsdir]}/rubinius/preinstalled"
- FileList["preinstalled-gems/data/**/*"].each do |name|
- install_file name, %r[^preinstalled-gems/data], gems_dest
- end
+ bin = "#{BUILD_CONFIG[:bindir]}/#{BUILD_CONFIG[:program_name]}"
+ install_bin "#{stagingdir}#{bin}", prefixdir
- FileList["preinstalled-gems/bin/*"].each do |name|
- install_file name, /^preinstalled-gems/, BUILD_CONFIG[:gemsdir]
- end
+ install_gems "#{stagingdir}#{BUILD_CONFIG[:gemsdir]}", prefixdir
- # Install the Rubinius executable
- exe = "#{BUILD_CONFIG[:bindir]}/#{BUILD_CONFIG[:program_name]}"
- install "vm/vm", install_dir(exe), :mode => 0755, :verbose => true
-
- # Install the testrb command
- testrb = "#{BUILD_CONFIG[:bindir]}/testrb"
- install "bin/testrb", install_dir(testrb), :mode => 0755, :verbose => true
-
- # Create symlinks for common commands
- begin
- ["ruby", "rake", "gem", "irb", "rdoc", "ri"].each do |command|
- name = install_dir("#{BUILD_CONFIG[:bindir]}/#{command}")
- File.delete name if File.exists? name
- File.symlink BUILD_CONFIG[:program_name], name
- end
- rescue NotImplementedError
- # ignore
+ # Install the testrb command
+ testrb = "#{prefixdir}#{BUILD_CONFIG[:bindir]}/testrb"
+ install "bin/testrb", testrb, :mode => 0755, :verbose => $verbose
end
end
end
@@ -169,7 +237,7 @@ namespace :install do
Successfully installed Rubinius #{BUILD_CONFIG[:version]}
-Add '#{BUILD_CONFIG[:bindir]}' to your PATH. Available commands are:
+Add '#{BUILD_CONFIG[:prefixdir]}#{BUILD_CONFIG[:bindir]}' to your PATH. Available commands are:
#{BUILD_CONFIG[:program_name]}, ruby, rake, gem, irb, rdoc, ri
View
7 rakelib/kernel.rake
@@ -219,10 +219,9 @@ end
namespace :compiler do
signature_path = File.expand_path("../../kernel/signature", __FILE__)
- path = File.expand_path("../../lib", __FILE__)
- Rubinius::COMPILER_PATH = path
- Rubinius::PARSER_PATH = "#{path}/melbourne"
- Rubinius::PARSER_EXT_PATH = "#{path}/ext/melbourne/build/melbourne20"
+ Rubinius::COMPILER_PATH = libprefixdir
+ Rubinius::PARSER_PATH = "#{libprefixdir}/melbourne"
+ Rubinius::PARSER_EXT_PATH = "#{libprefixdir}/ext/melbourne/build/melbourne20"
melbourne = "lib/ext/melbourne/build/melbourne.#{$dlext}"
View
16 rakelib/vm.rake
@@ -137,8 +137,15 @@ namespace :build do
task :build => %W[
build:llvm
#{VM_EXE}
+ stage:bin
+ stage:capi_include
+ stage:lib
+ stage:tooling
+ stage:kernel
kernel:build
build:ffi:preprocessor
+ stage:runtime
+ stage:documentation
build:zlib
extensions
]
@@ -368,6 +375,13 @@ namespace :vm do
'vm/test/runner.cpp',
'vm/test/runner.o',
VM_EXE,
+ 'bin/rbx',
+ 'bin/ruby',
+ 'bin/rake',
+ 'bin/ri',
+ 'bin/rdoc',
+ 'bin/irb',
+ 'bin/gem',
'vm/.deps',
'lib/zlib/*',
'lib/zlib'
@@ -377,6 +391,8 @@ namespace :vm do
rm_rf filename, :verbose => $verbose
end
+ rm_rf BUILD_CONFIG[:stagingdir] if BUILD_CONFIG[:stagingdir]
+
blueprint.clean
end
View
56 vm/agent.cpp
@@ -35,14 +35,6 @@
#include <sstream>
#include <fstream>
-#ifdef __APPLE__
-#include <mach-o/dyld.h>
-#endif
-
-#ifdef __FreeBSD__
-#include <sys/sysctl.h>
-#endif
-
namespace rubinius {
static char tmp_path[PATH_MAX];
@@ -599,53 +591,7 @@ namespace rubinius {
}
stream << "\n";
- char buf[PATH_MAX];
-#ifdef __APPLE__
- uint32_t size = PATH_MAX;
- if(_NSGetExecutablePath(buf, &size) == 0) {
- stream << buf << "\n";
- } else if(realpath(argv[0], buf)) {
- stream << buf << "\n";
- } else {
- stream << argv[0] << "\n";
- }
-#elif defined(__FreeBSD__)
- int oid[4];
- size_t len;
-
- oid[0] = CTL_KERN;
- oid[1] = KERN_PROC;
- oid[2] = KERN_PROC_PATHNAME;
- oid[3] = getpid();
- len = PATH_MAX;
- if(sysctl(oid, 4, buf, &len, 0, 0) == 0) {
- stream << buf << "\n";
- } else if(realpath(argv[0], buf)) {
- stream << buf << "\n";
- } else {
- stream << argv[0] << "\n";
- }
-#elif defined(__linux__)
- {
- std::ifstream exe("/proc/self/exe");
- if(exe) {
- char buf[PATH_MAX];
- exe.get(buf, PATH_MAX);
-
- stream << buf << "\n";
- } else if(realpath(argv[0], buf)) {
- stream << buf << "\n";
- } else {
- stream << argv[0] << "\n";
- }
- }
-#else
- if(realpath(argv[0], buf)) {
- stream << buf << "\n";
- } else {
- stream << argv[0] << "\n";
- }
-#endif
+ stream << shared_.env()->executable_name() << "\n";
stream.close();
View
50 vm/drivers/cli.cpp
@@ -18,8 +18,6 @@
using namespace std;
using namespace rubinius;
-static void check_directory(std::string root);
-
/**
* Main rbx entry point.
*
@@ -53,12 +51,7 @@ int main(int argc, char** argv) {
env.load_conf(path);
}
- const char* runtime = getenv("RBX_RUNTIME");
-
- if(!runtime) runtime = RBX_RUNTIME;
-
- check_directory(runtime);
- env.run_from_filesystem(runtime);
+ env.run_from_filesystem();
} catch(Assertion *e) {
std::cout << "VM Assertion:" << std::endl;
std::cout << " " << e->reason << std::endl << std::endl;
@@ -102,6 +95,24 @@ int main(int argc, char** argv) {
std::cout << "Ruby backtrace:" << std::endl;
env.state->vm()->print_backtrace();
exit_code = 1;
+ } catch(MissingRuntime& e) {
+ std::cerr << std::endl;
+ std::cerr << e.what() << std::endl;
+ std::cerr << "Rubinius was configured to find the directories relative to:" << std::endl;
+ std::cerr << std::endl << " " << RBX_PREFIX_PATH << std::endl << std::endl;
+ std::cerr << "Set the environment variable RBX_PREFIX_PATH to the directory";
+ std::cerr << std::endl;
+ std::cerr << "that is the prefix of the following runtime directories:" << std::endl;
+ std::cerr << std::endl;
+ std::cerr << " BIN_PATH: " << RBX_BIN_PATH << std::endl;
+ std::cerr << " RUNTIME_PATH: " << RBX_RUNTIME_PATH << std::endl;
+ std::cerr << " KERNEL_PATH: " << RBX_KERNEL_PATH << std::endl;
+ std::cerr << " LIB_PATH: " << RBX_LIB_PATH << std::endl;
+ std::cerr << " SITE_PATH: " << RBX_SITE_PATH << std::endl;
+ std::cerr << " VENDOR_PATH: " << RBX_VENDOR_PATH << std::endl;
+ std::cerr << " GEMS_PATH: " << RBX_GEMS_PATH << std::endl;
+ std::cerr << std::endl;
+ exit_code = 1;
} catch(BadKernelFile& e) {
std::cout << "ERROR: Unable to load: " << e.what() << std::endl << std::endl;
std::cout << "Please run the following commands to rebuild:" << std::endl;
@@ -131,26 +142,3 @@ int main(int argc, char** argv) {
return exit_code;
}
-
-static void check_directory(std::string runtime) {
- struct stat st;
-
- if(stat(runtime.c_str(), &st) == -1 || !S_ISDIR(st.st_mode)) {
-
- std::cerr << "ERROR: unable to find runtime directory" << std::endl;
- std::cerr << std::endl;
- std::cerr << "Rubinius was configured to find the runtime directory at:" << std::endl;
- std::cerr << std::endl << " " << runtime << std::endl;
- std::cerr << std::endl;
- std::cerr << "but that directory does not exist." << std::endl;
- std::cerr << std::endl;
- std::cerr << "Set the environment variable RBX_RUNTIME to the location" << std::endl;
- std::cerr << "of the directory with the compiled Rubinius kernel files." << std::endl;
- std::cerr << std::endl;
- std::cerr << "You may have configured Rubinius for a different install" << std::endl;
- std::cerr << "directory but you have not run \'rake install\' yet." << std::endl;
- std::cerr << std::endl;
-
- exit(1);
- }
-}
View
129 vm/environment.cpp
@@ -52,10 +52,20 @@
#endif
#include <fcntl.h>
#include <unistd.h>
+#include <stdlib.h>
#include <sys/param.h>
+#include <sys/stat.h>
#include "missing/setproctitle.h"
+#ifdef __APPLE__
+#include <mach-o/dyld.h>
+#endif
+
+#ifdef __FreeBSD__
+#include <sys/sysctl.h>
+#endif
+
namespace rubinius {
// Used by the segfault reporter. Calculated up front to avoid
@@ -716,19 +726,111 @@ namespace rubinius {
}
}
+ std::string Environment::executable_name() {
+ char name[PATH_MAX];
+
+#ifdef __APPLE__
+ uint32_t size = PATH_MAX;
+ if(_NSGetExecutablePath(name, &size) == 0) {
+ return name;
+ } else if(realpath(argv_[0], name)) {
+ return name;
+ }
+#elif defined(__FreeBSD__)
+ size_t size = PATH_MAX;
+ int oid[4];
+
+ oid[0] = CTL_KERN;
+ oid[1] = KERN_PROC;
+ oid[2] = KERN_PROC_PATHNAME;
+ oid[3] = getpid();
+
+ if(sysctl(oid, 4, name, &size, 0, 0) == 0) {
+ return name;
+ } else if(realpath(argv_[0], name)) {
+ return name;
+ }
+#elif defined(__linux__)
+ {
+ std::ifstream exe("/proc/self/exe");
+ if(exe) {
+ return exe.get(name, PATH_MAX);
+ } else if(realpath(argv[0], name)) {
+ return name;
+ }
+ }
+#else
+ if(realpath(argv_[0], name)) {
+ return name;
+ }
+#endif
+
+ return argv_[0];
+ }
+
+ static bool verify_and_set_paths(STATE, std::string prefix) {
+ struct stat st;
+
+ std::string dir = prefix + RBX_RUNTIME_PATH;
+ if(stat(dir.c_str(), &st) == -1 || !S_ISDIR(st.st_mode)) return false;
+
+ dir = prefix + RBX_BIN_PATH;
+ if(stat(dir.c_str(), &st) == -1 || !S_ISDIR(st.st_mode)) return false;
+
+ dir = prefix + RBX_KERNEL_PATH;
+ if(stat(dir.c_str(), &st) == -1 || !S_ISDIR(st.st_mode)) return false;
+
+ dir = prefix + RBX_LIB_PATH;
+ if(stat(dir.c_str(), &st) == -1 || !S_ISDIR(st.st_mode)) return false;
+
+ return true;
+ }
+
+ std::string Environment::system_prefix() {
+ if(!system_prefix_.empty()) return system_prefix_;
+
+ // 1. Check if our configure prefix is overridden by the environment.
+ const char* path = getenv("RBX_PREFIX_PATH");
+ if(path && verify_and_set_paths(state, path)) {
+ system_prefix_ = path;
+ return path;
+ }
+
+ // 2. Check if our configure prefix is valid.
+ path = RBX_PREFIX_PATH;
+ if(verify_and_set_paths(state, path)) {
+ system_prefix_ = path;
+ return path;
+ }
+
+ // 3. Check if we can derive paths from the executable name.
+ // TODO: For Windows, substitute '/' for '\\'
+ std::string name = executable_name();
+ size_t exe = name.rfind('/');
+
+ if(exe != std::string::npos) {
+ std::string prefix = name.substr(0, exe - strlen(RBX_BIN_PATH));
+ if(verify_and_set_paths(state, prefix)) {
+ system_prefix_ = prefix;
+ return prefix;
+ }
+ }
+
+ throw MissingRuntime("FATAL ERROR: unable to find Rubinius runtime directories.");
+ }
+
/**
- * Runs rbx from the filesystem, loading the Ruby kernel files relative to
- * the supplied root directory.
- *
- * @param root The path to the Rubinius /runtime directory, which contains
- * the loader.rbc and kernel files.
+ * Runs rbx from the filesystem. Searches for the Rubinius runtime files
+ * according to the algorithm in find_runtime().
*/
- void Environment::run_from_filesystem(std::string root) {
+ void Environment::run_from_filesystem() {
int i = 0;
state->vm()->set_root_stack(reinterpret_cast<uintptr_t>(&i),
VM::cStackDepthMax);
- load_platform_conf(root);
+ std::string runtime = system_prefix() + RBX_RUNTIME_PATH;
+
+ load_platform_conf(runtime);
load_vm_options(argc_, argv_);
boot_vm();
load_argv(argc_, argv_);
@@ -738,18 +840,19 @@ namespace rubinius {
load_tool();
if(LANGUAGE_20_ENABLED(state)) {
- root += "/20";
+ runtime += "/20";
} else if(LANGUAGE_19_ENABLED(state)) {
- root += "/19";
+ runtime += "/19";
} else {
- root += "/18";
+ runtime += "/18";
}
- G(rubinius)->set_const(state, "RUNTIME_PATH", String::create(state, root.c_str(), root.size()));
+ G(rubinius)->set_const(state, "RUNTIME_PATH", String::create(state,
+ runtime.c_str(), runtime.size()));
- load_kernel(root);
+ load_kernel(runtime);
start_signals();
- run_file(root + "/loader.rbc");
+ run_file(runtime + "/loader.rbc");
state->vm()->thread_state()->clear();
View
16 vm/environment.hpp
@@ -15,6 +15,16 @@ namespace rubinius {
class SignalHandler;
/**
+ * Thrown when unable to find Rubinius runtime directories.
+ */
+ class MissingRuntime : public std::runtime_error {
+ public:
+ MissingRuntime(const std::string& str)
+ : std::runtime_error(str)
+ {}
+ };
+
+ /**
* Thrown when there is a bad signature on a kernel .rbc file.
*/
class BadKernelFile : public std::runtime_error {
@@ -47,6 +57,8 @@ namespace rubinius {
SignalHandler* sig_handler_;
+ std::string system_prefix_;
+
public:
SharedState* shared;
VM* root_vm;
@@ -74,6 +86,8 @@ namespace rubinius {
void setup_cpp_terminate();
+ std::string executable_name();
+ std::string system_prefix();
void load_vm_options(int argc, char** argv);
void load_argv(int argc, char** argv);
void load_kernel(std::string root);
@@ -83,7 +97,7 @@ namespace rubinius {
void load_string(std::string str);
void run_file(std::string path);
void load_tool();
- void run_from_filesystem(std::string root);
+ void run_from_filesystem();
void boot_vm();
void halt(STATE);
View
37 vm/ontology.cpp
@@ -47,6 +47,7 @@
#include "builtin/class.hpp"
#include "builtin/atomic.hpp"
+#include "environment.hpp"
#include "configuration.hpp"
#include "config.h"
#include "revision.h"
@@ -417,15 +418,33 @@ namespace rubinius {
* because some are passed to e.g. File.expand_path and having them
* be uniform is simpler.
*/
- G(rubinius)->set_const(state, "BIN_PATH", String::create(state, RBX_BIN_PATH));
- G(rubinius)->set_const(state, "KERNEL_PATH", String::create(state, RBX_KERNEL_PATH));
- G(rubinius)->set_const(state, "LIB_PATH", String::create(state, RBX_LIB_PATH));
- G(rubinius)->set_const(state, "HDR18_PATH", String::create(state, RBX_HDR18_PATH));
- G(rubinius)->set_const(state, "HDR19_PATH", String::create(state, RBX_HDR19_PATH));
- G(rubinius)->set_const(state, "HDR20_PATH", String::create(state, RBX_HDR20_PATH));
- G(rubinius)->set_const(state, "GEMS_PATH", String::create(state, RBX_GEMS_PATH));
- G(rubinius)->set_const(state, "SITE_PATH", String::create(state, RBX_SITE_PATH));
- G(rubinius)->set_const(state, "VENDOR_PATH", String::create(state, RBX_VENDOR_PATH));
+ Environment* env = state->shared().env();
+
+ if(env) {
+ std::string prefix = env->system_prefix();
+ G(rubinius)->set_const(state, "PREFIX_PATH", String::create(state, prefix.c_str()));
+ std::string path = prefix + RBX_RUNTIME_PATH;
+ G(rubinius)->set_const(state, "RUNTIME_PATH", String::create(state, path.c_str()));
+ path = prefix + RBX_BIN_PATH;
+ G(rubinius)->set_const(state, "BIN_PATH", String::create(state, path.c_str()));
+ path = prefix + RBX_KERNEL_PATH;
+ G(rubinius)->set_const(state, "KERNEL_PATH", String::create(state, path.c_str()));
+ path = prefix + RBX_LIB_PATH;
+ G(rubinius)->set_const(state, "LIB_PATH", String::create(state, path.c_str()));
+ path = prefix + RBX_SITE_PATH;
+ G(rubinius)->set_const(state, "SITE_PATH", String::create(state, path.c_str()));
+ path = prefix + RBX_VENDOR_PATH;
+ G(rubinius)->set_const(state, "VENDOR_PATH", String::create(state, path.c_str()));
+ path = prefix + RBX_GEMS_PATH;
+ G(rubinius)->set_const(state, "GEMS_PATH", String::create(state, path.c_str()));
+
+ path = prefix + RBX_HDR18_PATH;
+ G(rubinius)->set_const(state, "HDR18_PATH", String::create(state, path.c_str()));
+ path = prefix + RBX_HDR19_PATH;
+ G(rubinius)->set_const(state, "HDR19_PATH", String::create(state, path.c_str()));
+ path = prefix + RBX_HDR20_PATH;
+ G(rubinius)->set_const(state, "HDR20_PATH", String::create(state, path.c_str()));
+ }
G(rubinius)->set_const(state, "ZLIB_PATH", String::create(state, RBX_ZLIB_PATH));
G(rubinius)->set_const(state, "VERSION", String::create(state, RBX_VERSION));
Please sign in to comment.
Something went wrong with that request. Please try again.