Skip to content
Browse files

Install gems with API instead of using subprocesses.

  • Loading branch information...
1 parent d1ecf2c commit 8029ae33fe209be7287808605b6a3570aa708653 @brixen brixen committed Jul 26, 2012
Showing with 32 additions and 14 deletions.
  1. +1 −14 rakelib/gems.rake
  2. +31 −0 rakelib/preinstall_gems.rb
View
15 rakelib/gems.rake
@@ -1,29 +1,16 @@
namespace :gems do
desc 'Install the pre-installed gems'
task :install do
- STDOUT.puts "Installing pre-installed gems..."
ENV['GEM_HOME'] = ENV['GEM_PATH'] = nil
if BUILD_CONFIG[:stagingdir]
rbx = "#{BUILD_CONFIG[:stagingdir]}#{BUILD_CONFIG[:bindir]}/#{BUILD_CONFIG[:program_name]}"
else
rbx = "#{BUILD_CONFIG[:sourcedir]}/bin/#{BUILD_CONFIG[:program_name]}"
end
- gems = Dir["preinstalled-gems/*.gem"]
- options = "--local --conservative --ignore-dependencies --no-rdoc --no-ri"
BUILD_CONFIG[:version_list].each do |ver|
- gems.each do |gem|
- parts = File.basename(gem, ".gem").split "-"
- gem_name = parts[0..-2].join "-"
- gem_version = parts[-1]
-
- system "#{rbx} -X#{ver} -S gem query --name-matches #{gem_name} --installed --version #{gem_version} > #{DEV_NULL}"
-
- unless $?.success?
- sh "#{rbx} -X#{ver} -S gem install #{options} #{gem}"
- end
- end
+ sh "#{rbx} -X#{ver} #{BUILD_CONFIG[:sourcedir]}/rakelib/preinstall_gems.rb"
end
end
end
View
31 rakelib/preinstall_gems.rb
@@ -0,0 +1,31 @@
+require 'rubygems'
+require 'rubygems/dependency_installer'
+
+puts "Pre-installing gems for #{RUBY_VERSION}..."
+
+gems = Dir["preinstalled-gems/*.gem"]
+options = {
+ :wrappers => true,
+ :domain => :local,
+ :generate_ri => false,
+ :generate_rdoc => false,
+ :ignore_dependencies => true,
+ :conservative => true
+}
+
+gems.each do |gem|
+ parts = File.basename(gem, ".gem").split "-"
+ gem_name = parts[0..-2].join "-"
+ gem_version = parts[-1]
+
+ name_re = /#{gem_name}/
+ version_req = Gem::Requirement.create "=#{gem_version}"
+ unless Gem::Specification.any? { |s| s.name =~ name_re and version_req =~ s.version }
+ options[:args] = gem
+ options[:version] = version_req
+ inst = Gem::DependencyInstaller.new options
+ inst.install gem, version_req
+
+ puts "Installed #{gem_name}-#{gem_version}"
+ end
+end

0 comments on commit 8029ae3

Please sign in to comment.
Something went wrong with that request. Please try again.