1
+ #!/usr/bin/env rake
2
+
3
+ require_relative './lib/extension_helper'
4
+
5
+ ## load the two gemspec files
1
6
CORE_GEMSPEC = Gem ::Specification . load ( 'concurrent-ruby.gemspec' )
2
7
EXT_GEMSPEC = Gem ::Specification . load ( 'concurrent-ruby-ext.gemspec' )
8
+
9
+ ## constants used for compile/build tasks
10
+
3
11
GEM_NAME = 'concurrent-ruby'
4
12
EXTENSION_NAME = 'extension'
5
13
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
8
23
9
24
def safe_load ( file )
10
25
begin
11
26
load file
12
27
rescue LoadError => ex
13
- puts ' Error loading rake tasks, but will continue...'
28
+ puts " Error loading rake tasks from ' #{ file } ' but will continue..."
14
29
puts ex . message
15
30
end
16
31
end
@@ -19,17 +34,21 @@ Dir.glob('tasks/**/*.rake').each do |rakefile|
19
34
safe_load rakefile
20
35
end
21
36
22
- if defined? ( JRUBY_VERSION )
37
+ if Concurrent . jruby?
38
+
39
+ ## create the compile task for the JRuby-specific gem
23
40
require 'rake/javaextensiontask'
24
41
25
- Rake ::JavaExtensionTask . new ( 'concurrent_ruby_ext ' , CORE_GEMSPEC ) do |ext |
42
+ Rake ::JavaExtensionTask . new ( 'java ' , CORE_GEMSPEC ) do |ext |
26
43
ext . ext_dir = 'ext'
27
44
end
28
45
29
46
elsif Concurrent . allow_c_extensions?
47
+
48
+ ## create the compile tasks for the extension gem
30
49
require 'rake/extensiontask'
31
50
32
- Rake ::ExtensionTask . new ( EXTENSION_NAME , EXT_GEMSPEC ) do |ext |
51
+ Rake ::ExtensionTask . new ( 'ext' , EXT_GEMSPEC ) do |ext |
33
52
ext . ext_dir = 'ext/concurrent'
34
53
ext . lib_dir = 'lib/concurrent'
35
54
ext . source_pattern = '*.{c,h}'
@@ -52,6 +71,7 @@ elsif Concurrent.allow_c_extensions?
52
71
end
53
72
end
54
73
else
74
+ ## create an empty compile task
55
75
task :compile
56
76
end
57
77
@@ -66,52 +86,55 @@ task :clean do
66
86
mkdir_p 'pkg'
67
87
end
68
88
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
91
90
92
91
namespace :build do
93
92
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"
95
97
task :core => build_deps do
96
98
sh "gem build #{ CORE_GEMSPEC . name } .gemspec"
97
99
sh 'mv *.gem pkg/'
98
100
end
99
101
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"
103
104
task :ext => [ :clean ] do
104
105
sh "gem build #{ EXT_GEMSPEC . name } .gemspec"
105
106
sh 'mv *.gem pkg/'
106
107
end
108
+ end
107
109
108
- desc "Build #{ NativeGem } into the pkg directory"
110
+ if Concurrent . allow_c_extensions?
111
+ desc "Build #{ NATIVE_GEM } into the pkg directory"
109
112
task :native do
110
- sh "gem compile pkg/#{ ExtensionGem } "
113
+ sh "gem compile pkg/#{ EXTENSION_GEM } "
111
114
sh 'mv *.gem pkg/'
112
115
end
113
116
end
114
117
end
115
118
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