Skip to content

Commit

Permalink
Tilman Sauerbeck's patch to support
Browse files Browse the repository at this point in the history
        extensions built with Rake!


git-svn-id: svn+ssh://rubyforge.org/var/svn/rubygems/trunk@945 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information
chad committed Oct 31, 2005
1 parent 22a6a4e commit 5834d27
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 19 deletions.
4 changes: 4 additions & 0 deletions rubygems/ChangeLog
@@ -1,3 +1,7 @@
2005-10-31 Chad Fowler <chad@chadfowler.com>
* lib/rubygems/installer.rb: Tilman Sauerbeck's patch to support
extensions built with Rake!

2005-09-13 Jim Weirich <jim@weirichhouse.org>

* lib/rubygems/package.rb (TarInput::initialize): Removed
Expand Down
81 changes: 62 additions & 19 deletions rubygems/lib/rubygems/installer.rb
Expand Up @@ -284,29 +284,32 @@ def build_extensions(directory, spec)
say "Building native extensions. This could take a while..."
start_dir = Dir.pwd
dest_path = File.join(directory, spec.require_paths[0])

spec.extensions.each do |extension|
Dir.chdir File.join(directory, File.dirname(extension))
results = ["#{Gem.ruby} #{File.basename(extension)} #{ARGV.join(" ")}"]
results << `#{Gem.ruby} #{File.basename(extension)} #{ARGV.join(" ")}`
if File.exist?('Makefile')
mf = File.read('Makefile')
mf = mf.gsub(/^RUBYARCHDIR\s*=\s*\$.*/, "RUBYARCHDIR = #{dest_path}")
mf = mf.gsub(/^RUBYLIBDIR\s*=\s*\$.*/, "RUBYLIBDIR = #{dest_path}")
File.open('Makefile', 'wb') {|f| f.print mf}
make_program = ENV['make']
unless make_program
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
end
results << "#{make_program}"
results << `#{make_program}`
results << "#{make_program} install"
results << `#{make_program} install`
say results.join("\n")
if extension.match(/extconf/)
builder = ExtExtConfBuilder
elsif extension.match(/rakefile/i)
builder = ExtRakeBuilder
else
File.open(File.join(Dir.pwd, 'gem_make.out'), 'wb') {|f| f.puts results.join("\n")}
raise "ERROR: Failed to build gem native extension.\nGem files will remain installed in #{directory} for inspection.\n #{results.join('\n')}\n\nResults logged to #{File.join(Dir.pwd, 'gem_make.out')}"
builder = nil
results = ["No builder for extension '#{extension}'"]
end

begin
err = false
Dir.chdir File.join(directory, File.dirname(extension))
p builder
results = builder.build(extension, directory, dest_path)
rescue
err = true
end

say results.join("\n")
File.open('gem_make.out', 'wb') {|f| f.puts results.join("\n")}

if err
raise "ERROR: Failed to build gem native extension.\nGem files will remain installed in #{directory} for inspection.\n #{results.join('\n')}\n\nResults logged to #{File.join(Dir.pwd, 'gem_make.out')}"
end
end
Dir.chdir start_dir
end
Expand Down Expand Up @@ -535,4 +538,44 @@ def remove_app_stubs(spec, other_specs)

end # class Uninstaller

class ExtExtConfBuilder
def ExtExtConfBuilder.build(extension, directory, dest_path)
results = ["#{Gem.ruby} #{File.basename(extension)} #{ARGV.join(" ")}"]
results << `#{Gem.ruby} #{File.basename(extension)} #{ARGV.join(" ")}`

raise unless File.exist?('Makefile')
mf = File.read('Makefile')
mf = mf.gsub(/^RUBYARCHDIR\s*=\s*\$.*/, "RUBYARCHDIR = #{dest_path}")
mf = mf.gsub(/^RUBYLIBDIR\s*=\s*\$.*/, "RUBYLIBDIR = #{dest_path}")
File.open('Makefile', 'wb') {|f| f.print mf}

make_program = ENV['make']
unless make_program
make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
end

['', 'install', 'clean'].each do |target|
results << "#{make_program} #{target}".strip
results << `#{make_program} #{target}`
end

results
end
end

class ExtRakeBuilder
def ExtRakeBuilder.build(ext, directory, dest_path)
make_program = ENV['rake'] || 'rake'
make_program += " RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}"

results = []

['', 'install', 'clean'].each do |target|
results << "#{make_program} #{target}".strip
results << `#{make_program} #{target}`
end

results
end
end
end # module Gem

0 comments on commit 5834d27

Please sign in to comment.