1+ #!/usr/bin/env rake
2+
3+ require_relative './lib/extension_helper'
4+
5+ ## load the two gemspec files
16CORE_GEMSPEC = Gem ::Specification . load ( 'concurrent-ruby.gemspec' )
27EXT_GEMSPEC = Gem ::Specification . load ( 'concurrent-ruby-ext.gemspec' )
8+
9+ ## constants used for compile/build tasks
10+
311GEM_NAME = 'concurrent-ruby'
412EXTENSION_NAME = 'extension'
513
6- $:. push File . join ( File . dirname ( __FILE__ ) , 'lib' )
7- require 'extension_helper'
14+ if Concurrent . jruby?
15+ CORE_GEM = "#{ GEM_NAME } -#{ Concurrent ::VERSION } -java.gem"
16+ else
17+ CORE_GEM = "#{ GEM_NAME } -#{ Concurrent ::VERSION } .gem"
18+ EXTENSION_GEM = "#{ GEM_NAME } -ext-#{ Concurrent ::VERSION } .gem"
19+ NATIVE_GEM = "#{ GEM_NAME } -ext-#{ Concurrent ::VERSION } -#{ Gem ::Platform . new ( RUBY_PLATFORM ) } .gem"
20+ end
21+
22+ ## safely load all the rake tasks in the `tasks` directory
823
924def safe_load ( file )
1025 begin
1126 load file
1227 rescue LoadError => ex
13- puts ' Error loading rake tasks, but will continue...'
28+ puts " Error loading rake tasks from ' #{ file } ' but will continue..."
1429 puts ex . message
1530 end
1631end
@@ -19,17 +34,21 @@ Dir.glob('tasks/**/*.rake').each do |rakefile|
1934 safe_load rakefile
2035end
2136
22- if defined? ( JRUBY_VERSION )
37+ if Concurrent . jruby?
38+
39+ ## create the compile task for the JRuby-specific gem
2340 require 'rake/javaextensiontask'
2441
25- Rake ::JavaExtensionTask . new ( 'concurrent_ruby_ext ' , CORE_GEMSPEC ) do |ext |
42+ Rake ::JavaExtensionTask . new ( 'java ' , CORE_GEMSPEC ) do |ext |
2643 ext . ext_dir = 'ext'
2744 end
2845
2946elsif Concurrent . allow_c_extensions?
47+
48+ ## create the compile tasks for the extension gem
3049 require 'rake/extensiontask'
3150
32- Rake ::ExtensionTask . new ( EXTENSION_NAME , EXT_GEMSPEC ) do |ext |
51+ Rake ::ExtensionTask . new ( 'ext' , EXT_GEMSPEC ) do |ext |
3352 ext . ext_dir = 'ext/concurrent'
3453 ext . lib_dir = 'lib/concurrent'
3554 ext . source_pattern = '*.{c,h}'
@@ -52,6 +71,7 @@ elsif Concurrent.allow_c_extensions?
5271 end
5372 end
5473else
74+ ## create an empty compile task
5575 task :compile
5676end
5777
@@ -66,52 +86,55 @@ task :clean do
6686 mkdir_p 'pkg'
6787end
6888
69- begin
70- require 'rspec'
71- require 'rspec/core/rake_task'
72-
73- RSpec ::Core ::RakeTask . new ( :spec ) do |t |
74- t . rspec_opts = '--color --backtrace --format documentation'
75- end
76-
77- task :default => [ :clean , :compile , :spec ]
78- rescue LoadError
79- puts 'Error loading Rspec rake tasks, probably building the gem...'
80- end
81-
82- build_deps = [ :clean ]
83- build_deps << :compile if defined? ( JRUBY_VERSION )
84-
85- build_tasks = [ 'build:core' ]
86- build_tasks += [ 'build:ext' , 'build:native' ] if Concurrent . allow_c_extensions?
87-
88- CoreGem = "#{ GEM_NAME } -#{ Concurrent ::VERSION } .gem"
89- ExtensionGem = "#{ GEM_NAME } -ext-#{ Concurrent ::VERSION } .gem"
90- NativeGem = "#{ GEM_NAME } -ext-#{ Concurrent ::VERSION } -#{ Gem ::Platform . new ( RUBY_PLATFORM ) } .gem"
89+ ## create build tasks tailored to current platform
9190
9291namespace :build do
9392
94- desc "Build #{ CoreGem } into the pkg directory"
93+ build_deps = [ :clean ]
94+ build_deps << :compile if Concurrent . jruby?
95+
96+ desc "Build #{ CORE_GEM } into the pkg directory"
9597 task :core => build_deps do
9698 sh "gem build #{ CORE_GEMSPEC . name } .gemspec"
9799 sh 'mv *.gem pkg/'
98100 end
99101
100- if Concurrent . allow_c_extensions?
101-
102- desc "Build #{ ExtensionGem } .gem into the pkg directory"
102+ unless Concurrent . jruby?
103+ desc "Build #{ EXTENSION_GEM } into the pkg directory"
103104 task :ext => [ :clean ] do
104105 sh "gem build #{ EXT_GEMSPEC . name } .gemspec"
105106 sh 'mv *.gem pkg/'
106107 end
108+ end
107109
108- desc "Build #{ NativeGem } into the pkg directory"
110+ if Concurrent . allow_c_extensions?
111+ desc "Build #{ NATIVE_GEM } into the pkg directory"
109112 task :native do
110- sh "gem compile pkg/#{ ExtensionGem } "
113+ sh "gem compile pkg/#{ EXTENSION_GEM } "
111114 sh 'mv *.gem pkg/'
112115 end
113116 end
114117end
115118
116- desc 'Build all gems for this platform'
117- task :build => build_tasks
119+ if Concurrent . jruby?
120+ desc 'Build JRuby-specific core gem (alias for `build:core`)'
121+ task :build => [ 'build:core' ]
122+ else
123+ desc 'Build core and extension gems'
124+ task :build => [ 'build:core' , 'build:ext' ]
125+ end
126+
127+ ## the RSpec task that compiles extensions when available
128+
129+ begin
130+ require 'rspec'
131+ require 'rspec/core/rake_task'
132+
133+ RSpec ::Core ::RakeTask . new ( :spec ) do |t |
134+ t . rspec_opts = '--color --backtrace --format documentation'
135+ end
136+
137+ task :default => [ :clean , :compile , :spec ]
138+ rescue LoadError
139+ puts 'Error loading Rspec rake tasks, probably building the gem...'
140+ end
0 commit comments