/
Rakefile
376 lines (295 loc) · 9.15 KB
/
Rakefile
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
# NOTE! When updating this file, also update INSTALL, if necessary.
require 'tsort'
task :default => :build
class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end
def newer?(file, cmp)
File.exists?(cmp) and File.mtime(cmp) >= File.mtime(file)
end
@setup_stable = false
def setup_stable
return if @setup_stable
@setup_stable = true
@pb = "runtime/stable/bootstrap.rba"
@pp = "runtime/stable/platform.rba"
@pc = "runtime/stable/core.rba"
@pl = "runtime/stable/loader.rbc"
@pr = "runtime/stable/compiler.rba"
if ENV['USE_CURRENT']
puts "Use current versions, not stable."
else
ENV['BOOTSTRAP'] = @pb
ENV['CORE'] = @pc
ENV['LOADER'] = @pl
ENV['PLATFORM'] = @pp
ENV['COMPILER'] = @pr
end
@compiler = ENV['COMPILER']
end
def source_name(compiled)
File.basename(compiled, '.*') + '.rb'
end
def compiled_name(source, dir)
File.join(dir, File.basename(source, '.*') + '.rbc')
end
# Some files have load order dependencies. To specify a load order
# dependency, include a comment in the file that has the dependency.
# For example, assume files a.rb and b.rb, where a.rb requires that
# b.rb is loaded first. In a.rb, include a comment
# # depends on: b.rb
#
# The 'depends on:' declaration takes a space separated list of file.
# When the '.load_order.txt' file is created, a topological sort
# (see name caveat in TSort) of the dependencies is performed
# so files that are depended on are loaded first.
#
# If there is a 'depends on:' declarations for a non-existent file,
# or if there are cyclic dependencies, this method will not create
# the '.load_order.txt' file.
def create_load_order(files, output=".load_order.txt")
d = Hash.new { |h,k| h[k] = [] }
# assume all the files are in the same directory
dir = File.dirname(files.first)
found = false
files.each do |fname|
name = source_name(fname)
# Force every entry to be in the hash
d[name]
File.open(File.join(dir, name), "r") do |f|
f.each do |line|
if m = /#\s*depends on:\s*(.*)/.match(line)
found = true
m[1].split.each { |dep| d[name] << dep }
end
end
end
end
File.open(output, "w") do |f|
begin
if found
list = d.tsort
else
list = files.sort
end
f.puts list.collect { |n| compiled_name(n, dir) }.join("\n")
rescue IndexError => e
puts "Unable to generate '.load_order.txt'"
puts "Most likely, a file includes a 'depends on:' declaration for a non-existent file"
raise e
rescue TSort::Cyclic => e
puts "Unable to generate '.load_order.txt' due to a cyclic dependency\n (#{e.message})"
raise e
end
end
end
def compile(name, output)
setup_stable
dir = File.dirname(output)
unless File.exists?(dir)
FileUtils.mkdir_p dir
end
if @compiler
sh "shotgun/rubinius -I#{@compiler} compile #{name} #{output}", :verbose => false
else
sh "shotgun/rubinius compile #{name} #{output}", :verbose => false
end
end
rule ".rbc" => ".rb" do |t|
compile(t.source, t.name)
end
#file 'runtime/core/kernel/core/proc.rbc' => 'kernel/core/proc.rb' do |t|
# p t.prerequisites
# p t.name
#end
class CodeGroup
def initialize(files, dir, load_order=true)
@files = FileList[files]
@output = nil
@directory = dir
map(dir, load_order)
end
attr_reader :output
def map(dir, load_order)
unless File.exists?(dir)
Dir.mkdir dir
end
prc = proc do |t|
compile(t.prerequisites.first, t.name)
end
@output = []
@files.each do |source|
runtime = File.join(dir, source.ext("rbc"))
@output << runtime
file(runtime => source, &prc)
end
if load_order
lo = File.join(dir, '.load_order.txt')
file lo => @files do
create_load_order(@files, lo)
end
@output << lo
end
return @output
end
def clean
sh "find #{@directory} -name '*.rbc' -delete"
end
end
Core = CodeGroup.new 'kernel/core/*.rb', 'runtime/core'
Bootstrap = CodeGroup.new 'kernel/bootstrap/*.rb', 'runtime/bootstrap'
Platform = CodeGroup.new 'kernel/platform/*.rb', 'runtime/platform'
Compiler = CodeGroup.new 'compiler/**/*.rb', 'runtime', false
file 'runtime/loader.rbc' => 'kernel/loader.rb' do
compile 'kernel/loader.rb', 'runtime/loader.rbc'
end
AllPreCompiled = Core.output + Bootstrap.output + Platform.output + Compiler.output
AllPreCompiled << "runtime/loader.rbc"
# spec tasks
desc "Run all 'known good' specs (task alias for spec:ci)"
task :spec => 'spec:ci'
namespace :spec do
namespace :setup do
# Setup for 'Subtend' specs. No need to call this yourself.
task :subtend do
Dir["spec/subtend/**/Rakefile"].each do |rakefile|
sh "rake -f #{rakefile}"
end
end
end
desc "Run continuous integration examples"
task :ci do
target = ENV['SPEC_TARGET'] || 'rbx'
system %(shotgun/rubinius -e 'puts "rbx build: \#{Rubinius::BUILDREV}"') if target == 'rbx'
sh "bin/ci -t #{target}"
end
spec_targets = %w(compiler core language library parser rubinius)
# Build a spec:<task_name> for each group of Rubinius specs
spec_targets.each do |group|
desc "Run #{group} examples"
task group do
sh "bin/mspec spec/#{group}"
end
end
desc "Run subtend (Rubinius C API) examples"
task :subtend => "spec:setup:subtend" do
sh "bin/mspec spec/rubinius/subtend"
end
# Specdiffs to make it easier to see what your changes have affected :)
desc 'Run specs and produce a diff against current base'
task :diff => 'diff:run'
namespace :diff do
desc 'Run specs and produce a diff against current base'
task :run do
system 'bin/mspec -f ci -o spec/reports/specdiff.txt spec'
system 'diff -u spec/reports/base.txt spec/reports/specdiff.txt'
system 'rm spec/reports/specdiff.txt'
end
desc 'Replace the base spec file with a new one'
task :replace do
system 'bin/mspec -f ci -o spec/reports/base.txt spec'
end
end
task :r2r do
puts ARGV.inspect
end
end
desc "Build everything that needs to be built"
task :build => ['build:all']
desc "Install rubinius as rbx"
task :install => :config_env do
sh "cd shotgun; make install"
mkdir_p ENV['RBAPATH'], :verbose => true
mkdir_p ENV['CODEPATH'], :verbose => true
Rake::FileList.new('runtime/**/*.rb{a,c}').sort.each do |rba_path|
rba_file = rba_path.sub %r|^runtime/|, ''
dest_file = File.join ENV['RBAPATH'], rba_file
dest_dir = File.dirname dest_file
mkdir_p dest_dir unless File.directory? dest_dir
install rba_path, dest_file, :mode => 0644, :verbose => true
end
Rake::FileList.new('lib/**').sort.each do |lib_path|
next if File.directory? lib_path
lib_file = lib_path.sub %r|^lib/|, ''
dest_file = File.join ENV['RBAPATH'], lib_file
dest_dir = File.dirname dest_file
mkdir_p dest_dir unless File.directory? dest_dir
install lib_path, dest_file, :mode => 0644, :verbose => true
end
mkdir_p File.join(ENV['CODEPATH'], 'bin'), :verbose => true
Rake::FileList.new("#{ENV['CODEPATH']}/**/*.rb").sort.each do |rb_file|
sh File.join(ENV['BINPATH'], 'rbx'), 'compile', rb_file, :verbose => true
end
end
task :config_env do
File.foreach 'shotgun/config.mk' do |line|
next unless line =~ /(.*?)=(.*)/
ENV[$1] = $2
end
end
desc "Recompile all ruby system files"
task :rebuild => ['clean:rbc', 'clean:shotgun', 'build:all']
desc "Remove all ruby system files"
task :distclean => 'clean:rbc'
desc "Remove all stray compiled Ruby files"
task :pristine do
FileList['**/*.rbc'].each do |fn|
next if /^runtime/.match(fn)
FileUtils.rm fn rescue nil
end
end
namespace :clean do
desc "Remove all compile system ruby files (runtime/)"
task :rbc do
AllPreCompiled.each do |f|
File.unlink f rescue nil
end
end
desc "Cleans up VM building site"
task :shotgun do
sh "make clean"
end
end
namespace :build do
task :all => ["build:shotgun", "build:rbc"]
# This nobody rule lets use use all the shotgun files as
# prereqs. This rule is run for all those prereqs and just
# (obviously) does nothing, but it makes rake happy.
rule '^shotgun/.+' do
end
c_source = FileList["shotgun/lib/*.[ch]", "shotgun/main.c",
"shotgun/lib/*.rb", "shotgun/lib/subtend/*.[chS]"]
file "shotgun/rubinius.bin" => c_source do
sh "make vm"
end
task :extensions => ["build:shotgun", "build:rbc"] do
sh "./shotgun/rubinius compile lib/ext/syck"
end
file "shotgun/config.h" do
sh "./configure"
raise 'Failed to configure Rubinius' unless $?.success?
end
task :configure => ["shotgun/config.h"]
desc "Compiles shotgun (the C-code VM)"
task :shotgun => [:configure, "shotgun/rubinius.bin"]
task :setup_rbc do
setup_stable
end
task :rbc => ([:setup_rbc] + AllPreCompiled)
task :core => :rbc do
raise "OBSOLETE. Use 'rake build'"
end
task :bootstrap => :rbc do
raise "OBSOLETE. Use 'rake build'"
end
task :platform => :rbc do
raise "OBSOLETE. Use 'rake build'"
end
task :loader => :rbc do
raise "OBSOLETE. Use 'rake build'"
end
end