diff options
Diffstat (limited to 'lib')
80 files changed, 358 insertions, 230 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 610cc484e3..f6ad7ccaef 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -353,7 +353,10 @@ EOF env.delete_if {|k, _| k[0, 7] == "BUNDLE_" } if env.key?("RUBYOPT") - env["RUBYOPT"] = env["RUBYOPT"].sub "-rbundler/setup", "" + rubyopt = env["RUBYOPT"].split(" ") + rubyopt.delete("-r#{File.expand_path("bundler/setup", __dir__)}") + rubyopt.delete("-rbundler/setup") + env["RUBYOPT"] = rubyopt.join(" ") end if env.key?("RUBYLIB") @@ -453,7 +456,7 @@ EOF # 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 set bindir foo`. + # the directory to be set as well, via `bundle config set --local bindir foo`. Bundler.settings[:system_bindir] || Bundler.rubygems.gem_bindir end @@ -621,7 +624,7 @@ EOF @rubygems = nil end - private + private def eval_yaml_gemspec(path, contents) require_relative "bundler/psyched_yaml" diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb index 4dfad2f8d8..0846e82e06 100644 --- a/lib/bundler/build_metadata.rb +++ b/lib/bundler/build_metadata.rb @@ -27,19 +27,11 @@ module Bundler # If Bundler has been installed without its .git directory and without a # commit instance variable then we can't determine its commits SHA. - git_dir = File.join(File.expand_path("../../..", __FILE__), ".git") + git_dir = File.join(File.expand_path("../../../..", __FILE__), ".git") if File.directory?(git_dir) return @git_commit_sha = Dir.chdir(git_dir) { `git rev-parse --short HEAD`.strip.freeze } end - # If Bundler is a submodule in RubyGems, get the submodule commit - git_sub_dir = File.join(File.expand_path("../../../..", __FILE__), ".git") - if File.directory?(git_sub_dir) - return @git_commit_sha = Dir.chdir(git_sub_dir) do - `git ls-tree --abbrev=8 HEAD bundler`.split(/\s/).fetch(2, "").strip.freeze - end - end - @git_commit_sha ||= "unknown" end diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index e8193cef14..b4196621e5 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -134,7 +134,7 @@ module Bundler if Bundler.which("man") && man_path !~ %r{^file:/.+!/META-INF/jruby.home/.+} Kernel.exec "man #{man_page}" else - puts File.read("#{File.dirname(man_page)}/#{File.basename(man_page)}.txt") + puts File.read("#{File.dirname(man_page)}/#{File.basename(man_page)}.ronn") end elsif command_path = Bundler.which("bundler-#{cli}") Kernel.exec(command_path, "--help") @@ -439,11 +439,18 @@ module Bundler Outdated.new(options, gems).run end - 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)." + desc "fund [OPTIONS]", "Lists information about gems seeking funding assistance" + method_option "group", :aliases => "-g", :type => :array, :banner => + "Fetch funding information for a specific group" + def fund + require_relative "cli/fund" + Fund.new(options).run end + + desc "cache [OPTIONS]", "Locks and then caches all of the gems into vendor/cache" + method_option "all", :type => :boolean, + :default => Bundler.feature_flag.cache_all?, + :banner => "Include all sources (including path and git)." method_option "all-platforms", :type => :boolean, :banner => "Include gems for all platforms present in the lockfile, not only the current one" method_option "cache-path", :type => :string, :banner => "Specify a different cache path than the default (vendor/cache)." @@ -462,6 +469,12 @@ module Bundler bundle without having to download any additional gems. D def cache + SharedHelpers.major_deprecation 2, + "The `--all` flag is deprecated because it relies on being " \ + "remembered across bundler invocations, which bundler will no longer " \ + "do in future versions. Instead please use `bundle config set cache_all true`, " \ + "and stop using this flag" if ARGV.include?("--all") + require_relative "cli/cache" Cache.new(options).run end @@ -565,18 +578,18 @@ module Bundler desc "gem NAME [OPTIONS]", "Creates a skeleton for creating a rubygem" method_option :exe, :type => :boolean, :default => false, :aliases => ["--bin", "-b"], :desc => "Generate a binary executable for your library." - method_option :coc, :type => :boolean, :desc => "Generate a code of conduct file. Set a default with `bundle config set gem.coc true`." + method_option :coc, :type => :boolean, :desc => "Generate a code of conduct file. Set a default with `bundle config set --global gem.coc true`." method_option :edit, :type => :string, :aliases => "-e", :required => false, :banner => "EDITOR", :lazy_default => [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? }, :desc => "Open generated gemspec in the specified editor (defaults to $EDITOR or $BUNDLER_EDITOR)" method_option :ext, :type => :boolean, :default => false, :desc => "Generate the boilerplate for C extension code" method_option :git, :type => :boolean, :default => true, :desc => "Initialize a git repo inside your library." - method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set gem.mit true`." - method_option :rubocop, :type => :boolean, :desc => "Add rubocop to the generated Rakefile and gemspec. Set a default with `bundle config set gem.rubocop true`." + method_option :mit, :type => :boolean, :desc => "Generate an MIT license file. Set a default with `bundle config set --global gem.mit true`." + method_option :rubocop, :type => :boolean, :desc => "Add rubocop to the generated Rakefile and gemspec. Set a default with `bundle config set --global gem.rubocop true`." method_option :test, :type => :string, :lazy_default => Bundler.settings["gem.test"] || "", :aliases => "-t", :banner => "Use the specified test framework for your library", - :desc => "Generate a test directory for your library, either rspec, minitest or test-unit. Set a default with `bundle config set gem.test (rspec|minitest|test-unit)`." + :desc => "Generate a test directory for your library, either rspec, minitest or test-unit. Set a default with `bundle config set --global gem.test (rspec|minitest|test-unit)`." method_option :ci, :type => :string, :lazy_default => Bundler.settings["gem.ci"] || "", - :desc => "Generate CI configuration, either GitHub Actions, Travis CI, GitLab CI or CircleCI. Set a default with `bundle config set gem.ci (github|travis|gitlab|circle)`" + :desc => "Generate CI configuration, either GitHub Actions, Travis CI, GitLab CI or CircleCI. Set a default with `bundle config set --global gem.ci (github|travis|gitlab|circle)`" def gem(name) end @@ -740,11 +753,11 @@ module Bundler end end - private + private # Automatically invoke `bundle install` and resume if # Bundler.settings[:auto_install] exists. This is set through config cmd - # `bundle config set auto_install 1`. + # `bundle config set --global auto_install 1`. # # Note that this method `nil`s out the global Definition object, so it # should be called first, before you instantiate anything like an @@ -839,10 +852,10 @@ module Bundler value = options[name] value = value.join(" ").to_s if option.type == :array - Bundler::SharedHelpers.major_deprecation 2,\ + Bundler::SharedHelpers.major_deprecation 2, "The `#{flag_name}` flag is deprecated because it relies on being " \ "remembered across bundler invocations, which bundler will no longer " \ - "do in future versions. Instead please use `bundle config set #{name.tr("-", "_")} " \ + "do in future versions. Instead please use `bundle config set --local #{name.tr("-", "_")} " \ "'#{value}'`, and stop using this flag" end end diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index 07b951f1ef..5bcf30d82d 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -17,7 +17,7 @@ module Bundler perform_bundle_install unless options["skip-install"] end - private + private def perform_bundle_install Installer.install(Bundler.root, Bundler.definition) diff --git a/lib/bundler/cli/cache.rb b/lib/bundler/cli/cache.rb index 5e8420990f..c14c8877f0 100644 --- a/lib/bundler/cli/cache.rb +++ b/lib/bundler/cli/cache.rb @@ -24,7 +24,7 @@ module Bundler end end - private + private def install require_relative "install" @@ -37,12 +37,6 @@ module Bundler 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/clean.rb b/lib/bundler/cli/clean.rb index 4a407fbae7..c6b0968e3e 100644 --- a/lib/bundler/cli/clean.rb +++ b/lib/bundler/cli/clean.rb @@ -13,7 +13,7 @@ module Bundler Bundler.load.clean(options[:"dry-run"]) end - protected + protected def require_path_or_force return unless Bundler.use_system_gems? && !options[:force] diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index cec7bcadb4..23ac78a103 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -14,6 +14,20 @@ module Bundler Bundler.ui.info msg end + def self.output_fund_metadata_summary + definition = Bundler.definition + current_dependencies = definition.requested_dependencies + current_specs = definition.specs + + count = current_dependencies.count {|dep| current_specs[dep.name].first.metadata.key?("funding_uri") } + + return if count.zero? + + intro = count > 1 ? "#{count} installed gems you directly depend on are" : "#{count} installed gem you directly depend on is" + message = "#{intro} looking for funding.\n Run `bundle fund` for details" + Bundler.ui.info message + end + def self.output_without_groups_message(command) return if Bundler.settings[:without].empty? Bundler.ui.confirm without_groups_message(command) diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index fcf139ed1e..2986ddbc99 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -93,7 +93,7 @@ module Bundler end end - private + private def check_home_permissions require "find" diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 0a1edbdbbd..0412d3adb0 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -34,7 +34,7 @@ module Bundler end end - private + private def validate_cmd! return unless cmd.nil? diff --git a/lib/bundler/cli/fund.rb b/lib/bundler/cli/fund.rb new file mode 100644 index 0000000000..52db5aef68 --- /dev/null +++ b/lib/bundler/cli/fund.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Bundler + class CLI::Fund + attr_reader :options + + def initialize(options) + @options = options + end + + def run + Bundler.definition.validate_runtime! + + groups = Array(options[:group]).map(&:to_sym) + + deps = if groups.any? + Bundler.definition.dependencies_for(groups) + else + Bundler.definition.current_dependencies + end + + fund_info = deps.each_with_object([]) do |dep, arr| + spec = Bundler.definition.specs[dep.name].first + if spec.metadata.key?("funding_uri") + arr << "* #{spec.name} (#{spec.version})\n Funding: #{spec.metadata["funding_uri"]}" + end + end + + if fund_info.empty? + Bundler.ui.info "None of the installed gems you directly depend on are looking for funding." + else + Bundler.ui.info fund_info.join("\n") + end + end + end +end diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 5b4e436d99..8d26e4c1f4 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -192,7 +192,7 @@ module Bundler raise GenericSystemCallError.new(e, "There was a conflict while creating the new gem.") end - private + private def resolve_name(name) SharedHelpers.pwd.join(name).basename.to_s diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 7f4ef0d03a..3111b64a33 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -22,7 +22,7 @@ module Bundler end end - private + private def spec_for_gem(gem_name) spec = Bundler.definition.specs.find {|s| s.name == gem_name } @@ -60,6 +60,7 @@ module Bundler gem_info << "\tHomepage: #{spec.homepage}\n" if spec.homepage gem_info << "\tDocumentation: #{metadata["documentation_uri"]}\n" if metadata.key?("documentation_uri") gem_info << "\tSource Code: #{metadata["source_code_uri"]}\n" if metadata.key?("source_code_uri") + gem_info << "\tFunding: #{metadata["funding_uri"]}\n" if metadata.key?("funding_uri") gem_info << "\tWiki: #{metadata["wiki_uri"]}\n" if metadata.key?("wiki_uri") gem_info << "\tChangelog: #{metadata["changelog_uri"]}\n" if metadata.key?("changelog_uri") gem_info << "\tBug Tracker: #{metadata["bug_tracker_uri"]}\n" if metadata.key?("bug_tracker_uri") diff --git a/lib/bundler/cli/init.rb b/lib/bundler/cli/init.rb index f45871ce9c..d851d02d42 100644 --- a/lib/bundler/cli/init.rb +++ b/lib/bundler/cli/init.rb @@ -38,7 +38,7 @@ module Bundler puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}" end - private + private def gemfile @gemfile ||= Bundler.preferred_gemfile_name diff --git a/lib/bundler/cli/inject.rb b/lib/bundler/cli/inject.rb index b00675d348..8093a85283 100644 --- a/lib/bundler/cli/inject.rb +++ b/lib/bundler/cli/inject.rb @@ -44,7 +44,7 @@ module Bundler end end - private + private def last_version_number definition = Bundler.definition(true) diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 893ed59cdf..edf86fe1ba 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -53,7 +53,7 @@ module Bundler if options["binstubs"] Bundler::SharedHelpers.major_deprecation 2, - "The --binstubs option will be removed in favor of `bundle binstubs`" + "The --binstubs option will be removed in favor of `bundle binstubs --all`" end Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins? @@ -82,6 +82,8 @@ module Bundler require_relative "clean" Bundler::CLI::Clean.new(options).run end + + Bundler::CLI::Common.output_fund_metadata_summary rescue GemNotFound, VersionConflict => e if options[:local] && Bundler.app_cache.exist? Bundler.ui.warn "Some gems seem to be missing from your #{Bundler.settings.app_cache_path} directory." @@ -100,7 +102,7 @@ module Bundler raise e end - private + private def warn_if_root return if Bundler.settings[:silence_root_warning] || Bundler::WINDOWS || !Process.uid.zero? diff --git a/lib/bundler/cli/list.rb b/lib/bundler/cli/list.rb index c172e8d182..66abd32650 100644 --- a/lib/bundler/cli/list.rb +++ b/lib/bundler/cli/list.rb @@ -31,7 +31,7 @@ module Bundler Bundler.ui.info "Use `bundle info` to print more detailed information about a gem" end - private + private def verify_group_exists(groups) (@without_group + @only_group).each do |group| diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 892c29c4d2..109c5f417f 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -127,7 +127,7 @@ module Bundler end end - private + private def groups_text(group_text, groups) "#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\"" diff --git a/lib/bundler/cli/show.rb b/lib/bundler/cli/show.rb index 3748c25b89..5eaaba1ef7 100644 --- a/lib/bundler/cli/show.rb +++ b/lib/bundler/cli/show.rb @@ -53,7 +53,7 @@ module Bundler end end - private + private def fetch_latest_specs definition = Bundler.definition(true) diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index 529dd9c94d..ae908be65e 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -106,6 +106,8 @@ module Bundler Bundler.ui.confirm "Bundle updated!" Bundler::CLI::Common.output_without_groups_message(:update) Bundler::CLI::Common.output_post_install_messages installer.post_install_messages + + Bundler::CLI::Common.output_fund_metadata_summary end end end diff --git a/lib/bundler/compact_index_client.rb b/lib/bundler/compact_index_client.rb index a5120dbba4..cf67f0e7a0 100644 --- a/lib/bundler/compact_index_client.rb +++ b/lib/bundler/compact_index_client.rb @@ -87,7 +87,7 @@ module Bundler @parsed_checksums = true end - private + private def update(local_path, remote_path) Bundler::CompactIndexClient.debug { "update(#{local_path}, #{remote_path})" } diff --git a/lib/bundler/compact_index_client/cache.rb b/lib/bundler/compact_index_client/cache.rb index f6105d3bb3..8f73298fbe 100644 --- a/lib/bundler/compact_index_client/cache.rb +++ b/lib/bundler/compact_index_client/cache.rb @@ -83,7 +83,7 @@ module Bundler gem_line ? parse_gem(gem_line) : nil end - private + private def lines(path) return [] unless path.file? diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index e668ac7953..1a4b703aa5 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -199,10 +199,6 @@ module Bundler @locked_specs - specs end - def new_platform? - @new_platform - end - def missing_specs missing = [] resolve.materialize(requested_dependencies, missing) @@ -232,6 +228,12 @@ module Bundler end end + def requested_dependencies + groups = requested_groups + groups.map!(&:to_sym) + dependencies_for(groups) + end + def current_dependencies dependencies.select do |d| d.should_include? && !d.gem_platforms(@platforms).empty? @@ -243,6 +245,12 @@ module Bundler specs.for(expand_dependencies(deps)) end + def dependencies_for(groups) + current_dependencies.reject do |d| + (d.groups & groups).empty? + end + end + # Resolve all the dependencies specified in Gemfile. It ensures that # dependencies that have been already resolved via locked file and are fresh # are reused when resolving dependencies @@ -318,10 +326,6 @@ module Bundler sources.rubygems_sources.any? {|s| s.remotes.any? } end - def has_local_dependencies? - !sources.path_sources.empty? || !sources.git_sources.empty? - end - def spec_git_paths sources.git_sources.map {|s| File.realpath(s.path) if File.exist?(s.path) }.compact end @@ -541,7 +545,7 @@ module Bundler @unlocking end - private + private def add_platforms (@dependencies.flat_map(&:expanded_platforms) + current_platforms).uniq.each do |platform| @@ -550,10 +554,9 @@ module Bundler end def current_platforms - current_platform = Bundler.local_platform [].tap do |platforms| - platforms << current_platform if Bundler.feature_flag.specific_platform? - platforms << generic(current_platform) + platforms << local_platform if Bundler.feature_flag.specific_platform? + platforms << generic_local_platform end end @@ -821,7 +824,7 @@ module Bundler end resolve = SpecSet.new(converged) - @locked_specs_incomplete_for_platform = !resolve.for(expand_dependencies(deps), @unlock[:gems], true, true) + @locked_specs_incomplete_for_platform = !resolve.for(expand_dependencies(requested_dependencies & deps), @unlock[:gems], true, true) resolve = resolve.for(expand_dependencies(deps, true), @unlock[:gems], false, false, false) diff = nil @@ -859,11 +862,7 @@ module Bundler def metadata_dependencies @metadata_dependencies ||= begin - ruby_versions = concat_ruby_version_requirements(@ruby_version) - if ruby_versions.empty? || !@ruby_version.exact? - concat_ruby_version_requirements(RubyVersion.system, ruby_versions) - concat_ruby_version_requirements(locked_ruby_version_object, ruby_versions) unless @unlock[:ruby] - end + ruby_versions = ruby_version_requirements(@ruby_version) [ Dependency.new("Ruby\0", ruby_versions), Dependency.new("RubyGems\0", Gem::VERSION), @@ -871,47 +870,39 @@ module Bundler end end - def concat_ruby_version_requirements(ruby_version, ruby_versions = []) - return ruby_versions unless ruby_version + def ruby_version_requirements(ruby_version) + return [] unless ruby_version if ruby_version.patchlevel - ruby_versions << ruby_version.to_gem_version_with_patchlevel + [ruby_version.to_gem_version_with_patchlevel] else - ruby_versions.concat(ruby_version.versions.map do |version| + ruby_version.versions.map do |version| requirement = Gem::Requirement.new(version) if requirement.exact? "~> #{version}.0" else requirement end - end) + end end end def expand_dependencies(dependencies, remote = false) - sorted_platforms = Resolver.sort_platforms(@platforms) deps = [] dependencies.each do |dep| dep = Dependency.new(dep, ">= 0") unless dep.respond_to?(:name) - next if !remote && !dep.current_platform? - dep.gem_platforms(sorted_platforms).each do |p| - deps << DepProxy.new(dep, p) if remote || p == generic_local_platform - end + next unless remote || dep.current_platform? + target_platforms = dep.gem_platforms(remote ? Resolver.sort_platforms(@platforms) : [generic_local_platform]) + deps += expand_dependency_with_platforms(dep, target_platforms) end deps end - def dependencies_for(groups) - current_dependencies.reject do |d| - (d.groups & groups).empty? + def expand_dependency_with_platforms(dep, platforms) + platforms.map do |p| + DepProxy.new(dep, p) end end - def requested_dependencies - groups = requested_groups - groups.map!(&:to_sym) - dependencies_for(groups) - end - def source_requirements # Load all specs from remote sources index diff --git a/lib/bundler/dep_proxy.rb b/lib/bundler/dep_proxy.rb index 6c32179ac1..bb09fe9ea6 100644 --- a/lib/bundler/dep_proxy.rb +++ b/lib/bundler/dep_proxy.rb @@ -39,7 +39,7 @@ module Bundler s end - private + private def method_missing(*args, &blk) @dep.send(*args, &blk) diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index dfc5254b2a..1cc7908b8a 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -63,7 +63,7 @@ module Bundler development_group = opts[:development_group] || :development expanded_path = gemfile_root.join(path) - gemspecs = Dir[File.join(expanded_path, "{,*}.gemspec")].map {|g| Bundler.load_gemspec(g) }.compact + gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact gemspecs.reject! {|s| s.name != name } if name Index.sort_specs(gemspecs) specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] } @@ -279,7 +279,7 @@ module Bundler raise GemfileError, "Undefined local variable or method `#{name}' for Gemfile" end - private + private def add_git_sources git_source(:github) do |repo_name| @@ -457,7 +457,7 @@ repo_name ||= user_name "Using `source` more than once without a block is a security risk, and " \ "may result in installing unexpected gems. To resolve this warning, use " \ "a block to indicate which gems should come from the secondary source. " \ - "To upgrade this warning to an error, run `bundle config set " \ + "To upgrade this warning to an error, run `bundle config set --local " \ "disable_multisource true`." end end @@ -567,7 +567,7 @@ The :#{name} git source is deprecated, and will be removed in the future.#{addit end end - private + private def parse_line_number_from_description description = self.description diff --git a/lib/bundler/endpoint_specification.rb b/lib/bundler/endpoint_specification.rb index 9a00b64e0e..476151ae56 100644 --- a/lib/bundler/endpoint_specification.rb +++ b/lib/bundler/endpoint_specification.rb @@ -104,7 +104,7 @@ module Bundler @remote_specification = spec end - private + private def local_specification_path "#{base_dir}/specifications/#{full_name}.gemspec" diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index abdf2a07fd..235eb9bbd3 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -47,7 +47,7 @@ module Bundler remote_uri = filter_uri(remote_uri) super "Authentication is required for #{remote_uri}.\n" \ "Please supply credentials for this source. You can do this by running:\n" \ - " bundle config set #{remote_uri} username:password" + " bundle config set --global #{remote_uri} username:password" end end # This error is raised if HTTP authentication is provided, but incorrect. @@ -216,7 +216,7 @@ module Bundler "#<#{self.class}:0x#{object_id} uri=#{uri}>" end - private + private FETCHERS = [CompactIndex, Dependency, Index].freeze @@ -303,7 +303,7 @@ module Bundler store end - private + private def remote_uri @remote.uri diff --git a/lib/bundler/fetcher/base.rb b/lib/bundler/fetcher/base.rb index 27987f670a..16cc98273a 100644 --- a/lib/bundler/fetcher/base.rb +++ b/lib/bundler/fetcher/base.rb @@ -38,7 +38,7 @@ module Bundler false end - private + private def log_specs(debug_msg) if Bundler.ui.debug? diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index f36d76d4ae..0304155bdd 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -83,7 +83,7 @@ module Bundler true end - private + private def compact_index_client @compact_index_client ||= diff --git a/lib/bundler/fetcher/downloader.rb b/lib/bundler/fetcher/downloader.rb index 498852c174..a2289aaaae 100644 --- a/lib/bundler/fetcher/downloader.rb +++ b/lib/bundler/fetcher/downloader.rb @@ -74,7 +74,7 @@ module Bundler end end - private + private def validate_uri_scheme!(uri) return if uri.scheme =~ /\Ahttps?\z/ diff --git a/lib/bundler/fetcher/index.rb b/lib/bundler/fetcher/index.rb index 034a225198..7e07eaea7b 100644 --- a/lib/bundler/fetcher/index.rb +++ b/lib/bundler/fetcher/index.rb @@ -42,7 +42,7 @@ module Bundler "Your network or your gem server is probably having issues right now." end - private + private # cached gem specification path, if one exists def gemspec_cached_path(spec_file_name) diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index e5facd31ea..8273064699 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -4,7 +4,7 @@ require_relative "vendored_thor" module Bundler module FriendlyErrors - module_function + module_function def log_error(error) case error @@ -51,7 +51,7 @@ module Bundler end def request_issue_report_for(e) - Bundler.ui.info <<-EOS.gsub(/^ {8}/, "") + Bundler.ui.error <<-EOS.gsub(/^ {8}/, ""), nil, nil --- ERROR REPORT TEMPLATE ------------------------------------------------------- # Error Report @@ -94,7 +94,7 @@ module Bundler Bundler.ui.error "Unfortunately, an unexpected error occurred, and Bundler cannot continue." - Bundler.ui.warn <<-EOS.gsub(/^ {8}/, "") + Bundler.ui.error <<-EOS.gsub(/^ {8}/, ""), nil, :yellow First, try this link to see if there are any existing issue reports for this error: #{issues_url(e)} diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index 272e7ecb69..4ada36aef4 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -32,7 +32,7 @@ module Bundler def initialize(base = nil, name = nil) @base = File.expand_path(base || SharedHelpers.pwd) - gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Dir[File.join(@base, "{,*}.gemspec")] + gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Gem::Util.glob_files_in_dir("{,*}.gemspec", @base) raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1 @spec_path = gemspecs.first @gemspec = Bundler.load_gemspec(@spec_path) @@ -100,27 +100,35 @@ module Bundler Bundler.ui.confirm "#{name} (#{version}) installed." end - protected + protected def rubygem_push(path) cmd = [*gem_command, "push", path] cmd << "--key" << gem_key if gem_key cmd << "--host" << allowed_push_host if allowed_push_host - unless allowed_push_host || Bundler.user_home.join(".gem/credentials").file? - raise "Your rubygems.org credentials aren't set. Run `gem signin` to set them." - end sh_with_input(cmd) Bundler.ui.confirm "Pushed #{name} #{version} to #{gem_push_host}" end def built_gem_path - Dir[File.join(base, "#{name}-*.gem")].sort_by {|f| File.mtime(f) }.last + Gem::Util.glob_files_in_dir("#{name}-*.gem", base).sort_by {|f| File.mtime(f) }.last end - def git_push(remote = "") + def git_push(remote = nil) + remote ||= default_remote perform_git_push remote - perform_git_push "#{remote} --tags" - Bundler.ui.confirm "Pushed git commits and tags." + perform_git_push "#{remote} #{version_tag}" + Bundler.ui.confirm "Pushed git commits and release tag." + end + + def default_remote + current_branch = sh(%w[git rev-parse --abbrev-ref HEAD]).strip + return "origin" if current_branch.empty? + + remote_for_branch = sh(%W[git config --get branch.#{current_branch}.remote]).strip + return "origin" if remote_for_branch.empty? + + remote_for_branch end def allowed_push_host diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb index be047f4397..2a097375c0 100644 --- a/lib/bundler/gem_helpers.rb +++ b/lib/bundler/gem_helpers.rb @@ -24,10 +24,15 @@ module Bundler module_function :generic def generic_local_platform - generic(Bundler.local_platform) + generic(local_platform) end module_function :generic_local_platform + def local_platform + Bundler.local_platform + end + module_function :local_platform + def platform_specificity_match(spec_platform, user_platform) spec_platform = Gem::Platform.new(spec_platform) return PlatformMatch::EXACT_MATCH if spec_platform == user_platform diff --git a/lib/bundler/gem_version_promoter.rb b/lib/bundler/gem_version_promoter.rb index 76912940ac..2e87b7d443 100644 --- a/lib/bundler/gem_version_promoter.rb +++ b/lib/bundler/gem_version_promoter.rb @@ -98,7 +98,7 @@ module Bundler level == :minor end - private + private def filter_dep_specs(spec_groups, locked_spec) res = spec_groups.select do |spec_group| diff --git a/lib/bundler/graph.rb b/lib/bundler/graph.rb index 5644e41079..8f52e2f0f0 100644 --- a/lib/bundler/graph.rb +++ b/lib/bundler/graph.rb @@ -27,7 +27,7 @@ module Bundler GraphVizClient.new(self).run end - private + private def _populate_relations parent_dependencies = _groups.values.to_set.flatten diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb index 9166a92738..fa48df738c 100644 --- a/lib/bundler/index.rb +++ b/lib/bundler/index.rb @@ -179,7 +179,7 @@ module Bundler @sources.uniq! # need to use uniq! here instead of checking for the item before adding end - private + private def specs_by_name(name) @specs[name].values diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index 6694642246..02c3e6189f 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -74,7 +74,7 @@ module Bundler end end - private + private def conservative_version(spec) version = spec.version diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 8be4bb1189..e08cc9722b 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -196,7 +196,7 @@ module Bundler end end - private + private # the order that the resolver provides is significant, since # dependencies might affect the installation of a gem. diff --git a/lib/bundler/installer/gem_installer.rb b/lib/bundler/installer/gem_installer.rb index b41b3fdf28..507fd1802c 100644 --- a/lib/bundler/installer/gem_installer.rb +++ b/lib/bundler/installer/gem_installer.rb @@ -27,7 +27,7 @@ module Bundler return false, specific_failure_message(e) end - private + private def specific_failure_message(e) message = "#{e.class}: #{e.message}\n" diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index ad34e4f484..a6d1de29e6 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -130,7 +130,7 @@ module Bundler Bundler.ui.warn(warning.join("\n")) end - private + private def failed_specs @specs.select(&:failed?) diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index e1beb25ad1..0720d6d38a 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -16,12 +16,12 @@ module Bundler file.puts "ruby_version = RbConfig::CONFIG[\"ruby_version\"]" file.puts "path = File.expand_path('..', __FILE__)" paths.each do |path| - file.puts %($:.unshift "\#{path}/#{path}") + file.puts %($:.unshift File.expand_path("\#{path}/#{path}")) end end end - private + private def paths @specs.map do |spec| diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index ad8488d089..546b8d9b09 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -12,7 +12,7 @@ module Bundler [name, version, platform_string] <=> [other.name, other.version, other.platform_string] end - protected + protected def platform_string platform_string = platform.to_s @@ -89,7 +89,7 @@ module Bundler if search && Gem::Platform.new(search.platform) != platform_object && !search.runtime_dependencies.-(dependencies.reject {|d| d.type == :development }).empty? Bundler.ui.warn "Unable to use the platform-specific (#{search.platform}) version of #{name} (#{version}) " \ "because it has different dependencies from the #{platform} version. " \ - "To use the platform-specific version of the gem, run `bundle config set specific_platform true` and install again." + "To use the platform-specific version of the gem, run `bundle config set --local specific_platform true` and install again." search = source.specs.search(self).last end search.dependencies = dependencies if search && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification)) @@ -118,7 +118,7 @@ module Bundler " #{source.revision[0..6]}" end - private + private def to_ary nil diff --git a/lib/bundler/lockfile_generator.rb b/lib/bundler/lockfile_generator.rb index 585077d18d..3bc6bd7339 100644 --- a/lib/bundler/lockfile_generator.rb +++ b/lib/bundler/lockfile_generator.rb @@ -25,7 +25,7 @@ module Bundler out end - private + private def add_sources definition.send(:sources).lock_sources.each_with_index do |source, idx| diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index caabd524d4..f836737621 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -109,7 +109,7 @@ module Bundler "bundler:#{bundler_version}#{prerelease_text}`.\n" end - private + private TYPES = { GIT => Bundler::Source::Git, diff --git a/lib/bundler/mirror.rb b/lib/bundler/mirror.rb index 0e554bcc3f..a63b45b47d 100644 --- a/lib/bundler/mirror.rb +++ b/lib/bundler/mirror.rb @@ -43,7 +43,7 @@ module Bundler config.update_mirror(mirror) end - private + private def fetch_valid_mirror_for(uri) downcased = uri.to_s.downcase @@ -158,7 +158,7 @@ module Bundler end end - private + private def wait_for_writtable_socket(socket, address, timeout) if IO.select(nil, [socket], nil, timeout) diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index 2025e09b3d..da3f468da5 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -16,7 +16,7 @@ module Bundler PLUGIN_FILE_NAME = "plugins.rb".freeze - module_function + module_function def reset! instance_variables.each {|i| remove_instance_variable(i) } @@ -39,12 +39,11 @@ module Bundler save_plugins names, specs rescue PluginError => e - if specs - specs_to_delete = Hash[specs.select {|k, _v| names.include?(k) && !index.commands.values.include?(k) }] - specs_to_delete.values.each {|spec| Bundler.rm_rf(spec.full_gem_path) } - end + specs_to_delete = specs.select {|k, _v| names.include?(k) && !index.commands.values.include?(k) } + specs_to_delete.each_value {|spec| Bundler.rm_rf(spec.full_gem_path) } - Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}" + names_list = names.map {|name| "`#{name}`" }.join(", ") + Bundler.ui.error "Failed to install the following plugins: #{names_list}. The underlying error was: #{e.message}.\n #{e.backtrace.join("\n ")}" end # Uninstalls plugins by the given names diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 8aea92ca0c..819bc60588 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -133,7 +133,7 @@ module Bundler @hooks[event] || [] end - private + private # Reads the index file from the directory and initializes the instance # variables. diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb index bcea3f0e45..26cec4f18c 100644 --- a/lib/bundler/plugin/installer.rb +++ b/lib/bundler/plugin/installer.rb @@ -41,7 +41,7 @@ module Bundler install_from_specs specs end - private + private def check_sources_consistency!(options) if options.key?(:git) && options.key?(:local_git) diff --git a/lib/bundler/plugin/installer/rubygems.rb b/lib/bundler/plugin/installer/rubygems.rb index 7ae74fa93b..e144c14b24 100644 --- a/lib/bundler/plugin/installer/rubygems.rb +++ b/lib/bundler/plugin/installer/rubygems.rb @@ -8,7 +8,7 @@ module Bundler "#{spec.name} #{spec.version}" end - private + private def requires_sudo? false # Will change on implementation of project level plugins diff --git a/lib/bundler/plugin/source_list.rb b/lib/bundler/plugin/source_list.rb index f0e212205f..b90a331d28 100644 --- a/lib/bundler/plugin/source_list.rb +++ b/lib/bundler/plugin/source_list.rb @@ -17,7 +17,7 @@ module Bundler path_sources + git_sources + rubygems_sources + [metadata_source] end - private + private def rubygems_aggregate_class Plugin::Installer::Rubygems diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb index 00fe4da93f..89b69e1045 100644 --- a/lib/bundler/remote_specification.rb +++ b/lib/bundler/remote_specification.rb @@ -91,7 +91,7 @@ module Bundler " #{source.revision[0..6]}" end - private + private def to_ary nil diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index 61bb648598..926c08c4c9 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -158,10 +158,10 @@ module Bundler # spec group. sg_ruby = sg.copy_for(Gem::Platform::RUBY) selected_sgs << sg_ruby if sg_ruby - sg_all_platforms = nil all_platforms = @platforms + [platform] - sorted_all_platforms = self.class.sort_platforms(all_platforms) - sorted_all_platforms.reverse_each do |other_platform| + next if all_platforms.to_a == [Gem::Platform::RUBY] + sg_all_platforms = nil + self.class.sort_platforms(all_platforms).reverse_each do |other_platform| if sg_all_platforms.nil? sg_all_platforms = sg.copy_for(other_platform) else @@ -250,7 +250,7 @@ module Bundler ["00", *platform.to_a.map {|part| part || "" }] end - private + private # returns an integer \in (-\infty, 0] # a number closer to 0 means the dependency is less constraining diff --git a/lib/bundler/resolver/spec_group.rb b/lib/bundler/resolver/spec_group.rb index d5d12f7a2d..8b5759cfad 100644 --- a/lib/bundler/resolver/spec_group.rb +++ b/lib/bundler/resolver/spec_group.rb @@ -87,13 +87,13 @@ module Bundler name.hash ^ version.hash ^ sorted_activated_platforms.hash ^ source.hash end - protected + protected def sorted_activated_platforms @activated_platforms.sort_by(&:to_s) end - private + private def __dependencies @dependencies = Hash.new do |dependencies, platform| diff --git a/lib/bundler/retry.rb b/lib/bundler/retry.rb index d64958ba70..e95f15f7fb 100644 --- a/lib/bundler/retry.rb +++ b/lib/bundler/retry.rb @@ -32,7 +32,7 @@ module Bundler end alias_method :attempts, :attempt - private + private def run(&block) @failed = false diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index 7e403ce6fc..491f8c55a4 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -123,7 +123,7 @@ module Bundler @exact = versions.all? {|v| Gem::Requirement.create(v).exact? } end - private + private def matches?(requirements, version) # Handles RUBY_PATCHLEVEL of -1 for instances like ruby-head diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 66f9a45cbd..0322b06d07 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -85,7 +85,7 @@ module Gem dependencies - development_dependencies end - private + private def dependencies_to_gemfile(dependencies, group = nil) gemfile = String.new @@ -129,6 +129,35 @@ module Gem end end + # comparison is done order independently since rubygems 3.2.0.rc.2 + unless Gem::Requirement.new("> 1", "< 2") == Gem::Requirement.new("< 2", "> 1") + class Requirement + module OrderIndependentComparison + def ==(other) + if _requirements_sorted? && other._requirements_sorted? + super + else + _with_sorted_requirements == other._with_sorted_requirements + end + end + + protected + + def _requirements_sorted? + return @_are_requirements_sorted if defined?(@_are_requirements_sorted) + strings = as_list + @_are_requirements_sorted = strings == strings.sort + end + + def _with_sorted_requirements + @_with_sorted_requirements ||= _requirements_sorted? ? self : self.class.new(as_list.sort) + end + end + + prepend OrderIndependentComparison + end + end + class Platform JAVA = Gem::Platform.new("java") unless defined?(JAVA) MSWIN = Gem::Platform.new("mswin32") unless defined?(MSWIN) @@ -144,6 +173,22 @@ module Gem undef_method :eql? if method_defined? :eql? alias_method :eql?, :== end + + require "rubygems/util" + + Util.singleton_class.module_eval do + if Util.singleton_methods.include?(:glob_files_in_dir) # since 3.0.0.beta.2 + remove_method :glob_files_in_dir + end + + def glob_files_in_dir(glob, base_path) + if RUBY_VERSION >= "2.5" + Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) } + else + Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) } + end + end + end end module Gem diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb index 8ce33c3953..cd5eb152f9 100644 --- a/lib/bundler/rubygems_gem_installer.rb +++ b/lib/bundler/rubygems_gem_installer.rb @@ -34,7 +34,7 @@ module Bundler end end - private + private def validate_bundler_checksum(checksum) return true if Bundler.settings[:disable_checksum_validation] @@ -60,7 +60,7 @@ module Bundler If you wish to continue installing the downloaded gem, and are certain it does not pose a \ security issue despite the mismatching checksum, do the following: - 1. run `bundle config set disable_checksum_validation true` to turn off checksum verification + 1. run `bundle config set --local disable_checksum_validation true` to turn off checksum verification 2. run `bundle install` (More info: The expected SHA256 checksum was #{checksum.inspect}, but the \ diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index 9256fa274c..17402f16f2 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -313,8 +313,13 @@ module Bundler end message = if spec.nil? + target_file = begin + Bundler.default_gemfile.basename + rescue GemfileNotFound + "inline Gemfile" + end "#{dep.name} is not part of the bundle." \ - " Add it to your #{Bundler.default_gemfile.basename}." + " Add it to your #{target_file}." else "can't activate #{dep}, already activated #{spec.full_name}. " \ "Make sure all dependencies are added to Gemfile." @@ -406,6 +411,17 @@ module Bundler # Replace or hook into RubyGems to provide a bundlerized view # of the world. def replace_entrypoints(specs) + specs_by_name = add_default_gems_to(specs) + + replace_gem(specs, specs_by_name) + stub_rubygems(specs) + replace_bin_path(specs_by_name) + + Gem.clear_paths + end + + # Add default gems not already present in specs, and return them as a hash. + def add_default_gems_to(specs) specs_by_name = specs.reduce({}) do |h, s| h[s.name] = s h @@ -420,11 +436,7 @@ module Bundler specs_by_name[default_spec_name] = default_spec end - replace_gem(specs, specs_by_name) - stub_rubygems(specs) - replace_bin_path(specs_by_name) - - Gem.clear_paths + specs_by_name end def undo_replacements diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index a58a8386e9..e259b590bf 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -155,7 +155,7 @@ module Bundler spec_cache_paths = [] spec_gemspec_paths = [] spec_extension_paths = [] - specs.each do |spec| + Bundler.rubygems.add_default_gems_to(specs).values.each do |spec| spec_gem_paths << spec.full_gem_path # need to check here in case gems are nested like for the rails git repo md = %r{(.+bundler/gems/.+-[a-f0-9]{7,12})}.match(spec.full_gem_path) @@ -203,7 +203,7 @@ module Bundler output end - private + private def prune_gem_cache(resolve, cache_path) cached = Dir["#{cache_path}/*.gem"] diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index d6962e5b6e..6ce81b5006 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -63,30 +63,25 @@ module Bundler ].freeze DEFAULT_CONFIG = { - :silence_deprecations => false, - :disable_version_check => true, - :prefer_patch => false, - :redirect => 5, - :retry => 3, - :timeout => 10, + "BUNDLE_SILENCE_DEPRECATIONS" => false, + "BUNDLE_DISABLE_VERSION_CHECK" => true, + "BUNDLE_PREFER_PATCH" => false, + "BUNDLE_REDIRECT" => 5, + "BUNDLE_RETRY" => 3, + "BUNDLE_TIMEOUT" => 10, }.freeze def initialize(root = nil) @root = root @local_config = load_config(local_config_file) + @env_config = ENV.to_h.select {|key, _value| key =~ /\ABUNDLE_.+/ } @global_config = load_config(global_config_file) @temporary = {} end def [](name) key = key_for(name) - value = @temporary.fetch(key) do - @local_config.fetch(key) do - ENV.fetch(key) do - @global_config.fetch(key) do - DEFAULT_CONFIG.fetch(name) do - nil - end end end end end + value = configs.values.map {|config| config[key] }.compact.first converted_value(value, name) end @@ -129,9 +124,7 @@ module Bundler end def all - env_keys = ENV.keys.grep(/\ABUNDLE_.+/) - - keys = @temporary.keys | @global_config.keys | @local_config.keys | env_keys + keys = @temporary.keys | @global_config.keys | @local_config.keys | @env_config.keys keys.map do |key| key.sub(/^BUNDLE_/, "").gsub(/__/, ".").downcase @@ -168,13 +161,11 @@ module Bundler def locations(key) key = key_for(key) - locations = {} - locations[:temporary] = @temporary[key] if @temporary.key?(key) - locations[:local] = @local_config[key] if @local_config.key?(key) - locations[:env] = ENV[key] if ENV[key] - locations[:global] = @global_config[key] if @global_config.key?(key) - locations[:default] = DEFAULT_CONFIG[key] if DEFAULT_CONFIG.key?(key) - locations + configs.keys.inject({}) do |partial_locations, level| + value_on_level = configs[level][key] + partial_locations[level] = value_on_level unless value_on_level.nil? + partial_locations + end end def pretty_values_for(exposed_key) @@ -182,20 +173,20 @@ module Bundler locations = [] - if @temporary.key?(key) - locations << "Set for the current command: #{converted_value(@temporary[key], exposed_key).inspect}" + if value = @temporary[key] + locations << "Set for the current command: #{converted_value(value, exposed_key).inspect}" end - if @local_config.key?(key) - locations << "Set for your local app (#{local_config_file}): #{converted_value(@local_config[key], exposed_key).inspect}" + if value = @local_config[key] + locations << "Set for your local app (#{local_config_file}): #{converted_value(value, exposed_key).inspect}" end - if value = ENV[key] + if value = @env_config[key] locations << "Set via #{key}: #{converted_value(value, exposed_key).inspect}" end - if @global_config.key?(key) - locations << "Set for the current user (#{global_config_file}): #{converted_value(@global_config[key], exposed_key).inspect}" + if value = @global_config[key] + locations << "Set for the current user (#{global_config_file}): #{converted_value(value, exposed_key).inspect}" end return ["You have not configured a value for `#{exposed_key}`"] if locations.empty? @@ -204,17 +195,19 @@ module Bundler # for legacy reasons, in Bundler 2, we do not respect :disable_shared_gems def path - key = key_for(:path) - path = ENV[key] || @global_config[key] - if path && [email protected]?(key) && !@local_config.key?(key) - return Path.new(path, false, false) + configs.each do |_level, settings| + path = value_for("path", settings) + path_system = value_for("path.system", settings) + disabled_shared_gems = value_for("disable_shared_gems", settings) + next if path.nil? && path_system.nil? && disabled_shared_gems.nil? + system_path = path_system || (disabled_shared_gems == false) + return Path.new(path, system_path) end - system_path = self["path.system"] || (self[:disable_shared_gems] == false) - Path.new(self[:path], system_path, Bundler.feature_flag.default_install_uses_path?) + Path.new(nil, false) end - Path = Struct.new(:explicit_path, :system_path, :default_install_uses_path) do + Path = Struct.new(:explicit_path, :system_path) do def path path = base_path path = File.join(path, Bundler.ruby_scope) unless use_system_gems? @@ -224,7 +217,7 @@ module Bundler def use_system_gems? return true if system_path return false if explicit_path - !default_install_uses_path + !Bundler.feature_flag.default_install_uses_path? end def base_path @@ -277,9 +270,9 @@ module Bundler def validate! all.each do |raw_key| - [@local_config, ENV, @global_config].each do |settings| - value = converted_value(settings[key_for(raw_key)], raw_key) - Validator.validate!(raw_key, value, settings.to_hash.dup) + [@local_config, @env_config, @global_config].each do |settings| + value = value_for(raw_key, settings) + Validator.validate!(raw_key, value, settings.dup) end end end @@ -290,7 +283,21 @@ module Bundler "BUNDLE_#{key}" end - private + private + + def configs + { + :temporary => @temporary, + :local => @local_config, + :env => @env_config, + :global => @global_config, + :default => DEFAULT_CONFIG, + } + end + + def value_for(name, config) + converted_value(config[key_for(name)], name) + end def parent_setting_for(name) split_specific_setting_for(name)[0] diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 19fab78cc3..ca0ab67fb8 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -212,7 +212,7 @@ module Bundler filesystem_access(gemfile_path) {|g| File.open(g, "w") {|file| file.puts contents } } end - private + private def validate_bundle_path path_separator = Bundler.rubygems.path_separator diff --git a/lib/bundler/similarity_detector.rb b/lib/bundler/similarity_detector.rb index bd9971f884..50e66b9cab 100644 --- a/lib/bundler/similarity_detector.rb +++ b/lib/bundler/similarity_detector.rb @@ -26,7 +26,7 @@ module Bundler end end - protected + protected # https://www.informit.com/articles/article.aspx?p=683059&seqNum=36 def levenshtein_distance(this, that, ins = 2, del = 2, sub = 1) diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 4b2e305bda..be00143f5a 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -63,7 +63,7 @@ module Bundler ) end - private + private def version_color(spec_version, locked_spec_version) if Gem::Version.correct?(spec_version) && Gem::Version.correct?(locked_spec_version) diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 0b4d76939b..0157995cb0 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -234,7 +234,7 @@ module Bundler @local end - private + private def serialize_gemspecs_in(destination) destination = destination.expand_path(Bundler.root) if destination.relative? diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index da03efde0c..5dc1c8de32 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -136,11 +136,13 @@ module Bundler if submodules git_retry "submodule update --init --recursive", :dir => destination elsif Gem::Version.create(version) >= Gem::Version.create("2.9.0") - git_retry "submodule deinit --all --force", :dir => destination + inner_command = "git -C $toplevel submodule deinit --force $sm_path" + inner_command = inner_command.gsub("$") { '\$' } unless Bundler::WINDOWS + git_retry "submodule foreach --quiet \"#{inner_command}\"", :dir => destination end end - private + private def git_null(command, dir: SharedHelpers.pwd) check_allowed(command) diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index e73e33d922..2c2e9023b3 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -125,7 +125,7 @@ module Bundler @expanded_original_path ||= expand(original_path) end - private + private def expanded_path @expanded_path ||= expand(path) @@ -171,7 +171,7 @@ module Bundler if File.directory?(expanded_path) # We sort depth-first since `<<` will override the earlier-found specs - Dir["#{expanded_path}/#{@glob}"].sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file| + Gem::Util.glob_files_in_dir(@glob, expanded_path).sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file| next unless spec = load_gemspec(file) spec.source = self diff --git a/lib/bundler/source/path/installer.rb b/lib/bundler/source/path/installer.rb index 909e248412..6be58e2087 100644 --- a/lib/bundler/source/path/installer.rb +++ b/lib/bundler/source/path/installer.rb @@ -40,7 +40,7 @@ module Bundler Bundler.rm_rf(@tmp_dir) if Bundler.requires_sudo? end - private + private def generate_bin super diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index ee11feda5c..97f9808578 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -291,7 +291,7 @@ module Bundler names end - protected + protected def credless_remotes remotes.map(&method(:suppress_configured_credentials)) @@ -465,7 +465,7 @@ module Bundler Bundler.app_cache end - private + private # Checks if the requested spec exists in the global cache. If it does, # we copy it to the download path, and if it does not, we download it. diff --git a/lib/bundler/source/rubygems/remote.rb b/lib/bundler/source/rubygems/remote.rb index 45ea61acb2..82c850ffbb 100644 --- a/lib/bundler/source/rubygems/remote.rb +++ b/lib/bundler/source/rubygems/remote.rb @@ -39,7 +39,7 @@ module Bundler "rubygems remote at #{anonymized_uri}" end - private + private def apply_auth(uri, auth) if auth && uri.userinfo.nil? diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index d3f649a12c..731a791531 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -116,7 +116,7 @@ module Bundler @rubygems_aggregate.remotes end - private + private def rubygems_aggregate_class Source::Rubygems @@ -147,7 +147,7 @@ module Bundler if source.uri =~ /^git\:/ Bundler.ui.warn "The git source `#{source.uri}` uses the `git` protocol, " \ "which transmits data without encryption. Disable this warning with " \ - "`bundle config set git.allow_insecure true`, or switch to the `https` " \ + "`bundle config set --local git.allow_insecure true`, or switch to the `https` " \ "protocol to keep your data secure." end end diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 463113ef8e..46e023de87 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -147,7 +147,7 @@ module Bundler sorted.each(&b) end - private + private def sorted rake = @specs.find {|s| s.name == "rake" } diff --git a/lib/bundler/stub_specification.rb b/lib/bundler/stub_specification.rb index c87b66ee19..a45e28b8a7 100644 --- a/lib/bundler/stub_specification.rb +++ b/lib/bundler/stub_specification.rb @@ -83,7 +83,7 @@ module Bundler stub.raw_require_paths end - private + private def _remote_specification @_remote_specification ||= begin diff --git a/lib/bundler/templates/newgem/README.md.tt b/lib/bundler/templates/newgem/README.md.tt index c2f5f9dca7..f81b85ca97 100644 --- a/lib/bundler/templates/newgem/README.md.tt +++ b/lib/bundler/templates/newgem/README.md.tt @@ -28,7 +28,7 @@ TODO: Write usage instructions here After checking out the repo, run `bin/setup` to install dependencies.<% if config[:test] %> Then, run `rake <%= config[:test].sub('mini', '').sub('rspec', 'spec') %>` to run the tests.<% end %> You can also run `bin/console` for an interactive prompt that will allow you to experiment.<% if config[:bin] %> Run `bundle exec <%= config[:name] %>` to use the gem in this directory, ignoring other installed copies of this gem.<% end %> -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing diff --git a/lib/bundler/templates/newgem/spec/spec_helper.rb.tt b/lib/bundler/templates/newgem/spec/spec_helper.rb.tt index 0bb8e6f165..70c6d1fcde 100644 --- a/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +++ b/lib/bundler/templates/newgem/spec/spec_helper.rb.tt @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "bundler/setup" require "<%= config[:namespaced_path] %>" RSpec.configure do |config| diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb index 92476be7d2..17777af4ac 100644 --- a/lib/bundler/ui/shell.rb +++ b/lib/bundler/ui/shell.rb @@ -28,17 +28,17 @@ module Bundler tell_me(msg, :green, newline) if level("confirm") end - def warn(msg, newline = nil) + def warn(msg, newline = nil, color = :yellow) return unless level("warn") return if @warning_history.include? msg @warning_history << msg - tell_err(msg, :yellow, newline) + tell_err(msg, color, newline) end - def error(msg, newline = nil) + def error(msg, newline = nil, color = :red) return unless level("error") - tell_err(msg, :red, newline) + tell_err(msg, color, newline) end def debug(msg, newline = nil) @@ -92,7 +92,7 @@ module Bundler [] end - private + private # valimism def tell_me(msg, color = nil, newline = nil) diff --git a/lib/bundler/uri_credentials_filter.rb b/lib/bundler/uri_credentials_filter.rb index 9b9e9c2799..3f49254e71 100644 --- a/lib/bundler/uri_credentials_filter.rb +++ b/lib/bundler/uri_credentials_filter.rb @@ -2,7 +2,7 @@ module Bundler module URICredentialsFilter - module_function + module_function def credential_filtered_uri(uri_to_anonymize) return uri_to_anonymize if uri_to_anonymize.nil? diff --git a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb index d0ab956faf..847479a0af 100644 --- a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +++ b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb @@ -3,8 +3,6 @@ require_relative '../../../../uri/lib/uri' require 'cgi' # for escaping require_relative '../../../../connection_pool/lib/connection_pool' -autoload :OpenSSL, 'openssl' - ## # Persistent connections for Net::HTTP # @@ -149,9 +147,14 @@ class Bundler::Persistent::Net::HTTP::Persistent EPOCH = Time.at 0 # :nodoc: ## - # Is OpenSSL available? This test works with autoload + # Is OpenSSL available? - HAVE_OPENSSL = defined? OpenSSL::SSL # :nodoc: + HAVE_OPENSSL = begin # :nodoc: + require 'openssl' + true + rescue LoadError + false + end ## # The default connection pool size is 1/4 the allowed open files diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 272fe85cab..4b2b0ec3c1 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.2.0.rc.1".freeze + VERSION = "2.2.0.rc.2".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/bundler/worker.rb b/lib/bundler/worker.rb index 3471654b43..10139ed25b 100644 --- a/lib/bundler/worker.rb +++ b/lib/bundler/worker.rb @@ -48,7 +48,7 @@ module Bundler stop_threads end - private + private def process_queue(i) loop do diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index 374b3bb5e3..d5ecbd4aef 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -3,7 +3,7 @@ module Bundler # A stub yaml serializer that can handle only hashes and strings (as of now). module YAMLSerializer - module_function + module_function def dump(hash) yaml = String.new("---") |