lib/rake/extensiontask.rb in luislavena-rake-compiler-0.3.0 vs lib/rake/extensiontask.rb in luislavena-rake-compiler-0.3.1
- old
+ new
@@ -74,26 +74,26 @@
# tmp_path
tmp_path = "#{@tmp_dir}/#{platf}/#{@name}"
# cleanup and clobbering
CLEAN.include(tmp_path)
- CLOBBER.include("#{@lib_dir}/#{binary}")
+ CLOBBER.include("#{@lib_dir}/#{binary(platf)}")
CLOBBER.include("#{@tmp_dir}")
# directories we need
directory tmp_path
directory lib_dir
# copy binary from temporary location to final lib
# tmp/extension_name/extension_name.{so,bundle} => lib/
- task "copy:#{@name}:#{platf}" => [lib_dir, "#{tmp_path}/#{binary}"] do
- cp "#{tmp_path}/#{binary}", "#{@lib_dir}/#{binary}"
+ task "copy:#{@name}:#{platf}" => [lib_dir, "#{tmp_path}/#{binary(platf)}"] do
+ cp "#{tmp_path}/#{binary(platf)}", "#{@lib_dir}/#{binary(platf)}"
end
# binary in temporary folder depends on makefile and source files
# tmp/extension_name/extension_name.{so,bundle}
- file "#{tmp_path}/#{binary}" => ["#{tmp_path}/Makefile"] + source_files do
+ file "#{tmp_path}/#{binary(platf)}" => ["#{tmp_path}/Makefile"] + source_files do
chdir tmp_path do
sh make
end
end
@@ -134,11 +134,11 @@
# Only add this extension to the compile chain if current
# platform matches the indicated one.
if platf == RUBY_PLATFORM then
# ensure file is always copied
- file "#{@lib_dir}/#{binary}" => ["copy:#{name}:#{platf}"]
+ file "#{@lib_dir}/#{binary(platf)}" => ["copy:#{name}:#{platf}"]
task "compile:#{@name}" => ["compile:#{@name}:#{platf}"]
task "compile" => ["compile:#{platf}"]
end
end
@@ -148,14 +148,16 @@
# tmp_path
tmp_path = "#{@tmp_dir}/#{platf}/#{@name}"
# create 'native:gem_name' and chain it to 'native' task
- spec = @gem_spec.dup
-
unless Rake::Task.task_defined?("native:#{@gem_spec.name}:#{platf}")
task "native:#{@gem_spec.name}:#{platf}" do |t|
+ # FIXME: truly duplicate the Gem::Specification
+ # workaround the lack of #dup for Gem::Specification
+ spec = Gem::Specification.from_yaml(gem_spec.to_yaml)
+
# adjust to specified platform
spec.platform = platf
# clear the extensions defined in the specs
spec.extensions.clear
@@ -183,11 +185,11 @@
task "#{gem_package.package_dir}/#{gem_package.gem_file}" => ["copy:#{@name}:#{platf}"]
end
end
# add binaries to the dependency chain
- task "native:#{@gem_spec.name}:#{platf}" => ["#{tmp_path}/#{binary}"]
+ task "native:#{@gem_spec.name}:#{platf}" => ["#{tmp_path}/#{binary(platf)}"]
# Allow segmented packaging by platfrom (open door for 'cross compile')
task "native:#{platf}" => ["native:#{@gem_spec.name}:#{platf}"]
# Only add this extension to the compile chain if current
@@ -238,12 +240,15 @@
# chain the cross platform ones
task 'compile' => ["compile:#{cross_platform}"]
# clear lib/binary dependencies and trigger cross platform ones
- Rake::Task["#{@lib_dir}/#{binary}"].prerequisites.clear
- file "#{@lib_dir}/#{binary}" => ["copy:#{@name}:#{cross_platform}"]
+ # check if lib/binary is defined (damn bundle versus so versus dll)
+ if Rake::Task.task_defined?("#{@lib_dir}/#{binary(cross_platform)}") then
+ Rake::Task["#{@lib_dir}/#{binary(cross_platform)}"].prerequisites.clear
+ end
+ file "#{@lib_dir}/#{binary(cross_platform)}" => ["copy:#{@name}:#{cross_platform}"]
# if everything for native task is in place
if @gem_spec && @gem_spec.platform == 'ruby' then
Rake::Task['native'].prerequisites.clear
task 'native' => ["native:#{cross_platform}"]
@@ -257,11 +262,19 @@
def make
RUBY_PLATFORM =~ /mswin/ ? 'nmake' : 'make'
end
- def binary
- "#{@name}.#{RbConfig::CONFIG['DLEXT']}"
+ def binary(platform = nil)
+ ext = case platform
+ when /darwin/
+ 'bundle'
+ when /mingw|mswin|linux/
+ 'so'
+ else
+ RbConfig::CONFIG['DLEXT']
+ end
+ "#{@name}.#{ext}"
end
def source_files
@source_files ||= FileList["#{@ext_dir}/#{@name}/#{@source_pattern}"]
end