diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-11-11 17:57:45 +0900 |
---|---|---|
committer | SHIBATA Hiroshi <hsbt@ruby-lang.org> | 2019-11-11 18:56:25 +0900 |
commit | 7585bc31877d4f9725f8de51b4a2faf47acb6f34 (patch) | |
tree | adf61a7c20f7e54b595ebde05284b5e2862f552c /lib | |
parent | fd69f82675bf93a848e5aa58d117bf8bbf604188 (diff) | |
download | ruby-7585bc31877d4f9725f8de51b4a2faf47acb6f34.tar.gz |
Merge Bundler 2.1.0.pre.3
Features:
- Add caller information to some deprecation messages to make them easier to fix [#7361](https://github.com/bundler/bundler/pull/7361)
- Reconcile `bundle cache` vs `bundle package` everywhere. Now in docs, CLI help and everywhere else `bundle cache` is the preferred version and `bundle package` remains as an alias [#7389](https://github.com/bundler/bundler/pull/7389)
- Display some basic `bundler` documentation together with ruby's RDoc based documentation [#7394](https://github.com/bundler/bundler/pull/7394)
Bugfixes:
- Fix typos deprecation message and upgrading docs [#7374](https://github.com/bundler/bundler/pull/7374)
- Deprecation warnings about `taint` usage on ruby 2.7 [#7385](https://github.com/bundler/bundler/pull/7385)
- Fix `--help` flag not correctly delegating to `man` when used with command aliases [#7388](https://github.com/bundler/bundler/pull/7388)
- `bundle add` should cache newly added gems if an application cache exists [#7393](https://github.com/bundler/bundler/pull/7393)
- Stop using an insecure folder as a "fallback home" when user home is not defined [#7416](https://github.com/bundler/bundler/pull/7416)
- Fix `bundler/inline` warning about `Bundler.root` redefinition [#7417](https://github.com/bundler/bundler/pull/7417)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler.rb | 111 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 80 | ||||
-rw-r--r-- | lib/bundler/cli/add.rb | 1 | ||||
-rw-r--r-- | lib/bundler/cli/cache.rb | 48 | ||||
-rw-r--r-- | lib/bundler/cli/exec.rb | 7 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 2 | ||||
-rw-r--r-- | lib/bundler/friendly_errors.rb | 2 | ||||
-rw-r--r-- | lib/bundler/gem_helper.rb | 1 | ||||
-rw-r--r-- | lib/bundler/gem_helpers.rb | 2 | ||||
-rw-r--r-- | lib/bundler/inline.rb | 10 | ||||
-rw-r--r-- | lib/bundler/lockfile_parser.rb | 1 | ||||
-rw-r--r-- | lib/bundler/rubygems_ext.rb | 2 | ||||
-rw-r--r-- | lib/bundler/rubygems_integration.rb | 1 | ||||
-rw-r--r-- | lib/bundler/setup.rb | 11 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 37 | ||||
-rw-r--r-- | lib/bundler/source/git.rb | 2 | ||||
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 2 | ||||
-rw-r--r-- | lib/bundler/vendor/fileutils/lib/fileutils.rb | 241 | ||||
-rw-r--r-- | lib/bundler/vendor/fileutils/lib/fileutils/version.rb | 2 | ||||
-rw-r--r-- | lib/bundler/version.rb | 2 |
20 files changed, 353 insertions, 212 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index a21dc7726d..3b494a6cdf 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -14,6 +14,25 @@ require_relative "bundler/constants" require_relative "bundler/current_ruby" require_relative "bundler/build_metadata" +# Bundler provides a consistent environment for Ruby projects by +# tracking and installing the exact gems and versions that are needed. +# +# Since Ruby 2.6, Bundler is a part of Ruby's standard library. +# +# Bunder is used by creating _gemfiles_ listing all the project dependencies +# and (optionally) their versions and then using +# +# require 'bundler/setup' +# +# or Bundler.setup to setup environment where only specified gems and their +# specified versions could be used. +# +# See {Bundler website}[https://bundler.io/docs.html] for extensive documentation +# on gemfiles creation and Bundler usage. +# +# As a standard library inside project, Bundler could be used for introspection +# of loaded and required modules. +# module Bundler environment_preserver = EnvironmentPreserver.new(ENV, EnvironmentPreserver::BUNDLER_KEYS) ORIGINAL_ENV = environment_preserver.restore @@ -64,11 +83,11 @@ module Bundler end def ui - (defined?(@ui) && @ui) || (self.ui = UI::Silent.new) + (defined?(@ui) && @ui) || (self.ui = UI::Shell.new) end def ui=(ui) - Bundler.rubygems.ui = ui ? UI::RGProxy.new(ui) : nil + Bundler.rubygems.ui = UI::RGProxy.new(ui) @ui = ui end @@ -91,6 +110,33 @@ module Bundler end end + # Turns on the Bundler runtime. After +Bundler.setup+ call, all +load+ or + # +require+ of the gems would be allowed only if they are part of + # the Gemfile or Ruby's standard library. If the versions specified + # in Gemfile, only those versions would be loaded. + # + # Assuming Gemfile + # + # gem 'first_gem', '= 1.0' + # group :test do + # gem 'second_gem', '= 1.0' + # end + # + # The code using Bundler.setup works as follows: + # + # require 'third_gem' # allowed, required from global gems + # require 'first_gem' # allowed, loads the last installed version + # Bundler.setup + # require 'fourth_gem' # fails with LoadError + # require 'second_gem' # loads exactly version 1.0 + # + # +Bundler.setup+ can be called only once, all subsequent calls are no-op. + # + # If _groups_ list is provided, only gems from specified groups would + # be allowed (gems specified outside groups belong to special +:default+ group). + # + # To require all gems from Gemfile (or only some groups), see Bundler.require. + # def setup(*groups) # Return if all groups are already loaded return @setup if defined?(@setup) && @setup @@ -107,6 +153,24 @@ module Bundler end end + # Setups Bundler environment (see Bundler.setup) if it is not already set, + # and loads all gems from groups specified. Unlike ::setup, can be called + # multiple times with different groups (if they were allowed by setup). + # + # Assuming Gemfile + # + # gem 'first_gem', '= 1.0' + # group :test do + # gem 'second_gem', '= 1.0' + # end + # + # The code will work as follows: + # + # Bundler.setup # allow all groups + # Bundler.require(:default) # requires only first_gem + # # ...later + # Bundler.require(:test) # requires second_gem + # def require(*groups) setup(*groups).require(*groups) end @@ -116,7 +180,7 @@ module Bundler end def environment - SharedHelpers.major_deprecation 2, "Bundler.environment has been removed in favor of Bundler.load" + SharedHelpers.major_deprecation 2, "Bundler.environment has been removed in favor of Bundler.load", :print_caller_location => true load end @@ -167,8 +231,7 @@ module Bundler end if warning - Kernel.send(:require, "etc") - user_home = tmp_home_path(Etc.getlogin, warning) + user_home = tmp_home_path(warning) Bundler.ui.warn "#{warning}\nBundler will use `#{user_home}' as your home directory temporarily.\n" user_home else @@ -177,21 +240,6 @@ module Bundler 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) - end - tmp_home_path.join(login).tap(&:mkpath) - end - rescue RuntimeError => e - raise e.exception("#{warning}\nBundler also failed to create a temporary home directory at `#{path}':\n#{e}") - end - def user_bundle_path(dir = "home") env_var, fallback = case dir when "home" @@ -282,7 +330,8 @@ EOF Bundler::SharedHelpers.major_deprecation( 2, "`Bundler.clean_env` has been deprecated in favor of `Bundler.unbundled_env`. " \ - "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`" + "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`", + :print_caller_location => true ) unbundled_env @@ -321,7 +370,8 @@ EOF Bundler::SharedHelpers.major_deprecation( 2, "`Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. " \ - "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env`" + "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env`", + :print_caller_location => true ) with_env(unbundled_env) { yield } @@ -342,7 +392,8 @@ EOF Bundler::SharedHelpers.major_deprecation( 2, "`Bundler.clean_system` has been deprecated in favor of `Bundler.unbundled_system`. " \ - "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`" + "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`", + :print_caller_location => true ) with_env(unbundled_env) { Kernel.system(*args) } @@ -363,7 +414,8 @@ EOF Bundler::SharedHelpers.major_deprecation( 2, "`Bundler.clean_exec` has been deprecated in favor of `Bundler.unbundled_exec`. " \ - "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`" + "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`", + :print_caller_location => true ) with_env(unbundled_env) { Kernel.exec(*args) } @@ -608,6 +660,17 @@ EOF Bundler.rubygems.clear_paths end + def tmp_home_path(warning) + Kernel.send(:require, "tmpdir") + SharedHelpers.filesystem_access(Dir.tmpdir) do + path = Bundler.tmp + at_exit { Bundler.rm_rf(path) } + path + end + rescue RuntimeError => e + raise e.exception("#{warning}\nBundler also failed to create a temporary home directory':\n#{e}") + end + # @param env [Hash] def with_env(env) backup = ENV.to_hash diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 45db2a3200..d7f749a672 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -9,15 +9,19 @@ module Bundler package_name "Bundler" AUTO_INSTALL_CMDS = %w[show binstubs outdated exec open console licenses clean].freeze - PARSEABLE_COMMANDS = %w[ - check config help exec platform show version - ].freeze + PARSEABLE_COMMANDS = %w[check config help exec platform show version].freeze + + COMMAND_ALIASES = { + "check" => "c", + "install" => "i", + "list" => "ls", + "exec" => ["e", "ex", "exe"], + "cache" => ["package", "pack"], + "version" => ["-v", "--version"], + }.freeze def self.start(*) super - rescue Exception => e # rubocop:disable Lint/RescueException - Bundler.ui = UI::Shell.new - raise e ensure Bundler::SharedHelpers.print_major_deprecations! end @@ -29,6 +33,24 @@ module Bundler end end + def self.all_aliases + @all_aliases ||= begin + command_aliases = {} + + COMMAND_ALIASES.each do |name, aliases| + Array(aliases).each do |one_alias| + command_aliases[one_alias] = name + end + end + + command_aliases + end + end + + def self.aliases_for(command_name) + COMMAND_ALIASES.select {|k, _| k == command_name }.invert + end + def initialize(*args) super @@ -68,9 +90,7 @@ module Bundler version Bundler.ui.info "\n" - primary_commands = ["install", "update", - Bundler.feature_flag.bundler_3_mode? ? "cache" : "package", - "exec", "config", "help"] + primary_commands = ["install", "update", "cache", "exec", "config", "help"] list = self.class.printable_commands(true) by_name = list.group_by {|name, _message| name.match(/^bundle (\w+)/)[1] } @@ -154,7 +174,6 @@ module Bundler "Use the specified gemfile instead of Gemfile" method_option "path", :type => :string, :banner => "Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME).#{" Bundler will remember this value for future installs on this machine" unless Bundler.feature_flag.forget_cli_options?}" - map "c" => "check" def check remembered_flag_deprecation("path") @@ -162,6 +181,8 @@ module Bundler Check.new(options).run end + map aliases_for("check") + desc "remove [GEM [GEM ...]]", "Removes gems from the Gemfile" long_desc <<-D Removes the given gems from the Gemfile while ensuring that the resulting Gemfile is still valid. If the gem is not found, Bundler prints a error message and if gem could not be removed due to any reason Bundler will display a warning. @@ -223,7 +244,6 @@ module Bundler "Exclude gems that are part of the specified named group." method_option "with", :type => :array, :banner => "Include gems that are part of the specified named group." - map "i" => "install" def install SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force") @@ -237,6 +257,8 @@ module Bundler end end + map aliases_for("install") + desc "update [OPTIONS]", "Update the current environment" long_desc <<-D Update will install the newest versions of the gems listed in the Gemfile. Use @@ -328,7 +350,7 @@ module Bundler List.new(options).run end - map %w[ls] => "list" + map aliases_for("list") desc "info GEM [OPTIONS]", "Show information for the given gem" method_option "path", :type => :boolean, :banner => "Print full path to gem" @@ -412,7 +434,7 @@ module Bundler Outdated.new(options, gems).run end - desc "#{Bundler.feature_flag.bundler_3_mode? ? :cache : :package} [OPTIONS]", "Locks and then caches all of the gems into vendor/cache" + desc "cache [OPTIONS]", "Locks and then caches all of the gems into vendor/cache" unless Bundler.feature_flag.cache_all? method_option "all", :type => :boolean, :banner => "Include all sources (including path and git)." @@ -421,24 +443,25 @@ module Bundler method_option "cache-path", :type => :string, :banner => "Specify a different cache path than the default (vendor/cache)." method_option "gemfile", :type => :string, :banner => "Use the specified gemfile instead of Gemfile" - method_option "no-install", :type => :boolean, :banner => "Don't install the gems, only the package." + method_option "no-install", :type => :boolean, :banner => "Don't install the gems, only update the cache." method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache." method_option "path", :type => :string, :banner => "Specify a different path than the system default ($BUNDLE_PATH or $GEM_HOME).#{" Bundler will remember this value for future installs on this machine" unless Bundler.feature_flag.forget_cli_options?}" method_option "quiet", :type => :boolean, :banner => "Only output warnings and errors." method_option "frozen", :type => :boolean, :banner => - "Do not allow the Gemfile.lock to be updated after this package operation's install" + "Do not allow the Gemfile.lock to be updated after this bundle cache operation's install" long_desc <<-D - The package command will copy the .gem files for every gem in the bundle into the + The cache command will copy the .gem files for every gem in the bundle into the directory ./vendor/cache. If you then check that directory into your source control repository, others who check out your source will be able to install the bundle without having to download any additional gems. D - def package - require_relative "cli/package" - Package.new(options).run + def cache + require_relative "cli/cache" + Cache.new(options).run end - map %w[cache pack] => :package + + map aliases_for("cache") desc "exec [OPTIONS]", "Run the command in context of the bundle" method_option :keep_file_descriptors, :type => :boolean, :default => false @@ -448,12 +471,13 @@ module Bundler bundle exec you can require and call the bundled gems as if they were installed into the system wide RubyGems repository. D - map "e" => "exec" def exec(*args) require_relative "cli/exec" Exec.new(options, args).run end + map aliases_for("exec") + desc "config NAME [VALUE]", "Retrieve or set a configuration value" long_desc <<-D Retrieves or sets a configuration value. If only one parameter is provided, retrieve the value. If two parameters are provided, replace the @@ -496,7 +520,8 @@ module Bundler Bundler.ui.info "Bundler version #{Bundler::VERSION}#{build_info}" end end - map %w[-v --version] => :version + + map aliases_for("version") desc "licenses", "Prints the license of all gems in the bundle" def licenses @@ -680,12 +705,17 @@ module Bundler # Reformat the arguments passed to bundle that include a --help flag # into the corresponding `bundle help #{command}` call def self.reformatted_help_args(args) - bundler_commands = all_commands.keys + bundler_commands = (COMMAND_ALIASES.keys + COMMAND_ALIASES.values).flatten + help_flags = %w[--help -h] - exec_commands = %w[e ex exe exec] + exec_commands = ["exec"] + COMMAND_ALIASES["exec"] + help_used = args.index {|a| help_flags.include? a } exec_used = args.index {|a| exec_commands.include? a } + command = args.find {|a| bundler_commands.include? a } + command = all_aliases[command] if all_aliases[command] + if exec_used && help_used if exec_used + help_used == 1 %w[help exec] @@ -790,7 +820,7 @@ module Bundler Bundler::SharedHelpers.major_deprecation 2,\ "The `#{flag_name}` flag is deprecated because it relies on being " \ - "remembered across bundler invokations, which bundler will no longer " \ + "remembered across bundler invocations, which bundler will no longer " \ "do in future versions. Instead please use `bundle config set #{name} " \ "'#{value}'`, and stop using this flag" end diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index 7c6235f17c..07b951f1ef 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -21,6 +21,7 @@ module Bundler def perform_bundle_install Installer.install(Bundler.root, Bundler.definition) + Bundler.load.cache if Bundler.app_cache.exist? end def inject_dependencies diff --git a/lib/bundler/cli/cache.rb b/lib/bundler/cli/cache.rb new file mode 100644 index 0000000000..5e8420990f --- /dev/null +++ b/lib/bundler/cli/cache.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Bundler + class CLI::Cache + attr_reader :options + + def initialize(options) + @options = options + end + + def run + Bundler.ui.level = "error" if options[:quiet] + Bundler.settings.set_command_option_if_given :path, options[:path] + Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"] + + setup_cache_all + install + + # TODO: move cache contents here now that all bundles are locked + custom_path = Bundler.settings[:path] if options[:path] + + Bundler.settings.temporary(:cache_all_platforms => options["all-platforms"]) do + Bundler.load.cache(custom_path) + end + end + + private + + def install + require_relative "install" + options = self.options.dup + options["local"] = false if Bundler.settings[:cache_all_platforms] + Bundler::CLI::Install.new(options).run + end + + def setup_cache_all + all = options.fetch(:all, Bundler.feature_flag.cache_all? || nil) + + Bundler.settings.set_command_option_if_given :cache_all, all + + if Bundler.definition.has_local_dependencies? && !Bundler.feature_flag.cache_all? + Bundler.ui.warn "Your Gemfile contains path and git dependencies. If you want " \ + "to cache them as well, please pass the --all flag. This will be the default " \ + "on Bundler 3.0." + end + end + end +end diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 0b0e991ea5..0a1edbdbbd 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -43,15 +43,11 @@ module Bundler end def kernel_exec(*args) - ui = Bundler.ui - Bundler.ui = nil Kernel.exec(*args) rescue Errno::EACCES, Errno::ENOEXEC - Bundler.ui = ui Bundler.ui.error "bundler: not executable: #{cmd}" exit 126 rescue Errno::ENOENT - Bundler.ui = ui Bundler.ui.error "bundler: command not found: #{cmd}" Bundler.ui.warn "Install missing gem executables with `bundle install`" exit 127 @@ -62,15 +58,12 @@ module Bundler ARGV.replace(args) $0 = file Process.setproctitle(process_title(file, args)) if Process.respond_to?(:setproctitle) - ui = Bundler.ui - Bundler.ui = nil require_relative "../setup" TRAPPED_SIGNALS.each {|s| trap(s, "DEFAULT") } Kernel.load(file) rescue SystemExit, SignalException raise rescue Exception => e # rubocop:disable Lint/RescueException - Bundler.ui = ui Bundler.ui.error "bundler: failed to load command: #{cmd} (#{file})" backtrace = e.backtrace ? e.backtrace.take_while {|bt| !bt.start_with?(__FILE__) } : [] abort "#{e.class}: #{e.message}\n #{backtrace.join("\n ")}" diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index cc23f9b389..99a369281a 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -44,7 +44,7 @@ module Bundler @gemfile = expanded_gemfile_path @gemfiles << expanded_gemfile_path contents ||= Bundler.read_file(@gemfile.to_s) - instance_eval(contents.dup.untaint, gemfile.to_s, 1) + instance_eval(contents.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" }, gemfile.to_s, 1) rescue Exception => e # rubocop:disable Lint/RescueException message = "There was an error " \ "#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \ diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index e9f06d90be..273573e820 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -16,7 +16,7 @@ module Bundler Bundler.ui.error error.message when GemRequireError Bundler.ui.error error.message - Bundler.ui.trace error.orig_exception, nil, true + Bundler.ui.trace error.orig_exception when BundlerError Bundler.ui.error error.message, :wrap => true Bundler.ui.trace error diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index d00c1894a8..81872b9429 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -26,7 +26,6 @@ module Bundler attr_reader :spec_path, :base, :gemspec def initialize(base = nil, name = nil) - Bundler.ui = UI::Shell.new @base = (base ||= SharedHelpers.pwd) gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "{,*}.gemspec")] raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1 diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb index 90dfb70867..be047f4397 100644 --- a/lib/bundler/gem_helpers.rb +++ b/lib/bundler/gem_helpers.rb @@ -2,7 +2,7 @@ module Bundler module GemHelpers - GENERIC_CACHE = { Gem::Platform::RUBY => Gem::Platform::RUBY } # rubocop:disable MutableConstant + GENERIC_CACHE = { Gem::Platform::RUBY => Gem::Platform::RUBY } # rubocop:disable Style/MutableConstant GENERICS = [ [Gem::Platform.new("java"), Gem::Platform.new("java")], [Gem::Platform.new("mswin32"), Gem::Platform.new("mswin32")], diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index dbf737c7ee..152d7d3f60 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -38,6 +38,8 @@ def gemfile(install = false, options = {}, &gemfile) raise ArgumentError, "Unknown options: #{opts.keys.join(", ")}" unless opts.empty? old_root = Bundler.method(:root) + bundler_module = class << Bundler; self; end + bundler_module.send(:remove_method, :root) def Bundler.root Bundler::SharedHelpers.pwd.expand_path end @@ -56,7 +58,7 @@ def gemfile(install = false, options = {}, &gemfile) definition.missing_specs? end - Bundler.ui = ui if install + Bundler.ui = install ? ui : Bundler::UI::Silent.new if install || missing_specs.call Bundler.settings.temporary(:inline => true, :disable_platform_warnings => true) do installer = Bundler::Installer.install(Bundler.root, definition, :system => true) @@ -70,6 +72,8 @@ def gemfile(install = false, options = {}, &gemfile) runtime.setup.require end ensure - bundler_module = class << Bundler; self; end - bundler_module.send(:define_method, :root, old_root) if old_root + if bundler_module + bundler_module.send(:remove_method, :root) + bundler_module.send(:define_method, :root, old_root) + end end diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 5658ec1205..caabd524d4 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +#-- # Some versions of the Bundler 1.1 RC series introduced corrupted # lockfiles. There were two major problems: # diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 96b93836c7..eda826422f 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -29,7 +29,7 @@ module Gem # gems at that time, this method could be called inside another require, # thus raising with that constant being undefined. Better to check a method if source.respond_to?(:path) || (source.respond_to?(:bundler_plugin_api_source?) && source.bundler_plugin_api_source?) - Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.untaint + Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" } else rg_full_gem_path end diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 7549c592f1..c4950d14e8 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -635,7 +635,6 @@ module Bundler ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile) require_relative "gemdeps" runtime = Bundler.setup - Bundler.ui = nil activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name) [Gemdeps.new(runtime), activated_spec_names] end diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb index d156f494a8..70a0968f4b 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -6,9 +6,8 @@ if Bundler::SharedHelpers.in_bundle? require_relative "../bundler" if STDOUT.tty? || ENV["BUNDLER_FORCE_TTY"] - Bundler.ui = Bundler::UI::Shell.new begin - Bundler.setup + Bundler.ui.silence { Bundler.setup } rescue Bundler::BundlerError => e Bundler.ui.warn "\e[31m#{e.message}\e[0m" Bundler.ui.warn e.backtrace.join("\n") if ENV["DEBUG"] @@ -18,12 +17,6 @@ if Bundler::SharedHelpers.in_bundle? exit e.status_code end else - Bundler.setup + Bundler.ui.silence { Bundler.setup } end - - # Add bundler to the load path after disabling system gems - bundler_lib = File.expand_path("../..", __FILE__) - $LOAD_PATH.unshift(bundler_lib) unless $LOAD_PATH.include?(bundler_lib) - - Bundler.ui = nil end diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index e6e2b79344..6e83bc5ff4 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -13,13 +13,13 @@ module Bundler def root gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile - Pathname.new(gemfile).untaint.expand_path.parent + Pathname.new(gemfile).tap{|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path.parent end def default_gemfile gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile - Pathname.new(gemfile).untaint.expand_path + Pathname.new(gemfile).tap{|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path end def default_lockfile @@ -28,7 +28,7 @@ module Bundler case gemfile.basename.to_s when "gems.rb" then Pathname.new(gemfile.sub(/.rb$/, ".locked")) else Pathname.new("#{gemfile}.lock") - end.untaint + end.tap{|x| x.untaint if RUBY_VERSION < "2.7" } end def default_bundle_dir @@ -100,7 +100,7 @@ module Bundler # # @see {Bundler::PermissionError} def filesystem_access(path, action = :write, &block) - yield(path.dup.untaint) + yield(path.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" }) rescue Errno::EACCES raise PermissionError.new(path, action) rescue Errno::EAGAIN @@ -124,7 +124,12 @@ module Bundler namespace.const_get(constant_name) end - def major_deprecation(major_version, message) + def major_deprecation(major_version, message, print_caller_location: false) + if print_caller_location + caller_location = caller_locations(2, 2).first + message = "#{message} (called at #{caller_location.path}:#{caller_location.lineno})" + end + bundler_major_version = Bundler.bundler_major_version if bundler_major_version > major_version require_relative "errors" @@ -132,10 +137,7 @@ module Bundler end return unless bundler_major_version >= major_version && prints_major_deprecations? - @major_deprecation_ui ||= Bundler::UI::Shell.new("no-color" => true) - with_major_deprecation_ui do |ui| - ui.warn("[DEPRECATED] #{message}") - end + Bundler.ui.warn("[DEPRECATED] #{message}") end def print_major_deprecations! @@ -212,21 +214,6 @@ module Bundler private - def with_major_deprecation_ui(&block) - ui = Bundler.ui - - if ui.is_a?(@major_deprecation_ui.class) - yield ui - else - begin - Bundler.ui = @major_deprecation_ui - yield Bundler.ui - ensure - Bundler.ui = ui - end - end - end - def validate_bundle_path path_separator = Bundler.rubygems.path_separator return unless Bundler.bundle_path.to_s.split(path_separator).size > 1 @@ -263,7 +250,7 @@ module Bundler def search_up(*names) previous = nil - current = File.expand_path(SharedHelpers.pwd).untaint + current = File.expand_path(SharedHelpers.pwd).tap{|x| x.untaint if RUBY_VERSION < "2.7" } until !File.directory?(current) || current == previous if ENV["BUNDLE_SPEC_RUN"] diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 73123622d4..736f5bb546 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -316,7 +316,7 @@ module Bundler def load_gemspec(file) stub = Gem::StubSpecification.gemspec_stub(file, install_path.parent, install_path.parent) - stub.full_gem_path = Pathname.new(file).dirname.expand_path(root).to_s.untaint + stub.full_gem_path = Pathname.new(file).dirname.expand_path(root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" } StubSpecification.from_stub(stub) end diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index 1f6dc5d8f9..2a4d7138a4 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -2,7 +2,7 @@ require "open3" require "shellwords" -require "tempfile" + module Bundler class Source class Git diff --git a/lib/bundler/vendor/fileutils/lib/fileutils.rb b/lib/bundler/vendor/fileutils/lib/fileutils.rb index 6fbe741498..c1988dceab 100644 --- a/lib/bundler/vendor/fileutils/lib/fileutils.rb +++ b/lib/bundler/vendor/fileutils/lib/fileutils.rb @@ -24,46 +24,56 @@ require_relative "fileutils/version" # # require 'bundler/vendor/fileutils/lib/fileutils' # -# Bundler::FileUtils.cd(dir, options) -# Bundler::FileUtils.cd(dir, options) {|dir| block } +# Bundler::FileUtils.cd(dir, **options) +# Bundler::FileUtils.cd(dir, **options) {|dir| block } # Bundler::FileUtils.pwd() -# Bundler::FileUtils.mkdir(dir, options) -# Bundler::FileUtils.mkdir(list, options) -# Bundler::FileUtils.mkdir_p(dir, options) -# Bundler::FileUtils.mkdir_p(list, options) -# Bundler::FileUtils.rmdir(dir, options) -# Bundler::FileUtils.rmdir(list, options) -# Bundler::FileUtils.ln(target, link, options) -# Bundler::FileUtils.ln(targets, dir, options) -# Bundler::FileUtils.ln_s(target, link, options) -# Bundler::FileUtils.ln_s(targets, dir, options) -# Bundler::FileUtils.ln_sf(target, link, options) -# Bundler::FileUtils.cp(src, dest, options) -# Bundler::FileUtils.cp(list, dir, options) -# Bundler::FileUtils.cp_r(src, dest, options) -# Bundler::FileUtils.cp_r(list, dir, options) -# Bundler::FileUtils.mv(src, dest, options) -# Bundler::FileUtils.mv(list, dir, options) -# Bundler::FileUtils.rm(list, options) -# Bundler::FileUtils.rm_r(list, options) -# Bundler::FileUtils.rm_rf(list, options) -# Bundler::FileUtils.install(src, dest, options) -# Bundler::FileUtils.chmod(mode, list, options) -# Bundler::FileUtils.chmod_R(mode, list, options) -# Bundler::FileUtils.chown(user, group, list, options) -# Bundler::FileUtils.chown_R(user, group, list, options) -# Bundler::FileUtils.touch(list, options) +# Bundler::FileUtils.mkdir(dir, **options) +# Bundler::FileUtils.mkdir(list, **options) +# Bundler::FileUtils.mkdir_p(dir, **options) +# Bundler::FileUtils.mkdir_p(list, **options) +# Bundler::FileUtils.rmdir(dir, **options) +# Bundler::FileUtils.rmdir(list, **options) +# Bundler::FileUtils.ln(target, link, **options) +# Bundler::FileUtils.ln(targets, dir, **options) +# Bundler::FileUtils.ln_s(target, link, **options) +# Bundler::FileUtils.ln_s(targets, dir, **options) +# Bundler::FileUtils.ln_sf(target, link, **options) +# Bundler::FileUtils.cp(src, dest, **options) +# Bundler::FileUtils.cp(list, dir, **options) +# Bundler::FileUtils.cp_r(src, dest, **options) +# Bundler::FileUtils.cp_r(list, dir, **options) +# Bundler::FileUtils.mv(src, dest, **options) +# Bundler::FileUtils.mv(list, dir, **options) +# Bundler::FileUtils.rm(list, **options) +# Bundler::FileUtils.rm_r(list, **options) +# Bundler::FileUtils.rm_rf(list, **options) +# Bundler::FileUtils.install(src, dest, **options) +# Bundler::FileUtils.chmod(mode, list, **options) +# Bundler::FileUtils.chmod_R(mode, list, **options) +# Bundler::FileUtils.chown(user, group, list, **options) +# Bundler::FileUtils.chown_R(user, group, list, **options) +# Bundler::FileUtils.touch(list, **options) # -# The <tt>options</tt> parameter is a hash of options, taken from the list -# <tt>:force</tt>, <tt>:noop</tt>, <tt>:preserve</tt>, and <tt>:verbose</tt>. -# <tt>:noop</tt> means that no changes are made. The other three are obvious. -# Each method documents the options that it honours. +# Possible <tt>options</tt> are: +# +# <tt>:force</tt> :: forced operation (rewrite files if exist, remove +# directories if not empty, etc.); +# <tt>:verbose</tt> :: print command to be run, in bash syntax, before +# performing it; +# <tt>:preserve</tt> :: preserve object's group, user and modification +# time on copying; +# <tt>:noop</tt> :: no changes are made (usable in combination with +# <tt>:verbose</tt> which will print the command to run) +# +# Each method documents the options that it honours. See also ::commands, +# ::options and ::options_of methods to introspect which command have which +# options. # # All methods that have the concept of a "source" file or directory can take # either one file or a list of files in that argument. See the method # documentation for examples. # -# There are some `low level' methods, which do not accept any option: +# There are some `low level' methods, which do not accept keyword arguments: # # Bundler::FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false) # Bundler::FileUtils.copy_file(src, dest, preserve = false, dereference = true) @@ -119,7 +129,7 @@ module Bundler::FileUtils # # Bundler::FileUtils.cd('/') # change directory # - # Bundler::FileUtils.cd('/', :verbose => true) # change directory and report it + # Bundler::FileUtils.cd('/', verbose: true) # change directory and report it # # Bundler::FileUtils.cd('/') do # change directory # # ... # do something @@ -164,9 +174,9 @@ module Bundler::FileUtils # Creates one or more directories. # # Bundler::FileUtils.mkdir 'test' - # Bundler::FileUtils.mkdir %w( tmp data ) - # Bundler::FileUtils.mkdir 'notexist', :noop => true # Does not really create. - # Bundler::FileUtils.mkdir 'tmp', :mode => 0700 + # Bundler::FileUtils.mkdir %w(tmp data) + # Bundler::FileUtils.mkdir 'notexist', noop: true # Does not really create. + # Bundler::FileUtils.mkdir 'tmp', mode: 0700 # def mkdir(list, mode: nil, noop: nil, verbose: nil) list = fu_list(list) @@ -185,7 +195,7 @@ module Bundler::FileUtils # # Bundler::FileUtils.mkdir_p '/usr/local/lib/ruby' # - # causes to make following directories, if it does not exist. + # causes to make following directories, if they do not exist. # # * /usr # * /usr/local @@ -249,7 +259,7 @@ module Bundler::FileUtils # Bundler::FileUtils.rmdir 'somedir' # Bundler::FileUtils.rmdir %w(somedir anydir otherdir) # # Does not really remove directory; outputs message. - # Bundler::FileUtils.rmdir 'somedir', :verbose => true, :noop => true + # Bundler::FileUtils.rmdir 'somedir', verbose: true, noop: true # def rmdir(list, parents: nil, noop: nil, verbose: nil) list = fu_list(list) @@ -278,7 +288,7 @@ module Bundler::FileUtils # # In the first form, creates a hard link +link+ which points to +target+. # If +link+ already exists, raises Errno::EEXIST. - # But if the :force option is set, overwrites +link+. + # But if the +force+ option is set, overwrites +link+. # # Bundler::FileUtils.ln 'gcc', 'cc', verbose: true # Bundler::FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs' @@ -305,22 +315,22 @@ module Bundler::FileUtils module_function :link # - # :call-seq: - # Bundler::FileUtils.cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false) - # # Hard link +src+ to +dest+. If +src+ is a directory, this method links # all its contents recursively. If +dest+ is a directory, links # +src+ to +dest/src+. # # +src+ can be a list of files. # - # # Installing the library "mylib" under the site_ruby directory. - # Bundler::FileUtils.rm_r site_ruby + '/mylib', :force => true + # If +dereference_root+ is true, this method dereference tree root. + # + # If +remove_destination+ is true, this method removes each destination file before copy. + # + # Bundler::FileUtils.rm_r site_ruby + '/mylib', force: true # Bundler::FileUtils.cp_lr 'lib/', site_ruby + '/mylib' # # # Examples of linking several files to target directory. # Bundler::FileUtils.cp_lr %w(mail.rb field.rb debug/), site_ruby + '/tmail' - # Bundler::FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true + # Bundler::FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', noop: true, verbose: true # # # If you want to link all contents of a directory instead of the # # directory itself, c.f. src/x -> dest/x, src/y -> dest/y, @@ -345,7 +355,7 @@ module Bundler::FileUtils # # In the first form, creates a symbolic link +link+ which points to +target+. # If +link+ already exists, raises Errno::EEXIST. - # But if the :force option is set, overwrites +link+. + # But if the <tt>force</tt> option is set, overwrites +link+. # # Bundler::FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby' # Bundler::FileUtils.ln_s 'verylongsourcefilename.c', 'c', force: true @@ -411,7 +421,7 @@ module Bundler::FileUtils # # Bundler::FileUtils.cp 'eval.c', 'eval.c.org' # Bundler::FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6' - # Bundler::FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', :verbose => true + # Bundler::FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', verbose: true # Bundler::FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink # def cp(src, dest, preserve: nil, noop: nil, verbose: nil) @@ -433,13 +443,17 @@ module Bundler::FileUtils # # +src+ can be a list of files. # + # If +dereference_root+ is true, this method dereference tree root. + # + # If +remove_destination+ is true, this method removes each destination file before copy. + # # # Installing Ruby library "mylib" under the site_ruby - # Bundler::FileUtils.rm_r site_ruby + '/mylib', :force + # Bundler::FileUtils.rm_r site_ruby + '/mylib', force: true # Bundler::FileUtils.cp_r 'lib/', site_ruby + '/mylib' # # # Examples of copying several files to target directory. # Bundler::FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail' - # Bundler::FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', :noop => true, :verbose => true + # Bundler::FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', noop: true, verbose: true # # # If you want to copy all contents of a directory instead of the # # directory itself, c.f. src/x -> dest/x, src/y -> dest/y, @@ -474,7 +488,11 @@ module Bundler::FileUtils # If +remove_destination+ is true, this method removes each destination file before copy. # def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false) - Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent| + if dereference_root + src = File.realpath(src) + end + + Entry_.new(src, nil, false).wrap_traverse(proc do |ent| destent = Entry_.new(dest, ent.rel, false) File.unlink destent.path if remove_destination && (File.file?(destent.path) || File.symlink?(destent.path)) ent.copy destent.path @@ -511,10 +529,10 @@ module Bundler::FileUtils # disk partition, the file is copied then the original file is removed. # # Bundler::FileUtils.mv 'badname.rb', 'goodname.rb' - # Bundler::FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', :force => true # no error + # Bundler::FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', force: true # no error # # Bundler::FileUtils.mv %w(junk.txt dust.txt), '/home/foo/.trash/' - # Bundler::FileUtils.mv Dir.glob('test*.rb'), 'test', :noop => true, :verbose => true + # Bundler::FileUtils.mv Dir.glob('test*.rb'), 'test', noop: true, verbose: true # def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil) fu_output_message "mv#{force ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if verbose @@ -554,7 +572,7 @@ module Bundler::FileUtils # # Bundler::FileUtils.rm %w( junk.txt dust.txt ) # Bundler::FileUtils.rm Dir.glob('*.so') - # Bundler::FileUtils.rm 'NotExistFile', :force => true # never raises exception + # Bundler::FileUtils.rm 'NotExistFile', force: true # never raises exception # def rm(list, force: nil, noop: nil, verbose: nil) list = fu_list(list) @@ -573,7 +591,7 @@ module Bundler::FileUtils # # Equivalent to # - # Bundler::FileUtils.rm(list, :force => true) + # Bundler::FileUtils.rm(list, force: true) # def rm_f(list, noop: nil, verbose: nil) rm list, force: true, noop: noop, verbose: verbose @@ -589,18 +607,18 @@ module Bundler::FileUtils # StandardError when :force option is set. # # Bundler::FileUtils.rm_r Dir.glob('/tmp/*') - # Bundler::FileUtils.rm_r 'some_dir', :force => true + # Bundler::FileUtils.rm_r 'some_dir', force: true # # WARNING: This method causes local vulnerability # if one of parent directories or removing directory tree are world # writable (including /tmp, whose permission is 1777), and the current # process has strong privilege such as Unix super user (root), and the # system has symbolic link. For secure removing, read the documentation - # of #remove_entry_secure carefully, and set :secure option to true. - # Default is :secure=>false. + # of remove_entry_secure carefully, and set :secure option to true. + # Default is <tt>secure: false</tt>. # - # NOTE: This method calls #remove_entry_secure if :secure option is set. - # See also #remove_entry_secure. + # NOTE: This method calls remove_entry_secure if :secure option is set. + # See also remove_entry_secure. # def rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil) list = fu_list(list) @@ -619,10 +637,10 @@ module Bundler::FileUtils # # Equivalent to # - # Bundler::FileUtils.rm_r(list, :force => true) + # Bundler::FileUtils.rm_r(list, force: true) # # WARNING: This method causes local vulnerability. - # Read the documentation of #rm_r first. + # Read the documentation of rm_r first. # def rm_rf(list, noop: nil, verbose: nil, secure: nil) rm_r list, force: true, noop: noop, verbose: verbose, secure: secure @@ -636,7 +654,7 @@ module Bundler::FileUtils # This method removes a file system entry +path+. +path+ shall be a # regular file, a directory, or something. If +path+ is a directory, # remove it recursively. This method is required to avoid TOCTTOU - # (time-of-check-to-time-of-use) local security vulnerability of #rm_r. + # (time-of-check-to-time-of-use) local security vulnerability of rm_r. # #rm_r causes security hole when: # # * Parent directory is world writable (including /tmp). @@ -755,7 +773,7 @@ module Bundler::FileUtils # +path+ might be a regular file, a directory, or something. # If +path+ is a directory, remove it recursively. # - # See also #remove_entry_secure. + # See also remove_entry_secure. # def remove_entry(path, force = false) Entry_.new(path).postorder_traverse do |ent| @@ -839,8 +857,8 @@ module Bundler::FileUtils # mode to +mode+. If +dest+ is a directory, destination is +dest+/+src+. # This method removes destination before copy. # - # Bundler::FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true - # Bundler::FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true + # Bundler::FileUtils.install 'ruby', '/usr/local/bin/ruby', mode: 0755, verbose: true + # Bundler::FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', verbose: true # def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil, noop: nil, verbose: nil) @@ -970,12 +988,12 @@ module Bundler::FileUtils # Absolute mode is # Bundler::FileUtils.chmod 0755, 'somecommand' # Bundler::FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb) - # Bundler::FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true + # Bundler::FileUtils.chmod 0755, '/usr/bin/ruby', verbose: true # # Symbolic mode is # Bundler::FileUtils.chmod "u=wrx,go=rx", 'somecommand' # Bundler::FileUtils.chmod "u=wr,go=rr", %w(my.rb your.rb his.rb her.rb) - # Bundler::FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', :verbose => true + # Bundler::FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', verbose: true # # "a" :: is user, group, other mask. # "u" :: is user's mask. @@ -1035,7 +1053,7 @@ module Bundler::FileUtils # the attribute. # # Bundler::FileUtils.chown 'root', 'staff', '/usr/local/bin/ruby' - # Bundler::FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), :verbose => true + # Bundler::FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), verbose: true # def chown(user, group, list, noop: nil, verbose: nil) list = fu_list(list) @@ -1059,7 +1077,7 @@ module Bundler::FileUtils # method does not change the attribute. # # Bundler::FileUtils.chown_R 'www', 'www', '/var/www/htdocs' - # Bundler::FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', :verbose => true + # Bundler::FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', verbose: true # def chown_R(user, group, list, noop: nil, verbose: nil, force: nil) list = fu_list(list) @@ -1276,13 +1294,13 @@ module Bundler::FileUtils opts[:encoding] = ::Encoding::UTF_8 if fu_windows? files = if Dir.respond_to?(:children) - Dir.children(path, opts) + Dir.children(path, **opts) else - Dir.entries(path(), opts) + Dir.entries(path(), **opts) .reject {|n| n == '.' or n == '..' } end - files.map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) } + files.map {|n| Entry_.new(prefix(), join(rel(), n.tap{|x| x.untaint if RUBY_VERSION < "2.7" })) } end def stat @@ -1369,18 +1387,21 @@ module Bundler::FileUtils end when symlink? File.symlink File.readlink(path()), dest - when chardev? - raise "cannot handle device file" unless File.respond_to?(:mknod) - mknod dest, ?c, 0666, lstat().rdev - when blockdev? - raise "cannot handle device file" unless File.respond_to?(:mknod) - mknod dest, ?b, 0666, lstat().rdev + when chardev?, blockdev? + raise "cannot handle device file" when socket? - raise "cannot handle socket" unless File.respond_to?(:mknod) - mknod dest, nil, lstat().mode, 0 + begin + require 'socket' + rescue LoadError + raise "cannot handle socket" + else + raise "cannot handle socket" unless defined?(UNIXServer) + end + UNIXServer.new(dest).close + File.chmod lstat().mode, dest when pipe? raise "cannot handle FIFO" unless File.respond_to?(:mkfifo) - mkfifo dest, 0666 + File.mkfifo dest, lstat().mode when door? raise "cannot handle door: #{path()}" else @@ -1499,14 +1520,14 @@ module Bundler::FileUtils private - $fileutils_rb_have_lchmod = nil + @@fileutils_rb_have_lchmod = nil def have_lchmod? # This is not MT-safe, but it does not matter. - if $fileutils_rb_have_lchmod == nil - $fileutils_rb_have_lchmod = check_have_lchmod? + if @@fileutils_rb_have_lchmod == nil + @@fileutils_rb_have_lchmod = check_have_lchmod? end - $fileutils_rb_have_lchmod + @@fileutils_rb_have_lchmod end def check_have_lchmod? @@ -1517,14 +1538,14 @@ module Bundler::FileUtils return false end - $fileutils_rb_have_lchown = nil + @@fileutils_rb_have_lchown = nil def have_lchown? # This is not MT-safe, but it does not matter. - if $fileutils_rb_have_lchown == nil - $fileutils_rb_have_lchown = check_have_lchown? + if @@fileutils_rb_have_lchown == nil + @@fileutils_rb_have_lchown = check_have_lchown? end - $fileutils_rb_have_lchown + @@fileutils_rb_have_lchown end def check_have_lchown? @@ -1546,10 +1567,13 @@ module Bundler::FileUtils else DIRECTORY_TERM = "(?=/|\\z)" end - SYSCASE = File::FNM_SYSCASE.nonzero? ? "-i" : "" def descendant_directory?(descendant, ascendant) - /\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant) + if File::FNM_SYSCASE.nonzero? + File.expand_path(File.dirname(descendant)).casecmp(File.expand_path(ascendant)) == 0 + else + File.expand_path(File.dirname(descendant)) == File.expand_path(ascendant) + end end end # class Entry_ @@ -1588,13 +1612,13 @@ module Bundler::FileUtils end private_module_function :fu_same? - @fileutils_output = $stderr - @fileutils_label = '' - def fu_output_message(msg) #:nodoc: - @fileutils_output ||= $stderr - @fileutils_label ||= '' - @fileutils_output.puts @fileutils_label + msg + output = @fileutils_output if defined?(@fileutils_output) + output ||= $stderr + if defined?(@fileutils_label) + msg = @fileutils_label + msg + end + output.puts msg end private_module_function :fu_output_message @@ -1605,8 +1629,11 @@ module Bundler::FileUtils tbl } + public + # - # Returns an Array of method names which have any options. + # Returns an Array of names of high-level methods that accept any keyword + # arguments. # # p Bundler::FileUtils.commands #=> ["chmod", "cp", "cp_r", "install", ...] # @@ -1645,7 +1672,7 @@ module Bundler::FileUtils end # - # Returns an Array of method names which have the option +opt+. + # Returns an Array of methods names which have the option +opt+. # # p Bundler::FileUtils.collect_method(:preserve) #=> ["cp", "cp_r", "copy", "install"] # @@ -1653,14 +1680,16 @@ module Bundler::FileUtils OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) } end - LOW_METHODS = singleton_methods(false) - collect_method(:noop).map(&:intern) - module LowMethods + private + + LOW_METHODS = singleton_methods(false) - collect_method(:noop).map(&:intern) # :nodoc: + module LowMethods # :nodoc: internal use only private def _do_nothing(*)end ::Bundler::FileUtils::LOW_METHODS.map {|name| alias_method name, :_do_nothing} end - METHODS = singleton_methods() - [:private_module_function, + METHODS = singleton_methods() - [:private_module_function, # :nodoc: :commands, :options, :have_option?, :options_of, :collect_method] # @@ -1670,8 +1699,6 @@ module Bundler::FileUtils # module Verbose include Bundler::FileUtils - @fileutils_output = $stderr - @fileutils_label = '' names = ::Bundler::FileUtils.collect_method(:verbose) names.each do |name| module_eval(<<-EOS, __FILE__, __LINE__ + 1) @@ -1695,8 +1722,6 @@ module Bundler::FileUtils module NoWrite include Bundler::FileUtils include LowMethods - @fileutils_output = $stderr - @fileutils_label = '' names = ::Bundler::FileUtils.collect_method(:noop) names.each do |name| module_eval(<<-EOS, __FILE__, __LINE__ + 1) @@ -1721,8 +1746,6 @@ module Bundler::FileUtils module DryRun include Bundler::FileUtils include LowMethods - @fileutils_output = $stderr - @fileutils_label = '' names = ::Bundler::FileUtils.collect_method(:noop) names.each do |name| module_eval(<<-EOS, __FILE__, __LINE__ + 1) diff --git a/lib/bundler/vendor/fileutils/lib/fileutils/version.rb b/lib/bundler/vendor/fileutils/lib/fileutils/version.rb index 6d8504ccd5..b8f616e4fb 100644 --- a/lib/bundler/vendor/fileutils/lib/fileutils/version.rb +++ b/lib/bundler/vendor/fileutils/lib/fileutils/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Bundler::FileUtils - VERSION = "1.2.0" + VERSION = "1.3.0" end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index a2b824c471..4cf11c5fb5 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.1.0.pre.2".freeze + VERSION = "2.1.0.pre.3".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i |