luislavena-rake-compiler 0.3.0 → 0.4.0

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.
data/History.txt CHANGED
@@ -1,32 +1,70 @@
1
- === 0.3.0 / 2008-12-07
1
+ == 0.4.0 2009-04-03
2
2
 
3
- * 1 Major Enhancement:
3
+ === Enhancements
4
+
5
+ * Bended the convention for extension folder.
6
+ Defining <tt>ext_dir</tt> for custom extension location.
7
+
8
+ Rake::ExtensionTask.new('my_extension') do |ext|
9
+ ext.ext_dir = 'custom/location' # look into custom/location
10
+ end # instead of ext/my_extension
11
+
12
+ * Better detection of mingw target across Linux/OSX.
13
+ Exposed it as Rake::ExtensionCompiler
14
+
15
+ * Display list of available tasks when calling rake-compiler script
16
+
17
+ * Track Ruby full versioning (x.y.z).
18
+ This will help the compilation of extensions targetting 1.8.6/7 and 1.9.1
19
+
20
+ === Bugfixes
21
+
22
+ * Better output of Rake development tasks (Thanks to Luis Parravicini).
23
+ * Proper usage of Gem::Platform for native gems (Thanks to Dirkjan Bussink).
24
+ * Don't use autoload for YAML (present problems with Ruby 1.9.1).
25
+
26
+ == 0.3.1 / 2009-01-09
27
+
28
+ === Enhancements
29
+
30
+ * Download cross-ruby source code using HTTP instead of FTP.
31
+ * Disabled Tcl/Tk extension building on cross-ruby (helps with 1.9).
32
+
33
+ === Bugfixes
34
+
35
+ * Workaround bug introduced by lack of Gem::Specification cloning. Fixes DM LH #757.
36
+ * Use proper binary extension on OSX (reported by Dirkjan Bussink).
37
+ * Ensure lib/binary task is defined prior clear of requisites.
38
+
39
+ == 0.3.0 / 2008-12-07
40
+
41
+ === New features
4
42
 
5
43
  * Let you specify the Ruby version used for cross compilation instead
6
44
  of default one.
7
45
 
8
46
  rake cross compile RUBY_CC_VERSION=1.8
9
47
 
10
- * 2 Minor Enhancements:
48
+ === Enhancements
11
49
 
12
50
  * Properly update rake-compiler configuration when new version is installed.
13
51
  * Automated release process to RubyForge, yay!
14
52
 
15
- * 1 Bug fix:
53
+ === Bugfixes
16
54
 
17
55
  * Corrected documentation to reflect the available options
18
56
 
19
- === 0.2.1 / 2008-11-30
57
+ == 0.2.1 / 2008-11-30
20
58
 
21
- * 2 Major Enhancements:
59
+ === New features
22
60
 
23
61
  * Allow cross compilation (cross compile) using mingw32 on Linux or OSX.
24
62
  * Allow packaging of gems for Windows on Linux or OSX.
25
63
 
26
- * 1 Minor Enhancement:
64
+ === Enhancements
27
65
 
28
66
  * Made generation of extensions safe and target folders per-platform
29
67
 
30
- * 1 Bug Fix:
68
+ === Bugfixes
31
69
 
32
70
  * Ensure binaries for the specific platform are copied before packaging.
data/Rakefile CHANGED
@@ -20,4 +20,4 @@ rescue LoadError
20
20
  end
21
21
 
22
22
  # load rakefile extensions (tasks)
23
- Dir['tasks/*.rake'].each { |f| import f }
23
+ Dir['tasks/*.rake'].sort.each { |f| load f }
@@ -6,13 +6,14 @@ Given %r{^I'm running a POSIX operating system$} do
6
6
  end
7
7
 
8
8
  Given %r{^I've installed cross compile toolchain$} do
9
- compiler = 'i586-mingw32msvc-gcc'
10
- found = false
11
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
12
- next unless File.exist?(File.join(path, compiler))
13
- found = true
9
+ compilers = %w(i586-mingw32msvc-gcc i386-mingw32-gcc)
10
+ paths = ENV['PATH'].split(File::PATH_SEPARATOR)
11
+ compiler = compilers.find do |comp|
12
+ paths.find do |path|
13
+ File.exist? File.join(path, comp)
14
+ end
14
15
  end
15
- raise "Cannot locate '#{compiler}' in the PATH." unless found
16
+ raise "Cannot locate '#{compiler}' in the PATH." unless compiler
16
17
  end
17
18
 
18
19
  Then /^binaries for platform '(.*)' get generated$/ do |platform|
@@ -24,6 +24,7 @@ end
24
24
 
25
25
  def gem_file_platform(folder, name, version, platform = nil)
26
26
  file = "#{folder}/#{name}-#{version}"
27
- file << "-" << (platform || Gem::Platform.local.to_s)
27
+ file << "-" << (platform || Gem::Platform.new(RUBY_PLATFORM).to_s)
28
28
  file << ".gem"
29
+ file
29
30
  end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # HACK: Lousy API design, sue me. At least works ;-)
5
+ #
6
+ # Define a series of helpers to aid in search and usage of MinGW (GCC) Compiler
7
+ # by gem developer/creators.
8
+ #
9
+
10
+ module Rake
11
+ module ExtensionCompiler
12
+ # return the host portion from the installed MinGW
13
+ def self.mingw_host
14
+ return @mingw_host if @mingw_host
15
+
16
+ # the mingw_gcc_executable is helpful here
17
+ if target = mingw_gcc_executable then
18
+ # we only care for the filename
19
+ target = File.basename(target)
20
+
21
+ # now strip the extension (if present)
22
+ target.sub!(File.extname(target), '')
23
+
24
+ # get rid of '-gcc' portion too ;-)
25
+ target.sub!('-gcc', '')
26
+ end
27
+
28
+ raise "No MinGW tools or unknown setup platform?" unless target
29
+
30
+ @mingw_host = target
31
+ end
32
+
33
+ # return the first compiler found that includes both mingw and gcc conditions
34
+ # (this assumes you have one installed)
35
+ def self.mingw_gcc_executable
36
+ return @mingw_gcc_executable if @mingw_gcc_executable
37
+
38
+ # grab the paths defined in the environment
39
+ paths = ENV['PATH'].split(File::PATH_SEPARATOR)
40
+
41
+ # the pattern to look into (captures *nix and windows executables)
42
+ pattern = "*mingw*gcc{,.*}"
43
+
44
+ @mingw_gcc_executable = paths.find do |path|
45
+ # cleanup paths before globbing
46
+ gcc = Dir.glob("#{File.expand_path(path)}/#{pattern}").first
47
+ break gcc if gcc
48
+ end
49
+
50
+ @mingw_gcc_executable
51
+ end
52
+ end
53
+ end
@@ -7,10 +7,10 @@ require 'rake'
7
7
  require 'rake/clean'
8
8
  require 'rake/tasklib'
9
9
  require 'rbconfig'
10
+ require 'yaml'
10
11
 
11
12
  module Rake
12
13
  autoload :GemPackageTask, 'rake/gempackagetask'
13
- autoload :YAML, 'yaml'
14
14
 
15
15
  class ExtensionTask < TaskLib
16
16
  attr_accessor :name
@@ -37,7 +37,7 @@ module Rake
37
37
  @gem_spec = gem_spec
38
38
  @config_script = 'extconf.rb'
39
39
  @tmp_dir = 'tmp'
40
- @ext_dir = 'ext'
40
+ @ext_dir = "ext/#{@name}"
41
41
  @lib_dir = 'lib'
42
42
  @source_pattern = "*.c"
43
43
  @config_options = []
@@ -76,7 +76,7 @@ module Rake
76
76
 
77
77
  # cleanup and clobbering
78
78
  CLEAN.include(tmp_path)
79
- CLOBBER.include("#{@lib_dir}/#{binary}")
79
+ CLOBBER.include("#{@lib_dir}/#{binary(platf)}")
80
80
  CLOBBER.include("#{@tmp_dir}")
81
81
 
82
82
  # directories we need
@@ -85,13 +85,13 @@ module Rake
85
85
 
86
86
  # copy binary from temporary location to final lib
87
87
  # tmp/extension_name/extension_name.{so,bundle} => lib/
88
- task "copy:#{@name}:#{platf}" => [lib_dir, "#{tmp_path}/#{binary}"] do
89
- cp "#{tmp_path}/#{binary}", "#{@lib_dir}/#{binary}"
88
+ task "copy:#{@name}:#{platf}" => [lib_dir, "#{tmp_path}/#{binary(platf)}"] do
89
+ cp "#{tmp_path}/#{binary(platf)}", "#{@lib_dir}/#{binary(platf)}"
90
90
  end
91
91
 
92
92
  # binary in temporary folder depends on makefile and source files
93
93
  # tmp/extension_name/extension_name.{so,bundle}
94
- file "#{tmp_path}/#{binary}" => ["#{tmp_path}/Makefile"] + source_files do
94
+ file "#{tmp_path}/#{binary(platf)}" => ["#{tmp_path}/Makefile"] + source_files do
95
95
  chdir tmp_path do
96
96
  sh make
97
97
  end
@@ -102,17 +102,30 @@ module Rake
102
102
  file "#{tmp_path}/Makefile" => [tmp_path, extconf] do |t|
103
103
  options = @config_options.dup
104
104
 
105
+ # include current directory
106
+ cmd = ['-I.']
107
+
108
+ # if fake.rb is present, add to the command line
109
+ if t.prerequisites.include?("#{tmp_path}/fake.rb") then
110
+ cmd << '-rfake'
111
+ end
112
+
113
+ # now add the extconf script
114
+ cmd << File.join(Dir.pwd, extconf)
115
+
105
116
  # rbconfig.rb will be present if we are cross compiling
106
117
  if t.prerequisites.include?("#{tmp_path}/rbconfig.rb") then
107
118
  options.push(*@cross_config_options)
108
119
  end
109
120
 
110
- parent = Dir.pwd
121
+ # add options to command
122
+ cmd.push(*options)
123
+
111
124
  chdir tmp_path do
112
125
  # FIXME: Rake is broken for multiple arguments system() calls.
113
126
  # Add current directory to the search path of Ruby
114
127
  # Also, include additional parameters supplied.
115
- ruby ['-I.', File.join(parent, extconf), *options].join(' ')
128
+ ruby cmd.join(' ')
116
129
  end
117
130
  end
118
131
 
@@ -128,7 +141,7 @@ module Rake
128
141
  task "compile:#{@name}"
129
142
  end
130
143
 
131
- # Allow segmented compilation by platfrom (open door for 'cross compile')
144
+ # Allow segmented compilation by platform (open door for 'cross compile')
132
145
  task "compile:#{@name}:#{platf}" => ["copy:#{@name}:#{platf}"]
133
146
  task "compile:#{platf}" => ["compile:#{@name}:#{platf}"]
134
147
 
@@ -136,7 +149,7 @@ module Rake
136
149
  # platform matches the indicated one.
137
150
  if platf == RUBY_PLATFORM then
138
151
  # ensure file is always copied
139
- file "#{@lib_dir}/#{binary}" => ["copy:#{name}:#{platf}"]
152
+ file "#{@lib_dir}/#{binary(platf)}" => ["copy:#{name}:#{platf}"]
140
153
 
141
154
  task "compile:#{@name}" => ["compile:#{@name}:#{platf}"]
142
155
  task "compile" => ["compile:#{platf}"]
@@ -150,12 +163,14 @@ module Rake
150
163
  tmp_path = "#{@tmp_dir}/#{platf}/#{@name}"
151
164
 
152
165
  # create 'native:gem_name' and chain it to 'native' task
153
- spec = @gem_spec.dup
154
-
155
166
  unless Rake::Task.task_defined?("native:#{@gem_spec.name}:#{platf}")
156
167
  task "native:#{@gem_spec.name}:#{platf}" do |t|
168
+ # FIXME: truly duplicate the Gem::Specification
169
+ # workaround the lack of #dup for Gem::Specification
170
+ spec = Gem::Specification.from_yaml(gem_spec.to_yaml)
171
+
157
172
  # adjust to specified platform
158
- spec.platform = platf
173
+ spec.platform = Gem::Platform.new(platf)
159
174
 
160
175
  # clear the extensions defined in the specs
161
176
  spec.extensions.clear
@@ -185,7 +200,7 @@ module Rake
185
200
  end
186
201
 
187
202
  # add binaries to the dependency chain
188
- task "native:#{@gem_spec.name}:#{platf}" => ["#{tmp_path}/#{binary}"]
203
+ task "native:#{@gem_spec.name}:#{platf}" => ["#{tmp_path}/#{binary(platf)}"]
189
204
 
190
205
  # Allow segmented packaging by platfrom (open door for 'cross compile')
191
206
  task "native:#{platf}" => ["native:#{@gem_spec.name}:#{platf}"]
@@ -200,7 +215,7 @@ module Rake
200
215
 
201
216
  def define_cross_platform_tasks
202
217
  config_path = File.expand_path("~/.rake-compiler/config.yml")
203
- major_ver = (ENV['RUBY_CC_VERSION'] || RUBY_VERSION).match(/(\d+.\d+)/)[1]
218
+ ruby_ver = ENV['RUBY_CC_VERSION'] || RUBY_VERSION
204
219
 
205
220
  # warn the user about the need of configuration to use cross compilation.
206
221
  unless File.exist?(config_path)
@@ -213,21 +228,28 @@ module Rake
213
228
  # tmp_path
214
229
  tmp_path = "#{@tmp_dir}/#{cross_platform}/#{@name}"
215
230
 
216
- unless rbconfig_file = config_file["rbconfig-#{major_ver}"] then
217
- fail "no configuration section for this version of Ruby (rbconfig-#{major_ver})"
231
+ unless rbconfig_file = config_file["rbconfig-#{ruby_ver}"] then
232
+ fail "no configuration section for specified version of Ruby (rbconfig-#{ruby_ver})"
218
233
  end
219
234
 
220
235
  # define compilation tasks for cross platfrom!
221
236
  define_compile_tasks(cross_platform)
222
237
 
223
- # chain rbconfig.rb to Makefile generation
224
- file "#{tmp_path}/Makefile" => ["#{tmp_path}/rbconfig.rb"]
238
+ # chain fake.rb and rbconfig.rb to Makefile generation
239
+ file "#{tmp_path}/Makefile" => ["#{tmp_path}/fake.rb", "#{tmp_path}/rbconfig.rb"]
225
240
 
226
241
  # copy the file from the cross-ruby location
227
242
  file "#{tmp_path}/rbconfig.rb" => [rbconfig_file] do |t|
228
243
  cp t.prerequisites.first, t.name
229
244
  end
230
245
 
246
+ # genearte fake.rb for different ruby versions
247
+ file "#{tmp_path}/fake.rb" do |t|
248
+ File.open(t.name, 'w') do |f|
249
+ f.write fake_rb(ruby_ver)
250
+ end
251
+ end
252
+
231
253
  # now define native tasks for cross compiled files
232
254
  define_native_tasks(cross_platform) if @gem_spec && @gem_spec.platform == 'ruby'
233
255
 
@@ -240,8 +262,11 @@ module Rake
240
262
  task 'compile' => ["compile:#{cross_platform}"]
241
263
 
242
264
  # clear lib/binary dependencies and trigger cross platform ones
243
- Rake::Task["#{@lib_dir}/#{binary}"].prerequisites.clear
244
- file "#{@lib_dir}/#{binary}" => ["copy:#{@name}:#{cross_platform}"]
265
+ # check if lib/binary is defined (damn bundle versus so versus dll)
266
+ if Rake::Task.task_defined?("#{@lib_dir}/#{binary(cross_platform)}") then
267
+ Rake::Task["#{@lib_dir}/#{binary(cross_platform)}"].prerequisites.clear
268
+ end
269
+ file "#{@lib_dir}/#{binary(cross_platform)}" => ["copy:#{@name}:#{cross_platform}"]
245
270
 
246
271
  # if everything for native task is in place
247
272
  if @gem_spec && @gem_spec.platform == 'ruby' then
@@ -252,19 +277,38 @@ module Rake
252
277
  end
253
278
 
254
279
  def extconf
255
- "#{@ext_dir}/#{@name}/#{@config_script}"
280
+ "#{@ext_dir}/#{@config_script}"
256
281
  end
257
282
 
258
283
  def make
259
284
  RUBY_PLATFORM =~ /mswin/ ? 'nmake' : 'make'
260
285
  end
261
286
 
262
- def binary
263
- "#{@name}.#{RbConfig::CONFIG['DLEXT']}"
287
+ def binary(platform = nil)
288
+ ext = case platform
289
+ when /darwin/
290
+ 'bundle'
291
+ when /mingw|mswin|linux/
292
+ 'so'
293
+ else
294
+ RbConfig::CONFIG['DLEXT']
295
+ end
296
+ "#{@name}.#{ext}"
264
297
  end
265
298
 
266
299
  def source_files
267
- @source_files ||= FileList["#{@ext_dir}/#{@name}/#{@source_pattern}"]
300
+ @source_files ||= FileList["#{@ext_dir}/#{@source_pattern}"]
301
+ end
302
+
303
+ def fake_rb(version)
304
+ <<-FAKE_RB
305
+ class Object
306
+ remove_const :RUBY_PLATFORM
307
+ remove_const :RUBY_VERSION
308
+ RUBY_PLATFORM = "i386-mingw32"
309
+ RUBY_VERSION = "#{version}"
310
+ end
311
+ FAKE_RB
268
312
  end
269
313
  end
270
314
  end
@@ -68,10 +68,6 @@ describe Rake::ExtensionTask do
68
68
  @ext.tmp_dir.should == 'tmp'
69
69
  end
70
70
 
71
- it 'should look for extension inside ext/' do
72
- @ext.ext_dir.should == 'ext'
73
- end
74
-
75
71
  it 'should copy build extension into lib/' do
76
72
  @ext.lib_dir.should == 'lib'
77
73
  end
@@ -195,6 +191,23 @@ describe Rake::ExtensionTask do
195
191
  end
196
192
  end
197
193
 
194
+ describe '(extension in custom location)' do
195
+ before :each do
196
+ Rake::FileList.stub!(:[]).and_return(["ext/extension_one/source.c"])
197
+ @ext = Rake::ExtensionTask.new('extension_one') do |ext|
198
+ ext.ext_dir = 'custom/ext/foo'
199
+ end
200
+ @ext_bin = ext_bin('extension_one')
201
+ @platform = RUBY_PLATFORM
202
+ end
203
+
204
+ describe 'tmp/{platform}/extension_one/Makefile' do
205
+ it "should depend on 'custom/ext/foo/extconf.rb'" do
206
+ Rake::Task["tmp/#{@platform}/extension_one/Makefile"].prerequisites.should include("custom/ext/foo/extconf.rb")
207
+ end
208
+ end
209
+ end
210
+
198
211
  describe '(native tasks)' do
199
212
  before :each do
200
213
  Rake::FileList.stub!(:[]).and_return(["ext/extension_one/source.c"])
@@ -246,8 +259,10 @@ describe Rake::ExtensionTask do
246
259
  Rake::FileList.stub!(:[]).and_return(["ext/extension_one/source.c"])
247
260
  @spec = mock_gem_spec
248
261
  @config_file = File.expand_path("~/.rake-compiler/config.yml")
249
- @major_ver = RUBY_VERSION.match(/(\d+.\d+)/)[1]
250
- @config_path = mock_config_yml["rbconfig-#{@major_ver}"]
262
+ @ruby_ver = RUBY_VERSION
263
+ @config_path = mock_config_yml["rbconfig-#{@ruby_ver}"]
264
+
265
+ File.stub!(:open).and_yield(mock_fake_rb)
251
266
  end
252
267
 
253
268
  it 'should not generate an error if no rake-compiler configuration exist' do
@@ -268,29 +283,30 @@ describe Rake::ExtensionTask do
268
283
 
269
284
  it 'should fail if no section of config file defines running version of ruby' do
270
285
  config = mock(Hash)
271
- config.should_receive(:[]).with("rbconfig-#{@major_ver}").and_return(nil)
286
+ config.should_receive(:[]).with("rbconfig-#{@ruby_ver}").and_return(nil)
272
287
  YAML.stub!(:load_file).and_return(config)
273
288
  lambda {
274
289
  Rake::ExtensionTask.new('extension_one') do |ext|
275
290
  ext.cross_compile = true
276
291
  end
277
- }.should raise_error(RuntimeError, /no configuration section for this version of Ruby/)
292
+ }.should raise_error(RuntimeError, /no configuration section for specified version of Ruby/)
278
293
  end
279
294
 
280
295
  it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
281
296
  config = mock(Hash)
282
- config.should_receive(:[]).with("rbconfig-2.0").and_return('/path/to/ruby/2.0/rbconfig.rb')
297
+ config.should_receive(:[]).with("rbconfig-1.9.1").and_return('/path/to/ruby/1.9.1/rbconfig.rb')
283
298
  YAML.stub!(:load_file).and_return(config)
284
- begin
285
- ENV['RUBY_CC_VERSION'] = '2.0'
286
- Rake::ExtensionTask.new('extension_one') do |ext|
287
- ext.cross_compile = true
288
- end
289
- ensure
290
- ENV.delete('RUBY_CC_VERSION')
299
+
300
+ ENV['RUBY_CC_VERSION'] = '1.9.1'
301
+ Rake::ExtensionTask.new('extension_one') do |ext|
302
+ ext.cross_compile = true
291
303
  end
292
304
  end
293
305
 
306
+ after :each do
307
+ ENV.delete('RUBY_CC_VERSION')
308
+ end
309
+
294
310
  describe "(cross for 'universal-unknown' platform)" do
295
311
  before :each do
296
312
  @ext = Rake::ExtensionTask.new('extension_one', @spec) do |ext|
@@ -299,6 +315,12 @@ describe Rake::ExtensionTask do
299
315
  end
300
316
  end
301
317
 
318
+ describe 'fake' do
319
+ it 'should chain fake task to Makefile generation' do
320
+ Rake::Task['tmp/universal-unknown/extension_one/Makefile'].prerequisites.should include('tmp/universal-unknown/extension_one/fake.rb')
321
+ end
322
+ end
323
+
302
324
  describe 'rbconfig' do
303
325
  it 'should chain rbconfig tasks to Makefile generation' do
304
326
  Rake::Task['tmp/universal-unknown/extension_one/Makefile'].prerequisites.should include('tmp/universal-unknown/extension_one/rbconfig.rb')
@@ -345,8 +367,13 @@ describe Rake::ExtensionTask do
345
367
 
346
368
  def mock_config_yml
347
369
  {
348
- 'rbconfig-1.8' => '/some/path/version/1.8/to/rbconfig.rb',
349
- 'rbconfig-1.9' => '/some/path/version/1.9/to/rbconfig.rb'
370
+ 'rbconfig-1.8.6' => '/some/path/version/1.8/to/rbconfig.rb',
371
+ 'rbconfig-1.9.1' => '/some/path/version/1.9.1/to/rbconfig.rb',
372
+ 'rbconfig-3.0.0' => '/some/fake/version/3.0.0/to/rbconfig.rb'
350
373
  }
351
374
  end
375
+
376
+ def mock_fake_rb
377
+ mock(File, :write => 45)
378
+ end
352
379
  end
@@ -21,12 +21,22 @@ require 'rake'
21
21
  require 'rake/clean'
22
22
  require 'yaml'
23
23
 
24
+ # load compiler helpers
25
+ # add lib directory to the search path
26
+ libdir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
27
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
28
+
29
+ require 'rake/extensioncompiler'
30
+
24
31
  USER_HOME = File.expand_path("~/.rake-compiler")
25
32
  RUBY_CC_VERSION = "ruby-#{ENV['VERSION'] || '1.8.6-p287'}"
26
33
 
27
34
  # grab the major "1.8" or "1.9" part of the version number
28
35
  MAJOR = RUBY_CC_VERSION.match(/.*-(\d.\d).\d/)[1]
29
36
 
37
+ # Use Rake::ExtensionCompiler helpers to find the proper host
38
+ MINGW_HOST = Rake::ExtensionCompiler.mingw_host
39
+
30
40
  # define a location where sources will be stored
31
41
  directory "#{USER_HOME}/sources/#{RUBY_CC_VERSION}"
32
42
  directory "#{USER_HOME}/builds/#{RUBY_CC_VERSION}"
@@ -45,7 +55,7 @@ CLOBBER.include("#{USER_HOME}/config.yml")
45
55
  file "#{USER_HOME}/sources/#{RUBY_CC_VERSION}.tar.gz" => ["#{USER_HOME}/sources"] do |t|
46
56
  # download the source file using wget or curl
47
57
  chdir File.dirname(t.name) do
48
- url = "ftp://ftp.ruby-lang.org/pub/ruby/#{MAJOR}/#{File.basename(t.name)}"
58
+ url = "http://ftp.ruby-lang.org/pub/ruby/#{MAJOR}/#{File.basename(t.name)}"
49
59
  sh "wget #{url} || curl -O #{url}"
50
60
  end
51
61
  end
@@ -82,9 +92,9 @@ file "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in" => ["#{USER_HOME}/sou
82
92
  end
83
93
 
84
94
  task :mingw32 do
85
- unless File.exist?('/usr/bin/i586-mingw32msvc-gcc') then
95
+ unless MINGW_HOST then
86
96
  warn "You need to install mingw32 cross compile functionality to be able to continue."
87
- warn "Please refer to your distro documentation about installation."
97
+ warn "Please refer to your distribution/package manager documentation about installation."
88
98
  fail
89
99
  end
90
100
  end
@@ -101,12 +111,14 @@ end
101
111
  file "#{USER_HOME}/builds/#{RUBY_CC_VERSION}/Makefile" => ["#{USER_HOME}/builds/#{RUBY_CC_VERSION}",
102
112
  "#{USER_HOME}/sources/#{RUBY_CC_VERSION}/Makefile.in"] do |t|
103
113
 
104
- # set the configure options
105
114
  options = [
106
- '--host=i586-mingw32msvc',
107
115
  '--target=i386-mingw32',
116
+ "--host=#{MINGW_HOST}",
108
117
  '--build=i686-linux',
109
- '--enable-shared'
118
+ '--enable-shared',
119
+ '--disable-install-doc',
120
+ '--without-tk',
121
+ '--without-tcl'
110
122
  ]
111
123
 
112
124
  chdir File.dirname(t.name) do
@@ -129,21 +141,26 @@ file "#{USER_HOME}/ruby/#{RUBY_CC_VERSION}/bin/ruby.exe" => ["#{USER_HOME}/build
129
141
  sh "make install"
130
142
  end
131
143
  end
144
+ task :install => ["#{USER_HOME}/ruby/#{RUBY_CC_VERSION}/bin/ruby.exe"]
132
145
 
133
- # rbconfig.rb location
134
- file "#{USER_HOME}/ruby/#{RUBY_CC_VERSION}/lib/ruby/#{MAJOR}/i386-mingw32/rbconfig.rb" => ["#{USER_HOME}/ruby/#{RUBY_CC_VERSION}/bin/ruby.exe"]
135
-
136
- file :update_config => ["#{USER_HOME}/ruby/#{RUBY_CC_VERSION}/lib/ruby/#{MAJOR}/i386-mingw32/rbconfig.rb"] do |t|
146
+ desc "Update rake-compiler list of installed Ruby versions"
147
+ task 'update-config' do
137
148
  config_file = "#{USER_HOME}/config.yml"
138
149
  if File.exist?(config_file) then
139
- puts "Updating #{t.name}"
150
+ puts "Updating #{config_file}"
140
151
  config = YAML.load_file(config_file)
141
152
  else
142
- puts "Generating #{t.name}"
153
+ puts "Generating #{config_file}"
143
154
  config = {}
144
155
  end
145
156
 
146
- config["rbconfig-#{MAJOR}"] = File.expand_path(t.prerequisites.first)
157
+ files = Dir.glob("#{USER_HOME}/ruby/**/rbconfig.rb").sort
158
+
159
+ files.each do |rbconfig|
160
+ version = rbconfig.match(/.*-(\d.\d.\d)/)[1]
161
+ config["rbconfig-#{version}"] = rbconfig
162
+ puts "Found Ruby version #{version} (#{rbconfig})"
163
+ end
147
164
 
148
165
  when_writing("Saving changes into #{config_file}") {
149
166
  File.open(config_file, 'w') do |f|
@@ -153,7 +170,10 @@ file :update_config => ["#{USER_HOME}/ruby/#{RUBY_CC_VERSION}/lib/ruby/#{MAJOR}/
153
170
  end
154
171
 
155
172
  task :default do
173
+ # Force the display of the available tasks when no option is given
174
+ Rake.application.options.show_task_pattern = //
175
+ Rake.application.display_tasks_and_comments
156
176
  end
157
177
 
158
178
  desc "Build #{RUBY_CC_VERSION} suitable for cross-platform development."
159
- task 'cross-ruby' => [:mingw32, :environment, :update_config]
179
+ task 'cross-ruby' => [:mingw32, :environment, :install, 'update-config']
data/tasks/common.rake CHANGED
@@ -11,3 +11,6 @@ task :package => [:spec, :features]
11
11
 
12
12
  # make the release re-generate the gemspec if required
13
13
  task :release => [:gemspec]
14
+
15
+ # publish documentation when doing a release
16
+ task :release => [:publish]
data/tasks/cucumber.rake CHANGED
@@ -1,5 +1,5 @@
1
1
  begin
2
- gem 'cucumber', '~> 0.1.8'
2
+ gem 'cucumber'
3
3
  require 'cucumber/rake/task'
4
4
  rescue Exception
5
5
  nil
@@ -12,3 +12,4 @@ if defined?(Cucumber)
12
12
  else
13
13
  warn "Cucumber gem is required, please install it. (gem install cucumber)"
14
14
  end
15
+
data/tasks/gem.rake CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
  GEM_SPEC = Gem::Specification.new do |s|
4
4
  # basic information
5
5
  s.name = "rake-compiler"
6
- s.version = "0.3.0"
6
+ s.version = "0.4.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
 
9
9
  # description and details
data/tasks/news.rake ADDED
@@ -0,0 +1,80 @@
1
+ begin
2
+ gem 'rubyforge', '~> 1.0.1'
3
+ require 'rubyforge'
4
+ rescue Exception
5
+ nil
6
+ end
7
+
8
+ if defined?(RubyForge) then
9
+ if defined?(GEM_SPEC) then
10
+ desc 'Create news email file and post to RubyForge.'
11
+ task :announce do |t|
12
+ ver = ENV['VERSION'] or fail "Must supply VERSION (rake announce VERSION=x.y.z)."
13
+
14
+ # compare versions to avoid mistakes
15
+ unless ver == GEM_SPEC.version.to_s then
16
+ fail "Version mismatch (supplied and specification versions differ)."
17
+ end
18
+
19
+ # no homepage? why announce it then?!
20
+ if GEM_SPEC.homepage == 'TODO' or GEM_SPEC.homepage.nil? then
21
+ fail "Must define homepage in your gem specification."
22
+ end
23
+
24
+ # no rubyforge project? no release for you!
25
+ if GEM_SPEC.rubyforge_project == 'TODO' or GEM_SPEC.rubyforge_project.nil? then
26
+ fail "Must define rubyforge_project in your gem specification."
27
+ end
28
+
29
+ # instantiate a RubyForge object
30
+ rf = RubyForge.new.configure
31
+
32
+ # read project info and overview
33
+ notes = begin
34
+ r = File.read("README.rdoc")
35
+ r.split(/^(=+ .*)/)[1..4].join.strip
36
+ rescue
37
+ warn "Missing README.rdoc"
38
+ ''
39
+ end
40
+
41
+ # read changes
42
+ changes = begin
43
+ h = File.read("History.txt")
44
+ h.split(/^(==.*)/)[1..2].join.strip
45
+ rescue
46
+ warn "Missing History.txt"
47
+ ''
48
+ end
49
+
50
+ # standard fields
51
+ subject = "#{GEM_SPEC.name} #{GEM_SPEC.version} Released"
52
+ title = "#{GEM_SPEC.name} version #{GEM_SPEC.version} has been released!"
53
+ body = "#{notes}\n\nChanges:\n\n#{changes}"
54
+ urls = [GEM_SPEC.homepage, "http://rubyforge.org/projects/#{GEM_SPEC.rubyforge_project}"].map { |u| "* <#{u.strip}>" }.join("\n")
55
+
56
+ puts "Logging in RubyForge..."
57
+ rf.login
58
+
59
+ puts "Generating email.txt..."
60
+ File.open("email.txt", "w") do |mail|
61
+ mail.puts "Subject: [ANN] #{subject}"
62
+ mail.puts
63
+ mail.puts title
64
+ mail.puts
65
+ mail.puts urls
66
+ mail.puts
67
+ mail.puts body
68
+ end
69
+ puts "Created email.txt"
70
+
71
+ puts "Posting news for #{GEM_SPEC.name} version #{GEM_SPEC.version}..."
72
+ rf.post_news GEM_SPEC.rubyforge_project, subject, "#{title}\n\n#{body}"
73
+ puts "Done."
74
+ end
75
+ else
76
+ warn "no GEM_SPEC is found or defined. 'announce' task cannot work without it."
77
+ end
78
+ else
79
+ warn "rubyforge gem is required to generate announces, please install it (gem install rubyforge)."
80
+ end
data/tasks/rdoc.rake CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rake/rdoctask'
2
2
 
3
- Rake::RDocTask.new(:rdoc) do |rd|
3
+ DOC = Rake::RDocTask.new(:rdoc) do |rd|
4
4
  rd.title = 'rake-compiler -- Documentation'
5
5
  rd.main = 'README.rdoc'
6
6
  rd.rdoc_dir = 'doc/api'
@@ -0,0 +1,44 @@
1
+ begin
2
+ gem 'rubyforge', '~> 1.0.1'
3
+ require 'rubyforge'
4
+ rescue Exception
5
+ nil
6
+ end
7
+
8
+ if defined?(RubyForge) then
9
+ if defined?(DOC) && defined?(GEM_SPEC) then
10
+ desc "Publish RDoc to RubyForge"
11
+ task :publish => [:clobber_rdoc, :rdoc] do
12
+ config_file = File.expand_path('~/.rubyforge/user-config.yml')
13
+ fail "You need rubyforge properly configured." unless File.exist?(config_file)
14
+
15
+ # no rubyforge project? no release for you!
16
+ if GEM_SPEC.rubyforge_project == 'TODO' or GEM_SPEC.rubyforge_project.nil? then
17
+ fail "Must define rubyforge_project in your gem specification."
18
+ end
19
+
20
+ # use YAML to load configuration file
21
+ config = YAML.load_file(config_file)
22
+
23
+ host = "#{config['username']}@rubyforge.org"
24
+ remote_dir = "/var/www/gforge-projects/#{GEM_SPEC.rubyforge_project}/"
25
+ local_dir = DOC.rdoc_dir
26
+
27
+ # use PuTTY pscp or scp on other platforms
28
+ ssh_exe = RUBY_PLATFORM =~ /mswin|mingw/ ? 'pscp' : 'scp'
29
+
30
+ # construct the command
31
+ cmd = [ssh_exe]
32
+ cmd << '-r' << '-q' # recursive and quiet options
33
+ cmd << "#{local_dir}/*"
34
+ cmd << "#{host}:#{remote_dir}"
35
+
36
+ puts "Publishing RDocs to RubyForge..."
37
+ sh cmd.join(' ')
38
+ end
39
+ else
40
+ warn "You need a GEM_SPEC and DOC rdoc definitions present. task publish not defined."
41
+ end
42
+ else
43
+ warn "rubyforge gem is required to generate releases, please install it (gem install rubyforge)."
44
+ end
data/tasks/release.rake CHANGED
@@ -7,7 +7,8 @@ end
7
7
 
8
8
  if defined?(RubyForge) then
9
9
  if defined?(GEM_SPEC) then
10
- task :release => [:clean, :package] do |t|
10
+ desc 'Package and upload to RubyForge'
11
+ task :release => [:clobber, :package] do |t|
11
12
  ver = ENV['VERSION'] or fail "Must supply VERSION (rake release VERSION=x.y.z)."
12
13
 
13
14
  # compare versions to avoid mistakes
@@ -50,12 +51,6 @@ if defined?(RubyForge) then
50
51
  # prepare configuration
51
52
  rf.configure config
52
53
 
53
- # ensure this was not released before
54
- releases = rf.autoconfig['release_ids']
55
- if releases.has_key?(GEM_SPEC.name) and releases[GEM_SPEC.name][GEM_SPEC.version] then
56
- fail "Release #{GEM_SPEC.version} already exist. Unable to release."
57
- end
58
-
59
54
  files = FileList["pkg/#{GEM_SPEC.name}-#{GEM_SPEC.version}*.*"].to_a
60
55
  fail "No files found for the release." if files.empty?
61
56
 
@@ -68,7 +63,7 @@ if defined?(RubyForge) then
68
63
  end
69
64
 
70
65
  puts "Releasing #{GEM_SPEC.name} version #{GEM_SPEC.version}..."
71
- #rf.add_release GEM_SPEC.rubyforge_project, GEM_SPEC.name, GEM_SPEC.version, *files
66
+ rf.add_release GEM_SPEC.rubyforge_project, GEM_SPEC.name, GEM_SPEC.version, *files
72
67
  puts "Done."
73
68
  end
74
69
  else
data/tasks/rspec.rake CHANGED
@@ -1,10 +1,14 @@
1
1
  begin
2
- gem 'rspec', '~> 1.1.9'
3
- gem 'rcov', '~> 0.8.1'
4
2
  require 'spec/rake/spectask'
5
- require 'rcov'
6
- rescue Exception
7
- nil
3
+
4
+ begin
5
+ require 'rcov'
6
+ rescue LoadError
7
+ warn "RCov gem is required, please install it (gem install rcov)."
8
+ end
9
+
10
+ rescue LoadError
11
+ warn "RSpec gem is required, please install it (gem install rspec)."
8
12
  end
9
13
 
10
14
  if defined?(Spec)
@@ -25,9 +29,6 @@ if defined?(Spec)
25
29
  t.rcov_opts = ["--exclude", "spec/*,features/*,gems/*"]
26
30
  end
27
31
  end
28
- else
29
- warn "RCov gem is required, please install it (gem install rcov)."
30
32
  end
31
- else
32
- warn "RSpec gem is required, please install it (gem install rspec)."
33
33
  end
34
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luislavena-rake-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Lavena
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-06 21:00:00 -08:00
12
+ date: 2009-04-02 20:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ files:
49
49
  - features/support/file_templates.rb
50
50
  - features/support/generators.rb
51
51
  - bin/rake-compiler
52
+ - lib/rake/extensioncompiler.rb
52
53
  - lib/rake/extensiontask.rb
53
54
  - spec/lib/rake/extensiontask_spec.rb
54
55
  - spec/spec_helper.rb
@@ -56,7 +57,9 @@ files:
56
57
  - tasks/common.rake
57
58
  - tasks/cucumber.rake
58
59
  - tasks/gem.rake
60
+ - tasks/news.rake
59
61
  - tasks/rdoc.rake
62
+ - tasks/rdoc_publish.rake
60
63
  - tasks/release.rake
61
64
  - tasks/rspec.rake
62
65
  - Rakefile