From ebf77c78b2fc4e4fd753eeb78c65890ff07474a1 Mon Sep 17 00:00:00 2001 From: Jeremy Hinegardner Date: Tue, 27 Jul 2010 01:10:27 -0600 Subject: [PATCH] coordinate building of gems for 3 different platforms --- gemspec.rb | 7 ++++++- tasks/distribution.rake | 21 ++++++++++++++++++--- tasks/extension.rake | 25 ++++++++++++++----------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/gemspec.rb b/gemspec.rb index 3a23c4e..126713b 100644 --- a/gemspec.rb +++ b/gemspec.rb @@ -57,4 +57,9 @@ Hitimes::GEM_SPEC_MINGW32.platform = ::Gem::Platform.new( "i386-mingw32" ) Hitimes::GEM_SPEC_MINGW32.extensions = [] -Hitimes::SPECS = [ Hitimes::GEM_SPEC, Hitimes::GEM_SPEC_MSWIN32, Hitimes::GEM_SPEC_MINGW32 ] +Hitimes::GEM_SPEC_JAVA = Hitimes::GEM_SPEC.clone +Hitimes::GEM_SPEC_JAVA.platform = ::Gem::Platform.new( 'java' ) +Hitimes::GEM_SPEC_JAVA.extensions = [] + +Hitimes::SPECS = [ Hitimes::GEM_SPEC, Hitimes::GEM_SPEC_MSWIN32, Hitimes::GEM_SPEC_MINGW32, Hitimes::GEM_SPEC_JAVA ] + diff --git a/tasks/distribution.rake b/tasks/distribution.rake index 8775744..1a10efa 100644 --- a/tasks/distribution.rake +++ b/tasks/distribution.rake @@ -36,11 +36,16 @@ if pkg_config = Configuration.for_if_exist?("packaging") then puts Hitimes::GEM_SPEC_WIN.to_ruby end + desc "dump gemspec for java" + task :gemspec_java do + puts Hitimes::GEM_SPEC_JAVA.to_ruby + end + desc "reinstall gem" task :reinstall => [:uninstall, :repackage, :install] desc "package up a windows gem" - task :package_win => :clean do + task :package_win => :clean do Configuration.for("extension").cross_rbconfig.keys.each do |rbconfig| v = rbconfig.split("-").last s = v.sub(/\.\d$/,'') @@ -58,15 +63,25 @@ if pkg_config = Configuration.for_if_exist?("packaging") then end end + if RUBY_PLATFORM == "java" then + desc "package up a jruby gem" + task :package_java => "ext:build_java" do + Hitimes::GEM_SPEC_JAVA.files += FileList["lib/hitimes/java/*.jar"] + Gem::Builder.new( Hitimes::GEM_SPEC_JAVA ).build + mv Dir["*.gem"].first, "pkg" + end + end + task :clobber do rm_rf "lib/hitimes/1.8" rm_rf "lib/hitimes/1.9" + rm_rf "lib/hitimes/*.jar" end - task :prep => [:clean, :package, :package_win] + task :prep => [:clean, :package, :package_win, :package_java ] desc "distribute copiously" - task :copious => [:clean, :package, :package_win ] do + task :copious => [:clean, :package, :package_win, :package_java ] do gems = Hitimes::SPECS.collect { |s| "#{s.full_name}.gem" } Rake::SshFilePublisher.new('jeremy@copiousfreetime.org', '/var/www/vhosts/www.copiousfreetime.org/htdocs/gems/gems', diff --git a/tasks/extension.rake b/tasks/extension.rake index 73d32fb..b52c334 100644 --- a/tasks/extension.rake +++ b/tasks/extension.rake @@ -8,7 +8,7 @@ require 'pathname' if ext_config = Configuration.for_if_exist?('extension') then namespace :ext do desc "Build the extension(s)" - task :build => :clean do + task :build => :clobber do ext_config.configs.each do |extension| path = Pathname.new(extension) parts = path.split @@ -26,17 +26,20 @@ if ext_config = Configuration.for_if_exist?('extension') then end end - desc "Build the jruby extension" - task :build_jruby => :clean do - path = "ext/java" - Dir.chdir( path ) do |d| - #java_ext = "lib/hitimes/java/#{RUBY_VERSION.sub(/\.\d$/,'')}/hitimes_ext.#{Config::CONFIG['DLEXT']}" - java_ext = "lib/hitimes/hitimes.jar" + if RUBY_PLATFORM == "java" then + desc "Build the jruby extension" + task :build_java => [ :clobber, "lib/hitimes/hitimes.jar" ] + + file "lib/hitimes/hitimes.jar" => FileList["ext/java/src/hitimes/*.java"] do |t| jruby_home = Config::CONFIG['prefix'] - classpath = "#{jruby_home}/lib/jruby.jar" - FileUtils.mkdir_p "../../#{File.dirname( java_ext )}" - sh "javac -g -cp #{classpath} hitimes/*.java" - sh "jar cf ../../#{java_ext} hitimes/*.class" + jruby_jar = File.join( jruby_home, 'lib', 'jruby.jar' ) + + mkdir_p 'pkg/classes' + sh "javac -classpath #{jruby_jar} -d pkg/classes #{t.prerequisites.join(' ')}" + + dest_dir = File.dirname(t.name) + mkdir_p dest_dir + sh "jar cf #{t.name} -C pkg/classes ." end end