0
-require 'rubygems/dependency_installer'
0
-require 'rubygems/uninstaller'
0
-require 'rubygems/dependency'
0
module ColorfulMessages
0
@@ -22,8 +19,24 @@ module ColorfulMessages
0
alias_method :message, :success
0
+ puts messages.map { |msg| "\033[1;35m#{msg}\033[0m" }
0
+ puts messages.map { |msg| "\033[1;34m#{msg}\033[0m" }
0
+##############################################################################
0
+require 'rubygems/dependency_installer'
0
+require 'rubygems/uninstaller'
0
+require 'rubygems/dependency'
0
include ColorfulMessages
0
@@ -39,13 +52,13 @@ module GemManagement
0
version = options.delete(:version)
0
Gem.configuration.update_sources = false
0
+ # Limit source index to install dir
0
update_source_index(options[:install_dir]) if options[:install_dir]
0
installer = Gem::DependencyInstaller.new(options.merge(:user_install => false))
0
- # Exclude gems to refresh from index - force (re)install of new version
0
- # def installer.source_index; @source_index; end
0
+ # Force-refresh certain gems by excluding them from the current index
0
+ if refresh.respond_to?(:include?) && !refresh.empty?
0
source_index = installer.instance_variable_get(:@source_index)
0
source_index.gems.each do |name, spec|
0
source_index.gems.delete(name) if refresh.include?(spec.name)
0
@@ -103,79 +116,54 @@ module GemManagement
0
# Install a gem from source - builds and packages it first then installs.
0
- def install_gem_from_src(gem_src_dir, options = {})
0
- if !File.directory?(gem_src_dir)
0
- raise "Missing rubygem source path: #{gem_src_dir}"
0
- if options[:install_dir] && !File.directory?(options[:install_dir])
0
- raise "Missing rubygems path: #{options[:install_dir]}"
0
- gem_name = File.basename(gem_src_dir)
0
- gem_pkg_dir = File.expand_path(File.join(gem_src_dir, 'pkg'))
0
+ # install_from_source(source_dir, :install_dir => ...)
0
+ # install_from_source(source_dir, gem_name)
0
+ # install_from_source(source_dir, :skip => [...])
0
+ def install_from_source(source_dir, *args)
0
+ Dir.chdir(source_dir) do
0
+ options = args.last.is_a?(Hash) ? args.pop : {}
0
+ gem_name = args[0] || File.basename(source_dir)
0
+ gem_pkg_dir = File.join(source_dir, 'pkg')
0
+ skip_gems = options.delete(:skip) || []
0
- # We need to use local bin executables if available.
0
- thor = "#{Gem.ruby} -S #{which('thor')}"
0
- rake = "#{Gem.ruby} -S #{which('rake')}"
0
+ # Cleanup what's already there
0
+ FileUtils.mkdir_p(gem_pkg_dir) unless File.directory?(gem_pkg_dir)
0
- # Handle pure Thor installation instead of Rake
0
- if File.exists?(File.join(gem_src_dir, 'Thorfile'))
0
- # Remove any existing packages.
0
- FileUtils.rm_rf(gem_pkg_dir) if File.directory?(gem_pkg_dir)
0
- FileUtils.cd(gem_src_dir) { system("#{thor} :package") }
0
- # Install the package using rubygems.
0
- if package = Dir[File.join(gem_pkg_dir, "#{gem_name}-*.gem")].last
0
- FileUtils.cd(File.dirname(package)) do
0
- install_gem(File.basename(package), options.dup)
0
+ # Recursively process all gem packages within the source dir
0
+ packages = package_all(source_dir, skip_gems)
0
+ if packages.length == 1
0
+ # The are no subpackages for the main package
0
+ options[:refresh] = [gem_name]
0
- raise Gem::InstallError, "No package found for #{gem_name}"
0
- # Handle elaborate installation through Rake
0
- # Clean and regenerate any subgems for meta gems.
0
- Dir[File.join(gem_src_dir, '*', 'Rakefile')].each do |rakefile|
0
- FileUtils.cd(File.dirname(rakefile)) do
0
- system("#{rake} clobber_package; #{rake} package")
0
+ # Gather all packages into the top-level pkg directory
0
+ packages.each do |pkg|
0
+ FileUtils.copy_entry(pkg, File.join(gem_pkg_dir, File.basename(pkg)))
0
+ # Finally package the main gem - without clobbering the already copied pkgs
0
+ package(source_dir, false)
0
+ # Gather subgems to refresh during installation of the main gem
0
+ options[:refresh] = packages.map do |pkg|
0
+ File.basename(pkg, '.gem')[/^(.*?)-([\d\.]+)$/, 1] rescue nil
0
- # Handle the main gem install.
0
- if File.exists?(File.join(gem_src_dir, 'Rakefile'))
0
- # Remove any existing packages.
0
- FileUtils.cd(gem_src_dir) { system("#{rake} clobber_package") }
0
- # Create the main gem pkg dir if it doesn't exist.
0
- FileUtils.mkdir_p(gem_pkg_dir) unless File.directory?(gem_pkg_dir)
0
- # Copy any subgems to the main gem pkg dir.
0
- Dir[File.join(gem_src_dir, '*', 'pkg', '*.gem')].each do |subgem_pkg|
0
- if name = File.basename(subgem_pkg, '.gem')[/^(.*?)-([\d\.]+)$/, 1]
0
- dest = File.join(gem_pkg_dir, File.basename(subgem_pkg))
0
- FileUtils.copy_entry(subgem_pkg, dest, true, false, true)
0
- # Finally generate the main package and install it; subgems
0
- # (dependencies) are local to the main package.
0
- FileUtils.cd(gem_src_dir) do
0
- system("#{rake} package")
0
- FileUtils.cd(gem_pkg_dir) do
0
- if package = Dir[File.join(gem_pkg_dir, "#{gem_name}-*.gem")].last
0
- # If the (meta) gem has it's own package, install it.
0
- install_gem(File.basename(package), options.merge(:refresh => subgems))
0
- # Otherwise install each package seperately.
0
- Dir["*.gem"].each { |gem| install_gem(gem, options.dup) }
0
+ gem_pkg = Dir[File.join(gem_pkg_dir, "#{gem_name}-*.gem")][0]
0
+ if File.exists?(gem_pkg)
0
+ # Needs to be executed from the directory that contains all packages
0
+ Dir.chdir(File.dirname(gem_pkg)) do
0
+ install_gem(gem_pkg, options)
0
- raise Gem::InstallError, "No Rakefile found for #{gem_name}"
0
@@ -187,6 +175,44 @@ module GemManagement
0
Gem::Uninstaller.new(gem, options).uninstall
0
+ def clobber(source_dir)
0
+ Dir.chdir(source_dir) do
0
+ sh "#{Gem.ruby} -S rake -s clobber" if File.exists?('Rakefile')
0
+ def package(source_dir, clobber = true)
0
+ Dir.chdir(source_dir) do
0
+ if File.exists?('Rakefile')
0
+ rake "clobber" if clobber
0
+ Dir[File.join(source_dir, 'pkg/*.gem')]
0
+ def package_all(source_dir, skip = [], packages = [])
0
+ if Dir[File.join(source_dir, '{Rakefile,Thorfile}')][0] &&
0
+ !skip.include?(File.basename(source_dir))
0
+ Dir[File.join(source_dir, '*', '{Rakefile,Thorfile}')].each do |taskfile|
0
+ package_all(File.dirname(taskfile), skip, packages)
0
+ packages.push(*package(source_dir))
0
+ sh "#{Gem.ruby} -S #{which('rake')} -s #{cmd}"
0
+ sh "#{Gem.ruby} -S #{which('thor')} #{cmd}"
0
# Use the local bin/* executables if available.
0
if File.executable?(exec = File.join(Dir.pwd, 'bin', executable))
0
@@ -196,6 +222,29 @@ module GemManagement
0
+ # Partition gems into system, local and missing gems
0
+ def partition_dependencies(dependencies, gem_dir)
0
+ system_specs, local_specs, missing_deps = [], [], []
0
+ if gem_dir && File.directory?(gem_dir)
0
+ gem_dir = File.expand_path(gem_dir)
0
+ ::Gem.clear_paths; ::Gem.path.unshift(gem_dir)
0
+ ::Gem.source_index.refresh!
0
+ dependencies.each do |dep|
0
+ if gemspec = ::Gem.source_index.search(dep).last
0
+ if gemspec.loaded_from.index(gem_dir) == 0
0
+ local_specs << gemspec
0
+ system_specs << gemspec
0
+ [system_specs, local_specs, missing_deps]
0
# Create a modified executable wrapper in the specified bin directory.
0
def ensure_bin_wrapper_for(gem_dir, bin_dir, *gems)
0
if bin_dir && File.directory?(bin_dir)
Comments
No one has commented yet.