rake-compiler 1.2.1 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 530d28062d0a6bc7601e7aec15adba736048594ad4e0026dff17594f4462a2ca
4
- data.tar.gz: 94dea28437dd1dedaef5a48f7eb13672102bc11d43a371e755d593126cac20b7
3
+ metadata.gz: 348048ed79bcda098bdaa8f8fa523e2e3b85263911f81ccbb173b879d2d9fd05
4
+ data.tar.gz: 2485652f621bcb18ee6a552d2a278ddf6f8cbe584848d6d14799325e1cdad1bd
5
5
  SHA512:
6
- metadata.gz: 8c4066120b1718f19299eacfee717a8efd7ca381078124e38107b372f3925791b9016aa6048bd773c6aebf6875e94937cb5eff38365e759c665102e6f55e8b1f
7
- data.tar.gz: 804376554f6efa4c5b4e62b28b2d18cbffb0273c0de6e0bbc3fb7674dc4669a1bab83e121c3dd2bb1f5c1a1cffc89b5977ca96410c7599b589affbe075c0abd9
6
+ metadata.gz: a2053558c9908644a0aea5a3fd758b2ee11bf8b57e7e91dd9cb794acd391b5ea35232ad75780f2f86e394c0867fcde13e2fef0913990feff8f1d5dd6745b16f0
7
+ data.tar.gz: 0e2da4951102147e9e92e88fbcfd5f6bef58462f82a0c012a22aeaca451d2629994b20db243b7ea93ca09b8682b03ed6229ef8a46b7fada9c76729e6d3c8fbba
data/History.md CHANGED
@@ -1,3 +1,37 @@
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
+
15
+ ### 1.2.2 / 2023-05-25
16
+
17
+ * Enhancements:
18
+ * GH-211: Added `extra_sources` that is for dynamic sources.
19
+ [Patch by James Tucker]
20
+ * GH-213: Stopped using `--release` on Java 8.
21
+ [Patch by James Pavel Rosický]
22
+ * GH-215: Added support for extra options with space.
23
+ [Reported by Jun Aruga]
24
+
25
+ * Fixes:
26
+ * GH-212: Fixed a typo in documentation.
27
+ [Patch by Jan-Benedikt Jagusch]
28
+
29
+ * Thanks:
30
+ * James Tucker
31
+ * Jan-Benedikt Jagusch
32
+ * Pavel Rosický
33
+ * Jun Aruga
34
+
1
35
  ### 1.2.1 / 2022-12-16
2
36
 
3
37
  * Enhancements:
data/README.md CHANGED
@@ -349,7 +349,7 @@ Now, you only need specify a few additional options in your extension definition
349
349
  # platform build, with platform-specific options in a hash.
350
350
  ext.cross_config_options << '--with-common-option'
351
351
  ext.cross_config_options << {
352
- 'x86-mswin32-60 => '--with-some-option',
352
+ 'x86-mswin32-60' => '--with-some-option',
353
353
  'x64-mingw32' => '--enable-64bits',
354
354
  }
355
355
  ext.cross_config_options << '--with-final-option'
@@ -18,6 +18,7 @@ module Rake
18
18
  attr_accessor :config_options
19
19
  attr_accessor :source_pattern
20
20
  attr_accessor :extra_options
21
+ attr_accessor :extra_sources
21
22
  attr_writer :platform
22
23
 
23
24
  def platform
@@ -41,6 +42,7 @@ module Rake
41
42
  end
42
43
  @config_options = []
43
44
  @extra_options = ARGV.select { |i| i =~ /\A--?/ }
45
+ @extra_sources = FileList[]
44
46
  end
45
47
 
46
48
  def define
@@ -71,7 +73,7 @@ module Rake
71
73
  end
72
74
 
73
75
  def source_files
74
- FileList["#{@ext_dir}/#{@source_pattern}"]
76
+ FileList["#{@ext_dir}/#{@source_pattern}"] + @extra_sources
75
77
  end
76
78
 
77
79
  def warn_once(message)
@@ -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,36 +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
- options = @config_options.dup
192
-
193
- # include current directory
194
- include_dirs = ['.'].concat(@config_includes).uniq.join(File::PATH_SEPARATOR)
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)
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
- # add options to command
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
- # FIXME: Rake is broken for multiple arguments system() calls.
219
- # Add current directory to the search path of Ruby
220
- sh cmd.join(' ')
220
+ sh(*command)
221
221
  end
222
222
  end
223
223
 
@@ -212,7 +212,7 @@ execute the Rake compilation task using the JRuby interpreter.
212
212
  end
213
213
 
214
214
  def java_target_args
215
- if @release
215
+ if @release && release_flag_supported?
216
216
  ["--release=#{@release}"]
217
217
  else
218
218
  ["-target", @target_version, "-source", @source_version]
@@ -303,5 +303,11 @@ execute the Rake compilation task using the JRuby interpreter.
303
303
 
304
304
  "-Xlint:#{@lint_option}"
305
305
  end
306
+
307
+ def release_flag_supported?
308
+ return true unless RUBY_PLATFORM =~ /java/
309
+
310
+ Gem::Version.new(Java::java.lang.System.getProperty('java.version')) >= Gem::Version.new("9")
311
+ end
306
312
  end
307
313
  end
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.1
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: 2022-12-16 00:00:00.000000000 Z
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
@@ -147,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
141
  - !ruby/object:Gem::Version
148
142
  version: 1.8.23
149
143
  requirements: []
150
- rubygems_version: 3.4.0.dev
144
+ rubygems_version: 3.5.0.dev
151
145
  signing_key:
152
146
  specification_version: 4
153
147
  summary: Rake-based Ruby Extension (C, Java) task generator.
@@ -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,670 +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
- end
62
- end
63
-
64
- context '(defaults)' do
65
- before :each do
66
- @ext = Rake::ExtensionTask.new('extension_one')
67
- end
68
-
69
- it 'should look for extconf script' do
70
- @ext.config_script.should == 'extconf.rb'
71
- end
72
-
73
- it 'should dump intermediate files to tmp/' do
74
- @ext.tmp_dir.should == 'tmp'
75
- end
76
-
77
- it 'should copy build extension into lib/' do
78
- @ext.lib_dir.should == 'lib'
79
- end
80
-
81
- it 'should look for C/C++ files pattern (.c,.cc,.cpp)' do
82
- @ext.source_pattern.should == "*.{c,cc,cpp}"
83
- end
84
-
85
- it 'should have no configuration options preset to delegate' do
86
- @ext.config_options.should be_empty
87
- end
88
-
89
- it "should have no includes preset to delegate" do
90
- @ext.config_includes.should be_empty
91
- end
92
-
93
- it 'should default to current platform' do
94
- @ext.platform.should == RUBY_PLATFORM
95
- end
96
-
97
- it 'should default to no cross compilation' do
98
- @ext.cross_compile.should == false
99
- end
100
-
101
- it 'should have no configuration options for cross compilation' do
102
- @ext.cross_config_options.should be_empty
103
- end
104
-
105
- it "should have cross platform defined to 'i386-mingw32'" do
106
- @ext.cross_platform.should == 'i386-mingw32'
107
- end
108
- end
109
-
110
- context '(tasks)' do
111
- before :each do
112
- Rake.application.clear
113
- CLEAN.clear
114
- CLOBBER.clear
115
- end
116
-
117
- context '(one extension)' do
118
- before :each do
119
- allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
120
- @ext = Rake::ExtensionTask.new('extension_one')
121
- @ext_bin = ext_bin('extension_one')
122
- @platform = RUBY_PLATFORM
123
- @ruby_ver = RUBY_VERSION
124
- end
125
-
126
- context 'compile' do
127
- it 'should define as task' do
128
- Rake::Task.task_defined?('compile').should == true
129
- end
130
-
131
- it "should depend on 'compile:{platform}'" do
132
- Rake::Task['compile'].prerequisites.should include("compile:#{@platform}")
133
- end
134
- end
135
-
136
- context 'compile:extension_one' do
137
- it 'should define as task' do
138
- Rake::Task.task_defined?('compile:extension_one').should == true
139
- end
140
-
141
- it "should depend on 'compile:extension_one:{platform}'" do
142
- Rake::Task['compile:extension_one'].prerequisites.should include("compile:extension_one:#{@platform}")
143
- end
144
- end
145
-
146
- context 'lib/extension_one.{so,bundle}' do
147
- it 'should define as task' do
148
- Rake::Task.task_defined?("lib/#{@ext_bin}").should == true
149
- end
150
-
151
- it "should depend on 'copy:extension_one:{platform}:{ruby_ver}'" do
152
- Rake::Task["lib/#{@ext_bin}"].prerequisites.should include("copy:extension_one:#{@platform}:#{@ruby_ver}")
153
- end
154
- end
155
-
156
- context 'tmp/{platform}/extension_one/{ruby_ver}/extension_one.{so,bundle}' do
157
- it 'should define as task' do
158
- Rake::Task.task_defined?("tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}").should == true
159
- end
160
-
161
- it "should depend on 'tmp/{platform}/extension_one/{ruby_ver}/Makefile'" do
162
- Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile")
163
- end
164
-
165
- it "should depend on 'ext/extension_one/source.c'" do
166
- Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should include("ext/extension_one/source.c")
167
- end
168
-
169
- it "should not depend on 'ext/extension_one/source.h'" do
170
- Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/#{@ext_bin}"].prerequisites.should_not include("ext/extension_one/source.h")
171
- end
172
- end
173
-
174
- context 'tmp/{platform}/extension_one/{ruby_ver}/Makefile' do
175
- it 'should define as task' do
176
- Rake::Task.task_defined?("tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile").should == true
177
- end
178
-
179
- it "should depend on 'tmp/{platform}/extension_one/{ruby_ver}'" do
180
- Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}")
181
- end
182
-
183
- it "should depend on 'ext/extension_one/extconf.rb'" do
184
- Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("ext/extension_one/extconf.rb")
185
- end
186
- end
187
-
188
- context 'clean' do
189
- it "should include 'tmp/{platform}/extension_one/{ruby_ver}' in the pattern" do
190
- CLEAN.should include("tmp/#{@platform}/extension_one/#{@ruby_ver}")
191
- end
192
- end
193
-
194
- context 'clobber' do
195
- it "should include 'lib/extension_one.{so,bundle}'" do
196
- CLOBBER.should include("lib/#{@ext_bin}")
197
- end
198
-
199
- it "should include 'tmp'" do
200
- CLOBBER.should include('tmp')
201
- end
202
- end
203
-
204
- it "should warn when pre-compiled files exist in extension directory" do
205
- allow(Rake::FileList).to receive(:[]).
206
- and_return(["ext/extension_one/source.c"],
207
- ["ext/extension_one/source.o"])
208
-
209
- _, err = capture_output do
210
- Rake::ExtensionTask.new('extension_one')
211
- end
212
- err.should match(/rake-compiler found compiled files in 'ext\/extension_one' directory. Please remove them./)
213
- end
214
- end
215
-
216
- context '(extension in custom location)' do
217
- before :each do
218
- allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
219
- @ext = Rake::ExtensionTask.new('extension_one') do |ext|
220
- ext.ext_dir = 'custom/ext/foo'
221
- end
222
- @ext_bin = ext_bin('extension_one')
223
- @platform = RUBY_PLATFORM
224
- @ruby_ver = RUBY_VERSION
225
- end
226
-
227
- context 'tmp/{platform}/extension_one/{ruby_ver}/Makefile' do
228
- it "should depend on 'custom/ext/foo/extconf.rb'" do
229
- Rake::Task["tmp/#{@platform}/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("custom/ext/foo/extconf.rb")
230
- end
231
- end
232
- end
233
-
234
- context '(native tasks)' do
235
- before :each do
236
- allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
237
- @spec = mock_gem_spec
238
- @ext_bin = ext_bin('extension_one')
239
- @platform = RUBY_PLATFORM
240
- @ruby_ver = RUBY_VERSION
241
- end
242
-
243
- context 'native' do
244
- before :each do
245
- allow(@spec).to receive(:platform=).and_return('ruby')
246
- end
247
-
248
- it 'should define a task for building the supplied gem' do
249
- Rake::ExtensionTask.new('extension_one', @spec)
250
- Rake::Task.task_defined?('native:my_gem').should == true
251
- end
252
-
253
- it 'should define as task for pure ruby gems' do
254
- Rake::Task.task_defined?('native').should == false
255
- Rake::ExtensionTask.new('extension_one', @spec)
256
- Rake::Task.task_defined?('native').should == true
257
- end
258
-
259
- it 'should not define a task for already native gems' do
260
- allow(@spec).to receive(:platform).and_return('current')
261
- Rake::ExtensionTask.new('extension_one', @spec)
262
- Rake::Task.task_defined?('native').should == false
263
- end
264
-
265
- it 'should depend on platform specific native tasks' do
266
- Rake::ExtensionTask.new('extension_one', @spec)
267
- Rake::Task["native"].prerequisites.should include("native:#{@platform}")
268
- end
269
-
270
- context 'native:my_gem:{platform}' do
271
- it 'should depend on binary extension' do
272
- Rake::ExtensionTask.new('extension_one', @spec)
273
- Rake::Task["native:my_gem:#{@platform}"].prerequisites.should include("tmp/#{@platform}/stage/lib/#{@ext_bin}")
274
- end
275
- end
276
- end
277
- end
278
-
279
- context '(one extension whose name with directory prefixes)' do
280
- before :each do
281
- allow(Rake::FileList).to receive(:[]).and_return(["ext/prefix1/prefix2/extension_one/source.c"], [])
282
- @ext = Rake::ExtensionTask.new('prefix1/prefix2/extension_one')
283
- @ext_bin = ext_bin('extension_one')
284
- @platform = RUBY_PLATFORM
285
- @ruby_ver = RUBY_VERSION
286
- end
287
-
288
- context 'compile' do
289
- it 'should define as task' do
290
- Rake::Task.task_defined?('compile').should == true
291
- end
292
-
293
- it "should depend on 'compile:{platform}'" do
294
- Rake::Task['compile'].prerequisites.should include("compile:#{@platform}")
295
- end
296
- end
297
-
298
- context 'compile:prefix1/prefix2/extension_one' do
299
- it 'should define as task' do
300
- Rake::Task.task_defined?('compile:prefix1/prefix2/extension_one').should == true
301
- end
302
-
303
- it "should depend on 'compile:prefix1/prefix2/extension_one:{platform}'" do
304
- Rake::Task['compile:prefix1/prefix2/extension_one'].prerequisites.should include("compile:prefix1/prefix2/extension_one:#{@platform}")
305
- end
306
- end
307
-
308
- context 'lib/prefix1/prefix2/extension_one.{so,bundle}' do
309
- it 'should define as task' do
310
- Rake::Task.task_defined?("lib/prefix1/prefix2/#{@ext_bin}").should == true
311
- end
312
-
313
- it "should depend on 'copy:prefix1/prefix2/extension_one:{platform}:{ruby_ver}'" do
314
- Rake::Task["lib/prefix1/prefix2/#{@ext_bin}"].prerequisites.should include("copy:prefix1/prefix2/extension_one:#{@platform}:#{@ruby_ver}")
315
- end
316
- end
317
-
318
- context 'tmp/{platform}/prefix1/prefix2/extension_one/{ruby_ver}/prefix1/prefix2/extension_one.{so,bundle}' do
319
- it 'should define as task' do
320
- Rake::Task.task_defined?("tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}").should == true
321
- end
322
-
323
- it "should depend on 'tmp/{platform}/prefix1/prefix2/extension_one/{ruby_ver}/Makefile'" do
324
- 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")
325
- end
326
-
327
- it "should depend on 'ext/extension_one/source.c'" do
328
- Rake::Task["tmp/#{@platform}/prefix1/prefix2/extension_one/#{@ruby_ver}/prefix1/prefix2/#{@ext_bin}"].prerequisites.should include("ext/prefix1/prefix2/extension_one/source.c")
329
- end
330
-
331
- it "should not depend on 'ext/extension_one/source.h'" do
332
- 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")
333
- end
334
- end
335
- end
336
-
337
- context '(cross platform tasks)' do
338
- before :each do
339
- allow(File).to receive(:exist?).and_return(true)
340
- allow(YAML).to receive(:load_file).and_return(mock_config_yml)
341
- allow(Rake::FileList).to receive(:[]).and_return(["ext/extension_one/source.c"], [])
342
- @spec = mock_gem_spec
343
- @config_file = File.expand_path("~/.rake-compiler/config.yml")
344
- @ruby_ver = RUBY_VERSION
345
- @platform = 'i386-mingw32'
346
- @config_path = mock_config_yml["rbconfig-#{@platform}-#{@ruby_ver}"]
347
-
348
- allow(File).to receive(:open).and_yield(mock_fake_rb)
349
- end
350
-
351
- context 'if no rake-compiler configuration exists' do
352
- before :each do
353
- expect(File).to receive(:exist?).with(@config_file).and_return(false)
354
-
355
- _, @err = capture_output do
356
- Rake::ExtensionTask.new('extension_one') do |ext|
357
- ext.cross_compile = true
358
- end
359
- end
360
- end
361
-
362
- it 'should not generate a warning' do
363
- @err.should eq("")
364
- end
365
-
366
- it 'should create a dummy nested cross-compile target that raises an error' do
367
- Rake::Task.should have_defined("cross")
368
- Rake::Task["cross"].invoke
369
- lambda {
370
- Rake::Task["compile"].invoke
371
- }.should raise_error(RuntimeError,
372
- /rake-compiler must be configured first to enable cross-compilation/)
373
- end
374
- end
375
-
376
- it 'should parse the config file using YAML' do
377
- expect(YAML).to receive(:load_file).with(@config_file).and_return(mock_config_yml)
378
- Rake::ExtensionTask.new('extension_one') do |ext|
379
- ext.cross_compile = true
380
- end
381
- end
382
-
383
- it 'should warn if no section of config file defines running version of ruby' do
384
- allow_any_instance_of(Rake::CompilerConfig).to(
385
- receive(:find).with(@ruby_ver, @platform).and_return(nil)
386
- )
387
-
388
- out, err = capture_output do
389
- Rake::ExtensionTask.new('extension_one') do |ext|
390
- ext.cross_compile = true
391
- end
392
- end
393
- err.should match(/no configuration section for specified version of Ruby/)
394
- end
395
-
396
- it 'should capture an action block to be executed when cross compiling' do
397
- lambda {
398
- Rake::ExtensionTask.new('extension_one') do |ext|
399
- ext.cross_compiling do |gem_spec|
400
- gem_spec.post_install_message = "Cross compiled gem"
401
- end
402
- end
403
- }.should_not raise_error
404
- end
405
-
406
- it 'should generate additional rake tasks if files are added when cross compiling' do
407
- allow_any_instance_of(Rake::CompilerConfig).to(
408
- receive(:find).and_return("/rubies/1.9.1/rbconfig.rb")
409
- )
410
-
411
- # Use a real spec instead of a mock because define_native_tasks dups and
412
- # calls methods on Gem::Specification, which is more than mock can do.
413
- spec = Gem::Specification.new do |s|
414
- s.name = 'my_gem'
415
- s.platform = Gem::Platform::RUBY
416
- end
417
-
418
- # Gem::PackageTask calls Rake::PackageTask which sets Gem.configuration.verbose,
419
- # which initializes Gem::ConfigFile,
420
- # which gets mad if it cannot find `sysconfdir`/gemrc
421
- allow(Gem).to receive_message_chain(:configuration, :verbose=).and_return(true)
422
-
423
- ENV['RUBY_CC_VERSION'] = '1.9.1'
424
- Rake::ExtensionTask.new('extension_one', spec) do |ext|
425
- ext.cross_compile = true
426
- ext.cross_platform = 'universal-unknown'
427
- ext.cross_compiling do |gem_spec|
428
- gem_spec.files << 'somedir/somefile'
429
- end
430
- end
431
- Rake::Task['native:my_gem:universal-unknown'].execute
432
- Rake::Task.should have_defined("tmp/universal-unknown/stage/somedir")
433
- Rake::Task.should have_defined("tmp/universal-unknown/stage/somedir/somefile")
434
- end
435
-
436
- it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
437
- allow_any_instance_of(Rake::CompilerConfig).to(
438
- receive(:find)
439
- .with("1.9.1", "i386-mingw32")
440
- .and_return("/rubies/1.9.1/rbconfig.rb")
441
- )
442
-
443
- ENV['RUBY_CC_VERSION'] = '1.9.1'
444
- Rake::ExtensionTask.new('extension_one') do |ext|
445
- ext.cross_compile = true
446
- end
447
- end
448
-
449
- it 'should allow multiple versions be supplied to RUBY_CC_VERSION' do
450
- allow_any_instance_of(Rake::CompilerConfig).to(
451
- receive(:find)
452
- .with("1.8.6", "i386-mingw32")
453
- .and_return("/rubies/1.8.6/rbconfig.rb")
454
- )
455
- allow_any_instance_of(Rake::CompilerConfig).to(
456
- receive(:find)
457
- .with("1.9.1", "i386-mingw32")
458
- .and_return("/rubies/1.9.1/rbconfig.rb")
459
- )
460
-
461
- ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
462
- Rake::ExtensionTask.new('extension_one') do |ext|
463
- ext.cross_compile = true
464
- end
465
- end
466
-
467
- it "should set required_ruby_version from RUBY_CC_VERSION, set platform, clear extensions but keep metadata" do
468
- platforms = ["x86-mingw32", "x64-mingw32"]
469
- ruby_cc_versions = ["1.8.6", "2.1.10", "2.2.6", "2.3.3", "2.10.1", "2.11.0"]
470
- ENV["RUBY_CC_VERSION"] = ruby_cc_versions.join(":")
471
-
472
- ruby_cc_versions.each do |ruby_cc_version|
473
- platforms.each do |platform|
474
- unless platform == "x64-mingw32" && ruby_cc_version == "2.11.0"
475
- rbconf = "/rubies/#{ruby_cc_version}/rbconfig.rb"
476
- end
477
- allow_any_instance_of(Rake::CompilerConfig).to(
478
- receive(:find)
479
- .with(ruby_cc_version, platform)
480
- .and_return(rbconf)
481
- )
482
- end
483
- end
484
-
485
- allow(Gem).to receive_message_chain(:configuration, :verbose=).and_return(true)
486
-
487
- spec = Gem::Specification.new do |s|
488
- s.name = 'my_gem'
489
- s.platform = Gem::Platform::RUBY
490
- s.extensions = ['ext/somegem/extconf.rb']
491
- s.metadata['allowed_push_host'] = 'http://test'
492
- end
493
-
494
- cross_specs = []
495
- Rake::ExtensionTask.new("extension_one", spec) do |ext|
496
- ext.cross_platform = platforms
497
- ext.cross_compile = true
498
- ext.cross_compiling do |cross_spec|
499
- cross_specs << cross_spec
500
- end
501
- end
502
- platforms.each do |platform|
503
- Rake::Task["native:my_gem:#{platform}"].execute
504
- end
505
-
506
- expected_required_ruby_versions = [
507
- Gem::Requirement.new([">= 1.8", "< 2.12.dev"]),
508
- Gem::Requirement.new([">= 1.8", "< 2.11.dev"]),
509
- ]
510
- cross_specs.collect(&:required_ruby_version).should == expected_required_ruby_versions
511
- cross_specs.collect(&:extensions).should == [[], []]
512
- cross_specs.collect(&:platform).collect(&:to_s).should == platforms
513
- cross_specs.collect{|s| s.metadata['allowed_push_host']}.should == ['http://test', 'http://test']
514
-
515
- # original gemspec should keep unchanged
516
- spec.required_ruby_version.should == Gem::Requirement.new([">= 0"])
517
- spec.platform.should == Gem::Platform::RUBY
518
- spec.extensions.should == ['ext/somegem/extconf.rb']
519
- spec.metadata['allowed_push_host'].should == 'http://test'
520
- end
521
-
522
- after :each do
523
- ENV.delete('RUBY_CC_VERSION')
524
- end
525
-
526
- context "(cross compile for multiple versions)" do
527
- before :each do
528
- allow_any_instance_of(Rake::CompilerConfig).to(
529
- receive(:find)
530
- .with("1.8.6", "universal-unknown")
531
- .and_return("/rubies/1.8.6/rbconfig.rb")
532
- )
533
- allow_any_instance_of(Rake::CompilerConfig).to(
534
- receive(:find)
535
- .with("1.9.1", "universal-unknown")
536
- .and_return("/rubies/1.9.1/rbconfig.rb")
537
- )
538
-
539
- ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
540
- @ext = Rake::ExtensionTask.new('extension_one') do |ext|
541
- ext.cross_compile = true
542
- ext.cross_platform = 'universal-unknown'
543
- end
544
- end
545
-
546
- it 'should create specific copy of binaries for each version' do
547
- Rake::Task.should have_defined("copy:extension_one:universal-unknown:1.8.6")
548
- Rake::Task.should have_defined("copy:extension_one:universal-unknown:1.9.1")
549
- end
550
- end
551
-
552
- context "(cross for 'universal-unknown' platform)" do
553
- before :each do
554
- @ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
555
- ext.cross_compile = true
556
- ext.cross_platform = 'universal-unknown'
557
- end
558
- end
559
-
560
- context 'fake' do
561
- it 'should chain fake task to Makefile generation' do
562
- Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/universal-unknown/extension_one/#{@ruby_ver}/fake.rb")
563
- end
564
-
565
- it 'should chain rbconfig tasks to fake.rb generation' do
566
- Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/fake.rb"].prerequisites.should include(@config_path)
567
- end
568
- end
569
-
570
- context 'mkmf' do
571
- it 'should chain mkmf tasks to Makefile generation' do
572
- Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/Makefile"].prerequisites.should include("tmp/universal-unknown/extension_one/#{@ruby_ver}/mkmf.rb")
573
- end
574
-
575
- it 'should take mkmf from rake-compiler configuration' do
576
- mkmf_path = File.expand_path(File.join(File.dirname(@config_path), '..', 'mkmf.rb'))
577
- Rake::Task["tmp/universal-unknown/extension_one/#{@ruby_ver}/mkmf.rb"].prerequisites.should include(mkmf_path)
578
- end
579
- end
580
-
581
- context 'compile:universal-unknown' do
582
- it "should be defined" do
583
- Rake::Task.task_defined?('compile:universal-unknown').should == true
584
- end
585
-
586
- it "should depend on 'compile:extension_one:universal-unknown'" do
587
- Rake::Task['compile:universal-unknown'].prerequisites.should include('compile:extension_one:universal-unknown')
588
- end
589
- end
590
-
591
- context 'native:universal-unknown' do
592
- it "should be defined" do
593
- Rake::Task.task_defined?('native:universal-unknown').should == true
594
- end
595
-
596
- it "should depend on 'native:my_gem:universal-unknown'" do
597
- Rake::Task['native:universal-unknown'].prerequisites.should include('native:my_gem:universal-unknown')
598
- end
599
- end
600
- end
601
-
602
- context '(cross for multiple platforms)' do
603
- before :each do
604
- @ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
605
- ext.cross_compile = true
606
- ext.cross_platform = ['universal-known', 'universal-unknown']
607
- ext.cross_config_options << '--with-something'
608
- ext.cross_config_options << {'universal-known' => '--with-known'}
609
- end
610
- end
611
-
612
- it 'should define task for each supplied platform' do
613
- Rake::Task.should have_defined('compile:universal-known')
614
- Rake::Task.should have_defined('compile:universal-unknown')
615
- end
616
-
617
- it 'should filter options for each supplied platform' do
618
- @ext.cross_config_options('universal-unknown').should eq(%w[--with-something])
619
- @ext.cross_config_options('universal-known').should eq(%w[--with-something --with-known])
620
- end
621
- end
622
- end
623
- end
624
-
625
- private
626
- def ext_bin(extension_name)
627
- "#{extension_name}.#{RbConfig::CONFIG['DLEXT']}"
628
- end
629
-
630
- def mock_gem_spec(stubs = {})
631
- double(Gem::Specification,
632
- { :name => 'my_gem', :platform => 'ruby', :files => [] }.merge(stubs)
633
- )
634
- end
635
-
636
- def mock_config_yml
637
- return @mock_config_yml if @mock_config_yml
638
-
639
- versions = {
640
- "1.8.6" => "1.8",
641
- "1.8.7" => "1.8",
642
- "1.9.3" => "1.9.1",
643
- "2.0.0" => "2.0.0",
644
- "2.1.2" => "2.1.0",
645
- RUBY_VERSION => RbConfig::CONFIG["ruby_version"]
646
- }
647
-
648
- platforms = [
649
- "i386-mingw32",
650
- "universal-known",
651
- "universal-unknown",
652
- "x64-mingw32",
653
- RUBY_PLATFORM
654
- ]
655
-
656
- @mock_config_yml = {}
657
-
658
- platforms.collect do |platform|
659
- versions.each do |version, api_version|
660
- @mock_config_yml["rbconfig-#{platform}-#{version}"] = "/rubies/#{api_version}/rbconfig.rb"
661
- end
662
- end
663
-
664
- @mock_config_yml
665
- end
666
-
667
- def mock_fake_rb
668
- double(File, :write => 45)
669
- end
670
- 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
@@ -1,3 +0,0 @@
1
- --colour
2
- --format nested
3
- --loadby mtime
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