jcaamano / rpms / vagrant

Forked from rpms/vagrant 3 years ago
Clone
c11853f
# Monkey-patching for RubyGems and Bundler to play nicely with Vagrant
c11853f
c11853f
# Fix rubygems 2.2 compatibility
c11853f
# https://github.com/bundler/bundler/pull/3237
c11853f
module Bundler
c11853f
  module SharedHelpers
c11853f
    private
c11853f
    def clean_load_path
c11853f
      # handle 1.9 where system gems are always on the load path
c11853f
      if defined?(::Gem)
c11853f
        me = File.expand_path("../../", __FILE__)
c11853f
c11853f
        # RubyGems 2.2+ can put binary extension into dedicated folders,
c11853f
        # therefore use RubyGems facilities to obtain their load paths.
c11853f
        if Gem::Specification.method_defined? :full_require_paths
c11853f
          loaded_gem_paths = Gem.loaded_specs.map do |n, s|
c11853f
            s.full_require_paths.none? {|path| File.expand_path(path) =~ /^#{Regexp.escape(me)}/} ? s.full_require_paths : []
c11853f
          end
c11853f
          loaded_gem_paths.flatten!
c11853f
c11853f
          $LOAD_PATH.reject! {|p| loaded_gem_paths.delete(p) }
c11853f
        else
c11853f
          $LOAD_PATH.reject! do |p|
c11853f
            next if File.expand_path(p) =~ /^#{Regexp.escape(me)}/
c11853f
            p != File.dirname(__FILE__) &&
c11853f
              Bundler.rubygems.gem_path.any?{|gp| p =~ /^#{Regexp.escape(gp)}/ }
c11853f
          end
c11853f
        end
c11853f
        $LOAD_PATH.uniq!
c11853f
      end
c11853f
    end
c11853f
  end
c11853f
end
c11853f
c11853f
# Remove useless gem build step.
c11853f
# https://github.com/bundler/bundler/pull/3238
c11853f
module Bundler
c11853f
  class Source
c11853f
c11853f
    class Path < Source
c11853f
c11853f
      private
c11853f
      def generate_bin(spec, disable_extensions = false)
c11853f
        gem_dir  = Pathname.new(spec.full_gem_path)
c11853f
c11853f
        # Some gem authors put absolute paths in their gemspec
c11853f
        # and we have to save them from themselves
c11853f
        spec.files = spec.files.map do |p|
c11853f
          next if File.directory?(p)
c11853f
          begin
c11853f
            Pathname.new(p).relative_path_from(gem_dir).to_s
c11853f
          rescue ArgumentError
c11853f
            p
c11853f
          end
c11853f
        end.compact
c11853f
c11853f
        SharedHelpers.chdir(gem_dir) do
c11853f
          installer = Path::Installer.new(spec, :env_shebang => false)
c11853f
          run_hooks(:pre_install, installer)
c11853f
          installer.build_extensions unless disable_extensions
c11853f
          run_hooks(:post_build, installer)
c11853f
          installer.generate_bin
c11853f
          run_hooks(:post_install, installer)
c11853f
        end
c11853f
      rescue Gem::InvalidSpecificationException => e
c11853f
        Bundler.ui.warn "\n#{spec.name} at #{spec.full_gem_path} did not have a valid gemspec.\n" \
c11853f
                        "This prevents bundler from installing bins or native extensions, but " \
c11853f
                        "that may not affect its functionality."
c11853f
c11853f
        if !spec.extensions.empty? && !spec.email.empty?
c11853f
          Bundler.ui.warn "If you need to use this package without installing it from a gem " \
c11853f
                          "repository, please contact #{spec.email} and ask them " \
c11853f
                          "to modify their .gemspec so it can work with `gem build`."
c11853f
        end
c11853f
c11853f
        Bundler.ui.warn "The validation message from Rubygems was:\n  #{e.message}"
c11853f
      end
c11853f
    end
c11853f
  end
c11853f
end