Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved, applied fixes from bundler team
- Loading branch information
Showing
4 changed files
with
131 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,64 @@ | ||
module Gem::BundlerInstaller | ||
def bundler_generate_bin | ||
return if @spec.executables.nil? or @spec.executables.empty? | ||
|
||
# If the user has asked for the gem to be installed in a directory that is | ||
# the system gem directory, then use the system bin directory, else create | ||
# (or use) a new bin dir under the gem_home. | ||
bindir = @bin_dir ? @bin_dir : Gem.bindir(@gem_home) | ||
|
||
Dir.mkdir bindir unless File.exist? bindir | ||
raise Gem::FilePermissionError.new(bindir) unless File.writable? bindir | ||
|
||
@spec.executables.each do |filename| | ||
module RubyGemsBundlerInstaller | ||
# Iterate through executables and generate wrapper for each one, | ||
# extract of rubygems code | ||
def self.bundler_generate_bin(inst) | ||
return if inst.spec.executables.nil? or inst.spec.executables.empty? | ||
bindir = inst.bin_dir ? inst.bin_dir : Gem.bindir(inst.gem_home) | ||
inst.spec.executables.each do |filename| | ||
filename.untaint | ||
bin_path = File.expand_path "#{@spec.bindir}/#{filename}", @gem_dir | ||
if File.exist?(bin_path) | ||
mode = File.stat(bin_path).mode | 0111 | ||
File.chmod mode, bin_path | ||
end | ||
|
||
if @wrappers then | ||
bundler_generate_bin_script filename, bindir | ||
bin_script_path = File.join bindir, inst.formatted_program_filename(filename) | ||
FileUtils.rm_f bin_script_path | ||
File.open bin_script_path, 'wb', 0755 do |file| | ||
file.print bundler_app_script_text(inst, filename) | ||
end | ||
inst.say bin_script_path if Gem.configuration.really_verbose | ||
end | ||
end | ||
|
||
## | ||
# Creates the scripts to run the applications in the gem. | ||
#-- | ||
# The Windows script is generated in addition to the regular one due to a | ||
# bug or misfeature in the Windows shell's pipe. See | ||
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/193379 | ||
|
||
def bundler_generate_bin_script(filename, bindir) | ||
bin_script_path = File.join bindir, formatted_program_filename(filename) | ||
|
||
FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers | ||
|
||
File.open bin_script_path, 'wb', 0755 do |file| | ||
file.print bundler_app_script_text(filename) | ||
end | ||
|
||
say bin_script_path if Gem.configuration.really_verbose | ||
end | ||
|
||
## | ||
# Return the text for an application file. | ||
def bundler_app_script_text(bin_file_name) | ||
def self.bundler_app_script_text(inst, bin_file_name) | ||
<<-TEXT | ||
#{shebang bin_file_name} | ||
#{inst.shebang bin_file_name} | ||
# | ||
# This file was generated by RubyGems extended wrapper. | ||
# | ||
# The application '#{spec.name}' is installed as part of a gem, and | ||
# The application '#{inst.spec.name}' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
require 'rubygems' | ||
gemfile = ENV['BUNDLE_GEMFILE'] | ||
use_bundler = (ENV['USE_BUNDLER']||'').downcase | ||
try_bundler = %w{try check possibly}.include? use_bundler | ||
force_bundler = %w{force require yes true on}.include? use_bundler | ||
version = "#{Gem::Requirement.default}" | ||
if !gemfile.nil? && File.exist?(gemfile) | ||
if try_bundler || force_bundler | ||
begin | ||
require 'bundler/setup' | ||
rescue LoadError | ||
gemfile = nil | ||
raise '\n\nPlease install bundler first.\n\n' if force_bundler | ||
try_bundler = false | ||
end | ||
else | ||
gemfile = nil | ||
end | ||
if gemfile.nil? | ||
unless try_bundler | ||
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then | ||
version = $1 | ||
ARGV.shift | ||
end | ||
gem '#{spec.name}', version | ||
gem '#{inst.spec.name}', version | ||
end | ||
load Gem.bin_path('#{spec.name}', '#{bin_file_name}', version) | ||
load Gem.bin_path('#{inst.spec.name}', '#{bin_file_name}', version) | ||
TEXT | ||
end | ||
|
||
end | ||
|
||
module Gem | ||
post_install do |inst| | ||
class << inst | ||
include Gem::BundlerInstaller | ||
end | ||
inst.bundler_generate_bin | ||
RubyGemsBundlerInstaller.bundler_generate_bin(inst) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters