/
rubinius.rb
154 lines (117 loc) · 3.08 KB
/
rubinius.rb
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
def clear_compiler
ENV.delete 'RBX_BOOTSTRAP'
ENV.delete 'RBX_CORE'
ENV.delete 'RBX_LOADER'
ENV.delete 'RBX_PLATFORM'
end
def expand(path)
File.expand_path path
end
def make(args = nil)
if RUBY_PLATFORM =~ /bsd/ || RUBY_PLATFORM =~ /solaris/
gmake = 'gmake'
else
gmake = 'make'
end
"#{ENV['MAKE'] || gmake} #{args}"
end
def rbx(*args)
clear_compiler
sh('bin/rbx', *args)
end
def newer?(file, cmp)
File.exists?(cmp) and File.mtime(cmp) >= File.mtime(file)
end
def source_name(compiled)
File.basename(compiled, '.*') + '.rb'
end
def compiled_name(source, dir)
File.join(dir, File.basename(source, '.*') + '.rbc')
end
def compile(name, output=nil, check_mtime=false)
if output
dir = File.dirname(output)
unless File.exists?(dir)
FileUtils.mkdir_p dir
end
if check_mtime and File.exists?(output) and File.mtime(output) > File.mtime(name)
return
end
end
inc = "-Iruntime/stable/compiler.rba -rcompiler/compiler"
flags = "-frbx-safe-math -frbx-kernel"
if ENV['SYSTEM']
sh "rbx compile -f #{flags} #{name} #{output}", :verbose => $verbose
elsif ENV['GDB']
sh "bin/rbx --gdb #{inc} compile #{flags} #{name} #{output}", :verbose => $verbose
elsif ENV['NATIVE']
sh "bin/rbx #{inc} compile #{flags} #{name} #{output}", :verbose => $verbose
else
ruby "lib/compiler/mri_compile.rb #{flags} #{name} #{output}"
end
end
def compile_dir(dir)
(Dir["#{dir}/*.rb"] + Dir["#{dir}/**/*.rb"]).each do |file|
compile file, "#{file}c", true
end
end
class CodeGroup
def initialize(files, compile_dir, rba_name, load_order=true)
if files.is_a?(FileList)
@files = files
else
@files = FileList[files]
end
@output = nil
@compile_dir = compile_dir
@build_dir = File.join 'runtime', rba_name
@rba_name = "#{rba_name}.rba"
if load_order
@load_order = File.join @compile_dir, 'load_order.txt'
else
@load_order = nil
end
@output = []
make_tasks
end
attr_reader :output
def clean
sh "find #{@compile_dir} -name '*.rbc' -delete"
end
def compile_task
@files.each do |source|
runtime = File.join(@compile_dir, source.ext("rbc"))
@output << runtime
deps = [source].compact
file runtime => deps do |t|
compile t.prerequisites.first, t.name
end
end
end
def load_order_task
return unless @load_order
file @load_order => @files do
create_load_order(@files, @load_order)
end
task "build:load_order" => @files do
create_load_order(@files, @load_order)
end
@output << @load_order
end
def make_tasks
FileUtils.mkdir_p @compile_dir unless File.exists? @compile_dir
compile_task
load_order_task
@output
end
end
def install_files(files, destination)
files.sort.each do |path|
next if File.directory? path
file = path.sub %r%^(runtime|lib)/%, ''
dest_file = File.join destination, file
dest_dir = File.dirname dest_file
mkdir_p dest_dir unless File.directory? dest_dir
install path, dest_file, :mode => 0644, :verbose => true
end
end