lib/bundler.rb in bundler-1.13.0.rc.1 vs lib/bundler.rb in bundler-1.13.0.rc.2
- old
+ new
@@ -1,18 +1,19 @@
# frozen_string_literal: true
require "fileutils"
require "pathname"
require "rbconfig"
require "thread"
+require "bundler/errors"
require "bundler/environment_preserver"
require "bundler/gem_remote_fetcher"
+require "bundler/plugin"
require "bundler/rubygems_ext"
require "bundler/rubygems_integration"
require "bundler/version"
require "bundler/constants"
require "bundler/current_ruby"
-require "bundler/errors"
module Bundler
environment_preserver = EnvironmentPreserver.new(ENV, %w(PATH GEM_PATH))
ORIGINAL_ENV = environment_preserver.restore
ENV.replace(environment_preserver.backup)
@@ -22,38 +23,37 @@
autoload :Dependency, "bundler/dependency"
autoload :DepProxy, "bundler/dep_proxy"
autoload :Deprecate, "bundler/deprecate"
autoload :Dsl, "bundler/dsl"
autoload :EndpointSpecification, "bundler/endpoint_specification"
- autoload :Environment, "bundler/environment"
autoload :Env, "bundler/env"
autoload :Fetcher, "bundler/fetcher"
autoload :GemHelper, "bundler/gem_helper"
autoload :GemHelpers, "bundler/gem_helpers"
+ autoload :GemVersionPromoter, "bundler/gem_version_promoter"
autoload :Graph, "bundler/graph"
autoload :Index, "bundler/index"
- autoload :Installer, "bundler/installer"
autoload :Injector, "bundler/injector"
+ autoload :Installer, "bundler/installer"
autoload :LazySpecification, "bundler/lazy_specification"
autoload :LockfileParser, "bundler/lockfile_parser"
autoload :MatchPlatform, "bundler/match_platform"
autoload :Mirror, "bundler/mirror"
autoload :Mirrors, "bundler/mirror"
- autoload :Plugin, "bundler/plugin"
autoload :RemoteSpecification, "bundler/remote_specification"
autoload :Resolver, "bundler/resolver"
autoload :Retry, "bundler/retry"
- autoload :RubyVersion, "bundler/ruby_version"
autoload :RubyDsl, "bundler/ruby_dsl"
+ autoload :RubyGemsGemInstaller, "bundler/rubygems_gem_installer"
+ autoload :RubyVersion, "bundler/ruby_version"
autoload :Runtime, "bundler/runtime"
autoload :Settings, "bundler/settings"
autoload :SharedHelpers, "bundler/shared_helpers"
- autoload :SpecSet, "bundler/spec_set"
- autoload :StubSpecification, "bundler/stub_specification"
autoload :Source, "bundler/source"
autoload :SourceList, "bundler/source_list"
- autoload :RubyGemsGemInstaller, "bundler/rubygems_gem_installer"
+ autoload :SpecSet, "bundler/spec_set"
+ autoload :StubSpecification, "bundler/stub_specification"
autoload :UI, "bundler/ui"
autoload :URICredentialsFilter, "bundler/uri_credentials_filter"
class << self
attr_writer :bundle_path
@@ -86,11 +86,11 @@
end
end
def setup(*groups)
# Return if all groups are already loaded
- return @setup if defined?(@setup)
+ return @setup if defined?(@setup) && @setup
definition.validate_ruby!
SharedHelpers.print_major_deprecations!
@@ -109,11 +109,12 @@
def load
@load ||= Runtime.new(root, definition)
end
def environment
- Bundler::Environment.new(root, definition)
+ SharedHelpers.major_deprecation "Bundler.environment has been removed in favor of Bundler.load"
+ load
end
# Returns an instance of Bundler::Definition for given Gemfile and lockfile
#
# @param unlock [Hash, Boolean, nil] Gems that have been requested
@@ -121,23 +122,22 @@
# @return [Bundler::Definition]
def definition(unlock = nil)
@definition = nil if unlock
@definition ||= begin
configure
- upgrade_lockfile
Definition.build(default_gemfile, default_lockfile, unlock)
end
end
def locked_gems
- return @locked_gems if defined?(@locked_gems)
- if Bundler.default_lockfile.exist?
- lock = Bundler.read_file(Bundler.default_lockfile)
- @locked_gems = LockfileParser.new(lock)
- else
- @locked_gems = nil
- end
+ @locked_gems ||=
+ if defined?(@definition) && @definition
+ definition.locked_gems
+ elsif Bundler.default_lockfile.exist?
+ lock = Bundler.read_file(Bundler.default_lockfile)
+ LockfileParser.new(lock)
+ end
end
def ruby_scope
"#{Bundler.rubygems.ruby_engine}/#{Bundler.rubygems.config_map[:ruby_version]}"
end
@@ -193,10 +193,18 @@
Pathname.new(Dir.mktmpdir(["bundler", name]))
end
def rm_rf(path)
FileUtils.remove_entry_secure(path) if path && File.exist?(path)
+ rescue ArgumentError
+ message = <<EOF
+It is a security vulnerability to allow your home directory to be world-writable, and bundler can not continue.
+You should probably consider fixing this issue by running `chmod o-w ~` on *nix.
+Please refer to http://ruby-doc.org/stdlib-2.1.2/libdoc/fileutils/rdoc/FileUtils.html#method-c-remove_entry_secure for details.
+EOF
+ File.world_writable?(path) ? Bundler.ui.warn(message) : raise
+ raise PathError, "Please fix the world-writable issue with your #{path} directory"
end
def settings
@settings ||= Settings.new(app_config_path)
rescue GemfileNotFound
@@ -212,12 +220,12 @@
# @return [Hash] Environment with all bundler-related variables removed
def clean_env
Bundler::SharedHelpers.major_deprecation("`Bundler.clean_env` has weird edge cases, use `.original_env` instead")
env = original_env
- if env.key?("BUNDLE_ORIG_MANPATH")
- env["MANPATH"] = env["BUNDLE_ORIG_MANPATH"]
+ if env.key?("BUNDLER_ORIG_MANPATH")
+ env["MANPATH"] = env["BUNDLER_ORIG_MANPATH"]
end
env.delete_if {|k, _| k[0, 7] == "BUNDLE_" }
if env.key?("RUBYOPT")
@@ -383,10 +391,22 @@
def reset!
@root = nil
@settings = nil
@definition = nil
+ @setup = nil
+ @load = nil
+ @locked_gems = nil
+ @bundle_path = nil
+ @bin_path = nil
+
+ Plugin.reset!
+
+ return unless defined?(@rubygems) && @rubygems
+ rubygems.undo_replacements
+ rubygems.reset
+ @rubygems = nil
end
private
def eval_yaml_gemspec(path, contents)
@@ -398,21 +418,17 @@
end
def eval_gemspec(path, contents)
eval(contents, TOPLEVEL_BINDING, path.expand_path.to_s)
rescue ScriptError, StandardError => e
- original_line = e.backtrace.find {|line| line.include?(path.to_s) }
- msg = String.new
- msg << "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
- msg << " from\n #{original_line}" if original_line
- msg << "\n"
+ msg = "There was an error while loading `#{path.basename}`: #{e.message}"
if e.is_a?(LoadError) && RUBY_VERSION >= "1.9"
- msg << "\nDoes it try to require a relative path? That's been removed in Ruby 1.9."
+ msg += "\nDoes it try to require a relative path? That's been removed in Ruby 1.9"
end
- raise GemspecError, msg
+ raise GemspecError, Dsl::DSLError.new(msg, path, e.backtrace, contents)
end
def configure_gem_home_and_path
configure_gem_path
configure_gem_home
@@ -438,16 +454,9 @@
nil
end
ENV["GEM_HOME"] = File.expand_path(bundle_path, root)
Bundler.rubygems.clear_paths
- end
-
- def upgrade_lockfile
- lockfile = default_lockfile
- return unless lockfile.exist? && lockfile.read(3) == "---"
- Bundler.ui.warn "Detected Gemfile.lock generated by 0.9, deleting..."
- lockfile.rmtree
end
# @param env [Hash]
def with_env(env)
backup = ENV.to_hash