-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrakefile
194 lines (162 loc) · 5.33 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/rdoctask"
files = ["java2ruby.rb", "rjava.rb", "LICENSE"] + Dir.glob("converter/**/*.*") + Dir.glob("rjava/**/*.*")
require "drb"
require "stringio"
require "yaml"
task :gemspec do
File.open("java2ruby.gemspec", "w") do |file|
file.write Gem::Specification.new { |s|
s.name = "java2ruby"
s.version = "1.0.1"
s.files = files
s.homepage = %q{http://github.com/neelance/java2ruby/}
s.has_rdoc = false
s.require_paths = ["."]
s.summary = "A source code converter from Java to Ruby, making it possible to use Java libraries with MRI."
s.add_dependency "ffi"
}.to_yaml
end
end
Rake::RDocTask.new do |rd|
rd.rdoc_files.include(*files.select { |file| file =~ /\.rb$/ })
rd.rdoc_dir = "doc"
end
libraries = ["antlr4ruby", "jface4ruby", "jre4ruby", "swt4ruby"]
file "../stable" do
puts "creating stable copy of converter libraries"
mkdir "../stable"
cp_r ["../jre4ruby", "../antlr4ruby"], "../stable"
end
task :load_current_converter do
$:.unshift "."
$:.unshift "../jre4ruby"
$:.unshift "../antlr4ruby"
require "converter"
end
task :load_stable_converter => ["../stable"] do
$:.unshift "."
$:.unshift "../stable/jre4ruby"
$:.unshift "../stable/antlr4ruby"
require "converter"
end
fakeout = StringIO.new
stdout = $stdout
task "test" do
Rake.application.invoke_task :load_current_converter
Dir.glob("test/*.java").sort.each do |file|
basename = File.basename file, ".java"
log = {}
begin
converter = Java2Ruby::Converter.new file
converter.log = log
converter.convert
if not File.exists? file.sub(".java", ".class")
sh "javac -J-Xms64m -J-Xmx512m #{file}"
end
java_output = File.popen("java -Xms64m -Xmx512m -cp #{File.dirname(file)} #{basename} 2>/dev/null").read
log["java output"] = java_output
begin
fakeout.string = ""
$stdout = fakeout
require File.absolute_path(converter.ruby_file)
Object.const_get(File.basename(converter.ruby_file, ".rb")).main([])
ensure
$stdout = stdout
end
if fakeout.string != java_output
log["mri output"] = fakeout.string
raise "Result output does not match"
end
rescue Interrupt
exit
rescue Exception => e
last = e.backtrace.index{ |bt| bt.include? "rakefile" }
log["exception"] = "#{e} (#{e.class})\n#{e.backtrace[0..(last ? last - 1 : -1)].join("\n")}"
end
File.open("#{File.dirname(file)}/#{basename}.log.yaml", "w") do |f|
log.each do |header, content|
f.puts "--- #{header.upcase} ---"
f.puts content
f.puts
end
end
print log["exception"] ? "\n#{file} failed: #{e}\n" : "."
$stdout.flush
end
puts "Done"
end
task :delete_test_results do
rm Dir.glob("test/*.rb")
rm Dir.glob("test/*.log.yaml")
rm Dir.glob("test/*.dump.gz")
end
task :retest => [:delete_test_results, :test]
convert_libraries = lambda { |selected_libraries, args|
profile = args.profile == "true"
process_count = args.process_count.to_i
process_count = nil if process_count < 1
if profile
require "perftools"
PerfTools::CpuProfiler.start("perftools_profile")
end
begin
Rake.application.invoke_task :load_stable_converter
require "conversion_controller"
controller = Java2Ruby::ConversionController.new
selected_libraries.each do |library|
src_dir = "../#{library}/#{library}/src"
files = Dir.glob("#{src_dir}/**/*").sort
controller.add_files files
end
controller.run process_count
ensure
PerfTools::CpuProfiler.stop if profile
end
}
libraries.each do |library|
task "convert_#{library}", [:process_count, :profile] do |t, args|
convert_libraries.call [library], args
end
task "reconvert_#{library}", [:process_count, :profile] do |t, args|
rm_rf "../#{library}/#{library}/lib"
rm_rf "../#{library}/#{library}/tmp"
convert_libraries.call [library], args
end
end
task "convert_all", [:process_count] do |t, args|
convert_libraries.call libraries, args.process_count
end
task "reconvert_all", [:process_count] do |t, args|
libraries.each { |library| rm_rf "#{library}/#{library}/lib" }
convert_libraries.call libraries, args.process_count
end
task :push_reconverted do
libraries.each do |library|
chdir "../#{library}" do
system "git add #{library}/lib"
system 'git commit -m "Reconverted."'
system "git push"
end
end
end
desc "generate FFI structs"
task :ffi_generate do
require "ffi"
require "ffi/tools/generator"
require "ffi/tools/struct_generator"
unless uptodate?("java2ruby/rjava/jni/jni_structs.rb", ["java2ruby/rjava/jni/jni_structs.rb.ffi", "java2ruby/rjava/jni/jni.rb"])
require "java2ruby/rjava/rjava_module"
require "java2ruby/rjava/jni/jni_structures"
filename = "java2ruby/rjava/jni/#{RJava::PLATFORM}/jni_structs.rb"
puts "generating: #{filename}"
FFI::Generator.new "java2ruby/rjava/jni/jni_structs.rb.ffi", filename, { :cflags => "-Ijava2ruby/rjava/jni -Ijava2ruby/rjava/jni/#{RJava::PLATFORM}" }
end
end
desc "build JNI tools"
task :build_jni_tools do
require "java2ruby/rjava/rjava_module"
chdir "java2ruby/rjava/jni" do
system "erb jni_tools.c.erb > jni_tools.c"
system "gcc jni_tools.c -shared -fPIC -g -I#{RJava::PLATFORM} -o #{RJava::PLATFORM}/jni_tools.so"
end
end