lib/bundler/source.rb in bundler-1.0.0.beta.4 vs lib/bundler/source.rb in bundler-1.0.0.beta.5

- old
+ new

@@ -84,23 +84,27 @@ end Bundler.ui.info "Installing #{spec.name} (#{spec.version}) " install_path = Bundler.requires_sudo? ? Bundler.tmp : Gem.dir - installer = Gem::Installer.new path, - :install_dir => install_path, - :ignore_dependencies => true, - :wrappers => true, - :env_shebang => true, - :bin_dir => "#{install_path}/bin" + options = { :install_dir => install_path, + :ignore_dependencies => true, + :wrappers => true, + :env_shebang => true } + options.merge!(:bin_dir => "#{install_path}/bin") unless spec.executables.nil? || spec.executables.empty? + + installer = Gem::Installer.new path, options installer.install # SUDO HAX if Bundler.requires_sudo? sudo "mkdir -p #{Gem.dir}/gems #{Gem.dir}/specifications" sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Gem.dir}/gems/" sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Gem.dir}/specifications/" + spec.executables.each do |exe| + Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Gem.dir}/bin/" + end end spec.loaded_from = "#{Gem.dir}/specifications/#{spec.full_name}.gemspec" end @@ -365,18 +369,31 @@ def local_specs @local_specs ||= load_spec_files end class Installer < Gem::Installer - def initialize(spec) + def initialize(spec, options = {}) @spec = spec - @bin_dir = "#{Gem.dir}/bin" + @bin_dir = Bundler.requires_sudo? ? "#{Bundler.tmp}/bin" : "#{Gem.dir}/bin" @gem_dir = spec.full_gem_path - @wrappers = true - @env_shebang = true - @format_executable = false + @wrappers = options[:wrappers] || true + @env_shebang = options[:env_shebang] || true + @format_executable = options[:format_executable] || false end + + def generate_bin + return if spec.executables.nil? || spec.executables.empty? + + FileUtils.mkdir_p("#{Bundler.tmp}/bin") if Bundler.requires_sudo? + super + if Bundler.requires_sudo? + Bundler.mkdir_p "#{Gem.dir}/bin" + spec.executables.each do |exe| + Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Gem.dir}/bin/" + end + end + end end def install(spec) Bundler.ui.info "Using #{spec.name} (#{spec.version}) from #{to_s} " # Let's be honest, when we're working from a path, we can't @@ -419,18 +436,11 @@ end end.compact gem_file = Dir.chdir(gem_dir){ Gem::Builder.new(spec).build } - installer = Gem::Installer.new File.join(gem_dir, gem_file), - :bin_dir => "#{Gem.dir}/bin", - :wrappers => true, - :env_shebang => false, - :format_executable => false - - installer.instance_eval { @gem_dir = gem_dir } - + installer = Installer.new(spec, :env_shebang => false) installer.build_extensions installer.generate_bin rescue Gem::InvalidSpecificationException => e Bundler.ui.warn "\n#{spec.name} at #{spec.full_gem_path} did not have a valid gemspec.\n" \ "This prevents bundler from installing bins or native extensions, but " \ @@ -532,10 +542,11 @@ end generate_bin(spec) end def load_spec_files - super if cache_path.exist? + return super if cache_path.exist? + raise PathError rescue PathError raise PathError, "#{to_s} is not checked out. Please run `bundle install`" end private