[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / lib / bundler.rb
blob5033109db64a7eb54dd75f287646f3d49032e57b
1 # frozen_string_literal: true
3 require_relative "bundler/vendored_fileutils"
4 require "pathname"
5 require "rbconfig"
7 require_relative "bundler/errors"
8 require_relative "bundler/environment_preserver"
9 require_relative "bundler/plugin"
10 require_relative "bundler/rubygems_ext"
11 require_relative "bundler/rubygems_integration"
12 require_relative "bundler/version"
13 require_relative "bundler/constants"
14 require_relative "bundler/current_ruby"
15 require_relative "bundler/build_metadata"
17 # Bundler provides a consistent environment for Ruby projects by
18 # tracking and installing the exact gems and versions that are needed.
20 # Bundler is a part of Ruby's standard library.
22 # Bundler is used by creating _gemfiles_ listing all the project dependencies
23 # and (optionally) their versions and then using
25 #   require 'bundler/setup'
27 # or Bundler.setup to setup environment where only specified gems and their
28 # specified versions could be used.
30 # See {Bundler website}[https://bundler.io/docs.html] for extensive documentation
31 # on gemfiles creation and Bundler usage.
33 # As a standard library inside project, Bundler could be used for introspection
34 # of loaded and required modules.
36 module Bundler
37   environment_preserver = EnvironmentPreserver.from_env
38   ORIGINAL_ENV = environment_preserver.restore
39   environment_preserver.replace_with_backup
40   SUDO_MUTEX = Thread::Mutex.new
42   autoload :Checksum,               File.expand_path("bundler/checksum", __dir__)
43   autoload :CLI,                    File.expand_path("bundler/cli", __dir__)
44   autoload :CIDetector,             File.expand_path("bundler/ci_detector", __dir__)
45   autoload :Definition,             File.expand_path("bundler/definition", __dir__)
46   autoload :Dependency,             File.expand_path("bundler/dependency", __dir__)
47   autoload :Deprecate,              File.expand_path("bundler/deprecate", __dir__)
48   autoload :Digest,                 File.expand_path("bundler/digest", __dir__)
49   autoload :Dsl,                    File.expand_path("bundler/dsl", __dir__)
50   autoload :EndpointSpecification,  File.expand_path("bundler/endpoint_specification", __dir__)
51   autoload :Env,                    File.expand_path("bundler/env", __dir__)
52   autoload :Fetcher,                File.expand_path("bundler/fetcher", __dir__)
53   autoload :FeatureFlag,            File.expand_path("bundler/feature_flag", __dir__)
54   autoload :GemHelper,              File.expand_path("bundler/gem_helper", __dir__)
55   autoload :GemHelpers,             File.expand_path("bundler/gem_helpers", __dir__)
56   autoload :GemVersionPromoter,     File.expand_path("bundler/gem_version_promoter", __dir__)
57   autoload :Graph,                  File.expand_path("bundler/graph", __dir__)
58   autoload :Index,                  File.expand_path("bundler/index", __dir__)
59   autoload :Injector,               File.expand_path("bundler/injector", __dir__)
60   autoload :Installer,              File.expand_path("bundler/installer", __dir__)
61   autoload :LazySpecification,      File.expand_path("bundler/lazy_specification", __dir__)
62   autoload :LockfileParser,         File.expand_path("bundler/lockfile_parser", __dir__)
63   autoload :MatchRemoteMetadata,    File.expand_path("bundler/match_remote_metadata", __dir__)
64   autoload :ProcessLock,            File.expand_path("bundler/process_lock", __dir__)
65   autoload :RemoteSpecification,    File.expand_path("bundler/remote_specification", __dir__)
66   autoload :Resolver,               File.expand_path("bundler/resolver", __dir__)
67   autoload :Retry,                  File.expand_path("bundler/retry", __dir__)
68   autoload :RubyDsl,                File.expand_path("bundler/ruby_dsl", __dir__)
69   autoload :RubyVersion,            File.expand_path("bundler/ruby_version", __dir__)
70   autoload :Runtime,                File.expand_path("bundler/runtime", __dir__)
71   autoload :SelfManager,            File.expand_path("bundler/self_manager", __dir__)
72   autoload :Settings,               File.expand_path("bundler/settings", __dir__)
73   autoload :SharedHelpers,          File.expand_path("bundler/shared_helpers", __dir__)
74   autoload :Source,                 File.expand_path("bundler/source", __dir__)
75   autoload :SourceList,             File.expand_path("bundler/source_list", __dir__)
76   autoload :SourceMap,              File.expand_path("bundler/source_map", __dir__)
77   autoload :SpecSet,                File.expand_path("bundler/spec_set", __dir__)
78   autoload :StubSpecification,      File.expand_path("bundler/stub_specification", __dir__)
79   autoload :UI,                     File.expand_path("bundler/ui", __dir__)
80   autoload :URICredentialsFilter,   File.expand_path("bundler/uri_credentials_filter", __dir__)
81   autoload :URINormalizer,          File.expand_path("bundler/uri_normalizer", __dir__)
82   autoload :SafeMarshal,            File.expand_path("bundler/safe_marshal", __dir__)
84   class << self
85     def configure
86       @configure ||= configure_gem_home_and_path
87     end
89     def ui
90       (defined?(@ui) && @ui) || (self.ui = UI::Shell.new)
91     end
93     def ui=(ui)
94       Bundler.rubygems.ui = UI::RGProxy.new(ui)
95       @ui = ui
96     end
98     # Returns absolute path of where gems are installed on the filesystem.
99     def bundle_path
100       @bundle_path ||= Pathname.new(configured_bundle_path.path).expand_path(root)
101     end
103     def create_bundle_path
104       mkdir_p(bundle_path) unless bundle_path.exist?
106       @bundle_path = bundle_path.realpath
107     rescue Errno::EEXIST
108       raise PathError, "Could not install to path `#{bundle_path}` " \
109         "because a file already exists at that path. Either remove or rename the file so the directory can be created."
110     end
112     def configured_bundle_path
113       @configured_bundle_path ||= settings.path.tap(&:validate!)
114     end
116     # Returns absolute location of where binstubs are installed to.
117     def bin_path
118       @bin_path ||= begin
119         path = settings[:bin] || "bin"
120         path = Pathname.new(path).expand_path(root).expand_path
121         mkdir_p(path)
122         path
123       end
124     end
126     # Turns on the Bundler runtime. After +Bundler.setup+ call, all +load+ or
127     # +require+ of the gems would be allowed only if they are part of
128     # the Gemfile or Ruby's standard library. If the versions specified
129     # in Gemfile, only those versions would be loaded.
130     #
131     # Assuming Gemfile
132     #
133     #    gem 'first_gem', '= 1.0'
134     #    group :test do
135     #      gem 'second_gem', '= 1.0'
136     #    end
137     #
138     # The code using Bundler.setup works as follows:
139     #
140     #    require 'third_gem' # allowed, required from global gems
141     #    require 'first_gem' # allowed, loads the last installed version
142     #    Bundler.setup
143     #    require 'fourth_gem' # fails with LoadError
144     #    require 'second_gem' # loads exactly version 1.0
145     #
146     # +Bundler.setup+ can be called only once, all subsequent calls are no-op.
147     #
148     # If _groups_ list is provided, only gems from specified groups would
149     # be allowed (gems specified outside groups belong to special +:default+ group).
150     #
151     # To require all gems from Gemfile (or only some groups), see Bundler.require.
152     #
153     def setup(*groups)
154       # Return if all groups are already loaded
155       return @setup if defined?(@setup) && @setup
157       definition.validate_runtime!
159       SharedHelpers.print_major_deprecations!
161       if groups.empty?
162         # Load all groups, but only once
163         @setup = load.setup
164       else
165         load.setup(*groups)
166       end
167     end
169     # Automatically install dependencies if Bundler.settings[:auto_install] exists.
170     # This is set through config cmd `bundle config set --global auto_install 1`.
171     #
172     # Note that this method `nil`s out the global Definition object, so it
173     # should be called first, before you instantiate anything like an
174     # `Installer` that'll keep a reference to the old one instead.
175     def auto_install
176       return unless settings[:auto_install]
178       begin
179         definition.specs
180       rescue GemNotFound, GitError
181         ui.info "Automatically installing missing gems."
182         reset!
183         CLI::Install.new({}).run
184         reset!
185       end
186     end
188     # Setups Bundler environment (see Bundler.setup) if it is not already set,
189     # and loads all gems from groups specified. Unlike ::setup, can be called
190     # multiple times with different groups (if they were allowed by setup).
191     #
192     # Assuming Gemfile
193     #
194     #    gem 'first_gem', '= 1.0'
195     #    group :test do
196     #      gem 'second_gem', '= 1.0'
197     #    end
198     #
199     # The code will work as follows:
200     #
201     #    Bundler.setup # allow all groups
202     #    Bundler.require(:default) # requires only first_gem
203     #    # ...later
204     #    Bundler.require(:test)   # requires second_gem
205     #
206     def require(*groups)
207       load_plugins
208       setup(*groups).require(*groups)
209     end
211     def load
212       @load ||= Runtime.new(root, definition)
213     end
215     def environment
216       SharedHelpers.major_deprecation 2, "Bundler.environment has been removed in favor of Bundler.load", print_caller_location: true
217       load
218     end
220     # Returns an instance of Bundler::Definition for given Gemfile and lockfile
221     #
222     # @param unlock [Hash, Boolean, nil] Gems that have been requested
223     #   to be updated or true if all gems should be updated
224     # @param lockfile [Pathname] Path to Gemfile.lock
225     # @return [Bundler::Definition]
226     def definition(unlock = nil, lockfile = default_lockfile)
227       @definition = nil if unlock
228       @definition ||= begin
229         configure
230         Definition.build(default_gemfile, lockfile, unlock)
231       end
232     end
234     def frozen_bundle?
235       frozen = settings[:frozen]
236       return frozen unless frozen.nil?
238       settings[:deployment]
239     end
241     def locked_gems
242       @locked_gems ||=
243         if defined?(@definition) && @definition
244           definition.locked_gems
245         elsif Bundler.default_lockfile.file?
246           lock = Bundler.read_file(Bundler.default_lockfile)
247           LockfileParser.new(lock)
248         end
249     end
251     def most_specific_locked_platform?(platform)
252       return false unless defined?(@definition) && @definition
254       definition.most_specific_locked_platform == platform
255     end
257     def ruby_scope
258       "#{Bundler.rubygems.ruby_engine}/#{RbConfig::CONFIG["ruby_version"]}"
259     end
261     def user_home
262       @user_home ||= begin
263         home = Bundler.rubygems.user_home
264         bundle_home = home ? File.join(home, ".bundle") : nil
266         warning = if home.nil?
267           "Your home directory is not set."
268         elsif !File.directory?(home)
269           "`#{home}` is not a directory."
270         elsif !File.writable?(home) && (!File.directory?(bundle_home) || !File.writable?(bundle_home))
271           "`#{home}` is not writable."
272         end
274         if warning
275           Bundler.ui.warn "#{warning}\n"
276           user_home = tmp_home_path
277           Bundler.ui.warn "Bundler will use `#{user_home}' as your home directory temporarily.\n"
278           user_home
279         else
280           Pathname.new(home)
281         end
282       end
283     end
285     def user_bundle_path(dir = "home")
286       env_var, fallback = case dir
287                           when "home"
288                             ["BUNDLE_USER_HOME", proc { Pathname.new(user_home).join(".bundle") }]
289                           when "cache"
290                             ["BUNDLE_USER_CACHE", proc { user_bundle_path.join("cache") }]
291                           when "config"
292                             ["BUNDLE_USER_CONFIG", proc { user_bundle_path.join("config") }]
293                           when "plugin"
294                             ["BUNDLE_USER_PLUGIN", proc { user_bundle_path.join("plugin") }]
295                           else
296                             raise BundlerError, "Unknown user path requested: #{dir}"
297       end
298       # `fallback` will already be a Pathname, but Pathname.new() is
299       # idempotent so it's OK
300       Pathname.new(ENV.fetch(env_var, &fallback))
301     end
303     def user_cache
304       user_bundle_path("cache")
305     end
307     def home
308       bundle_path.join("bundler")
309     end
311     def install_path
312       home.join("gems")
313     end
315     def specs_path
316       bundle_path.join("specifications")
317     end
319     def root
320       @root ||= begin
321                   SharedHelpers.root
322                 rescue GemfileNotFound
323                   bundle_dir = default_bundle_dir
324                   raise GemfileNotFound, "Could not locate Gemfile or .bundle/ directory" unless bundle_dir
325                   Pathname.new(File.expand_path("..", bundle_dir))
326                 end
327     end
329     def app_config_path
330       if app_config = ENV["BUNDLE_APP_CONFIG"]
331         app_config_pathname = Pathname.new(app_config)
333         if app_config_pathname.absolute?
334           app_config_pathname
335         else
336           app_config_pathname.expand_path(root)
337         end
338       else
339         root.join(".bundle")
340       end
341     end
343     def app_cache(custom_path = nil)
344       path = custom_path || root
345       Pathname.new(path).join(settings.app_cache_path)
346     end
348     def tmp(name = Process.pid.to_s)
349       Kernel.send(:require, "tmpdir")
350       Pathname.new(Dir.mktmpdir(["bundler", name]))
351     end
353     def rm_rf(path)
354       FileUtils.remove_entry_secure(path) if path && File.exist?(path)
355     end
357     def settings
358       @settings ||= Settings.new(app_config_path)
359     rescue GemfileNotFound
360       @settings = Settings.new(Pathname.new(".bundle").expand_path)
361     end
363     # @return [Hash] Environment present before Bundler was activated
364     def original_env
365       ORIGINAL_ENV.clone
366     end
368     # @deprecated Use `unbundled_env` instead
369     def clean_env
370       message =
371         "`Bundler.clean_env` has been deprecated in favor of `Bundler.unbundled_env`. " \
372         "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`"
373       removed_message =
374         "`Bundler.clean_env` has been removed in favor of `Bundler.unbundled_env`. " \
375         "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`"
376       Bundler::SharedHelpers.major_deprecation(2, message, removed_message: removed_message, print_caller_location: true)
377       unbundled_env
378     end
380     # @return [Hash] Environment with all bundler-related variables removed
381     def unbundled_env
382       env = original_env
384       if env.key?("BUNDLER_ORIG_MANPATH")
385         env["MANPATH"] = env["BUNDLER_ORIG_MANPATH"]
386       end
388       env.delete_if {|k, _| k[0, 7] == "BUNDLE_" }
390       if env.key?("RUBYOPT")
391         rubyopt = env["RUBYOPT"].split(" ")
392         rubyopt.delete("-r#{File.expand_path("bundler/setup", __dir__)}")
393         rubyopt.delete("-rbundler/setup")
394         env["RUBYOPT"] = rubyopt.join(" ")
395       end
397       if env.key?("RUBYLIB")
398         rubylib = env["RUBYLIB"].split(File::PATH_SEPARATOR)
399         rubylib.delete(__dir__)
400         env["RUBYLIB"] = rubylib.join(File::PATH_SEPARATOR)
401       end
403       env
404     end
406     # Run block with environment present before Bundler was activated
407     def with_original_env
408       with_env(original_env) { yield }
409     end
411     # @deprecated Use `with_unbundled_env` instead
412     def with_clean_env
413       message =
414         "`Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. " \
415         "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env`"
416       removed_message =
417         "`Bundler.with_clean_env` has been removed in favor of `Bundler.with_unbundled_env`. " \
418         "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env`"
419       Bundler::SharedHelpers.major_deprecation(2, message, removed_message: removed_message, print_caller_location: true)
420       with_env(unbundled_env) { yield }
421     end
423     # Run block with all bundler-related variables removed
424     def with_unbundled_env
425       with_env(unbundled_env) { yield }
426     end
428     # Run subcommand with the environment present before Bundler was activated
429     def original_system(*args)
430       with_original_env { Kernel.system(*args) }
431     end
433     # @deprecated Use `unbundled_system` instead
434     def clean_system(*args)
435       message =
436         "`Bundler.clean_system` has been deprecated in favor of `Bundler.unbundled_system`. " \
437         "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`"
438       removed_message =
439         "`Bundler.clean_system` has been removed in favor of `Bundler.unbundled_system`. " \
440         "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`"
441       Bundler::SharedHelpers.major_deprecation(2, message, removed_message: removed_message, print_caller_location: true)
442       with_env(unbundled_env) { Kernel.system(*args) }
443     end
445     # Run subcommand in an environment with all bundler related variables removed
446     def unbundled_system(*args)
447       with_unbundled_env { Kernel.system(*args) }
448     end
450     # Run a `Kernel.exec` to a subcommand with the environment present before Bundler was activated
451     def original_exec(*args)
452       with_original_env { Kernel.exec(*args) }
453     end
455     # @deprecated Use `unbundled_exec` instead
456     def clean_exec(*args)
457       message =
458         "`Bundler.clean_exec` has been deprecated in favor of `Bundler.unbundled_exec`. " \
459         "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`"
460       removed_message =
461         "`Bundler.clean_exec` has been removed in favor of `Bundler.unbundled_exec`. " \
462         "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`"
463       Bundler::SharedHelpers.major_deprecation(2, message, removed_message: removed_message, print_caller_location: true)
464       with_env(unbundled_env) { Kernel.exec(*args) }
465     end
467     # Run a `Kernel.exec` to a subcommand in an environment with all bundler related variables removed
468     def unbundled_exec(*args)
469       with_env(unbundled_env) { Kernel.exec(*args) }
470     end
472     def local_platform
473       return Gem::Platform::RUBY if settings[:force_ruby_platform]
474       Gem::Platform.local
475     end
477     def default_gemfile
478       SharedHelpers.default_gemfile
479     end
481     def default_lockfile
482       SharedHelpers.default_lockfile
483     end
485     def default_bundle_dir
486       SharedHelpers.default_bundle_dir
487     end
489     def system_bindir
490       # Gem.bindir doesn't always return the location that RubyGems will install
491       # system binaries. If you put '-n foo' in your .gemrc, RubyGems will
492       # install binstubs there instead. Unfortunately, RubyGems doesn't expose
493       # that directory at all, so rather than parse .gemrc ourselves, we allow
494       # the directory to be set as well, via `bundle config set --local bindir foo`.
495       Bundler.settings[:system_bindir] || Bundler.rubygems.gem_bindir
496     end
498     def preferred_gemfile_name
499       Bundler.settings[:init_gems_rb] ? "gems.rb" : "Gemfile"
500     end
502     def use_system_gems?
503       configured_bundle_path.use_system_gems?
504     end
506     def mkdir_p(path)
507       SharedHelpers.filesystem_access(path, :write) do |p|
508         FileUtils.mkdir_p(p)
509       end
510     end
512     def which(executable)
513       if File.file?(executable) && File.executable?(executable)
514         executable
515       elsif paths = ENV["PATH"]
516         quote = '"'
517         paths.split(File::PATH_SEPARATOR).find do |path|
518           path = path[1..-2] if path.start_with?(quote) && path.end_with?(quote)
519           executable_path = File.expand_path(executable, path)
520           return executable_path if File.file?(executable_path) && File.executable?(executable_path)
521         end
522       end
523     end
525     def read_file(file)
526       SharedHelpers.filesystem_access(file, :read) do
527         File.open(file, "r:UTF-8", &:read)
528       end
529     end
531     def safe_load_marshal(data)
532       if Gem.respond_to?(:load_safe_marshal)
533         Gem.load_safe_marshal
534         begin
535           Gem::SafeMarshal.safe_load(data)
536         rescue Gem::SafeMarshal::Reader::Error, Gem::SafeMarshal::Visitors::ToRuby::Error => e
537           raise MarshalError, "#{e.class}: #{e.message}"
538         end
539       else
540         load_marshal(data, marshal_proc: SafeMarshal.proc)
541       end
542     end
544     def load_gemspec(file, validate = false)
545       @gemspec_cache ||= {}
546       key = File.expand_path(file)
547       @gemspec_cache[key] ||= load_gemspec_uncached(file, validate)
548       # Protect against caching side-effected gemspecs by returning a
549       # new instance each time.
550       @gemspec_cache[key]&.dup
551     end
553     def load_gemspec_uncached(file, validate = false)
554       path = Pathname.new(file)
555       contents = read_file(file)
556       spec = if contents.start_with?("---") # YAML header
557         eval_yaml_gemspec(path, contents)
558       else
559         # Eval the gemspec from its parent directory, because some gemspecs
560         # depend on "./" relative paths.
561         SharedHelpers.chdir(path.dirname.to_s) do
562           eval_gemspec(path, contents)
563         end
564       end
565       return unless spec
566       spec.loaded_from = path.expand_path.to_s
567       Bundler.rubygems.validate(spec) if validate
568       spec
569     end
571     def clear_gemspec_cache
572       @gemspec_cache = {}
573     end
575     def git_present?
576       return @git_present if defined?(@git_present)
577       @git_present = Bundler.which("git#{RbConfig::CONFIG["EXEEXT"]}")
578     end
580     def feature_flag
581       @feature_flag ||= FeatureFlag.new(VERSION)
582     end
584     def load_plugins(definition = Bundler.definition)
585       return if defined?(@load_plugins_ran)
587       Bundler.rubygems.load_plugins
589       requested_path_gems = definition.requested_specs.select {|s| s.source.is_a?(Source::Path) }
590       path_plugin_files = requested_path_gems.map do |spec|
591         Bundler.rubygems.spec_matches_for_glob(spec, "rubygems_plugin#{Bundler.rubygems.suffix_pattern}")
592       rescue TypeError
593         error_message = "#{spec.name} #{spec.version} has an invalid gemspec"
594         raise Gem::InvalidSpecificationException, error_message
595       end.flatten
596       Bundler.rubygems.load_plugin_files(path_plugin_files)
597       Bundler.rubygems.load_env_plugins
598       @load_plugins_ran = true
599     end
601     def reset!
602       reset_paths!
603       Plugin.reset!
604       reset_rubygems!
605     end
607     def reset_settings_and_root!
608       @settings = nil
609       @root = nil
610     end
612     def reset_paths!
613       @bin_path = nil
614       @bundler_major_version = nil
615       @bundle_path = nil
616       @configure = nil
617       @configured_bundle_path = nil
618       @definition = nil
619       @load = nil
620       @locked_gems = nil
621       @root = nil
622       @settings = nil
623       @setup = nil
624       @user_home = nil
625     end
627     def reset_rubygems!
628       return unless defined?(@rubygems) && @rubygems
629       rubygems.undo_replacements
630       rubygems.reset
631       @rubygems = nil
632     end
634     def configure_gem_home_and_path(path = bundle_path)
635       configure_gem_path
636       configure_gem_home(path)
637       Bundler.rubygems.clear_paths
638     end
640     def self_manager
641       @self_manager ||= begin
642                           require_relative "bundler/self_manager"
643                           Bundler::SelfManager.new
644                         end
645     end
647     private
649     def load_marshal(data, marshal_proc: nil)
650       Marshal.load(data, marshal_proc)
651     rescue TypeError => e
652       raise MarshalError, "#{e.class}: #{e.message}"
653     end
655     def eval_yaml_gemspec(path, contents)
656       Kernel.require "psych"
658       Gem::Specification.from_yaml(contents)
659     rescue ::Psych::SyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception
660       eval_gemspec(path, contents)
661     end
663     def eval_gemspec(path, contents)
664       eval(contents, TOPLEVEL_BINDING.dup, path.expand_path.to_s)
665     rescue ScriptError, StandardError => e
666       msg = "There was an error while loading `#{path.basename}`: #{e.message}"
668       raise GemspecError, Dsl::DSLError.new(msg, path, e.backtrace, contents)
669     end
671     def configure_gem_path
672       unless use_system_gems?
673         # this needs to be empty string to cause
674         # PathSupport.split_gem_path to only load up the
675         # Bundler --path setting as the GEM_PATH.
676         Bundler::SharedHelpers.set_env "GEM_PATH", ""
677       end
678     end
680     def configure_gem_home(path)
681       Bundler::SharedHelpers.set_env "GEM_HOME", path.to_s
682     end
684     def tmp_home_path
685       Kernel.send(:require, "tmpdir")
686       SharedHelpers.filesystem_access(Dir.tmpdir) do
687         path = Bundler.tmp
688         at_exit { Bundler.rm_rf(path) }
689         path
690       end
691     end
693     # @param env [Hash]
694     def with_env(env)
695       backup = ENV.to_hash
696       ENV.replace(env)
697       yield
698     ensure
699       ENV.replace(backup)
700     end
701   end