rake-compiler 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +15 -1
- data/lib/rake/extensiontask.rb +26 -24
- metadata +2 -8
- data/spec/lib/rake/compiler_config_spec.rb +0 -54
- data/spec/lib/rake/extensiontask_spec.rb +0 -679
- data/spec/lib/rake/javaextensiontask_spec.rb +0 -237
- data/spec/spec.opts +0 -3
- data/spec/spec_helper.rb +0 -15
- data/spec/support/capture_output_helper.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 348048ed79bcda098bdaa8f8fa523e2e3b85263911f81ccbb173b879d2d9fd05
|
4
|
+
data.tar.gz: 2485652f621bcb18ee6a552d2a278ddf6f8cbe584848d6d14799325e1cdad1bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2053558c9908644a0aea5a3fd758b2ee11bf8b57e7e91dd9cb794acd391b5ea35232ad75780f2f86e394c0867fcde13e2fef0913990feff8f1d5dd6745b16f0
|
7
|
+
data.tar.gz: 0e2da4951102147e9e92e88fbcfd5f6bef58462f82a0c012a22aeaca451d2629994b20db243b7ea93ca09b8682b03ed6229ef8a46b7fada9c76729e6d3c8fbba
|
data/History.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
### 1.2.3 / 2023-05-30
|
2
|
+
|
3
|
+
* Enhancements:
|
4
|
+
* GH-217: Added support for `nil` in build options again.
|
5
|
+
[Patch by Mike Dalessio]
|
6
|
+
|
7
|
+
* Fixes:
|
8
|
+
* GH-219: Fixed a typo in documentation.
|
9
|
+
[Patch by y-yagi]
|
10
|
+
|
11
|
+
* Thanks:
|
12
|
+
* Mike Dalessio
|
13
|
+
* y-yagi
|
14
|
+
|
1
15
|
### 1.2.2 / 2023-05-25
|
2
16
|
|
3
17
|
* Enhancements:
|
@@ -9,7 +23,7 @@
|
|
9
23
|
[Reported by Jun Aruga]
|
10
24
|
|
11
25
|
* Fixes:
|
12
|
-
* GH-
|
26
|
+
* GH-212: Fixed a typo in documentation.
|
13
27
|
[Patch by Jan-Benedikt Jagusch]
|
14
28
|
|
15
29
|
* Thanks:
|
data/lib/rake/extensiontask.rb
CHANGED
@@ -79,6 +79,26 @@ module Rake
|
|
79
79
|
end.flatten
|
80
80
|
end
|
81
81
|
|
82
|
+
def make_makefile_cmd(root_path, tmp_path, extconf, siteconf_path, cross_platform) # :nodoc:
|
83
|
+
# include current directory
|
84
|
+
include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR)
|
85
|
+
|
86
|
+
# build a relative path to extconf script
|
87
|
+
abs_tmp_path = (Pathname.new(root_path) + tmp_path).realpath
|
88
|
+
abs_extconf = (Pathname.new(root_path) + extconf).realpath
|
89
|
+
rel_extconf = abs_extconf.relative_path_from(abs_tmp_path).to_s
|
90
|
+
|
91
|
+
# base command
|
92
|
+
cmd = [Gem.ruby, "-I#{include_dirs}", "-r#{File.basename(siteconf_path)}", rel_extconf]
|
93
|
+
|
94
|
+
# add all the options
|
95
|
+
cmd += @config_options
|
96
|
+
cmd += cross_config_options(cross_platform) if cross_platform
|
97
|
+
cmd += extra_options
|
98
|
+
|
99
|
+
cmd.compact
|
100
|
+
end
|
101
|
+
|
82
102
|
private
|
83
103
|
# copy other gem files to staging directory
|
84
104
|
def define_staging_file_tasks(files, lib_path, stage_path, platf, ruby_ver)
|
@@ -188,34 +208,16 @@ Java extension should be preferred.
|
|
188
208
|
# makefile depends of tmp_dir and config_script
|
189
209
|
# tmp/extension_name/Makefile
|
190
210
|
file "#{tmp_path}/Makefile" => [tmp_path, extconf, siteconf_path] do |t|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
cmd = [Gem.ruby, "-I#{include_dirs}", "-r#{File.basename(siteconf_path)}"]
|
196
|
-
|
197
|
-
# build a relative path to extconf script
|
198
|
-
abs_tmp_path = (Pathname.new(Dir.pwd) + tmp_path).realpath
|
199
|
-
abs_extconf = (Pathname.new(Dir.pwd) + extconf).realpath
|
200
|
-
|
201
|
-
# now add the extconf script
|
202
|
-
cmd << abs_extconf.relative_path_from(abs_tmp_path).to_s
|
203
|
-
|
204
|
-
# fake.rb will be present if we are cross compiling
|
205
|
-
if t.prerequisites.include?("#{tmp_path}/fake.rb") then
|
206
|
-
options.push(*cross_config_options(platf))
|
211
|
+
if t.prerequisites.include?("#{tmp_path}/fake.rb")
|
212
|
+
cross_platform = platf
|
213
|
+
else
|
214
|
+
cross_platform = nil
|
207
215
|
end
|
208
216
|
|
209
|
-
|
210
|
-
cmd.push(*options)
|
211
|
-
|
212
|
-
# add any extra command line options
|
213
|
-
unless extra_options.empty?
|
214
|
-
cmd.push(*extra_options)
|
215
|
-
end
|
217
|
+
command = make_makefile_cmd(Dir.pwd, tmp_path, extconf, siteconf_path, cross_platform)
|
216
218
|
|
217
219
|
chdir tmp_path do
|
218
|
-
sh
|
220
|
+
sh(*command)
|
219
221
|
end
|
220
222
|
end
|
221
223
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-05-
|
12
|
+
date: 2023-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -112,12 +112,6 @@ files:
|
|
112
112
|
- lib/rake/extensioncompiler.rb
|
113
113
|
- lib/rake/extensiontask.rb
|
114
114
|
- lib/rake/javaextensiontask.rb
|
115
|
-
- spec/lib/rake/compiler_config_spec.rb
|
116
|
-
- spec/lib/rake/extensiontask_spec.rb
|
117
|
-
- spec/lib/rake/javaextensiontask_spec.rb
|
118
|
-
- spec/spec.opts
|
119
|
-
- spec/spec_helper.rb
|
120
|
-
- spec/support/capture_output_helper.rb
|
121
115
|
- tasks/bin/cross-ruby.rake
|
122
116
|
- tasks/bootstrap.rake
|
123
117
|
- tasks/common.rake
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
require 'rake/extensiontask'
|
4
|
-
require 'rbconfig'
|
5
|
-
require 'tempfile'
|
6
|
-
|
7
|
-
describe Rake::CompilerConfig do
|
8
|
-
def config_file(contents)
|
9
|
-
Tempfile.new.tap do |tf|
|
10
|
-
tf.write(contents)
|
11
|
-
tf.close
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns the matching config for exact platform match" do
|
16
|
-
cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
|
17
|
-
---
|
18
|
-
rbconfig-x86_64-linux-3.0.0: "/path/to/aaa/rbconfig.rb"
|
19
|
-
rbconfig-x86_64-darwin-3.1.0: "/path/to/bbb/rbconfig.rb"
|
20
|
-
rbconfig-x86_64-linux-3.1.0: "/path/to/ccc/rbconfig.rb"
|
21
|
-
CONFIG
|
22
|
-
|
23
|
-
expect(cc.find("3.0.0", "x86_64-linux")).to eq("/path/to/aaa/rbconfig.rb")
|
24
|
-
expect(cc.find("3.1.0", "x86_64-darwin")).to eq("/path/to/bbb/rbconfig.rb")
|
25
|
-
expect(cc.find("3.1.0", "x86_64-linux")).to eq("/path/to/ccc/rbconfig.rb")
|
26
|
-
|
27
|
-
expect(cc.find("2.7.0", "x86_64-linux")).to be_nil
|
28
|
-
expect(cc.find("3.1.0", "arm64-linux")).to be_nil
|
29
|
-
end
|
30
|
-
|
31
|
-
it "returns the matching config for inexact platform match" do
|
32
|
-
cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
|
33
|
-
---
|
34
|
-
rbconfig-x86_64-linux-gnu-3.0.0: "/path/to/aaa/rbconfig.rb"
|
35
|
-
rbconfig-x86_64-linux-musl-3.1.0: "/path/to/bbb/rbconfig.rb"
|
36
|
-
CONFIG
|
37
|
-
|
38
|
-
expect(cc.find("3.0.0", "x86_64-linux")).to eq("/path/to/aaa/rbconfig.rb")
|
39
|
-
expect(cc.find("3.1.0", "x86_64-linux")).to eq("/path/to/bbb/rbconfig.rb")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "does not match the other way around" do
|
43
|
-
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("3.3.21")
|
44
|
-
skip "rubygems 3.3.21+ only"
|
45
|
-
end
|
46
|
-
|
47
|
-
cc = Rake::CompilerConfig.new(config_file(<<~CONFIG))
|
48
|
-
---
|
49
|
-
rbconfig-x86_64-linux-3.1.0: "/path/to/bbb/rbconfig.rb"
|
50
|
-
CONFIG
|
51
|
-
|
52
|
-
expect(cc.find("3.1.0", "x86_64-linux-musl")).to be_nil
|
53
|
-
end
|
54
|
-
end
|
@@ -1,679 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
require 'rake/extensiontask'
|
4
|
-
require 'rbconfig'
|
5
|
-
require 'yaml'
|
6
|
-
|
7
|
-
describe Rake::ExtensionTask do
|
8
|
-
context '#new' do
|
9
|
-
context '(basic)' do
|
10
|
-
it 'should raise an error if no name is provided' do
|
11
|
-
lambda {
|
12
|
-
Rake::ExtensionTask.new
|
13
|
-
}.should raise_error(RuntimeError, /Extension name must be provided/)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should allow string as extension name assignation' do
|
17
|
-
ext = Rake::ExtensionTask.new('extension_one')
|
18
|
-
ext.name.should == 'extension_one'
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should allow symbol as extension name assignation' do
|
22
|
-
ext = Rake::ExtensionTask.new(:extension_one)
|
23
|
-
ext.name.should == 'extension_one'
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should allow string as extension name using block assignation' do
|
27
|
-
ext = Rake::ExtensionTask.new do |ext|
|
28
|
-
ext.name = 'extension_two'
|
29
|
-
end
|
30
|
-
ext.name.should == 'extension_two'
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should return itself for the block' do
|
34
|
-
from_block = nil
|
35
|
-
from_lasgn = Rake::ExtensionTask.new('extension_three') do |ext|
|
36
|
-
from_block = ext
|
37
|
-
end
|
38
|
-
from_block.should == from_lasgn
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should accept a gem specification as parameter' do
|
42
|
-
spec = mock_gem_spec
|
43
|
-
ext = Rake::ExtensionTask.new('extension_three', spec)
|
44
|
-
ext.gem_spec.should == spec
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should allow gem specification be defined using block assignation' do
|
48
|
-
spec = mock_gem_spec
|
49
|
-
ext = Rake::ExtensionTask.new('extension_four') do |ext|
|
50
|
-
ext.gem_spec = spec
|
51
|
-
end
|
52
|
-
ext.gem_spec.should == spec
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should allow forcing of platform' do
|
56
|
-
ext = Rake::ExtensionTask.new('weird_extension') do |ext|
|
57
|
-
ext.platform = 'universal-foo-bar-10.5'
|
58
|
-
end
|
59
|
-
ext.platform.should == 'universal-foo-bar-10.5'
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should allow extra sources to be added' do
|
63
|
-
ext = Rake::ExtensionTask.new('extension_one') do |ext|
|
64
|
-
ext.extra_sources << 'extra.c'
|
65
|
-
end
|
66
|
-
ext.extra_sources.should include('extra.c')
|
67
|
-
# Private API between the base task and the extension task
|
68
|
-
ext.send(:source_files).should include('extra.c')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context '(defaults)' do
|
74
|
-
before :each do
|
75
|
-
@ext = Rake::ExtensionTask.new('extension_one')
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should look for extconf script' do
|
79
|
-
@ext.config_script.should == 'extconf.rb'
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should dump intermediate files to tmp/' do
|
83
|
-
@ext.tmp_dir.should == 'tmp'
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should copy build extension into lib/' do
|
87
|
-
@ext.lib_dir.should == 'lib'
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should look for C/C++ files pattern (.c,.cc,.cpp)' do
|
91
|
-
@ext.source_pattern.should == "*.{c,cc,cpp}"
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should have no configuration options preset to delegate' do
|
95
|
-
@ext.config_options.should be_empty
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should have no includes preset to delegate" do
|
99
|
-
@ext.config_includes.should be_empty
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should default to current platform' do
|
103
|
-
@ext.platform.should == RUBY_PLATFORM
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should default to no cross compilation' do
|
107
|
-
@ext.cross_compile.should == false
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should have no configuration options for cross compilation' do
|
111
|
-
@ext.cross_config_options.should be_empty
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should have cross platform defined to 'i386-mingw32'" do
|
115
|
-
@ext.cross_platform.should == 'i386-mingw32'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context '(tasks)' do
|
120
|
-
before :each do
|
121
|
-
Rake.application.clear
|
122
|
-
CLEAN.clear
|
123
|
-
CLOBBER.clear
|
124
|
-
end
|
125
|
-
|
126
|
-
context '(one extension)' do
|
127
|
-
before :each do
|
128
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
|
129
|
-
@ext = Rake::ExtensionTask.new('extension_one')
|
130
|
-
@ext_bin = ext_bin('extension_one')
|
131
|
-
@platform = RUBY_PLATFORM
|
132
|
-
@ruby_ver = RUBY_VERSION
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'compile' do
|
136
|
-
it 'should define as task' do
|
137
|
-
Rake::Task.task_defined?('compile').should == true
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should depend on 'compile:{platform}'" do
|
141
|
-
Rake::Task['compile'].prerequisites.should include("compile:#{@platform}")
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'compile:extension_one' do
|
146
|
-
it 'should define as task' do
|
147
|
-
Rake::Task.task_defined?('compile:extension_one').should == true
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should depend on 'compile:extension_one:{platform}'" do
|
151
|
-
Rake::Task['compile:extension_one'].prerequisites.should include("compile:extension_one:#{@platform}")
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
context 'lib/extension_one.{so,bundle}' do
|
156
|
-
it 'should define as task' do
|
157
|
-
Rake::Task.task_defined?("lib/#{@ext_bin}").should == true
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should depend on 'copy:extension_one:{platform}:{ruby_ver}'" do
|
161
|
-
Rake::Task["lib/#{@ext_bin}"].prerequisites.should include("copy:extension_one:#{@platform}:#{@ruby_ver}")
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context 'tmp/{platform}/extension_one/{ruby_ver}/extension_one.{so,bundle}' do
|
166
|
-
it 'should define as task' do
|
167
|
-
Rake::Task.task_defined?("tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}").should == true
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should depend on 'tmp/{platform}/extension_one/{ruby_ver}/Makefile'" do
|
171
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile")
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should depend on 'ext/extension_one/source.c'" do
|
175
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should include("ext/extension_one/source.c")
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should not depend on 'ext/extension_one/source.h'" do
|
179
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should_not include("ext/extension_one/source.h")
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context 'tmp/{platform}/extension_one/{ruby_ver}/Makefile' do
|
184
|
-
it 'should define as task' do
|
185
|
-
Rake::Task.task_defined?("tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile").should == true
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should depend on 'tmp/{platform}/extension_one/{ruby_ver}'" do
|
189
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}")
|
190
|
-
end
|
191
|
-
|
192
|
-
it "should depend on 'ext/extension_one/extconf.rb'" do
|
193
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("ext/extension_one/extconf.rb")
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context 'clean' do
|
198
|
-
it "should include 'tmp/{platform}/extension_one/{ruby_ver}' in the pattern" do
|
199
|
-
CLEAN.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}")
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context 'clobber' do
|
204
|
-
it "should include 'lib/extension_one.{so,bundle}'" do
|
205
|
-
CLOBBER.should include("lib/#{@ext_bin}")
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should include 'tmp'" do
|
209
|
-
CLOBBER.should include('tmp')
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
it "should warn when pre-compiled files exist in extension directory" do
|
214
|
-
allow(Rake::FileList).to receive(:[]).
|
215
|
-
and_return(["ext/extension_one/source.c"],
|
216
|
-
["ext/extension_one/source.o"])
|
217
|
-
|
218
|
-
_, err = capture_output do
|
219
|
-
Rake::ExtensionTask.new('extension_one')
|
220
|
-
end
|
221
|
-
err.should match(/rake-compiler found compiled files in 'ext\/extension_one' directory. Please remove them./)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
context '(extension in custom location)' do
|
226
|
-
before :each do
|
227
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
|
228
|
-
@ext = Rake::ExtensionTask.new('extension_one') do |ext|
|
229
|
-
ext.ext_dir = 'custom/ext/foo'
|
230
|
-
end
|
231
|
-
@ext_bin = ext_bin('extension_one')
|
232
|
-
@platform = RUBY_PLATFORM
|
233
|
-
@ruby_ver = RUBY_VERSION
|
234
|
-
end
|
235
|
-
|
236
|
-
context 'tmp/{platform}/extension_one/{ruby_ver}/Makefile' do
|
237
|
-
it "should depend on 'custom/ext/foo/extconf.rb'" do
|
238
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("custom/ext/foo/extconf.rb")
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
context '(native tasks)' do
|
244
|
-
before :each do
|
245
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
|
246
|
-
@spec = mock_gem_spec
|
247
|
-
@ext_bin = ext_bin('extension_one')
|
248
|
-
@platform = RUBY_PLATFORM
|
249
|
-
@ruby_ver = RUBY_VERSION
|
250
|
-
end
|
251
|
-
|
252
|
-
context 'native' do
|
253
|
-
before :each do
|
254
|
-
allow(@spec).to receive(:platform=).and_return('ruby')
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'should define a task for building the supplied gem' do
|
258
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
259
|
-
Rake::Task.task_defined?('native:my_gem').should == true
|
260
|
-
end
|
261
|
-
|
262
|
-
it 'should define as task for pure ruby gems' do
|
263
|
-
Rake::Task.task_defined?('native').should == false
|
264
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
265
|
-
Rake::Task.task_defined?('native').should == true
|
266
|
-
end
|
267
|
-
|
268
|
-
it 'should not define a task for already native gems' do
|
269
|
-
allow(@spec).to receive(:platform).and_return('current')
|
270
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
271
|
-
Rake::Task.task_defined?('native').should == false
|
272
|
-
end
|
273
|
-
|
274
|
-
it 'should depend on platform specific native tasks' do
|
275
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
276
|
-
Rake::Task["native"].prerequisites.should include("native:#{@platform}")
|
277
|
-
end
|
278
|
-
|
279
|
-
context 'native:my_gem:{platform}' do
|
280
|
-
it 'should depend on binary extension' do
|
281
|
-
Rake::ExtensionTask.new('extension_one', @spec)
|
282
|
-
Rake::Task["native:my_gem:#{@platform}"].prerequisites.should include("tmp/#{@platform}/stage/lib/#{@ext_bin}")
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
context '(one extension whose name with directory prefixes)' do
|
289
|
-
before :each do
|
290
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/prefix1/prefix2/extension_one/source.c"], [])
|
291
|
-
@ext = Rake::ExtensionTask.new('prefix1/prefix2/extension_one')
|
292
|
-
@ext_bin = ext_bin('extension_one')
|
293
|
-
@platform = RUBY_PLATFORM
|
294
|
-
@ruby_ver = RUBY_VERSION
|
295
|
-
end
|
296
|
-
|
297
|
-
context 'compile' do
|
298
|
-
it 'should define as task' do
|
299
|
-
Rake::Task.task_defined?('compile').should == true
|
300
|
-
end
|
301
|
-
|
302
|
-
it "should depend on 'compile:{platform}'" do
|
303
|
-
Rake::Task['compile'].prerequisites.should include("compile:#{@platform}")
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
context 'compile:prefix1/prefix2/extension_one' do
|
308
|
-
it 'should define as task' do
|
309
|
-
Rake::Task.task_defined?('compile:prefix1/prefix2/extension_one').should == true
|
310
|
-
end
|
311
|
-
|
312
|
-
it "should depend on 'compile:prefix1/prefix2/extension_one:{platform}'" do
|
313
|
-
Rake::Task['compile:prefix1/prefix2/extension_one'].prerequisites.should include("compile:prefix1/prefix2/extension_one:#{@platform}")
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
context 'lib/prefix1/prefix2/extension_one.{so,bundle}' do
|
318
|
-
it 'should define as task' do
|
319
|
-
Rake::Task.task_defined?("lib/prefix1/prefix2/#{@ext_bin}").should == true
|
320
|
-
end
|
321
|
-
|
322
|
-
it "should depend on 'copy:prefix1/prefix2/extension_one:{platform}:{ruby_ver}'" do
|
323
|
-
Rake::Task["lib/prefix1/prefix2/#{@ext_bin}"].prerequisites.should include("copy:prefix1/prefix2/extension_one:#{@platform}:#{@ruby_ver}")
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
context 'tmp/{platform}/prefix1/prefix2/extension_one/{ruby_ver}/prefix1/prefix2/extension_one.{so,bundle}' do
|
328
|
-
it 'should define as task' do
|
329
|
-
Rake::Task.task_defined?("tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}").should == true
|
330
|
-
end
|
331
|
-
|
332
|
-
it "should depend on 'tmp/{platform}/prefix1/prefix2/extension_one/{ruby_ver}/Makefile'" do
|
333
|
-
Rake::Task["tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}"].prerequisites.should include("tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/Makefile")
|
334
|
-
end
|
335
|
-
|
336
|
-
it "should depend on 'ext/extension_one/source.c'" do
|
337
|
-
Rake::Task["tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}"].prerequisites.should include("ext/prefix1/prefix2/extension_one/source.c")
|
338
|
-
end
|
339
|
-
|
340
|
-
it "should not depend on 'ext/extension_one/source.h'" do
|
341
|
-
Rake::Task["tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}"].prerequisites.should_not include("ext/prefix1/prefix2/extension_one/source.h")
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
context '(cross platform tasks)' do
|
347
|
-
before :each do
|
348
|
-
allow(File).to receive(:exist?).and_return(true)
|
349
|
-
allow(YAML).to receive(:load_file).and_return(mock_config_yml)
|
350
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
|
351
|
-
@spec = mock_gem_spec
|
352
|
-
@config_file = File.expand_path("~/.rake-compiler/config.yml")
|
353
|
-
@ruby_ver = RUBY_VERSION
|
354
|
-
@platform = 'i386-mingw32'
|
355
|
-
@config_path = mock_config_yml["rbconfig-#{@platform}-#{@ruby_ver}"]
|
356
|
-
|
357
|
-
allow(File).to receive(:open).and_yield(mock_fake_rb)
|
358
|
-
end
|
359
|
-
|
360
|
-
context 'if no rake-compiler configuration exists' do
|
361
|
-
before :each do
|
362
|
-
expect(File).to receive(:exist?).with(@config_file).and_return(false)
|
363
|
-
|
364
|
-
_, @err = capture_output do
|
365
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
366
|
-
ext.cross_compile = true
|
367
|
-
end
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
it 'should not generate a warning' do
|
372
|
-
@err.should eq("")
|
373
|
-
end
|
374
|
-
|
375
|
-
it 'should create a dummy nested cross-compile target that raises an error' do
|
376
|
-
Rake::Task.should have_defined("cross")
|
377
|
-
Rake::Task["cross"].invoke
|
378
|
-
lambda {
|
379
|
-
Rake::Task["compile"].invoke
|
380
|
-
}.should raise_error(RuntimeError,
|
381
|
-
/rake-compiler must be configured first to enable cross-compilation/)
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
it 'should parse the config file using YAML' do
|
386
|
-
expect(YAML).to receive(:load_file).with(@config_file).and_return(mock_config_yml)
|
387
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
388
|
-
ext.cross_compile = true
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
it 'should warn if no section of config file defines running version of ruby' do
|
393
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
394
|
-
receive(:find).with(@ruby_ver, @platform).and_return(nil)
|
395
|
-
)
|
396
|
-
|
397
|
-
out, err = capture_output do
|
398
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
399
|
-
ext.cross_compile = true
|
400
|
-
end
|
401
|
-
end
|
402
|
-
err.should match(/no configuration section for specified version of Ruby/)
|
403
|
-
end
|
404
|
-
|
405
|
-
it 'should capture an action block to be executed when cross compiling' do
|
406
|
-
lambda {
|
407
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
408
|
-
ext.cross_compiling do |gem_spec|
|
409
|
-
gem_spec.post_install_message = "Cross compiled gem"
|
410
|
-
end
|
411
|
-
end
|
412
|
-
}.should_not raise_error
|
413
|
-
end
|
414
|
-
|
415
|
-
it 'should generate additional rake tasks if files are added when cross compiling' do
|
416
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
417
|
-
receive(:find).and_return("/rubies/1.9.1/rbconfig.rb")
|
418
|
-
)
|
419
|
-
|
420
|
-
# Use a real spec instead of a mock because define_native_tasks dups and
|
421
|
-
# calls methods on Gem::Specification, which is more than mock can do.
|
422
|
-
spec = Gem::Specification.new do |s|
|
423
|
-
s.name = 'my_gem'
|
424
|
-
s.platform = Gem::Platform::RUBY
|
425
|
-
end
|
426
|
-
|
427
|
-
# Gem::PackageTask calls Rake::PackageTask which sets Gem.configuration.verbose,
|
428
|
-
# which initializes Gem::ConfigFile,
|
429
|
-
# which gets mad if it cannot find `sysconfdir`/gemrc
|
430
|
-
allow(Gem).to receive_message_chain(:configuration, :verbose=).and_return(true)
|
431
|
-
|
432
|
-
ENV['RUBY_CC_VERSION'] = '1.9.1'
|
433
|
-
Rake::ExtensionTask.new('extension_one', spec) do |ext|
|
434
|
-
ext.cross_compile = true
|
435
|
-
ext.cross_platform = 'universal-unknown'
|
436
|
-
ext.cross_compiling do |gem_spec|
|
437
|
-
gem_spec.files << 'somedir/somefile'
|
438
|
-
end
|
439
|
-
end
|
440
|
-
Rake::Task['native:my_gem:universal-unknown'].execute
|
441
|
-
Rake::Task.should have_defined("tmp/universal-unknown/stage/somedir")
|
442
|
-
Rake::Task.should have_defined("tmp/universal-unknown/stage/somedir/somefile")
|
443
|
-
end
|
444
|
-
|
445
|
-
it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
|
446
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
447
|
-
receive(:find)
|
448
|
-
.with("1.9.1", "i386-mingw32")
|
449
|
-
.and_return("/rubies/1.9.1/rbconfig.rb")
|
450
|
-
)
|
451
|
-
|
452
|
-
ENV['RUBY_CC_VERSION'] = '1.9.1'
|
453
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
454
|
-
ext.cross_compile = true
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
it 'should allow multiple versions be supplied to RUBY_CC_VERSION' do
|
459
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
460
|
-
receive(:find)
|
461
|
-
.with("1.8.6", "i386-mingw32")
|
462
|
-
.and_return("/rubies/1.8.6/rbconfig.rb")
|
463
|
-
)
|
464
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
465
|
-
receive(:find)
|
466
|
-
.with("1.9.1", "i386-mingw32")
|
467
|
-
.and_return("/rubies/1.9.1/rbconfig.rb")
|
468
|
-
)
|
469
|
-
|
470
|
-
ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
|
471
|
-
Rake::ExtensionTask.new('extension_one') do |ext|
|
472
|
-
ext.cross_compile = true
|
473
|
-
end
|
474
|
-
end
|
475
|
-
|
476
|
-
it "should set required_ruby_version from RUBY_CC_VERSION, set platform, clear extensions but keep metadata" do
|
477
|
-
platforms = ["x86-mingw32", "x64-mingw32"]
|
478
|
-
ruby_cc_versions = ["1.8.6", "2.1.10", "2.2.6", "2.3.3", "2.10.1", "2.11.0"]
|
479
|
-
ENV["RUBY_CC_VERSION"] = ruby_cc_versions.join(":")
|
480
|
-
|
481
|
-
ruby_cc_versions.each do |ruby_cc_version|
|
482
|
-
platforms.each do |platform|
|
483
|
-
unless platform == "x64-mingw32" && ruby_cc_version == "2.11.0"
|
484
|
-
rbconf = "/rubies/#{ruby_cc_version}/rbconfig.rb"
|
485
|
-
end
|
486
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
487
|
-
receive(:find)
|
488
|
-
.with(ruby_cc_version, platform)
|
489
|
-
.and_return(rbconf)
|
490
|
-
)
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
allow(Gem).to receive_message_chain(:configuration, :verbose=).and_return(true)
|
495
|
-
|
496
|
-
spec = Gem::Specification.new do |s|
|
497
|
-
s.name = 'my_gem'
|
498
|
-
s.platform = Gem::Platform::RUBY
|
499
|
-
s.extensions = ['ext/somegem/extconf.rb']
|
500
|
-
s.metadata['allowed_push_host'] = 'http://test'
|
501
|
-
end
|
502
|
-
|
503
|
-
cross_specs = []
|
504
|
-
Rake::ExtensionTask.new("extension_one", spec) do |ext|
|
505
|
-
ext.cross_platform = platforms
|
506
|
-
ext.cross_compile = true
|
507
|
-
ext.cross_compiling do |cross_spec|
|
508
|
-
cross_specs << cross_spec
|
509
|
-
end
|
510
|
-
end
|
511
|
-
platforms.each do |platform|
|
512
|
-
Rake::Task["native:my_gem:#{platform}"].execute
|
513
|
-
end
|
514
|
-
|
515
|
-
expected_required_ruby_versions = [
|
516
|
-
Gem::Requirement.new([">= 1.8", "< 2.12.dev"]),
|
517
|
-
Gem::Requirement.new([">= 1.8", "< 2.11.dev"]),
|
518
|
-
]
|
519
|
-
cross_specs.collect(&:required_ruby_version).should == expected_required_ruby_versions
|
520
|
-
cross_specs.collect(&:extensions).should == [[], []]
|
521
|
-
cross_specs.collect(&:platform).collect(&:to_s).should == platforms
|
522
|
-
cross_specs.collect{|s| s.metadata['allowed_push_host']}.should == ['http://test', 'http://test']
|
523
|
-
|
524
|
-
# original gemspec should keep unchanged
|
525
|
-
spec.required_ruby_version.should == Gem::Requirement.new([">= 0"])
|
526
|
-
spec.platform.should == Gem::Platform::RUBY
|
527
|
-
spec.extensions.should == ['ext/somegem/extconf.rb']
|
528
|
-
spec.metadata['allowed_push_host'].should == 'http://test'
|
529
|
-
end
|
530
|
-
|
531
|
-
after :each do
|
532
|
-
ENV.delete('RUBY_CC_VERSION')
|
533
|
-
end
|
534
|
-
|
535
|
-
context "(cross compile for multiple versions)" do
|
536
|
-
before :each do
|
537
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
538
|
-
receive(:find)
|
539
|
-
.with("1.8.6", "universal-unknown")
|
540
|
-
.and_return("/rubies/1.8.6/rbconfig.rb")
|
541
|
-
)
|
542
|
-
allow_any_instance_of(Rake::CompilerConfig).to(
|
543
|
-
receive(:find)
|
544
|
-
.with("1.9.1", "universal-unknown")
|
545
|
-
.and_return("/rubies/1.9.1/rbconfig.rb")
|
546
|
-
)
|
547
|
-
|
548
|
-
ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
|
549
|
-
@ext = Rake::ExtensionTask.new('extension_one') do |ext|
|
550
|
-
ext.cross_compile = true
|
551
|
-
ext.cross_platform = 'universal-unknown'
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
it 'should create specific copy of binaries for each version' do
|
556
|
-
Rake::Task.should have_defined("copy:extension_one:universal-unknown:1.8.6")
|
557
|
-
Rake::Task.should have_defined("copy:extension_one:universal-unknown:1.9.1")
|
558
|
-
end
|
559
|
-
end
|
560
|
-
|
561
|
-
context "(cross for 'universal-unknown' platform)" do
|
562
|
-
before :each do
|
563
|
-
@ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
|
564
|
-
ext.cross_compile = true
|
565
|
-
ext.cross_platform = 'universal-unknown'
|
566
|
-
end
|
567
|
-
end
|
568
|
-
|
569
|
-
context 'fake' do
|
570
|
-
it 'should chain fake task to Makefile generation' do
|
571
|
-
Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/universal-unknown/extension_one/#{@ruby_ver}/fake.rb")
|
572
|
-
end
|
573
|
-
|
574
|
-
it 'should chain rbconfig tasks to fake.rb generation' do
|
575
|
-
Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/fake.rb"].prerequisites.should include(@config_path)
|
576
|
-
end
|
577
|
-
end
|
578
|
-
|
579
|
-
context 'mkmf' do
|
580
|
-
it 'should chain mkmf tasks to Makefile generation' do
|
581
|
-
Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/universal-unknown/extension_one/#{@ruby_ver}/mkmf.rb")
|
582
|
-
end
|
583
|
-
|
584
|
-
it 'should take mkmf from rake-compiler configuration' do
|
585
|
-
mkmf_path = File.expand_path(File.join(File.dirname(@config_path), '..', 'mkmf.rb'))
|
586
|
-
Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/mkmf.rb"].prerequisites.should include(mkmf_path)
|
587
|
-
end
|
588
|
-
end
|
589
|
-
|
590
|
-
context 'compile:universal-unknown' do
|
591
|
-
it "should be defined" do
|
592
|
-
Rake::Task.task_defined?('compile:universal-unknown').should == true
|
593
|
-
end
|
594
|
-
|
595
|
-
it "should depend on 'compile:extension_one:universal-unknown'" do
|
596
|
-
Rake::Task['compile:universal-unknown'].prerequisites.should include('compile:extension_one:universal-unknown')
|
597
|
-
end
|
598
|
-
end
|
599
|
-
|
600
|
-
context 'native:universal-unknown' do
|
601
|
-
it "should be defined" do
|
602
|
-
Rake::Task.task_defined?('native:universal-unknown').should == true
|
603
|
-
end
|
604
|
-
|
605
|
-
it "should depend on 'native:my_gem:universal-unknown'" do
|
606
|
-
Rake::Task['native:universal-unknown'].prerequisites.should include('native:my_gem:universal-unknown')
|
607
|
-
end
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
context '(cross for multiple platforms)' do
|
612
|
-
before :each do
|
613
|
-
@ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
|
614
|
-
ext.cross_compile = true
|
615
|
-
ext.cross_platform = ['universal-known', 'universal-unknown']
|
616
|
-
ext.cross_config_options << '--with-something'
|
617
|
-
ext.cross_config_options << {'universal-known' => '--with-known'}
|
618
|
-
end
|
619
|
-
end
|
620
|
-
|
621
|
-
it 'should define task for each supplied platform' do
|
622
|
-
Rake::Task.should have_defined('compile:universal-known')
|
623
|
-
Rake::Task.should have_defined('compile:universal-unknown')
|
624
|
-
end
|
625
|
-
|
626
|
-
it 'should filter options for each supplied platform' do
|
627
|
-
@ext.cross_config_options('universal-unknown').should eq(%w[--with-something])
|
628
|
-
@ext.cross_config_options('universal-known').should eq(%w[--with-something --with-known])
|
629
|
-
end
|
630
|
-
end
|
631
|
-
end
|
632
|
-
end
|
633
|
-
|
634
|
-
private
|
635
|
-
def ext_bin(extension_name)
|
636
|
-
"#{extension_name}.#{RbConfig::CONFIG['DLEXT']}"
|
637
|
-
end
|
638
|
-
|
639
|
-
def mock_gem_spec(stubs = {})
|
640
|
-
double(Gem::Specification,
|
641
|
-
{ :name => 'my_gem', :platform => 'ruby', :files => [] }.merge(stubs)
|
642
|
-
)
|
643
|
-
end
|
644
|
-
|
645
|
-
def mock_config_yml
|
646
|
-
return @mock_config_yml if @mock_config_yml
|
647
|
-
|
648
|
-
versions = {
|
649
|
-
"1.8.6" => "1.8",
|
650
|
-
"1.8.7" => "1.8",
|
651
|
-
"1.9.3" => "1.9.1",
|
652
|
-
"2.0.0" => "2.0.0",
|
653
|
-
"2.1.2" => "2.1.0",
|
654
|
-
RUBY_VERSION => RbConfig::CONFIG["ruby_version"]
|
655
|
-
}
|
656
|
-
|
657
|
-
platforms = [
|
658
|
-
"i386-mingw32",
|
659
|
-
"universal-known",
|
660
|
-
"universal-unknown",
|
661
|
-
"x64-mingw32",
|
662
|
-
RUBY_PLATFORM
|
663
|
-
]
|
664
|
-
|
665
|
-
@mock_config_yml = {}
|
666
|
-
|
667
|
-
platforms.collect do |platform|
|
668
|
-
versions.each do |version, api_version|
|
669
|
-
@mock_config_yml["rbconfig-#{platform}-#{version}"] = "/rubies/#{api_version}/rbconfig.rb"
|
670
|
-
end
|
671
|
-
end
|
672
|
-
|
673
|
-
@mock_config_yml
|
674
|
-
end
|
675
|
-
|
676
|
-
def mock_fake_rb
|
677
|
-
double(File, :write => 45)
|
678
|
-
end
|
679
|
-
end
|
@@ -1,237 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
require 'rake/javaextensiontask'
|
4
|
-
require 'rbconfig'
|
5
|
-
|
6
|
-
describe Rake::JavaExtensionTask do
|
7
|
-
context '#new' do
|
8
|
-
context '(basic)' do
|
9
|
-
it 'should raise an error if no name is provided' do
|
10
|
-
lambda {
|
11
|
-
Rake::JavaExtensionTask.new
|
12
|
-
}.should raise_error(RuntimeError, /Extension name must be provided/)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should allow string as extension name assignation' do
|
16
|
-
ext = Rake::JavaExtensionTask.new('extension_one')
|
17
|
-
ext.name.should == 'extension_one'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should allow string as extension name using block assignation' do
|
21
|
-
ext = Rake::JavaExtensionTask.new do |ext|
|
22
|
-
ext.name = 'extension_two'
|
23
|
-
end
|
24
|
-
ext.name.should == 'extension_two'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should return itself for the block' do
|
28
|
-
from_block = nil
|
29
|
-
from_lasgn = Rake::JavaExtensionTask.new('extension_three') do |ext|
|
30
|
-
from_block = ext
|
31
|
-
end
|
32
|
-
from_block.should == from_lasgn
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should accept a gem specification as parameter' do
|
36
|
-
spec = mock_gem_spec
|
37
|
-
ext = Rake::JavaExtensionTask.new('extension_three', spec)
|
38
|
-
ext.gem_spec.should == spec
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should allow gem specification be defined using block assignation' do
|
42
|
-
spec = mock_gem_spec
|
43
|
-
ext = Rake::JavaExtensionTask.new('extension_four') do |ext|
|
44
|
-
ext.gem_spec = spec
|
45
|
-
end
|
46
|
-
ext.gem_spec.should == spec
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should allow forcing of platform' do
|
50
|
-
ext = Rake::JavaExtensionTask.new('weird_extension') do |ext|
|
51
|
-
ext.platform = 'java-128bit'
|
52
|
-
end
|
53
|
-
ext.platform.should == 'java-128bit'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context '(defaults)' do
|
59
|
-
before :each do
|
60
|
-
@ext = Rake::JavaExtensionTask.new('extension_one')
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should dump intermediate files to tmp/' do
|
64
|
-
@ext.tmp_dir.should == 'tmp'
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should copy build extension into lib/' do
|
68
|
-
@ext.lib_dir.should == 'lib'
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should look for Java files pattern (.java)' do
|
72
|
-
@ext.source_pattern.should == "**/*.java"
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should have no configuration options preset to delegate' do
|
76
|
-
@ext.config_options.should be_empty
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should have no lint option preset to delegate' do
|
80
|
-
@ext.lint_option.should be_falsey
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should default to Java platform' do
|
84
|
-
@ext.platform.should == 'java'
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context '(tasks)' do
|
89
|
-
before :each do
|
90
|
-
Rake.application.clear
|
91
|
-
CLEAN.clear
|
92
|
-
CLOBBER.clear
|
93
|
-
end
|
94
|
-
|
95
|
-
context '(one extension)' do
|
96
|
-
before :each do
|
97
|
-
allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.java"])
|
98
|
-
@ext = Rake::JavaExtensionTask.new('extension_one')
|
99
|
-
@ext_bin = ext_bin('extension_one')
|
100
|
-
@platform = 'java'
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'compile' do
|
104
|
-
it 'should define as task' do
|
105
|
-
Rake::Task.task_defined?('compile').should == true
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should depend on 'compile:{platform}'" do
|
109
|
-
pending 'needs fixing'
|
110
|
-
Rake::Task['compile'].prerequisites.should include("compile:#{@platform}")
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'compile:extension_one' do
|
115
|
-
it 'should define as task' do
|
116
|
-
Rake::Task.task_defined?('compile:extension_one').should == true
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should depend on 'compile:extension_one:{platform}'" do
|
120
|
-
pending 'needs fixing'
|
121
|
-
Rake::Task['compile:extension_one'].prerequisites.should include("compile:extension_one:#{@platform}")
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'lib/extension_one.jar' do
|
126
|
-
it 'should define as task' do
|
127
|
-
pending 'needs fixing'
|
128
|
-
Rake::Task.task_defined?("lib/#{@ext_bin}").should be_true
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should depend on 'copy:extension_one:{platform}'" do
|
132
|
-
pending 'needs fixing'
|
133
|
-
Rake::Task["lib/#{@ext_bin}"].prerequisites.should include("copy:extension_one:#{@platform}")
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'tmp/{platform}/extension_one/extension_one.jar' do
|
138
|
-
it 'should define as task' do
|
139
|
-
Rake::Task.task_defined?("tmp/#{@platform}/extension_one/#{@ext_bin}").should == true
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should depend on checkpoint file" do
|
143
|
-
Rake::Task["tmp/#{@platform}/extension_one/#{@ext_bin}"].prerequisites.should include("tmp/#{@platform}/extension_one/.build")
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'tmp/{platform}/extension_one/.build' do
|
148
|
-
it 'should define as task' do
|
149
|
-
Rake::Task.task_defined?("tmp/#{@platform}/extension_one/.build").should == true
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'should depend on source files' do
|
153
|
-
Rake::Task["tmp/#{@platform}/extension_one/.build"].prerequisites.should include("ext/extension_one/source.java")
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'clean' do
|
158
|
-
it "should include 'tmp/{platform}/extension_one' in the pattern" do
|
159
|
-
CLEAN.should include("tmp/#{@platform}/extension_one")
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'clobber' do
|
164
|
-
it "should include 'lib/extension_one.jar'" do
|
165
|
-
CLOBBER.should include("lib/#{@ext_bin}")
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should include 'tmp'" do
|
169
|
-
CLOBBER.should include('tmp')
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
context 'A custom extension' do
|
175
|
-
let(:extension) do
|
176
|
-
Rake::JavaExtensionTask.new('extension_two') do |ext|
|
177
|
-
ext.lint_option = lint_option if lint_option
|
178
|
-
ext.release = release if release
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
context 'without a specified lint option' do
|
183
|
-
let(:lint_option) { nil }
|
184
|
-
let(:release) { nil }
|
185
|
-
|
186
|
-
it 'should honor the lint option' do
|
187
|
-
(extension.lint_option).should be_falsey
|
188
|
-
(extension.send :java_lint_arg).should eq '-Xlint'
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context "with a specified lint option of 'deprecated'" do
|
193
|
-
let(:lint_option) { 'deprecated'.freeze }
|
194
|
-
let(:release) { nil }
|
195
|
-
|
196
|
-
it 'should honor the lint option' do
|
197
|
-
(extension.lint_option).should eq lint_option
|
198
|
-
(extension.send :java_lint_arg).should eq '-Xlint:deprecated'
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context "without release option" do
|
203
|
-
let(:lint_option) { nil }
|
204
|
-
let(:release) { nil }
|
205
|
-
|
206
|
-
it 'should generate -target and -source build options' do
|
207
|
-
extension.target_version = "1.8"
|
208
|
-
extension.source_version = "1.8"
|
209
|
-
(extension.send :java_target_args).should eq ["-target", "1.8", "-source", "1.8"]
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context "with release option" do
|
214
|
-
let(:lint_option) { nil }
|
215
|
-
let(:release) { '8' }
|
216
|
-
|
217
|
-
it 'should generate --release option even with target_version/source_version' do
|
218
|
-
extension.target_version = "1.8"
|
219
|
-
extension.source_version = "1.8"
|
220
|
-
(extension.send :java_target_args).should eq ["--release=8"]
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
private
|
226
|
-
|
227
|
-
def ext_bin(extension_name)
|
228
|
-
"#{extension_name}.jar"
|
229
|
-
end
|
230
|
-
|
231
|
-
def mock_gem_spec(stubs = {})
|
232
|
-
double(Gem::Specification,
|
233
|
-
{ :name => 'my_gem', :platform => 'ruby' }.merge(stubs)
|
234
|
-
)
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
|
3
|
-
# Console redirection helper
|
4
|
-
require File.expand_path('../support/capture_output_helper', __FILE__)
|
5
|
-
|
6
|
-
RSpec.configure do |config|
|
7
|
-
config.include CaptureOutputHelper
|
8
|
-
end
|
9
|
-
|
10
|
-
# Rake::Task matcher helper
|
11
|
-
RSpec::Matchers.define :have_defined do |task|
|
12
|
-
match do |tasks|
|
13
|
-
tasks.task_defined?(task)
|
14
|
-
end
|
15
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module CaptureOutputHelper
|
2
|
-
def capture_output(&block)
|
3
|
-
old_stdout = $stdout
|
4
|
-
old_stderr = $stderr
|
5
|
-
|
6
|
-
stream_out = StringIO.new
|
7
|
-
stream_err = StringIO.new
|
8
|
-
|
9
|
-
begin
|
10
|
-
$stdout = stream_out
|
11
|
-
$stderr = stream_err
|
12
|
-
yield
|
13
|
-
ensure
|
14
|
-
$stdout = old_stdout
|
15
|
-
$stderr = old_stderr
|
16
|
-
end
|
17
|
-
stream_out.rewind
|
18
|
-
stream_err.rewind
|
19
|
-
|
20
|
-
[stream_out.read, stream_err.read]
|
21
|
-
end
|
22
|
-
end
|