Skip to content

Commit

Permalink
Added new rake install tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ford committed Nov 25, 2009
1 parent 8bd6101 commit a632b48
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 100 deletions.
101 changes: 15 additions & 86 deletions Rakefile
Expand Up @@ -9,16 +9,18 @@ if !$verbose and respond_to?(:verbose)
verbose(false) if verbose() == :default
end

unless File.exists?(File.expand_path("../config.rb", __FILE__)) and
File.exists?(File.expand_path("../vm/gen/config.h", __FILE__))
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

$dlext = Config::CONFIG["DLEXT"]
$compiler = nil
require config_rb
BUILD_CONFIG = Rubinius::BUILD_CONFIG

RUBINIUS_BASE = File.expand_path(File.dirname(__FILE__))
$dlext = Config::CONFIG["DLEXT"]

$: << "lib"

Expand Down Expand Up @@ -47,87 +49,6 @@ task :distclean => %w[
vm:distclean
]

desc 'Move the preinstalled gem setup into place'
task :gem_bootstrap do
unless File.directory?("gems/rubinius")
sh "mkdir gems"
sh "cp -r preinstalled-gems/* gems/"
end
end

def install_bin
File.join RBX_BINPATH, 'rbx'
end

desc "Uninstall Rubinius"
task :uninstall do
rm_rf install_bin
rm_rf RBX_BASE_PATH
sh "rake -q clean"
end

desc "Install Rubinius"
task :install => %w[
clean
install:build
install:files
] do
sh "rake -q clean"
puts "Install complete."
puts "The install versions of files have been cleaned."
puts "Run 'rake build' to rebuild development versions."
end

namespace :install do
# Internal task, not documented with desc. Shells out
# to perform the build. See reason in doc/build_system.txt.
task :build do
ENV['RBX_PREFIX'] = ENV['PREFIX'] || "/usr/local"
ENV['RBX_RUNTIME'] = File.join(Dir.pwd, 'runtime')
sh "rake -q build"
end

# Internal task, not documented with desc. Performs the
# actual file installation enabling the :install task
# to clean up after itself.
task :files do
mkdir_p RBX_BASE_PATH, :verbose => true
mkdir_p RBX_RBA_PATH, :verbose => true
mkdir_p RBX_EXT_PATH, :verbose => true
mkdir_p RBX_BIN_PATH, :verbose => true
mkdir_p RBX_LIB_PATH, :verbose => true


capi_header_files = Rake::FileList.new "vm/capi/*.h"
install_files capi_header_files, RBX_EXT_PATH

File.open File.join(RBX_EXT_PATH, "missing.h"), "w" do |f|
f.puts "// This file left empty"
end

core_files = Rake::FileList.new('runtime/index',
'runtime/platform.conf',
'runtime/**/*.rb{a,c}',
'runtime/**/load_order.txt')
install_files core_files, RBX_RBA_PATH

lib_files = Rake::FileList.new 'lib/**/*'
install_files lib_files, RBX_LIB_PATH

Rake::FileList.new("#{RBX_LIB_PATH}/**/*.rb").sort.each do |rb|
begin
compile_ruby rb, "#{rb}c"
rescue Object => e
puts "Error compiling #{rb}!"
puts e.backtrace
puts "Install continuing but please file a ticket"
end
end

install 'vm/vm', install_bin, :mode => 0755, :verbose => true
end
end

namespace :clean do
desc "Cleans up editor files and other misc crap"
task :crap do
Expand All @@ -137,6 +58,14 @@ namespace :clean do
end
end

desc 'Move the preinstalled gem setup into place'
task :gem_bootstrap do
unless File.directory?("gems/rubinius")
sh "mkdir gems"
sh "cp -r preinstalled-gems gems/rubinius"
end
end

desc "Documents why no spec tasks exist"
task :spec do
puts <<-EOM
Expand Down
28 changes: 19 additions & 9 deletions configure
Expand Up @@ -23,6 +23,9 @@ class Configure
@bindir = root + "/bin"
@includedir = root + "/vm/capi"
@libdir = root
@runtime = @libdir + "/runtime"
@lib_path = @libdir + "/lib"
@ext_path = @libdir + "/lib/ext"
@mandir = root + "/man"
@gemsdir = root + "/gems"
@program_name = "rbx"
Expand Down Expand Up @@ -75,6 +78,9 @@ class Configure
@bindir = dir + "/bin"
@includedir = dir + "/include"
@libdir = dir
@runtime = @libdir + "/runtime"
@lib_path = @libdir + "/lib"
@ext_path = @libdir + "/lib/ext"
@mandir = dir + "/man"
@gemsdir = dir + "/gems"
end
Expand All @@ -88,7 +94,10 @@ class Configure
end

o.on "-L", "--libdir", "PATH", "Install Ruby library in PATH" do |dir|
@libdir = dir
@libdir = dir + "/rubinius"
@runtime = @libdir + "/runtime"
@lib_path = @libdir + "/lib"
@ext_path = @libdir + "/lib/ext"
end

o.on "-M", "--mandir", "PATH", "Install man pages in PATH" do |dir|
Expand All @@ -99,10 +108,6 @@ class Configure
@gemsdir = dir
end

o.on "--version", "VER", "Set Rubinius version to VER (default #{@version})" do |v|
@version = v
end

o.doc "\n Help!"

o.on "-V", "--verbose", "Print debugging info" do
Expand Down Expand Up @@ -329,10 +334,15 @@ module Rubinius
:os => "#{@os}",
:bindir => "#{@bindir}",
:libdir => "#{@libdir}",
:runtime => "#{@runtime}",
:lib_path => "#{@lib_path}",
:ext_path => "#{@ext_path}",
:includedir => "#{@includedir}",
:mandir => "#{@mandir}",
:gemsdir => "#{@gemsdir}",
:program_name => "#{@program_name}"
:program_name => "#{@program_name}",
:version => "#{@version}",
:libversion => "#{@libversion}"
}
end
EOC
Expand All @@ -348,9 +358,9 @@ end
#define RBX_OS "#{@os}"
#define RBX_BIN_PATH "#{@bindir}"
#define RBX_GEMS_PATH "#{@gemsdir}"
#define RBX_RUNTIME "#{@libdir}/runtime"
#define RBX_LIB_PATH "#{@libdir}/lib"
#define RBX_EXT_PATH "#{@libdir}/lib/ext"
#define RBX_RUNTIME "#{@runtime}"
#define RBX_LIB_PATH "#{@lib_path}"
#define RBX_EXT_PATH "#{@ext_path}"
#define RBX_HDR_PATH "#{@includedir}"
#define RBX_VERSION "#{@version}"
#define RBX_LIB_VERSION "#{@libversion}"
Expand Down
3 changes: 2 additions & 1 deletion kernel/loader.rb
Expand Up @@ -366,7 +366,8 @@ def irb
# Investigate when we have specs running.
require prog
rescue LoadError => e
STDERR.puts "Unable to find repr named '#{repr}' to load."
STDERR.puts "Unable to load REPL named '#{repr}'"
STDERR.puts e.message
puts e.awesome_backtrace.show
exit 1
end
Expand Down
117 changes: 117 additions & 0 deletions rakelib/install.rake
@@ -0,0 +1,117 @@
# Tasks for installing Rubinius. There are two guidelines here:
#
# 1. Only use sudo if necessary
# 2. Build all Ruby files using the bootstrap Ruby implementation
# and install the files with the 'install' command
#

install_dirs = [
BUILD_CONFIG[:bindir],
BUILD_CONFIG[:libdir],
BUILD_CONFIG[:includedir],
BUILD_CONFIG[:mandir],
BUILD_CONFIG[:gemsdir]
]

# 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
# directory name, if any of the paths leading up to the full A are
# writable, then A can be created. So A is decomposed one directory
# 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 = File.expand_path name

until dir == "/"
if File.directory? dir
return true unless File.writable? dir
break
end

dir = File.dirname dir
end
end

return false
end

def precompile(dir)
ruby "-Ilib lib/bin/compile.rb -V -T default #{dir}"
end

def install_file(source, pattern, dest)
return if File.directory? source

dest_name = File.join(dest, source.sub(pattern, ""))
dir = File.dirname(dest_name)
mkdir_p dir unless File.directory? dir

install source, dest_name, :mode => 0644, :verbose => true
end

desc "Install Rubinius"
task :install => %w[ build install:build install:files ]

namespace :install do
desc "Compile all lib Ruby files"
task :build do
puts "Compiling library files for install..."
precompile "lib"

puts "Compiling pre-installed gem files for install..."
precompile "preinstalled-gems/rubinius/0.13/gems"
end

desc "Install all the Rubinius files"
task :files do
if need_sudo? install_dirs
sh "sudo #{FileUtils::RUBY} -S rake install:files", :verbose => true
elsif File.expand_path(Dir.pwd) == BUILD_CONFIG[:libdir]
puts "Install directory is the same as build directory, nothing to install"
else
install_dirs.each { |name| mkdir_p name, :verbose => $verbose }

FileList["vm/capi/*.h"].each do |name|
install_file name, %r[^vm/capi], BUILD_CONFIG[:includedir]
end

FileList[
'runtime/index',
'runtime/platform.conf',
'runtime/**/*.rb{a,c}',
'runtime/**/load_order.txt'
].each do |name|
install_file name, /^runtime/, BUILD_CONFIG[:runtime]
end

FileList['lib/**/*.rbc'].each do |name|
install_file name, /^lib/, BUILD_CONFIG[:lib_path]
end

FileList["lib/ext/**/*.#{$dlext}"].each do |name|
install_file name, %r[^lib/ext], BUILD_CONFIG[:ext_path]
end

# TODO: the preinstalled gems are a total mess right now, they
# should not be in a source dir that includes any rbx version.
# Furthermore, we are going from the source dir here because the
# check on 'gems/rubinius' to copy them over will fail on any
# repo that used gems before since `gem` created the 'gems/rubinius'
# directory.
gems_dest = "#{BUILD_CONFIG[:gemsdir]}/rubinius/#{BUILD_CONFIG[:libversion]}"
FileList["preinstalled-gems/rubinius/0.13/**/*"].each do |name|
install_file name, %r[^preinstalled-gems/rubinius/0.13], gems_dest
end

FileList["preinstalled-gems/bin/*"].each do |name|
install_file name, /^preinstalled-gems/, BUILD_CONFIG[:gemsdir]
end

exe = "#{BUILD_CONFIG[:bindir]}/#{BUILD_CONFIG[:program_name]}"
install "vm/vm", exe, :mode => 0755, :verbose => true
end
end
end

2 changes: 0 additions & 2 deletions rakelib/release.rake
@@ -1,5 +1,3 @@
require 'config'

namespace :release do
desc "Create the tarball for the release"
task :tar do
Expand Down
2 changes: 0 additions & 2 deletions rakelib/vm.rake
Expand Up @@ -7,8 +7,6 @@ require 'ostruct'

require 'lib/ffi/generator_task.rb'

require 'config'

config = OpenStruct.new
config.use_jit = true
config.compile_with_llvm = false
Expand Down
1 change: 1 addition & 0 deletions vm/capi/missing.h
@@ -0,0 +1 @@
// This file is intentionally blank because it's all missing.

0 comments on commit a632b48

Please sign in to comment.