This repository has been archived by the owner on Apr 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Rakefile
194 lines (152 loc) · 5.48 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
require 'rake/clean'
# Path on the local filesystem to install reia/ire scripts to
BIN_INSTALL_DIR = ENV['REIA_BIN_DIR'] || "/usr/local/bin"
task :default => %w(check_erl_version build test)
# Returns the installed Erlang version
def erlang_version
version = `erl -version 2>&1`.strip.match(/\d\.\d(\.\d)?$/)
unless version
STDERR.puts "Error retrieving Erlang version. Do you have it installed?"
exit 1
end
version[0]
end
# Evaluate the given Erlang statement
def erl_eval(cmd, *pa)
pa_str = pa.empty? ? "" : "-pa #{pa.join(' ')}"
sh "erl -noshell #{pa_str} -eval '#{cmd}' -s erlang halt"
end
# Ensure the version of Erlang installed is recent enough
task :check_erl_version do
print "Checking Erlang version... "
version = erlang_version
if version >= "5.6.3"
puts "#{version} (ok)"
else
puts "#{version} (too old)"
puts "Sorry, the version of Erlang you have installed is too old to run Reia"
puts "Reia requires a minimum Erlang version of R12B-3 (5.6.3)"
puts "Please see http://wiki.reia-lang.org/wiki/Building#Prerequisites"
exit 1
end
end
# Neotoma (PEG for Erlang)
NEOTOMA_FILES = %w(neotoma neotoma_parse neotoma_peg)
task :neotoma => NEOTOMA_FILES.map { |f| "src/neotoma/ebin/#{f}.beam" }
NEOTOMA_FILES.each do |f|
input = "src/neotoma/src/#{f}.erl"
file "src/neotoma/ebin/#{f}.beam" => input do
sh "erlc -o src/neotoma/ebin #{input}"
end
end
# yecc/leex Scanner
file "src/leex/leex.beam" => "src/leex/leex.erl" do
sh "erlc -W0 -o src/leex src/leex/leex.erl"
end
file "src/compiler/reia_scan.erl" => %w(src/leex/leex.beam src/compiler/reia_scan.xrl) do
erl_eval 'leex:file("src/compiler/reia_scan.xrl")', 'src/leex'
end
# Parser
file "src/compiler/reia_parse.erl" => "src/compiler/reia_parse.peg" do
erl_eval 'neotoma:file("src/compiler/reia_parse.peg")', 'src/neotoma/ebin'
end
# yecc/leex Parser
file "src/compiler/reia_yecc_parse.erl" => %w(src/compiler/reia_parse.yrl) do
sh "cp src/compiler/reia_parse.yrl src/compiler/reia_yecc_parse.yrl"
erl_eval 'yecc:file("src/compiler/reia_yecc_parse.yrl", [verbose])'
end
# Generate an output path for the given input file
def output_file(input_file, dir = 'ebin/', ext = '.beam')
dir + File.basename(input_file).sub(/\.\w+$/, ext)
end
GENERATED_SRC = %w(src/compiler/reia_parse.erl src/compiler/reia_scan.erl src/compiler/reia_yecc_parse.erl)
PARSER_TEST_SRC = %w(test/parser/parser_test.erl test/parser/parser_ab.erl)
ERL_SRC = (GENERATED_SRC + PARSER_TEST_SRC + FileList.new('src/{compiler,core,builtins,json}/**/*.erl')).uniq
ERL_DEST = ERL_SRC.map { |input| output_file(input) }
QUIET_SRC = %w(src/compiler/reia_parse.erl)
ERL_SRC.each do |input|
file output_file(input) => input do
sh "erlc +debug_info -o ebin #{input}"
end
end
REIA_SRC = FileList.new('src/{builtins,core}/**/*.re')
REIA_SRC.include('lib/*.re')
REIA_DEST = REIA_SRC.map { |input| output_file(input, 'ebin/', '.reb') }
REIA_SRC.each do |input|
output = output_file(input, 'ebin/', '.reb')
file output => input do
sh "bin/reiac -o #{output} #{input}"
end
end
# Build rules
task :build => %w(scanner parser reia)
task :scanner => %w(src/leex/leex.beam src/compiler/reia_scan.erl)
#task :parser => %w(src/compiler/reia_parse.erl)
task :parser => %w(neotoma src/compiler/reia_parse.erl src/compiler/reia_yecc_parse.erl)
task :reia => ERL_DEST + REIA_DEST
# Test suite
task :test => :build do
erl_eval 'eunit:test(parser_test)', 'ebin'
sh "bin/reia test/runner.re"
erl_eval 'parser_ab:run()', 'ebin'
end
# Benchmarks
BENCHMARK_SRC = FileList.new('benchmarks/**/*.erl')
BENCHMARK_DEST = BENCHMARK_SRC.map { |input| output_file(input, 'benchmarks/ebin/') }
BENCHMARK_SRC.each do |input|
file output_file(input, 'benchmarks/ebin/') => input do
sh "erlc +debug_info -o benchmarks/ebin #{input}"
end
end
task :benchmark => BENCHMARK_DEST do
sh "bin/reia benchmarks/runner.re"
end
# Cleaning
CLEAN.include %w(ebin/* src/neotoma/ebin/* src/compiler/reia_parse.erl)
CLEAN.include %w(src/compiler/reia_scan.erl)
CLEAN.include %w(src/compiler/reia_yecc_parse.yrl src/compiler/reia_yecc_parse.erl)
CLEAN.include %w(**/*.beam **/*.reb)
CLEAN.include "erl_crash.dump"
#
# Installing
#
# Retrieve the directory Erlang libraries are stored in
def erl_lib_dir
ENV['ERL_LIB_DIR'] ||= `erl -noshell -eval "io:format(code:lib_dir())" -s erlang halt`
end
# Directory to install Reia into
def reia_install_dir
File.join(erl_lib_dir, 'reia', '')
end
# Munge Reia launcher scripts before installing
def munge_script(src, dest)
str = File.read(src)
# Remove REIA_HOME declaration
str.gsub!(/^export REIA_HOME=.*$/, '')
# Remove EXTRA_PATHS declaration
str.gsub!(/^EXTRA_PATHS=.*$/, '')
# Remove $EXTRA_PATHS variables
str.gsub!(/\$EXTRA_PATHS/, '')
# Strip all the extraneous newlines
str.gsub!(/\n\n+/m, "\n\n")
File.open(dest, "w", 0755) { |file| file << str }
end
directory BIN_INSTALL_DIR
task :install => [:check_erl_version, :build, BIN_INSTALL_DIR] do
reia_dir = reia_install_dir
STDERR.puts "*** Installing Reia into: #{reia_dir}"
rm_r reia_dir if File.exist?(reia_dir)
mkdir reia_dir
cp_r "ebin", reia_dir
%w[ire reia reiac].each do |script|
src = File.expand_path("../bin/#{script}", __FILE__)
dst = "#{BIN_INSTALL_DIR}/#{script}"
STDERR.puts "Creating #{dst}"
munge_script src, dst
end
end
task :uninstall do
reia_dir = reia_install_dir
rm_r reia_dir if File.directory?(reia_dir)
%w[ire reia reiac].each { |script| rm_f "#{BIN_INSTALL_DIR}/#{script}" }
end