rake-compiler 1.0.8 → 1.1.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.
@@ -19,6 +19,9 @@ module Rake
19
19
 
20
20
  attr_accessor :encoding
21
21
 
22
+ # Specify lint option
23
+ attr_accessor :lint_option
24
+
22
25
  def platform
23
26
  @platform ||= 'java'
24
27
  end
@@ -32,10 +35,11 @@ module Rake
32
35
  @source_pattern = '**/*.java'
33
36
  @classpath = nil
34
37
  @debug = false
35
- @source_version = '1.6'
36
- @target_version = '1.6'
38
+ @source_version = '1.7'
39
+ @target_version = '1.7'
37
40
  @encoding = nil
38
41
  @java_compiling = nil
42
+ @lint_option = nil
39
43
  end
40
44
 
41
45
  def define
@@ -95,10 +99,19 @@ execute the Rake compilation task using the JRuby interpreter.
95
99
  EOF
96
100
  warn_once(not_jruby_compile_msg) unless defined?(JRUBY_VERSION)
97
101
 
98
- classpath_arg = java_classpath_arg(@classpath)
99
- debug_arg = @debug ? '-g' : ''
100
-
101
- sh "javac #{java_encoding_arg} #{java_extdirs_arg} -target #{@target_version} -source #{@source_version} -Xlint:unchecked #{debug_arg} #{classpath_arg} -d #{tmp_path} #{source_files.join(' ')}"
102
+ javac_command_line = [
103
+ "javac",
104
+ "-target", @target_version,
105
+ "-source", @source_version,
106
+ java_lint_arg,
107
+ "-d", tmp_path,
108
+ ]
109
+ javac_command_line.concat(java_encoding_args)
110
+ javac_command_line.concat(java_extdirs_args)
111
+ javac_command_line.concat(java_classpath_args)
112
+ javac_command_line << "-g" if @debug
113
+ javac_command_line.concat(source_files)
114
+ sh(*javac_command_line)
102
115
 
103
116
  # Checkpoint file
104
117
  touch "#{tmp_path}/.build"
@@ -188,38 +201,43 @@ execute the Rake compilation task using the JRuby interpreter.
188
201
  end
189
202
 
190
203
  #
191
- # Discover Java Extension Directories and build an extdirs argument
204
+ # Discover Java Extension Directories and build an extdirs arguments
192
205
  #
193
- def java_extdirs_arg
206
+ def java_extdirs_args
194
207
  extdirs = Java::java.lang.System.getProperty('java.ext.dirs') rescue nil
195
- extdirs = ENV['JAVA_EXT_DIR'] unless extdirs
196
- java_extdir = extdirs.nil? ? "" : "-extdirs \"#{extdirs}\""
208
+ extdirs ||= ENV['JAVA_EXT_DIR']
209
+ if extdirs.nil?
210
+ []
211
+ else
212
+ ["-extdirs", extdirs]
213
+ end
197
214
  end
198
215
 
199
216
  #
200
- # Build an encoding argument
217
+ # Build an encoding arguments
201
218
  #
202
- def java_encoding_arg
203
- @encoding.nil? ? "" : "-encoding \"#{@encoding}\""
219
+ def java_encoding_args
220
+ if @encoding.nil?
221
+ []
222
+ else
223
+ ["-encoding", @encoding]
224
+ end
204
225
  end
205
226
 
206
227
  #
207
- # Discover the Java/JRuby classpath and build a classpath argument
208
- #
209
- # @params
210
- # *args:: Additional classpath arguments to append
228
+ # Discover the Java/JRuby classpath and build a classpath arguments
211
229
  #
212
230
  # Copied verbatim from the ActiveRecord-JDBC project. There are a small myriad
213
231
  # of ways to discover the Java classpath correctly.
214
232
  #
215
- def java_classpath_arg(*args)
233
+ def java_classpath_args
216
234
  jruby_cpath = nil
217
235
  if RUBY_PLATFORM =~ /java/
218
236
  begin
219
237
  cpath = Java::java.lang.System.getProperty('java.class.path').split(File::PATH_SEPARATOR)
220
238
  cpath += Java::java.lang.System.getProperty('sun.boot.class.path').split(File::PATH_SEPARATOR)
221
239
  jruby_cpath = cpath.compact.join(File::PATH_SEPARATOR)
222
- rescue => e
240
+ rescue
223
241
  end
224
242
  end
225
243
 
@@ -250,9 +268,21 @@ execute the Rake compilation task using the JRuby interpreter.
250
268
  raise "Could not find jruby.jar. Please set JRUBY_HOME or use jruby in rvm"
251
269
  end
252
270
 
253
- jruby_cpath += File::PATH_SEPARATOR + args.join(File::PATH_SEPARATOR) unless args.empty?
254
- jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
271
+ if @classpath and @classpath.size > 0
272
+ jruby_cpath = [jruby_cpath, *@classpath].join(File::PATH_SEPARATOR)
273
+ end
274
+ ["-cp", jruby_cpath]
255
275
  end
256
276
 
277
+ #
278
+ # Convert a `-Xlint:___` linting option such as `deprecation` into a full javac argument, such as `-Xlint:deprecation`.
279
+ #
280
+ # @return [String] Default: _Simply `-Xlint` is run, which enables recommended warnings.
281
+ #
282
+ def java_lint_arg
283
+ return '-Xlint' unless @lint_option
284
+
285
+ "-Xlint:#{@lint_option}"
286
+ end
257
287
  end
258
288
  end
@@ -76,9 +76,14 @@ describe Rake::JavaExtensionTask do
76
76
  @ext.config_options.should be_empty
77
77
  end
78
78
 
79
+ it 'should have no lint option preset to delegate' do
80
+ @ext.lint_option.should be_falsey
81
+ end
82
+
79
83
  it 'should default to Java platform' do
80
84
  @ext.platform.should == 'java'
81
85
  end
86
+ end
82
87
 
83
88
  context '(tasks)' do
84
89
  before :each do
@@ -165,6 +170,31 @@ describe Rake::JavaExtensionTask do
165
170
  end
166
171
  end
167
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
+ end
179
+ end
180
+
181
+ context 'without a specified lint option' do
182
+ let(:lint_option) { nil }
183
+
184
+ it 'should honor the lint option' do
185
+ (extension.lint_option).should be_falsey
186
+ (extension.send :java_lint_arg).should eq '-Xlint'
187
+ end
188
+ end
189
+
190
+ context "with a specified lint option of 'deprecated'" do
191
+ let(:lint_option) { 'deprecated'.freeze }
192
+
193
+ it 'should honor the lint option' do
194
+ (extension.lint_option).should eq lint_option
195
+ (extension.send :java_lint_arg).should eq '-Xlint:deprecated'
196
+ end
197
+ end
168
198
  end
169
199
  end
170
200
  private
@@ -41,127 +41,104 @@ end
41
41
  require 'rake/extensioncompiler'
42
42
 
43
43
  MAKE = ENV['MAKE'] || %w[gmake make].find { |c| system("#{c} -v > /dev/null 2>&1") }
44
- USER_HOME = File.expand_path("~/.rake-compiler")
45
- RUBY_CC_VERSION = "ruby-" << ENV.fetch("VERSION", "1.8.7-p371")
44
+ USER_HOME = File.realpath(File.expand_path("~/.rake-compiler"))
46
45
  RUBY_SOURCE = ENV['SOURCE']
47
46
  RUBY_BUILD = RbConfig::CONFIG["host"]
48
47
 
49
- # grab the major "1.8" or "1.9" part of the version number
50
- MAJOR = RUBY_CC_VERSION.match(/.*-(\d.\d).\d/)[1]
51
-
52
- # Use Rake::ExtensionCompiler helpers to find the proper host
53
- MINGW_HOST = ENV['HOST'] || Rake::ExtensionCompiler.mingw_host
54
- MINGW_TARGET = MINGW_HOST.gsub('msvc', '')
55
-
56
48
  # Unset any possible variable that might affect compilation
57
- ["CC", "CXX", "CPPFLAGS", "LDFLAGS", "RUBYOPT"].each do |var|
49
+ ["RUBYOPT"].each do |var|
58
50
  ENV.delete(var)
59
51
  end
60
52
 
61
- # define a location where sources will be stored
62
- directory "#{USER_HOME}/sources/#{RUBY_CC_VERSION}"
63
- directory "#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}"
64
-
65
- # clean intermediate files and folders
66
- CLEAN.include("#{USER_HOME}/sources/#{RUBY_CC_VERSION}")
67
- CLEAN.include("#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}")
68
-
69
- # remove the final products and sources
70
- CLOBBER.include("#{USER_HOME}/sources")
71
- CLOBBER.include("#{USER_HOME}/builds")
72
- CLOBBER.include("#{USER_HOME}/ruby/#{MINGW_HOST}/#{RUBY_CC_VERSION}")
73
- CLOBBER.include("#{USER_HOME}/config.yml")
53
+ RUBY_CC_VERSIONS = ENV.fetch("VERSION", "1.8.7-p371")
54
+ RUBY_CC_VERSIONS.split(":").each do |ruby_cc_version|
55
+ ruby_cc_version = "ruby-" + ruby_cc_version
56
+ # grab the major "1.8" or "1.9" part of the version number
57
+ major = ruby_cc_version.match(/.*-(\d.\d).\d/)[1]
58
+
59
+ # define a location where sources will be stored
60
+ source_dir = "#{USER_HOME}/sources/#{ruby_cc_version}"
61
+ directory source_dir
62
+ # clean intermediate files and folders
63
+ CLEAN.include(source_dir)
64
+
65
+ # remove the final products and sources
66
+ CLOBBER.include("#{USER_HOME}/sources")
67
+ CLOBBER.include("#{USER_HOME}/builds")
68
+ CLOBBER.include("#{USER_HOME}/config.yml")
69
+
70
+ # Extract the sources
71
+ source_file = RUBY_SOURCE ? RUBY_SOURCE.split('/').last : "#{ruby_cc_version}.tar.gz"
72
+ file source_dir => ["#{USER_HOME}/sources/#{source_file}"] do |t|
73
+ t.prerequisites.each { |f| sh "tar xf #{File.basename(f)}", chdir: File.dirname(t.name) }
74
+ end
74
75
 
75
- # ruby source file should be stored there
76
- file "#{USER_HOME}/sources/#{RUBY_CC_VERSION}.tar.bz2" => ["#{USER_HOME}/sources"] do |t|
77
- # download the source file using wget or curl
78
- chdir File.dirname(t.name) do
76
+ # ruby source file should be stored there
77
+ file "#{USER_HOME}/sources/#{ruby_cc_version}.tar.gz" => ["#{USER_HOME}/sources"] do |t|
78
+ # download the source file using wget or curl
79
79
  if RUBY_SOURCE
80
80
  url = RUBY_SOURCE
81
81
  else
82
- url = "http://cache.ruby-lang.org/pub/ruby/#{MAJOR}/#{File.basename(t.name)}"
82
+ url = "http://cache.ruby-lang.org/pub/ruby/#{major}/#{File.basename(t.name)}"
83
83
  end
84
- sh "wget #{url} || curl -O #{url}"
84
+ sh "wget #{url} || curl -O #{url}", chdir: File.dirname(t.name)
85
85
  end
86
- end
87
86
 
88
- # Extract the sources
89
- source_file = RUBY_SOURCE ? RUBY_SOURCE.split('/').last : "#{RUBY_CC_VERSION}.tar.bz2"
90
- file "#{USER_HOME}/sources/#{RUBY_CC_VERSION}" => ["#{USER_HOME}/sources/#{source_file}"] do |t|
91
- chdir File.dirname(t.name) do
92
- t.prerequisites.each { |f| sh "tar xf #{File.basename(f)}" }
93
- end
94
- end
95
-
96
- # backup makefile.in
97
- file "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in.bak" => ["#{USER_HOME}/sources/#{RUBY_CC_VERSION}"] do |t|
98
- cp "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in", t.name
99
- end
100
-
101
- # correct the makefiles
102
- file "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in" => ["#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in.bak"] do |t|
103
- content = File.open(t.name, 'rb') { |f| f.read }
104
-
105
- out = ""
106
-
107
- content.each_line do |line|
108
- if line =~ /^\s*ALT_SEPARATOR =/
109
- out << "\t\t ALT_SEPARATOR = \"\\\\\\\\\"; \\\n"
110
- else
111
- out << line
87
+ # Create tasks for each host out of the ":" separated hosts list in the HOST variable.
88
+ # These tasks are processed in parallel as dependencies to the "install" task.
89
+ mingw_hosts = ENV['HOST'] || Rake::ExtensionCompiler.mingw_host
90
+ mingw_hosts.split(":").each do |mingw_host|
91
+
92
+ # Use Rake::ExtensionCompiler helpers to find the proper host
93
+ mingw_target = mingw_host.gsub('msvc', '')
94
+
95
+ # define a location where built files for each host will be stored
96
+ build_dir = "#{USER_HOME}/builds/#{mingw_host}/#{ruby_cc_version}"
97
+ directory build_dir
98
+ install_dir = "#{USER_HOME}/ruby/#{mingw_host}/#{ruby_cc_version}"
99
+
100
+ # clean intermediate files and folders
101
+ CLEAN.include(build_dir)
102
+ CLOBBER.include(install_dir)
103
+
104
+ task :mingw32 do
105
+ unless mingw_host then
106
+ warn "You need to install mingw32 cross compile functionality to be able to continue."
107
+ warn "Please refer to your distribution/package manager documentation about installation."
108
+ fail
109
+ end
112
110
  end
113
- end
114
111
 
115
- when_writing("Patching Makefile.in") {
116
- File.open(t.name, 'wb') { |f| f.write(out) }
117
- }
118
- end
119
-
120
- task :mingw32 do
121
- unless MINGW_HOST then
122
- warn "You need to install mingw32 cross compile functionality to be able to continue."
123
- warn "Please refer to your distribution/package manager documentation about installation."
124
- fail
125
- end
126
- end
127
-
128
- # generate the makefile in a clean build location
129
- file "#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}/Makefile" => ["#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}",
130
- "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in"] do |t|
131
-
132
- options = [
133
- "--host=#{MINGW_HOST}",
134
- "--target=#{MINGW_TARGET}",
135
- "--build=#{RUBY_BUILD}",
136
- '--enable-shared',
137
- '--disable-install-doc',
138
- '--with-ext='
139
- ]
140
-
141
- # Force Winsock2 for Ruby 1.8, 1.9 defaults to it
142
- options << "--with-winsock2" if MAJOR == "1.8"
143
-
144
- chdir File.dirname(t.name) do
145
- prefix = File.expand_path("../../../ruby/#{MINGW_HOST}/#{RUBY_CC_VERSION}")
146
- options << "--prefix=#{prefix}"
147
- sh File.expand_path("../../../sources/#{RUBY_CC_VERSION}/configure"), *options
148
- end
149
- end
112
+ # generate the makefile in a clean build location
113
+ file "#{build_dir}/Makefile" => [build_dir, source_dir] do |t|
114
+
115
+ options = [
116
+ "--host=#{mingw_host}",
117
+ "--target=#{mingw_target}",
118
+ "--build=#{RUBY_BUILD}",
119
+ '--enable-shared',
120
+ '--disable-install-doc',
121
+ '--with-ext=',
122
+ ]
123
+
124
+ # Force Winsock2 for Ruby 1.8, 1.9 defaults to it
125
+ options << "--with-winsock2" if major == "1.8"
126
+ options << "--prefix=#{install_dir}"
127
+ sh File.expand_path("#{USER_HOME}/sources/#{ruby_cc_version}/configure"), *options, chdir: File.dirname(t.name)
128
+ end
150
129
 
151
- # make
152
- file "#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}/ruby.exe" => ["#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}/Makefile"] do |t|
153
- chdir File.dirname(t.prerequisites.first) do
154
- sh MAKE
155
- end
156
- end
130
+ # make
131
+ file "#{build_dir}/ruby.exe" => ["#{build_dir}/Makefile"] do |t|
132
+ sh MAKE, chdir: File.dirname(t.prerequisites.first)
133
+ end
157
134
 
158
- # make install
159
- file "#{USER_HOME}/ruby/#{MINGW_HOST}/#{RUBY_CC_VERSION}/bin/ruby.exe" => ["#{USER_HOME}/builds/#{MINGW_HOST}/#{RUBY_CC_VERSION}/ruby.exe"] do |t|
160
- chdir File.dirname(t.prerequisites.first) do
161
- sh "#{MAKE} install"
135
+ # make install
136
+ file "#{USER_HOME}/ruby/#{mingw_host}/#{ruby_cc_version}/bin/ruby.exe" => ["#{build_dir}/ruby.exe"] do |t|
137
+ sh "#{MAKE} install", chdir: File.dirname(t.prerequisites.first)
138
+ end
139
+ multitask :install => ["#{USER_HOME}/ruby/#{mingw_host}/#{ruby_cc_version}/bin/ruby.exe"]
162
140
  end
163
141
  end
164
- task :install => ["#{USER_HOME}/ruby/#{MINGW_HOST}/#{RUBY_CC_VERSION}/bin/ruby.exe"]
165
142
 
166
143
  desc "Update rake-compiler list of installed Ruby versions"
167
144
  task 'update-config' do
@@ -208,6 +185,5 @@ task :default do
208
185
  Rake.application.display_tasks_and_comments
209
186
  end
210
187
 
211
- desc "Build #{RUBY_CC_VERSION} suitable for cross-platform development."
188
+ desc "Build rubies suitable for cross-platform development."
212
189
  task 'cross-ruby' => [:mingw32, :install, 'update-config']
213
-
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.0.8
4
+ version: 1.1.2
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: 2019-09-20 00:00:00.000000000 Z
12
+ date: 2021-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -77,14 +77,14 @@ executables:
77
77
  - rake-compiler
78
78
  extensions: []
79
79
  extra_rdoc_files:
80
- - README.rdoc
80
+ - README.md
81
81
  - LICENSE.txt
82
- - History.txt
82
+ - History.md
83
83
  files:
84
84
  - Gemfile
85
- - History.txt
85
+ - History.md
86
86
  - LICENSE.txt
87
- - README.rdoc
87
+ - README.md
88
88
  - Rakefile
89
89
  - appveyor.yml
90
90
  - bin/rake-compiler
@@ -129,7 +129,7 @@ metadata: {}
129
129
  post_install_message:
130
130
  rdoc_options:
131
131
  - "--main"
132
- - README.rdoc
132
+ - README.md
133
133
  - "--title"
134
134
  - rake-compiler -- Documentation
135
135
  require_paths:
@@ -145,8 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: 1.8.23
147
147
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.7.6.2
148
+ rubygems_version: 3.3.0.dev
150
149
  signing_key:
151
150
  specification_version: 4
152
151
  summary: Rake-based Ruby Extension (C, Java) task generator.