summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--History.txt13
-rw-r--r--README.rdoc5
-rw-r--r--lib/rake/extensiontask.rb16
-rw-r--r--spec/lib/rake/extensiontask_spec.rb10
4 files changed, 42 insertions, 2 deletions
diff --git a/History.txt b/History.txt
index e00ed46..fd12a73 100644
--- a/History.txt
+++ b/History.txt
@@ -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.
diff --git a/README.rdoc b/README.rdoc
index 02e428b..480b158 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -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
diff --git a/lib/rake/extensiontask.rb b/lib/rake/extensiontask.rb
index 9cd94f0..d893110 100644
--- a/lib/rake/extensiontask.rb
+++ b/lib/rake/extensiontask.rb
@@ -44,6 +44,7 @@ module Rake
@config_options = []
@cross_compile = false
@cross_config_options = []
+ @cross_compiling = nil
end
def platform
@@ -54,6 +55,10 @@ module Rake
@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 @@ module Rake
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 @@ module Rake
# 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 @@ module Rake
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
diff --git a/spec/lib/rake/extensiontask_spec.rb b/spec/lib/rake/extensiontask_spec.rb
index 8045f0f..0fa55ef 100644
--- a/spec/lib/rake/extensiontask_spec.rb
+++ b/spec/lib/rake/extensiontask_spec.rb
@@ -299,6 +299,16 @@ describe Rake::ExtensionTask do
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')