forked from rubinius/rubinius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.rake
180 lines (146 loc) · 5.58 KB
/
install.rake
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
# 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
#
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]
]
# 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 = install_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 need_install?
File.expand_path(Dir.pwd) != install_dir(BUILD_CONFIG[:libdir])
end
def install_file(source, pattern, dest)
return if File.directory? source
dest_name = install_dir 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:files ]
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
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 the .rb files for the core library (kernel).
FileList['kernel/**/*.rb'].each do |name|
install_file name, /^kernel/, BUILD_CONFIG[:kernel_path]
end
# 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
FileList['lib/**/*.rbc'].each do |name|
install_file name, /^lib/, BUILD_CONFIG[:lib_path]
end
# 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
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 the documentation site
FileList['lib/rubinius/documentation/**/*'].each do |name|
install_file name, /^lib/, BUILD_CONFIG[:lib_path]
end
# Install the C extensions for the standard library.
FileList["lib/ext/**/*.#{$dlext}"].each do |name|
install_file name, %r[^lib/ext], BUILD_CONFIG[:ext_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
FileList["preinstalled-gems/bin/*"].each do |name|
install_file name, /^preinstalled-gems/, BUILD_CONFIG[:gemsdir]
end
# 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
end
STDOUT.puts <<-EOM
--------
Successfully installed Rubinius #{BUILD_CONFIG[:version]}
Add '#{BUILD_CONFIG[:bindir]}' to your PATH. Available commands are:
#{BUILD_CONFIG[:program_name]}, ruby, rake, gem, irb, rdoc, ri
1. Run Ruby files with '#{BUILD_CONFIG[:program_name]} path/to/file.rb'
2. Start IRB by running '#{BUILD_CONFIG[:program_name]}' with no arguments
EOM
end
end
end