rake-compiler 1.2.0 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 168f62a83a0e87ed5dd8ddc21151082d826a18af8baa3319be221704fd559e1b
4
- data.tar.gz: 62247a212ea5dce5803ef33d4490d3a6a982e5bf78716a5da0339e1c980b467a
3
+ metadata.gz: 1307a1f8d635b6fa407ce62a9e301a9d2ccfb358fb77e3ed85c3d22492fd6a1e
4
+ data.tar.gz: d562c91bfee82d65d39b67b118c9b9395e33be402b2c41058d4251ae2e88a37f
5
5
  SHA512:
6
- metadata.gz: 5857be6b32518649261bb405df56b6986083e019f38621801323aea374544a9771c30bca2f7cc539c7fc8cd4f0cc44b8861f93bab4877ff4bfc45aecbb6e5d44
7
- data.tar.gz: 61c4b8db10ff10e4b8ec45a7688241689981bc3c70f2a2b7eb2eebf877e9ca623844f70e70858daf899812a7ef8deb7c13c77b9fc0570d3bdcff7d367b445e07
6
+ metadata.gz: 1d1c34c803284711dff655cd8b4d7a34766d1ade90556ffeed111349777c67e143a55705bda5bce95f6629c2bc45a7e528da666f20595cb45c7e2986ee3c9269
7
+ data.tar.gz: dfabaa0805a27ee2150a406a2e7e26c6345ea279866e271c1936ab95b8090a0bb6fa0919a42509ae4d6652e8d249a694c4b70b7ace351335afb7cbace8fa7cf8
data/History.md CHANGED
@@ -1,3 +1,37 @@
1
+ ### 1.2.2 / 2023-05-25
2
+
3
+ * Enhancements:
4
+ * GH-211: Added `extra_sources` that is for dynamic sources.
5
+ [Patch by James Tucker]
6
+ * GH-213: Stopped using `--release` on Java 8.
7
+ [Patch by James Pavel Rosický]
8
+ * GH-215: Added support for extra options with space.
9
+ [Reported by Jun Aruga]
10
+
11
+ * Fixes:
12
+ * GH-211: Fixed a typo in documentation.
13
+ [Patch by Jan-Benedikt Jagusch]
14
+
15
+ * Thanks:
16
+ * James Tucker
17
+ * Jan-Benedikt Jagusch
18
+ * Pavel Rosický
19
+ * Jun Aruga
20
+
21
+ ### 1.2.1 / 2022-12-16
22
+
23
+ * Enhancements:
24
+ * GH-209: Added support for RubyGems 3.3.21 or later.
25
+ [Patch by Mike Dalessio]
26
+
27
+ * Fixes:
28
+ * GH-208: Fixed a typo in documentation.
29
+ [Patch by Garen Torikian]
30
+
31
+ * Thanks:
32
+ * Garen Torikian
33
+ * Mike Dalessio
34
+
1
35
  ### 1.2.0 / 2022-04-15
2
36
 
3
37
  * Enhancements:
data/README.md CHANGED
@@ -241,7 +241,7 @@ several settings for `Rake::ExtensionTask`:
241
241
  | no_native | ExtensionTask (CRuby) | [Optional] Set to true to prevent non-CRuby platforms from defining native tasks. Default: `false`. |
242
242
  | config_includes | ExtensionTask (CRuby) | [Optional] Specify an Array of paths to include as `-I...:...` includes during compilation. Default: `['.']`. |
243
243
  | classpath | JavaExtensionTask | [Optional] Specify additional classpath paths as an Array. Default: _Uses the current CLASSPATH._ |
244
- | debug | JavaExtensionTask | [Optional] Whether to set the debug flag during complication. Default: `false`. |
244
+ | debug | JavaExtensionTask | [Optional] Whether to set the debug flag during compilation. Default: `false`. |
245
245
  | source_version | JavaExtensionTask | [Optional] The JRE version that your source code requires to compile. Default: `1.6`. |
246
246
  | target_version | JavaExtensionTask | [Optional] The oldest JRE version you want to support. Default: `1.6`. |
247
247
  | encoding | JavaExtensionTask | [Optional] Specify an -encoding option to provide to the compiler. Default: `nil`. |
@@ -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'
@@ -5,6 +5,8 @@ require 'rbconfig'
5
5
 
6
6
  require 'pathname'
7
7
 
8
+ require_relative "compiler_config"
9
+
8
10
  module Rake
9
11
  class BaseExtensionTask < TaskLib
10
12
 
@@ -16,6 +18,7 @@ module Rake
16
18
  attr_accessor :config_options
17
19
  attr_accessor :source_pattern
18
20
  attr_accessor :extra_options
21
+ attr_accessor :extra_sources
19
22
  attr_writer :platform
20
23
 
21
24
  def platform
@@ -39,6 +42,7 @@ module Rake
39
42
  end
40
43
  @config_options = []
41
44
  @extra_options = ARGV.select { |i| i =~ /\A--?/ }
45
+ @extra_sources = FileList[]
42
46
  end
43
47
 
44
48
  def define
@@ -69,7 +73,7 @@ module Rake
69
73
  end
70
74
 
71
75
  def source_files
72
- FileList["#{@ext_dir}/#{@source_pattern}"]
76
+ FileList["#{@ext_dir}/#{@source_pattern}"] + @extra_sources
73
77
  end
74
78
 
75
79
  def warn_once(message)
@@ -0,0 +1,38 @@
1
+ module Rake
2
+ class CompilerConfig
3
+ def initialize(config_path)
4
+ require "yaml"
5
+ @config = YAML.load_file(config_path)
6
+ end
7
+
8
+ def find(ruby_version, gem_platform)
9
+ gem_platform = Gem::Platform.new(gem_platform)
10
+
11
+ @config.each do |config_name, config_location|
12
+ # There are two variations we might find in the rake-compiler config.yml
13
+ #
14
+ # 1. config_name: rbconfig-x86_64-linux-3.0.0
15
+ # runtime_platform_name: x86_64-linux
16
+ # runtime_version: 3.0.0
17
+ #
18
+ # 2. config_name: rbconfig-x86_64-linux-gnu-3.0.0
19
+ # runtime_platform_name: x86_64-linux-gnu
20
+ # runtime_version: 3.0.0
21
+ #
22
+ # With rubygems < 3.3.21, both variations will be present (two entries pointing at the same
23
+ # installation).
24
+ #
25
+ # With rubygems >= 3.3.21, only the second variation will be present.
26
+ runtime_platform_name = config_name.split("-")[1..-2].join("-")
27
+ runtime_version = config_name.split("-").last
28
+ runtime_platform = Gem::Platform.new(runtime_platform_name)
29
+
30
+ if (ruby_version == runtime_version) && (gem_platform =~ runtime_platform)
31
+ return config_location
32
+ end
33
+ end
34
+
35
+ nil
36
+ end
37
+ end
38
+ end
@@ -199,7 +199,7 @@ Java extension should be preferred.
199
199
  abs_extconf = (Pathname.new(Dir.pwd) + extconf).realpath
200
200
 
201
201
  # now add the extconf script
202
- cmd << abs_extconf.relative_path_from(abs_tmp_path)
202
+ cmd << abs_extconf.relative_path_from(abs_tmp_path).to_s
203
203
 
204
204
  # fake.rb will be present if we are cross compiling
205
205
  if t.prerequisites.include?("#{tmp_path}/fake.rb") then
@@ -215,9 +215,7 @@ Java extension should be preferred.
215
215
  end
216
216
 
217
217
  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(' ')
218
+ sh *cmd
221
219
  end
222
220
  end
223
221
 
@@ -393,8 +391,11 @@ Java extension should be preferred.
393
391
  return
394
392
  end
395
393
 
396
- require "yaml"
397
- config_file = YAML.load_file(config_path)
394
+ rbconfig_file = Rake::CompilerConfig.new(config_path).find(ruby_ver, for_platform)
395
+ unless rbconfig_file
396
+ warn "no configuration section for specified version of Ruby (rbconfig-#{for_platform}-#{ruby_ver})"
397
+ return
398
+ end
398
399
 
399
400
  # tmp_path
400
401
  tmp_path = "#{@tmp_dir}/#{for_platform}/#{@name}/#{ruby_ver}"
@@ -405,11 +406,6 @@ Java extension should be preferred.
405
406
  # lib_binary_path
406
407
  lib_binary_path = "#{lib_path}/#{File.basename(binary(for_platform))}"
407
408
 
408
- unless rbconfig_file = config_file["rbconfig-#{for_platform}-#{ruby_ver}"] then
409
- warn "no configuration section for specified version of Ruby (rbconfig-#{for_platform}-#{ruby_ver})"
410
- return
411
- end
412
-
413
409
  # mkmf
414
410
  mkmf_file = File.expand_path(File.join(File.dirname(rbconfig_file), '..', 'mkmf.rb'))
415
411
 
@@ -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
@@ -0,0 +1,54 @@
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
@@ -58,6 +58,15 @@ describe Rake::ExtensionTask do
58
58
  end
59
59
  ext.platform.should == 'universal-foo-bar-10.5'
60
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
61
70
  end
62
71
  end
63
72
 
@@ -381,9 +390,10 @@ describe Rake::ExtensionTask do
381
390
  end
382
391
 
383
392
  it 'should warn if no section of config file defines running version of ruby' do
384
- config = Hash.new
385
- expect(config).to receive(:[]).with("rbconfig-#{@platform}-#{@ruby_ver}").and_return(nil)
386
- allow(YAML).to receive(:load_file).and_return(config)
393
+ allow_any_instance_of(Rake::CompilerConfig).to(
394
+ receive(:find).with(@ruby_ver, @platform).and_return(nil)
395
+ )
396
+
387
397
  out, err = capture_output do
388
398
  Rake::ExtensionTask.new('extension_one') do |ext|
389
399
  ext.cross_compile = true
@@ -403,9 +413,9 @@ describe Rake::ExtensionTask do
403
413
  end
404
414
 
405
415
  it 'should generate additional rake tasks if files are added when cross compiling' do
406
- config = Hash.new
407
- allow(config).to receive(:[]).and_return('/rubies/1.9.1/rbconfig.rb')
408
- allow(YAML).to receive(:load_file).and_return(config)
416
+ allow_any_instance_of(Rake::CompilerConfig).to(
417
+ receive(:find).and_return("/rubies/1.9.1/rbconfig.rb")
418
+ )
409
419
 
410
420
  # Use a real spec instead of a mock because define_native_tasks dups and
411
421
  # calls methods on Gem::Specification, which is more than mock can do.
@@ -433,9 +443,11 @@ describe Rake::ExtensionTask do
433
443
  end
434
444
 
435
445
  it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
436
- config = Hash.new
437
- expect(config).to receive(:[]).with("rbconfig-i386-mingw32-1.9.1").and_return('/rubies/1.9.1/rbconfig.rb')
438
- allow(YAML).to receive(:load_file).and_return(config)
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
+ )
439
451
 
440
452
  ENV['RUBY_CC_VERSION'] = '1.9.1'
441
453
  Rake::ExtensionTask.new('extension_one') do |ext|
@@ -444,10 +456,16 @@ describe Rake::ExtensionTask do
444
456
  end
445
457
 
446
458
  it 'should allow multiple versions be supplied to RUBY_CC_VERSION' do
447
- config = Hash.new
448
- expect(config).to receive(:[]).once.with("rbconfig-i386-mingw32-1.8.6").and_return('/rubies/1.8.6/rbconfig.rb')
449
- expect(config).to receive(:[]).once.with("rbconfig-i386-mingw32-1.9.1").and_return('/rubies/1.9.1/rbconfig.rb')
450
- allow(YAML).to receive(:load_file).and_return(config)
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
+ )
451
469
 
452
470
  ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
453
471
  Rake::ExtensionTask.new('extension_one') do |ext|
@@ -459,18 +477,19 @@ describe Rake::ExtensionTask do
459
477
  platforms = ["x86-mingw32", "x64-mingw32"]
460
478
  ruby_cc_versions = ["1.8.6", "2.1.10", "2.2.6", "2.3.3", "2.10.1", "2.11.0"]
461
479
  ENV["RUBY_CC_VERSION"] = ruby_cc_versions.join(":")
462
- config = Hash.new
480
+
463
481
  ruby_cc_versions.each do |ruby_cc_version|
464
482
  platforms.each do |platform|
465
483
  unless platform == "x64-mingw32" && ruby_cc_version == "2.11.0"
466
484
  rbconf = "/rubies/#{ruby_cc_version}/rbconfig.rb"
467
485
  end
468
- allow(config).to receive(:[]).
469
- with("rbconfig-#{platform}-#{ruby_cc_version}").
470
- and_return(rbconf)
486
+ allow_any_instance_of(Rake::CompilerConfig).to(
487
+ receive(:find)
488
+ .with(ruby_cc_version, platform)
489
+ .and_return(rbconf)
490
+ )
471
491
  end
472
492
  end
473
- allow(YAML).to receive(:load_file).and_return(config)
474
493
 
475
494
  allow(Gem).to receive_message_chain(:configuration, :verbose=).and_return(true)
476
495
 
@@ -515,9 +534,16 @@ describe Rake::ExtensionTask do
515
534
 
516
535
  context "(cross compile for multiple versions)" do
517
536
  before :each do
518
- config = Hash.new
519
- allow(config).to receive(:[]).and_return('/rubies/1.8.6/rbconfig.rb', '/rubies/1.9.1/rbconfig.rb')
520
- allow(YAML).to receive(:load_file).and_return(config)
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
+ )
521
547
 
522
548
  ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
523
549
  @ext = Rake::ExtensionTask.new('extension_one') do |ext|
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  - Luis Lavena
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-04-15 00:00:00.000000000 Z
12
+ date: 2023-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -108,9 +108,11 @@ files:
108
108
  - features/support/generator_helpers.rb
109
109
  - features/support/platform_extension_helpers.rb
110
110
  - lib/rake/baseextensiontask.rb
111
+ - lib/rake/compiler_config.rb
111
112
  - lib/rake/extensioncompiler.rb
112
113
  - lib/rake/extensiontask.rb
113
114
  - lib/rake/javaextensiontask.rb
115
+ - spec/lib/rake/compiler_config_spec.rb
114
116
  - spec/lib/rake/extensiontask_spec.rb
115
117
  - spec/lib/rake/javaextensiontask_spec.rb
116
118
  - spec/spec.opts
@@ -126,7 +128,7 @@ homepage: https://github.com/rake-compiler/rake-compiler
126
128
  licenses:
127
129
  - MIT
128
130
  metadata: {}
129
- post_install_message:
131
+ post_install_message:
130
132
  rdoc_options:
131
133
  - "--main"
132
134
  - README.md
@@ -145,8 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
147
  - !ruby/object:Gem::Version
146
148
  version: 1.8.23
147
149
  requirements: []
148
- rubygems_version: 3.4.0.dev
149
- signing_key:
150
+ rubygems_version: 3.5.0.dev
151
+ signing_key:
150
152
  specification_version: 4
151
153
  summary: Rake-based Ruby Extension (C, Java) task generator.
152
154
  test_files: []