lib/bundler.rb in bundler-1.13.7 vs lib/bundler.rb in bundler-1.14.0.pre.1
- old
+ new
@@ -1,13 +1,14 @@
# frozen_string_literal: true
require "fileutils"
require "pathname"
require "rbconfig"
require "thread"
+require "tmpdir"
+
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"
@@ -25,12 +26,14 @@
autoload :Deprecate, "bundler/deprecate"
autoload :Dsl, "bundler/dsl"
autoload :EndpointSpecification, "bundler/endpoint_specification"
autoload :Env, "bundler/env"
autoload :Fetcher, "bundler/fetcher"
+ autoload :FeatureFlag, "bundler/feature_flag"
autoload :GemHelper, "bundler/gem_helper"
autoload :GemHelpers, "bundler/gem_helpers"
+ autoload :GemRemoteFetcher, "bundler/gem_remote_fetcher"
autoload :GemVersionPromoter, "bundler/gem_version_promoter"
autoload :Graph, "bundler/graph"
autoload :Index, "bundler/index"
autoload :Injector, "bundler/injector"
autoload :Installer, "bundler/installer"
@@ -88,11 +91,11 @@
def setup(*groups)
# Return if all groups are already loaded
return @setup if defined?(@setup) && @setup
- definition.validate_ruby!
+ definition.validate_runtime!
SharedHelpers.print_major_deprecations!
if groups.empty?
# Load all groups, but only once
@@ -140,12 +143,45 @@
def ruby_scope
"#{Bundler.rubygems.ruby_engine}/#{Bundler.rubygems.config_map[:ruby_version]}"
end
+ def user_home
+ @user_home ||= begin
+ home = Bundler.rubygems.user_home
+ warning = "Your home directory is not set properly:"
+ if home.nil?
+ warning += "\n * It is not set at all"
+ elsif !File.directory?(home)
+ warning += "\n * `#{home}` is not a directory"
+ elsif !File.writable?(home)
+ warning += "\n * `#{home}` is not writable"
+ else
+ return @user_home = Pathname.new(home)
+ end
+
+ login = Etc.getlogin || "unknown"
+
+ tmp_home = Pathname.new(Dir.tmpdir).join("bundler", "home", login)
+ begin
+ SharedHelpers.filesystem_access(tmp_home, :write) do |p|
+ FileUtils.mkdir_p(p)
+ end
+ rescue => e
+ warning += "\n\nBundler also failed to create a temporary home directory at `#{tmp_home}`:\n#{e}"
+ raise warning
+ end
+
+ warning += "\n\nBundler will use `#{tmp_home}` as your home directory temporarily"
+
+ Bundler.ui.warn(warning)
+ tmp_home
+ end
+ end
+
def user_bundle_path
- Pathname.new(Bundler.rubygems.user_home).join(".bundle")
+ Pathname.new(user_home).join(".bundle")
end
def home
bundle_path.join("bundler")
end
@@ -255,10 +291,15 @@
def clean_exec(*args)
with_clean_env { Kernel.exec(*args) }
end
+ def local_platform
+ return Gem::Platform::RUBY if settings[:force_ruby_platform]
+ Gem::Platform.local
+ end
+
def default_gemfile
SharedHelpers.default_gemfile
end
def default_lockfile
@@ -326,21 +367,27 @@
end
def sudo(str)
SUDO_MUTEX.synchronize do
prompt = "\n\n" + <<-PROMPT.gsub(/^ {6}/, "").strip + " "
- Your user account isn't allowed to install to the system Rubygems.
+ Your user account isn't allowed to install to the system RubyGems.
You can cancel this installation and run:
bundle install --path vendor/bundle
to install the gems into ./vendor/bundle/, or you can enter your password
- and install the bundled gems to Rubygems using sudo.
+ and install the bundled gems to RubyGems using sudo.
Password:
PROMPT
+ unless @prompted_for_sudo ||= system(%(sudo -k -p "#{prompt}" true))
+ raise SudoNotPermittedError,
+ "Bundler requires sudo access to install at the moment. " \
+ "Try installing again, granting Bundler sudo access when prompted, or installing into a different path."
+ end
+
`sudo -p "#{prompt}" #{str}`
end
end
def read_file(file)
@@ -387,18 +434,23 @@
def git_present?
return @git_present if defined?(@git_present)
@git_present = Bundler.which("git") || Bundler.which("git.exe")
end
+ def feature_flag
+ @feature_flag ||= FeatureFlag.new(VERSION)
+ end
+
def reset!
@root = nil
@settings = nil
@definition = nil
@setup = nil
@load = nil
@locked_gems = nil
@bundle_path = nil
@bin_path = nil
+ @user_home = nil
Plugin.reset!
return unless defined?(@rubygems) && @rubygems
rubygems.undo_replacements