Skip to content
Newer
Older
100644 285 lines (252 sloc) 8.57 KB
0ded1dc @headius Add Apache License 2.0 header to all source files (I could find).
headius authored
1 # Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
2 # All contributing project authors may be found in the NOTICE file.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
b2d8c9a Add Rakefile with TestTask.
headius authored
16 require 'rake'
17 require 'rake/testtask'
805586f @baroquebobcat add rake gem task
baroquebobcat authored
18 require 'rubygems'
19 require 'rubygems/package_task'
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
20 require 'bundler/setup'
5da2c15 Add simple import syntax that's close to Java, update examples for it…
headius@cnutter.local authored
21 require 'java'
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
22 require 'jruby/compiler'
23 require 'ant'
b2d8c9a Add Rakefile with TestTask.
headius authored
24
805586f @baroquebobcat add rake gem task
baroquebobcat authored
25 Gem::PackageTask.new Gem::Specification.load('mirah.gemspec') do |pkg|
26 pkg.need_zip = true
27 pkg.need_tar = true
28 end
29
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
30 bitescript_lib_dir = File.dirname Gem.find_files('bitescript').first
31
805586f @baroquebobcat add rake gem task
baroquebobcat authored
32 task :gem => 'jar:bootstrap'
82cf35c @ribrdb puts. Sweet. Except JRuby can't find it most of the time. Cry.
ribrdb authored
33 task :bootstrap => ['javalib/mirah-bootstrap.jar', 'javalib/mirah-builtins.jar']
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
34 task :default => :'test:jvm:bytecode'
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
35 def run_tests tests
36 results = tests.map do |name|
37 begin
38 Rake.application[name].invoke
39 rescue Exception
40 end
41 end
42
43 tests.zip(results).each do |name, passed|
44 unless passed
45 puts "Errors in #{name}"
46 end
47 end
48 fail if results.any?{|passed|!passed}
49 end
da60e32 Add default target to build.
headius authored
50
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
51 desc "run full test suite"
52 task :test do
53 run_tests [ 'test:core', 'test:plugins', 'test:jvm' ]
54 end
55
56 namespace :test do
57
58 desc "run the core tests"
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
59 Rake::TestTask.new :core => :bootstrap do |t|
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
60 t.libs << 'test'
61 t.test_files = FileList["test/core/**/*test.rb"]
62 java.lang.System.set_property("jruby.duby.enabled", "true")
63 end
64
65 desc "run tests for plugins"
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
66 Rake::TestTask.new :plugins => :bootstrap do |t|
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
67 t.libs << 'test'
68 t.test_files = FileList["test/plugins/**/*test.rb"]
69 java.lang.System.set_property("jruby.duby.enabled", "true")
70 end
71
72 desc "run jvm tests, both bytecode and java source"
73 task :jvm do
65c726d @ribrdb Don't run javac backend tests by default -- they're completely broken
ribrdb authored
74 run_tests ["test:jvm:bytecode"]
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
75 end
76
77 namespace :jvm do
78 desc "run jvm tests compiling to bytecode"
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
79 Rake::TestTask.new :bytecode => :bootstrap do |t|
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
80 t.libs << 'test' <<'test/jvm'
81 t.ruby_opts.concat ["-r", "bytecode_test_helper"]
82 t.test_files = FileList["test/jvm/**/*test.rb"]
83 end
84 end
756e06f @ribrdb Add support for compiling multiple files and a separate output directory
ribrdb authored
85 end
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
86
e9d892e @headius Clean up Rakefile, don't create dirs multiple times and eliminate unu…
headius authored
87 task :init do
88 mkdir_p 'dist'
89 mkdir_p 'build'
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
90 end
91
6ac3fb1 @baroquebobcat add descriptions to rake tasks
baroquebobcat authored
92 desc "clean up build artifacts"
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
93 task :clean do
94 ant.delete :quiet => true, :dir => 'build'
95 ant.delete :quiet => true, :dir => 'dist'
1dc2d5c @baroquebobcat rake clean should rm the bootstrap jar
baroquebobcat authored
96 rm 'javalib/mirah-bootstrap.jar'
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
97 end
98
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
99 task :compile => [:init, :bootstrap] do
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
100 require 'mirah'
15fb902 @headius Add a Compile Ant task and twiddle the build as appropriate to get it…
headius authored
101 # build the Ruby sources
102 puts "Compiling Ruby sources"
103 JRuby::Compiler.compile_argv([
104 '-t', 'build',
105 '--javac',
37eac87 @headius More renames to get the jar and complete jar moved over to the "Mirah…
headius authored
106 'src/org/mirah/mirah_command.rb'
15fb902 @headius Add a Compile Ant task and twiddle the build as appropriate to get it…
headius authored
107 ])
d3f9a62 @ribrdb Rename duby.rb -> mirah.rb
ribrdb authored
108
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
109 # TODO compile ant stuff
478b921 @ribrdb Work on fixing method lookup
ribrdb authored
110
ce9b740 @headius Update dynalink stuff, add JSR292 mock to enable compiling/including …
headius authored
111 # compile invokedynamic stuff
112 ant.javac :destdir => 'build', :srcdir => 'src',
113 :includes => 'org/mirah/DynalangBootstrap.java',
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
114 :classpath => 'javalib/dynalink-0.1.jar:javalib/jsr292-mock.jar',
115 :includeantruntime => false
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
116 end
117
6ac3fb1 @baroquebobcat add descriptions to rake tasks
baroquebobcat authored
118 desc "build basic jar for distribution"
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
119 task :jar => :compile do
37eac87 @headius More renames to get the jar and complete jar moved over to the "Mirah…
headius authored
120 ant.jar :jarfile => 'dist/mirah.jar' do
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
121 fileset :dir => 'lib'
122 fileset :dir => 'build'
123 fileset :dir => '.', :includes => 'bin/*'
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
124 fileset :dir => bitescript_lib_dir
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
125 zipfileset :src => 'javalib/mirah-bootstrap.jar'
15fb902 @headius Add a Compile Ant task and twiddle the build as appropriate to get it…
headius authored
126 manifest do
37eac87 @headius More renames to get the jar and complete jar moved over to the "Mirah…
headius authored
127 attribute :name => 'Main-Class', :value => 'org.mirah.MirahCommand'
15fb902 @headius Add a Compile Ant task and twiddle the build as appropriate to get it…
headius authored
128 end
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
129 end
130 end
131
132 namespace :jar do
6ac3fb1 @baroquebobcat add descriptions to rake tasks
baroquebobcat authored
133 desc "build self-contained, complete jar"
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
134 task :complete => :jar do
37eac87 @headius More renames to get the jar and complete jar moved over to the "Mirah…
headius authored
135 ant.jar :jarfile => 'dist/mirah-complete.jar' do
136 zipfileset :src => 'dist/mirah.jar'
44938b9 @headius Add a 1.5.0.dev jruby-complete to avoid needing that dependency alrea…
headius authored
137 zipfileset :src => 'javalib/jruby-complete.jar'
155e8ef @ribrdb Fix building mirah-complete.jar
ribrdb authored
138 zipfileset :src => 'javalib/mirah-parser.jar'
46422d3 @baroquebobcat merge master into new ast. It's crazy awesome.
baroquebobcat authored
139 zipfileset :src => 'javalib/dynalink-0.2.jar'
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
140 manifest do
37eac87 @headius More renames to get the jar and complete jar moved over to the "Mirah…
headius authored
141 attribute :name => 'Main-Class', :value => 'org.mirah.MirahCommand'
a7886e2 @headius Port build.xml bits into Rakefile (JRuby 1.5 required now)
headius authored
142 end
143 end
144 end
f9171ae @ribrdb Initial support for writing macros in duby.
ribrdb authored
145
6ac3fb1 @baroquebobcat add descriptions to rake tasks
baroquebobcat authored
146 desc "build bootstrap jar used by the gem"
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
147 task :bootstrap => 'javalib/mirah-bootstrap.jar'
155e8ef @ribrdb Fix building mirah-complete.jar
ribrdb authored
148 end
690f82b @headius Add zip, gem, and dist targets to Rakefile, to build a zip'ed distrib…
headius authored
149
150 desc "Build a distribution zip file"
a395dbf @headius Make zip task depend on jar:complete again.
headius authored
151 task :zip => 'jar:complete' do
bb39a69 @headius Put .zip contents into a mirah-VERSION directory (d'oh!).
headius authored
152 basedir = "tmp/mirah-#{Mirah::VERSION}"
153 mkdir_p "#{basedir}/lib"
154 mkdir_p "#{basedir}/bin"
155 cp 'dist/mirah-complete.jar', "#{basedir}/lib"
156 cp 'distbin/mirah.bash', "#{basedir}/bin/mirah"
157 cp 'distbin/mirahc.bash', "#{basedir}/bin/mirahc"
59409a1 @headius Add missing .bat files to dist.
headius authored
158 cp Dir['{distbin/*.bat}'], "#{basedir}/bin/"
bb39a69 @headius Put .zip contents into a mirah-VERSION directory (d'oh!).
headius authored
159 cp_r 'examples', "#{basedir}/examples"
160 rm_rf "#{basedir}/examples/wiki"
161 cp 'README.txt', "#{basedir}"
162 cp 'NOTICE', "#{basedir}"
163 cp 'LICENSE', "#{basedir}"
164 cp 'History.txt', "#{basedir}"
165 sh "sh -c 'cd tmp ; zip -r ../dist/mirah-#{Mirah::VERSION}.zip mirah-#{Mirah::VERSION}/*'"
690f82b @headius Add zip, gem, and dist targets to Rakefile, to build a zip'ed distrib…
headius authored
166 rm_rf 'tmp'
167 end
168
169 desc "Build all redistributable files"
a395dbf @headius Make zip task depend on jar:complete again.
headius authored
170 task :dist => [:gem, :zip]
6d0821f @ribrdb Add Rakefile support for building typer.jar
ribrdb authored
171
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
172 file_create 'javalib/mirah-newast-transitional.jar' do
6d0821f @ribrdb Add Rakefile support for building typer.jar
ribrdb authored
173 require 'open-uri'
174 puts "Downloading mirah-newast-transitional.jar"
175 open('http://mirah.googlecode.com/files/mirah-newast-transitional.jar', 'rb') do |src|
176 open('javalib/mirah-newast-transitional.jar', 'wb') do |dest|
177 dest.write(src.read)
178 end
179 end
180 end
181
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
182 file 'javalib/mirah-bootstrap.jar' => ['javalib/mirah-newast-transitional.jar',
c7fdf60 @ribrdb Mostly fix typer tests.
ribrdb authored
183 'src/org/mirah/MirahClassLoader.java',
257eb93 @ribrdb Merge
ribrdb authored
184 'src/org/mirah/IsolatedResourceLoader.java',
c7fdf60 @ribrdb Mostly fix typer tests.
ribrdb authored
185 'src/org/mirah/MirahLogFormatter.mirah'] +
9439368 @ribrdb Split up simple.mirah
ribrdb authored
186 Dir['src/org/mirah/{macros,typer}/*.mirah'] +
187 Dir['src/org/mirah/typer/simple/*.mirah'] +
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
188 Dir['src/org/mirah/macros/anno/*.java'] do
189 rm_rf 'build/bootstrap'
190 mkdir_p 'build/bootstrap'
191
192 # Compile annotations and class loader
193 ant.javac :destdir => 'build/bootstrap', :srcdir => 'src',
b5a61ad @ribrdb Quote macro implementation
ribrdb authored
194 :includeantruntime => false, :debug => true, :listfiles => true
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
195
196 # Compile the Typer and Macro compiler
c7fdf60 @ribrdb Mostly fix typer tests.
ribrdb authored
197 bootstrap_mirahc('src/org/mirah/macros', 'src/org/mirah/MirahLogFormatter.mirah', 'src/org/mirah/typer',
b5a61ad @ribrdb Quote macro implementation
ribrdb authored
198 :classpath => ['javalib/mirah-parser.jar', 'build/bootstrap'],
199 :dest => 'build/bootstrap'
200 # :options => ['-V']
201 )
7dc94c8 @ribrdb Fix the quote macro
ribrdb authored
202 add_quote_macro
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
203 cp Dir['src/org/mirah/macros/*.tpl'], 'build/bootstrap/org/mirah/macros'
204
205 # Build the jar
206 ant.jar :jarfile => 'javalib/mirah-bootstrap.jar' do
207 fileset :dir => 'build/bootstrap'
6d0821f @ribrdb Add Rakefile support for building typer.jar
ribrdb authored
208 end
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
209
210 rm_rf 'build/bootstrap'
211 end
7dc94c8 @ribrdb Fix the quote macro
ribrdb authored
212
82cf35c @ribrdb puts. Sweet. Except JRuby can't find it most of the time. Cry.
ribrdb authored
213 file 'javalib/mirah-builtins.jar' => ['javalib/mirah-bootstrap.jar'] + Dir['src/org/mirah/builtins/*.mirah'] do
214 rm_f 'javalib/mirah-builtins.jar'
215 rm_rf 'build/builtins'
216 mkdir_p 'build/builtins'
217 sh *%w(jruby -Ilib bin/mirahc --dest build/builtins src/org/mirah/builtins)
218 ant.jar :jarfile => 'javalib/mirah-builtins.jar' do
219 fileset :dir => 'build/builtins'
220 end
221 rm_rf 'build/builtins'
222 end
223
7dc94c8 @ribrdb Fix the quote macro
ribrdb authored
224 require 'bitescript'
225 class Annotater < BiteScript::ASM::ClassWriter
226 def initialize(filename, &block)
227 cr = BiteScript::ASM::ClassReader.new(java.io.FileInputStream.new(filename))
228 super(cr, 0)
229 @block = block
230 cr.accept(self, 0)
231 f = java.io.FileOutputStream.new(filename)
232 f.write(toByteArray)
233 f.close
234 end
235 def visitSource(*args); end
236 def visit(*args)
237 super
238 @block.call(self)
239 end
240 end
241
242 def add_quote_macro
243 Annotater.new('build/bootstrap/org/mirah/macros/QuoteMacro.class') do |klass|
a6f8a07 @ribrdb Some macro fixes
ribrdb authored
244 av = klass.visitAnnotation('Lorg/mirah/macros/anno/MacroDef;', true)
7dc94c8 @ribrdb Fix the quote macro
ribrdb authored
245 av.visit("name", "quote")
246 args = av.visitAnnotation('arguments', 'Lorg/mirah/macros/anno/MacroArgs;')
247 req = args.visitArray('required')
248 req.visit(nil, 'mirah.lang.ast.Block')
249 req.visitEnd
250 args.visitEnd
251 av.visitEnd
252 end
253 Annotater.new('build/bootstrap/org/mirah/macros/Macro.class') do |klass|
254 av = klass.visitAnnotation('Lorg/mirah/macros/anno/Extensions;', false)
255 macros = av.visitArray('macros')
256 macros.visit(nil, 'org.mirah.macros.QuoteMacro')
257 macros.visitEnd
258 av.visitEnd
259 end
260 end
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
261
262 def bootstrap_mirahc(*paths)
263 options = if paths[-1].kind_of?(Hash)
264 paths.pop
265 else
266 {}
267 end
268 args = options[:options] || []
269 if options[:classpath]
270 args << '--classpath' << options[:classpath].map {|p| File.expand_path(p)}.join(File::PATH_SEPARATOR)
6d0821f @ribrdb Add Rakefile support for building typer.jar
ribrdb authored
271 end
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
272 args << '-d' << File.expand_path(options[:dest])
273 jarfile = File.expand_path('javalib/mirah-newast-transitional.jar')
274 Dir.chdir(options[:dir] || '.') do
275 runjava(jarfile, 'compile', *(args + paths))
6d0821f @ribrdb Add Rakefile support for building typer.jar
ribrdb authored
276 end
277 end
278
0ffaa55 @ribrdb Fix compilation of mirah-bootstrap.jar
ribrdb authored
279 def runjava(jar, *args)
280 sh 'java', '-jar', jar, *args
281 unless $?.success?
282 exit $?.exitstatus
283 end
257eb93 @ribrdb Merge
ribrdb authored
284 end
Something went wrong with that request. Please try again.