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 37
/
Copy pathRakefile
167 lines (129 loc) · 4.32 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
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.7.0"
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 R13B (5.7.0)"
exit 1
end
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_scan.erl src/compiler/reia_parse.erl)
ERL_SRC = (GENERATED_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
opts = ""
opts << "+debug_info" unless QUIET_SRC.include? input
sh "erlc #{opts} -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 :reia => ERL_DEST + REIA_DEST
task :scanner => %w(src/compiler/reia_scan.erl)
task :parser => %w(src/compiler/reia_parse.erl)
file "src/compiler/reia_scan.erl" => %w(src/compiler/reia_scan.xrl) do
erl_eval 'leex:file("src/compiler/reia_scan.xrl")'
end
# Parser
file "src/compiler/reia_parse.erl" => %w(src/compiler/reia_parse.yrl) do
erl_eval 'yecc:file("src/compiler/reia_parse.yrl", [verbose])'
end
# Test suite
task :test => :build do
sh "bin/reia test/runner.re"
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(src/compiler/reia_scan.erl src/compiler/reia_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