Skip to content

Commit

Permalink
Rakefile for gen/compile/run of a single rb file
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
  • Loading branch information
shawn42 authored and headius committed Dec 28, 2012
1 parent 6f83a25 commit 8dd7d2e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
dependency-reduced-pom.xml
tags
build
target
*.swp
*.swo
40 changes: 40 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require 'rake/clean'

task :default => [:test]
task :test do
puts "TODO: test!"
end

CLEAN.include 'build'

desc "Runs a single file"
task :run, [:file_name] => [:compile] do |t, args|
Dir.chdir("#{File.dirname(__FILE__)}")
file_name = args[:file_name]
raise "must specify file to run" unless file_name && File.exists?(file_name)
Dir.chdir("#{File.dirname(__FILE__)}/build")
sh "java #{File.basename(file_name, '.rb')}"
end

desc "Generate the java source file"
task :generate, [:file_name] => [:jruby_check] do |t, args|
Dir.chdir("#{File.dirname(__FILE__)}")
file_name = args[:file_name]
raise "must specify file to generate" unless file_name && File.exists?(file_name)
sh "jruby -I target:src/main/ruby src/main/ruby/fast_ruby.rb #{file_name}"
end

desc "Compile the java source to bytecode"
task :compile, [:file_name] => [:generate] do |t, args|
Dir.chdir("#{File.dirname(__FILE__)}")
file_name = args[:file_name]

raise "must specify file to compile" unless file_name && File.exists?(file_name)
Dir.chdir("#{File.dirname(__FILE__)}/build")
sh "javac #{File.basename(file_name, '.rb')}.java"
end


task :jruby_check do |t|
raise "Must have jruby installed" if `which jruby`.strip.empty?
end
8 changes: 5 additions & 3 deletions src/main/ruby/fast_ruby/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ def compile

build_robject

FileUtils.mkdir('build') unless Dir.exists?('build')

# all generated sources
sources.each do |source|
type = source.types[0]
File.open(type.name.to_s + ".java", 'w') do |file|
File.open(File.join('build', type.name.to_s + ".java"), 'w') do |file|
file.write(source_to_document(source).get)
end
end

# all copied sources
COPIED_SOURCES.each do |srcname|
FileUtils.cp(File.join('src/main/java', srcname), ".")
FileUtils.cp(File.join('src/main/java', srcname), "build/.")
end
end

Expand Down Expand Up @@ -95,4 +97,4 @@ def build_robject
end
end
end
end
end
6 changes: 6 additions & 0 deletions src/test/ruby/playground.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if true
puts "IF"
else
puts "HUH"
end

0 comments on commit 8dd7d2e

Please sign in to comment.