-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile
171 lines (149 loc) · 5.37 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
require 'bundler/setup'
require 'ant'
require 'rake/testtask'
task :default => :test
task :jar => 'dist/mmeta.jar'
task :clean do
ant.delete :quiet => true, :dir => 'build'
ant.delete :quiet => true, :dir => 'dist'
end
task :bootstrap => ['dist/mmeta.jar'] do
runjava 'dist/mmeta.jar', '--auto_memo', 'boot/parser.mmeta', 'boot/parser.mirah'
runjava 'dist/mmeta.jar', 'boot/compiler.mmeta', 'boot/compiler.mirah'
end
file 'dist/mmeta-runtime.jar' => Dir.glob('mmeta/*.{java,mirah}') + ['build/runtime', 'dist', 'javalib/mirahc-prev.jar'] do
ENV['BS_CHECK_CLASSES'] = 'true'
mirahc('mmeta/ast.mirah', :dest => 'build/runtime')
ant.javac :srcDir=>'mmeta', :destDir=>'build/runtime', :debug=>true
ant.jar :destfile=>'dist/mmeta-runtime.jar', :basedir=>'build/runtime'
end
file 'build/boot/mmeta/MMetaParser.class' => ['boot/parser.mirah', 'build/boot/mmeta', 'dist/mmeta-runtime.jar', 'javalib/mirahc-prev.jar' ] do
cp 'boot/parser.mirah', 'build/boot/mmeta/'
mirahc('mmeta/parser.mirah',
:dir => 'build/boot',
:dest => 'build/boot',
:options => ['--classpath', 'dist/mmeta-runtime.jar'])
end
file 'build/boot/mmeta/MMetaCompiler.class' => ['boot/compiler.mirah', 'build/boot/mmeta', 'dist/mmeta-runtime.jar' , 'javalib/mirahc-prev.jar'] do
cp 'boot/compiler.mirah', 'build/boot/mmeta/'
mirahc('mmeta/compiler.mirah',
:dir => 'build/boot',
:dest => 'build/boot',
:options => [
'--classpath', "build/boot#{File::PATH_SEPARATOR}dist/mmeta-runtime.jar#{File::PATH_SEPARATOR}javalib/hapax-2.3.5-autoindent.jar"
])
end
file 'dist/mmeta.jar' => ['dist/mmeta-runtime.jar',
'build/boot/mmeta/MMetaParser.class',
'build/boot/mmeta/MMetaCompiler.class'] + Dir['boot/templates/*.xtm'] do
cp_r 'boot/templates', 'build/boot/mmeta/'
ant.jar :destfile => 'dist/mmeta.jar' do
fileset :dir => "build/boot", :includes => "mmeta/*.class"
fileset :dir => "build/boot", :includes => "mmeta/templates/*.xtm"
zipfileset :includes => "**/*.class",
:src => "javalib/hapax-2.3.5-autoindent.jar"
zipfileset :includes => "mmeta/*.class",
:src => 'dist/mmeta-runtime.jar'
manifest do
attribute :name => "Main-Class", :value => "mmeta.MMetaCompiler"
end
end
end
namespace :test do
task :compile => ['dist/mmeta.jar', 'build/test', 'build/test/MirahLexer.class']
file 'build/test/MirahLexer.class' => ['test/MirahLexer.java', 'test/Tokens.java', 'javalib/mirahc-prev.jar'] do
cp "test/MirahLexer.java", "build/test/"
cp "test/Tokens.java", "build/test/"
ant.javac :srcDir => 'build/test',
:classpath => 'dist/mmeta-runtime.jar',
:debug => true,
:destDir => 'build'
mirahc 'test',
:dir => 'build',
:dest => 'build',
:options => [
'--classpath', "dist/mmeta-runtime.jar#{File::PATH_SEPARATOR}build"
]
end
task :calc => :'test:compile' do
runjava('test.Calculator2',
'4 * 3 - 2',
:outputproperty => 'test.output2',
:classpath => "dist/mmeta-runtime.jar#{File::PATH_SEPARATOR}build",
:failonerror => false)
if ant.properties['test.output2'].to_s.strip == '10'
puts "Mirah Calculator passed"
else
puts "Expected calculator result 10, got #{ant.properties['test.output2']}"
exit(1)
end
end
Rake::TestTask.new :parser do |t|
t.libs << 'build/test'
t.test_files = FileList['test/test_parser.rb']
end
task :parser => ['test:compile']
end
def test_grammar(name, *options)
task('build/test/MirahLexer.class').enhance ["build/test/#{name}.mirah"]
file "build/test/#{name}.mirah" => ["test/#{name}.mmeta", 'dist/mmeta.jar', 'build/test'] do
cp "test/#{name}.mmeta", "build/test/"
args = ['dist/mmeta.jar', *options]
args.concat ["build/test/#{name}.mmeta", "build/test/#{name}.mirah"]
runjava *args
end
end
test_grammar('MirahCalculator', '--auto_memo', '--recursion')
#test_grammar('Mirah')
test_grammar('TestParser')
test_grammar('Java')
test_grammar('Left', '--auto_memo', '--recursion')
task :test => [:'test:calc',
:'test:parser',
]
directory 'dist'
directory 'build/test'
directory 'build/mmeta'
directory 'build/runtime'
directory 'build/boot/mmeta'
file_create 'javalib/mirahc-prev.jar' do
require 'open-uri'
url = ENV['MIRAH_PREV_PATH'] || 'https://search.maven.org/remotecontent?filepath=org/mirah/mirah/0.1.4/mirah-0.1.4.jar'
puts "Downloading mirahc-prev.jar from #{url}"
open(url, 'rb') do |src|
open('javalib/mirahc-prev.jar', 'wb') do |dest|
dest.write(src.read)
end
end
end
def runjava(jar, *args)
options = {:failonerror => true, :fork => true}
if jar =~ /\.jar$/
options[:jar] = jar
else
options[:classname] = jar
end
options.merge!(args.pop) if args[-1].kind_of?(Hash)
puts "java #{options} " + args.join(' ')
ant.java options do
args.each do |value|
arg :value => value
end
end
end
def mirahc(source, options)
puts "calling mirahc #{source} #{options}"
args = []
if options[:dest]
args += ['-d', options[:dest]]
end
if options[:options]
args += options[:options]
end
if options[:dir]
args += [options[:dir]+'/'+source]
else
args += [source]
end
runjava 'javalib/mirahc-prev.jar', *args
end