Permalink
Browse files

Allow alteration of the Gem Specification when cross compiling. Closes

…GH-3

This is useful to indicate a custom requirement message, like DLLs
installation or similar.

  Rake::ExtensionTask.new('my_extension', GEM_SPEC) do |ext|
    ext.cross_compile = true
    ext.cross_compiling do |gem_spec|
      gem_spec.post_install_message = "You've installed a binary version of this gem"
    end
  end
  • Loading branch information...
luislavena committed Oct 22, 2009
1 parent 9507950 commit 1bb1c7e9c3d02f6f37eb6c5bd9f7bc653d4c6196
Showing with 42 additions and 2 deletions.
  1. +13 −0 History.txt
  2. +5 −0 README.rdoc
  3. +14 −2 lib/rake/extensiontask.rb
  4. +10 −0 spec/lib/rake/extensiontask_spec.rb
@@ -1,5 +1,18 @@
=== (in Git)
* Enhancements
* Allow alteration of the Gem Specification when cross compiling. Closes GH-3
This is useful to indicate a custom requirement message, like DLLs
installation or similar.
Rake::ExtensionTask.new('my_extension', GEM_SPEC) do |ext|
ext.cross_compile = true
# ...
ext.cross_compiling do |gem_spec|
gem_spec.post_install_message = "You've installed a binary version of this gem"
end
end
* Bugfixes
* Detect GNU make independently of distribution based naming.
Thanks to flori for patches.
@@ -201,6 +201,11 @@ Now, you only need to use additional options in your extension definition:
ext.cross_platform = 'i386-mswin32' # forces the Windows platform instead of the default one
# configure options only for cross compile
ext.cross_config_options << '--with-something'
# perform alterations on the gemspec when cross compiling
ext.cross_compiling do |gem_spec|
gem_spec.post_install_message = "You installed the binary version of this gem!"
end
end
By default, cross compilation targets 'i386-mingw32' which is default GCC platform
@@ -44,6 +44,7 @@ def init(name = nil, gem_spec = nil)
@config_options = []
@cross_compile = false
@cross_config_options = []
@cross_compiling = nil
end
def platform
@@ -54,6 +55,10 @@ def cross_platform
@cross_platform ||= 'i386-mingw32'
end
def cross_compiling(&block)
@cross_compiling = block if block_given?
end
def define
fail "Extension name must be provided." if @name.nil?
@@ -169,7 +174,7 @@ def define_compile_tasks(for_platform = nil, ruby_ver = RUBY_VERSION)
end
end
def define_native_tasks(for_platform = nil, ruby_ver = RUBY_VERSION)
def define_native_tasks(for_platform = nil, ruby_ver = RUBY_VERSION, callback = nil)
platf = for_platform || platform
# tmp_path
@@ -202,6 +207,11 @@ def define_native_tasks(for_platform = nil, ruby_ver = RUBY_VERSION)
# include the files in the gem specification
spec.files += ext_files
# expose gem specification for customization
if callback
callback.call(spec)
end
# Generate a package for this gem
gem_package = Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_zip = false
@@ -306,7 +316,9 @@ def define_cross_platform_tasks_with_version(for_platform, ruby_ver)
end
# now define native tasks for cross compiled files
define_native_tasks(for_platform, ruby_ver) if @gem_spec && @gem_spec.platform == 'ruby'
if @gem_spec && @gem_spec.platform == 'ruby' then
define_native_tasks(for_platform, ruby_ver, @cross_compiling)
end
# create cross task
task 'cross' do
@@ -299,6 +299,16 @@
err.should match(/no configuration section for specified version of Ruby/)
end
it 'should capture an action block to be executed when cross compiling' do
lambda {
Rake::ExtensionTask.new('extension_one') do |ext|
ext.cross_compiling do |gem_spec|
gem_spec.post_install_message = "Cross compiled gem"
end
end
}.should_not raise_error
end
it 'should allow usage of RUBY_CC_VERSION to indicate a different version of ruby' do
config = mock(Hash)
config.should_receive(:[]).with("rbconfig-1.9.1").and_return('/path/to/ruby/1.9.1/rbconfig.rb')

0 comments on commit 1bb1c7e

Please sign in to comment.