Skip to content

Instantly share code, notes, and snippets.

@hakunin
Created October 21, 2010 05:45
Show Gist options
  • Save hakunin/638012 to your computer and use it in GitHub Desktop.
Save hakunin/638012 to your computer and use it in GitHub Desktop.
# simplest automatic dependency resoltuion
filemap = {}
classmap = {}
APP_SRC.each { |file|
name = File.basename(file)
name = name.split('_').map{ |f| f.capitalize }.join('').split('.')[0]
dest_name = name+'.class'
#puts name
compiled = OUTDIR + '/' + File.dirname(file).gsub('app/', '') + '/' + dest_name
filemap[name] = { :src => file, :dest => compiled }
classmap[compiled] = { :src => file, :class => name }
}
dependencies = {}
APP_CLASSES.each { |f|
#puts f
#p classmap[f]
dependencies[f] = {}
if (!classmap[f])
warn "WARNING! info for #{f} not found"
exit
end
if f.include? 'html.erb'
next
end
File.open(classmap[f][:src]).each { |line|
line.scan(/[A-Z][A-Za-z0-9]*/).each { |klass|
if (src = filemap[klass]) && (klass != classmap[f][:class])
if !dependencies[f][src[:dest]]
#puts f + " depends on " + src[:dest]
dependencies[f][src[:dest]] = true
#p [f, src[:dest]]
#file f, src[:dest]#dependencies[f].keys
end
end
}
}
file f => dependencies[f].keys
}
begin
require 'ant'
rescue LoadError
puts 'This Rakefile requires JRuby. Please use jruby -S rake.'
exit 1
end
neighbor_mirah = File.expand_path '../mirah'
if File.exists?(neighbor_mirah)
ENV['MIRAH_HOME'] ||= neighbor_mirah
end
if ENV['MIRAH_HOME'] && File.exist?(ENV['MIRAH_HOME'] +'/lib/mirah.rb')
$: << File.expand_path(ENV['MIRAH_HOME'] +'/lib')
end
require 'rake/clean'
require 'mirah/appengine_tasks'
if File.exist?('../bitescript/lib/bitescript.rb')
$: << File.expand_path('../bitescript/lib/')
end
MIRAH_HOME = ENV['MIRAH_HOME'] ? ENV['MIRAH_HOME'] : Gem.find_files('mirah').first.sub(/lib\/mirah.rb/,'')
MODEL_SRC_JAR = File.join(MIRAH_HOME, 'examples', 'appengine', 'war',
'WEB-INF', 'lib', 'dubydatastore.jar')
=begin
def mirahc *files
p files
if files[-1].kind_of?(Hash)
options = files.pop
else
options = {}
end
source_dir = options.fetch(:dir, Duby.source_path)
dest = File.expand_path(options.fetch(:dest, Duby.dest_path))
files = files.map {|f| f.sub(/^#{source_dir}\//, '')}
flags = options.fetch(:options, Duby.compiler_options)
args = ['-d', dest, *flags] + files
chdir(source_dir) do
cmd = "mirahc #{args.join ' '}"
puts cmd
Duby.compile(*args)
#Duby.reset
end
end
=end
OUTDIR = 'WEB-INF/classes'
def class_files_for files
files.map do |f|
explode = f.split('/')[1..-1]
explode.last.gsub!(/(^[a-z]|_[a-z])/) {|m|m.sub('_','').upcase}
explode.last.sub! /\.(duby|java|mirah)$/, '.class'
OUTDIR + '/' + explode.join('/')
end
end
MODEL_JAR = "WEB-INF/lib/dubydatastore.jar"
LIB_MIRAH_SRC = Dir["lib/**/*.{duby,mirah}"]
LIB_JAVA_SRC = Dir["lib/**/*.java"]
LIB_SRC = LIB_MIRAH_SRC + LIB_JAVA_SRC
LIB_CLASSES = class_files_for LIB_SRC
STDLIB_CLASSES= LIB_CLASSES.select{|l|l.include? 'stdlib'}
CLASSPATH = [AppEngine::Rake::SERVLET, AppEngine::SDK::API_JAR].join(":")
Duby.dest_paths << OUTDIR
Duby.source_paths << 'lib'
Duby.source_paths << 'app'
Duby.compiler_options << '--classpath' << [File.expand_path(OUTDIR), *FileList["WEB-INF/lib/*.jar"].map{|f|File.expand_path(f)}].join(':') + ':' + CLASSPATH
directory OUTDIR
CLEAN.include(OUTDIR)
CLOBBER.include("WEB-INF/lib/dubious.jar", 'WEB-INF/appengine-generated')
APP_SRC = Dir["app/**/{*.duby,*.mirah}"]
APP_CLASSES = class_files_for APP_SRC
APP_CONTROLLER_CLASSES = APP_CLASSES.select {|app| app.include? '/models' }
(APP_CLASSES+LIB_CLASSES).zip(APP_SRC+LIB_SRC).each do |klass,src|
file klass => src
end
TEMPLATES = Dir["app/views/**/*.erb"]
TEMPLATES.each do |klass|
file klass => APP_CONTROLLER_CLASSES
end
# simplest automatic dependency resoltuion
filemap = {}
classmap = {}
APP_SRC.each { |file|
name = File.basename(file)
name = name.split('_').map{ |f| f.capitalize }.join('').split('.')[0]
dest_name = name+'.class'
#puts name
compiled = OUTDIR + '/' + File.dirname(file).gsub('app/', '') + '/' + dest_name
filemap[name] = { :src => file, :dest => compiled }
classmap[compiled] = { :src => file, :class => name }
}
dependencies = {}
APP_CLASSES.each { |f|
#puts f
#p classmap[f]
dependencies[f] = {}
if (!classmap[f])
warn "WARNING! info for #{f} not found"
exit
end
if f.include? 'html.erb'
next
end
File.open(classmap[f][:src]).each { |line|
line.scan(/[A-Z][A-Za-z0-9]*/).each { |klass|
if (src = filemap[klass]) && (klass != classmap[f][:class])
if !dependencies[f][src[:dest]]
if f.include?("TestController")
puts f + " depends on " + src[:dest]
end
dependencies[f][src[:dest]] = true
#p [f, src[:dest]]
#file f, src[:dest]#dependencies[f].keys
end
end
}
}
file f => dependencies[f].keys
}
appengine_app :app, 'app', '' => APP_CLASSES+LIB_CLASSES
#there is an upload task in appengine_tasks, but I couldn't get it to work
desc "publish to appengine"
task :publish => 'compile:app' do
sh "appcfg.sh update ."
end
namespace :compile do
task :app => APP_CLASSES
task :java => OUTDIR do
ant.javac :srcdir => 'lib', :destdir => OUTDIR, :classpath => CLASSPATH
end
end
desc "compile app"
task :compile => 'compile:app'
desc "run development server"
task :server
task :default => :server
task :generate_build_properties do
def git_data(dir, file='')
returning = nil
chdir dir do
# ["commit abc....123", "2010-06-23 12:58:06 -0700"]
IO.popen("git rev-list --pretty=format:%ci -1 HEAD #{file}") do |f|
returning = [f.gets.chomp, f.gets.chomp]
end
end
returning
end
dubious_data = git_data(".")
mirah_data = git_data(MIRAH_HOME)
bite_data = git_data(MIRAH_HOME + '/../bitescript')
model_data = git_data(File.dirname(MODEL_SRC_JAR),File.basename(MODEL_SRC_JAR))
prop_file = "config/build.properties"
File.open(prop_file, 'w') do |f|
f.write <<-EOF
# the current build environment
application.build.time=#{Time.now.xmlschema}
dubious.version.commit=#{dubious_data[0][7..-1]}
dubious.version.time=#{Time.parse(dubious_data[1]).xmlschema}
mirah.version.commit=#{mirah_data[0][7..-1]}
mirah.version.time=#{Time.parse(mirah_data[1]).xmlschema}
bitescript.version.commit=#{bite_data[0][7..-1]}
bitescript.version.time=#{Time.parse(bite_data[1]).xmlschema}
model.version.commit=#{model_data[0][7..-1]}
model.version.time=#{Time.parse(model_data[1]).xmlschema}
EOF
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment