lib/bundler.rb in bundler-1.15.4 vs lib/bundler.rb in bundler-1.16.0.pre.1

- old
+ new

@@ -1,23 +1,26 @@ # frozen_string_literal: true -require "fileutils" + +require "bundler/compatibility_guard" + +require "bundler/vendored_fileutils" require "pathname" require "rbconfig" require "thread" -require "tmpdir" require "bundler/errors" require "bundler/environment_preserver" require "bundler/plugin" require "bundler/rubygems_ext" require "bundler/rubygems_integration" require "bundler/version" require "bundler/constants" require "bundler/current_ruby" +require "bundler/build_metadata" module Bundler - environment_preserver = EnvironmentPreserver.new(ENV, %w(PATH GEM_PATH)) + environment_preserver = EnvironmentPreserver.new(ENV, EnvironmentPreserver::BUNDLER_KEYS) ORIGINAL_ENV = environment_preserver.restore ENV.replace(environment_preserver.backup) SUDO_MUTEX = Mutex.new autoload :Definition, "bundler/definition" @@ -38,10 +41,11 @@ autoload :Injector, "bundler/injector" autoload :Installer, "bundler/installer" autoload :LazySpecification, "bundler/lazy_specification" autoload :LockfileParser, "bundler/lockfile_parser" autoload :MatchPlatform, "bundler/match_platform" + autoload :ProcessLock, "bundler/process_lock" autoload :RemoteSpecification, "bundler/remote_specification" autoload :Resolver, "bundler/resolver" autoload :Retry, "bundler/retry" autoload :RubyDsl, "bundler/ruby_dsl" autoload :RubyGemsGemInstaller, "bundler/rubygems_gem_installer" @@ -56,12 +60,10 @@ autoload :UI, "bundler/ui" autoload :URICredentialsFilter, "bundler/uri_credentials_filter" autoload :VersionRanges, "bundler/version_ranges" class << self - attr_writer :bundle_path - def configure @configured ||= configure_gem_home_and_path end def ui @@ -73,13 +75,17 @@ @ui = ui end # Returns absolute path of where gems are installed on the filesystem. def bundle_path - @bundle_path ||= Pathname.new(settings.path).expand_path(root) + @bundle_path ||= Pathname.new(configured_bundle_path.path).expand_path(root) end + def configured_bundle_path + @configured_bundle_path ||= settings.path.tap(&:validate!) + end + # Returns absolute location of where binstubs are installed to. def bin_path @bin_path ||= begin path = settings[:bin] || "bin" path = Pathname.new(path).expand_path(root).expand_path @@ -111,11 +117,11 @@ def load @load ||= Runtime.new(root, definition) end def environment - SharedHelpers.major_deprecation "Bundler.environment has been removed in favor of Bundler.load" + SharedHelpers.major_deprecation 2, "Bundler.environment has been removed in favor of Bundler.load" load end # Returns an instance of Bundler::Definition for given Gemfile and lockfile # @@ -128,10 +134,16 @@ configure Definition.build(default_gemfile, default_lockfile, unlock) end end + def frozen? + frozen = settings[:deployment] + frozen ||= settings[:frozen] unless feature_flag.deployment_means_frozen? + frozen + end + def locked_gems @locked_gems ||= if defined?(@definition) && @definition definition.locked_gems elsif Bundler.default_lockfile.file? @@ -166,10 +178,11 @@ end end def tmp_home_path(login, warning) login ||= "unknown" + Kernel.send(:require, "tmpdir") path = Pathname.new(Dir.tmpdir).join("bundler", "home") SharedHelpers.filesystem_access(path) do |tmp_home_path| unless tmp_home_path.exist? tmp_home_path.mkpath tmp_home_path.chmod(0o777) @@ -194,42 +207,39 @@ def specs_path bundle_path.join("specifications") end - def cache - bundle_path.join("cache/bundler") - end - def user_cache user_bundle_path.join("cache") end def root @root ||= begin - default_gemfile.dirname.expand_path + SharedHelpers.root rescue GemfileNotFound bundle_dir = default_bundle_dir raise GemfileNotFound, "Could not locate Gemfile or .bundle/ directory" unless bundle_dir Pathname.new(File.expand_path("..", bundle_dir)) end end def app_config_path - if ENV["BUNDLE_APP_CONFIG"] - Pathname.new(ENV["BUNDLE_APP_CONFIG"]).expand_path(root) + if app_config = ENV["BUNDLE_APP_CONFIG"] + Pathname.new(app_config).expand_path(root) else root.join(".bundle") end end def app_cache(custom_path = nil) path = custom_path || root - path.join(settings.app_cache_path) + Pathname.new(path).join(settings.app_cache_path) end def tmp(name = Process.pid.to_s) + Kernel.send(:require, "tmpdir") Pathname.new(Dir.mktmpdir(["bundler", name])) end def rm_rf(path) FileUtils.remove_entry_secure(path) if path && File.exist?(path) @@ -255,11 +265,11 @@ end # @deprecated Use `original_env` instead # @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") + Bundler::SharedHelpers.major_deprecation(2, "`Bundler.clean_env` has weird edge cases, use `.original_env` instead") env = original_env if env.key?("BUNDLER_ORIG_MANPATH") env["MANPATH"] = env["BUNDLER_ORIG_MANPATH"] end @@ -311,25 +321,29 @@ def default_bundle_dir SharedHelpers.default_bundle_dir end def system_bindir - # Gem.bindir doesn't always return the location that Rubygems will install - # system binaries. If you put '-n foo' in your .gemrc, Rubygems will - # install binstubs there instead. Unfortunately, Rubygems doesn't expose + # Gem.bindir doesn't always return the location that RubyGems will install + # system binaries. If you put '-n foo' in your .gemrc, RubyGems will + # install binstubs there instead. Unfortunately, RubyGems doesn't expose # that directory at all, so rather than parse .gemrc ourselves, we allow # the directory to be set as well, via `bundle config bindir foo`. Bundler.settings[:system_bindir] || Bundler.rubygems.gem_bindir end + def use_system_gems? + configured_bundle_path.use_system_gems? + end + def requires_sudo? return @requires_sudo if defined?(@requires_sudo_ran) sudo_present = which "sudo" if settings.allow_sudo? if sudo_present - # the bundle path and subdirectories need to be writable for Rubygems + # the bundle path and subdirectories need to be writable for RubyGems # to be able to unpack and install gems without exploding path = bundle_path path = path.parent until path.exist? # bins are written to a different location on OS X @@ -447,18 +461,21 @@ Plugin.reset! reset_rubygems! end def reset_paths! - @root = nil - @settings = nil + @bin_path = nil + @bundler_major_version = nil + @bundle_path = nil + @configured = nil + @configured_bundle_path = nil @definition = nil - @setup = nil @load = nil @locked_gems = nil - @bundle_path = nil - @bin_path = nil + @root = nil + @settings = nil + @setup = nil @user_home = nil end def reset_rubygems! return unless defined?(@rubygems) && @rubygems @@ -476,11 +493,11 @@ rescue YamlLibrarySyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception eval_gemspec(path, contents) end def eval_gemspec(path, contents) - eval(contents, TOPLEVEL_BINDING, path.expand_path.to_s) + eval(contents, TOPLEVEL_BINDING.dup, path.expand_path.to_s) rescue ScriptError, StandardError => e 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" @@ -493,32 +510,25 @@ configure_gem_path configure_gem_home bundle_path end - def configure_gem_path(env = ENV, settings = self.settings) + def configure_gem_path(env = ENV) blank_home = env["GEM_HOME"].nil? || env["GEM_HOME"].empty? - if settings[:disable_shared_gems] + if !use_system_gems? # this needs to be empty string to cause # PathSupport.split_gem_path to only load up the # Bundler --path setting as the GEM_PATH. env["GEM_PATH"] = "" - elsif blank_home || Bundler.rubygems.gem_dir != bundle_path.to_s + elsif blank_home possibles = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path] paths = possibles.flatten.compact.uniq.reject(&:empty?) env["GEM_PATH"] = paths.join(File::PATH_SEPARATOR) end end def configure_gem_home - # TODO: This mkdir_p is only needed for JRuby <= 1.5 and should go away (GH #602) - begin - FileUtils.mkdir_p bundle_path.to_s - rescue - nil - end - - ENV["GEM_HOME"] = File.expand_path(bundle_path, root) + Bundler::SharedHelpers.set_env "GEM_HOME", File.expand_path(bundle_path, root) Bundler.rubygems.clear_paths end # @param env [Hash] def with_env(env)