diff options
Diffstat (limited to 'lib/bundler')
206 files changed, 4918 insertions, 3978 deletions
diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb index 8bffb2fae7..5d2a8b53bb 100644 --- a/lib/bundler/build_metadata.rb +++ b/lib/bundler/build_metadata.rb @@ -29,7 +29,7 @@ module Bundler # commit instance variable then we can't determine its commits SHA. git_dir = File.expand_path("../../../.git", __dir__) if File.directory?(git_dir) - return @git_commit_sha = Dir.chdir(git_dir) { `git rev-parse --short HEAD`.strip.freeze } + return @git_commit_sha = IO.popen(%w[git rev-parse --short HEAD], { chdir: git_dir }, &:read).strip.freeze end @git_commit_sha ||= "unknown" diff --git a/lib/bundler/bundler.gemspec b/lib/bundler/bundler.gemspec index da50b46225..2d6269fae1 100644 --- a/lib/bundler/bundler.gemspec +++ b/lib/bundler/bundler.gemspec @@ -29,15 +29,17 @@ Gem::Specification.new do |s| "source_code_uri" => "https://github.com/rubygems/rubygems/tree/master/bundler", } - s.required_ruby_version = ">= 2.6.0" - s.required_rubygems_version = ">= 3.0.1" + s.required_ruby_version = ">= 3.0.0" + + # It should match the RubyGems version shipped with `required_ruby_version` above + s.required_rubygems_version = ">= 3.2.3" s.files = Dir.glob("lib/bundler{.rb,/**/*}", File::FNM_DOTMATCH).reject {|f| File.directory?(f) } # include the gemspec itself because warbler breaks w/o it s.files += %w[lib/bundler/bundler.gemspec] - s.bindir = "libexec" + s.bindir = "exe" s.executables = %w[bundle bundler] s.require_paths = ["lib"] end diff --git a/lib/bundler/capistrano.rb b/lib/bundler/capistrano.rb index 1f3712d48e..705840143f 100644 --- a/lib/bundler/capistrano.rb +++ b/lib/bundler/capistrano.rb @@ -17,6 +17,6 @@ end Capistrano::Configuration.instance(:must_exist).load do before "deploy:finalize_update", "bundle:install" - Bundler::Deployment.define_task(self, :task, :except => { :no_release => true }) + Bundler::Deployment.define_task(self, :task, except: { no_release: true }) set :rake, lambda { "#{fetch(:bundle_cmd, "bundle")} exec rake" } end diff --git a/lib/bundler/checksum.rb b/lib/bundler/checksum.rb new file mode 100644 index 0000000000..60ba93417c --- /dev/null +++ b/lib/bundler/checksum.rb @@ -0,0 +1,254 @@ +# frozen_string_literal: true + +module Bundler + class Checksum + ALGO_SEPARATOR = "=" + DEFAULT_ALGORITHM = "sha256" + private_constant :DEFAULT_ALGORITHM + DEFAULT_BLOCK_SIZE = 16_384 + private_constant :DEFAULT_BLOCK_SIZE + + class << self + def from_gem_package(gem_package, algo = DEFAULT_ALGORITHM) + return if Bundler.settings[:disable_checksum_validation] + return unless source = gem_package.instance_variable_get(:@gem) + return unless source.respond_to?(:with_read_io) + + source.with_read_io do |io| + from_gem(io, source.path) + ensure + io.rewind + end + end + + def from_gem(io, pathname, algo = DEFAULT_ALGORITHM) + digest = Bundler::SharedHelpers.digest(algo.upcase).new + buf = String.new(capacity: DEFAULT_BLOCK_SIZE) + digest << io.readpartial(DEFAULT_BLOCK_SIZE, buf) until io.eof? + Checksum.new(algo, digest.hexdigest!, Source.new(:gem, pathname)) + end + + def from_api(digest, source_uri, algo = DEFAULT_ALGORITHM) + return if Bundler.settings[:disable_checksum_validation] + + Checksum.new(algo, to_hexdigest(digest, algo), Source.new(:api, source_uri)) + end + + def from_lock(lock_checksum, lockfile_location) + algo, digest = lock_checksum.strip.split(ALGO_SEPARATOR, 2) + Checksum.new(algo, to_hexdigest(digest, algo), Source.new(:lock, lockfile_location)) + end + + def to_hexdigest(digest, algo = DEFAULT_ALGORITHM) + return digest unless algo == DEFAULT_ALGORITHM + return digest if digest.match?(/\A[0-9a-f]{64}\z/i) + + if digest.match?(%r{\A[-0-9a-z_+/]{43}={0,2}\z}i) + digest = digest.tr("-_", "+/") # fix urlsafe base64 + digest.unpack1("m0").unpack1("H*") + else + raise ArgumentError, "#{digest.inspect} is not a valid SHA256 hex or base64 digest" + end + end + end + + attr_reader :algo, :digest, :sources + + def initialize(algo, digest, source) + @algo = algo + @digest = digest + @sources = [source] + end + + def ==(other) + match?(other) && other.sources == sources + end + + alias_method :eql?, :== + + def same_source?(other) + sources.include?(other.sources.first) + end + + def match?(other) + other.is_a?(self.class) && other.digest == digest && other.algo == algo + end + + def hash + digest.hash + end + + def to_s + "#{to_lock} (from #{sources.first}#{", ..." if sources.size > 1})" + end + + def to_lock + "#{algo}#{ALGO_SEPARATOR}#{digest}" + end + + def merge!(other) + return nil unless match?(other) + + @sources.concat(other.sources).uniq! + self + end + + def formatted_sources + sources.join("\n and ").concat("\n") + end + + def removable? + sources.all?(&:removable?) + end + + def removal_instructions + msg = +"" + i = 1 + sources.each do |source| + msg << " #{i}. #{source.removal}\n" + i += 1 + end + msg << " #{i}. run `bundle install`\n" + end + + def inspect + abbr = "#{algo}#{ALGO_SEPARATOR}#{digest[0, 8]}" + from = "from #{sources.join(" and ")}" + "#<#{self.class}:#{object_id} #{abbr} #{from}>" + end + + class Source + attr_reader :type, :location + + def initialize(type, location) + @type = type + @location = location + end + + def removable? + type == :lock || type == :gem + end + + def ==(other) + other.is_a?(self.class) && other.type == type && other.location == location + end + + # phrased so that the usual string format is grammatically correct + # rake (10.3.2) sha256=abc123 from #{to_s} + def to_s + case type + when :lock + "the lockfile CHECKSUMS at #{location}" + when :gem + "the gem at #{location}" + when :api + "the API at #{location}" + else + "#{location} (#{type})" + end + end + + # A full sentence describing how to remove the checksum + def removal + case type + when :lock + "remove the matching checksum in #{location}" + when :gem + "remove the gem at #{location}" + when :api + "checksums from #{location} cannot be locally modified, you may need to update your sources" + else + "remove #{location} (#{type})" + end + end + end + + class Store + attr_reader :store + protected :store + + def initialize + @store = {} + @store_mutex = Mutex.new + end + + def inspect + "#<#{self.class}:#{object_id} size=#{store.size}>" + end + + # Replace when the new checksum is from the same source. + # The primary purpose is registering checksums from gems where there are + # duplicates of the same gem (according to full_name) in the index. + # + # In particular, this is when 2 gems have two similar platforms, e.g. + # "darwin20" and "darwin-20", both of which resolve to darwin-20. + # In the Index, the later gem replaces the former, so we do that here. + # + # However, if the new checksum is from a different source, we register like normal. + # This ensures a mismatch error where there are multiple top level sources + # that contain the same gem with different checksums. + def replace(spec, checksum) + return unless checksum + + lock_name = spec.name_tuple.lock_name + @store_mutex.synchronize do + existing = fetch_checksum(lock_name, checksum.algo) + if !existing || existing.same_source?(checksum) + store_checksum(lock_name, checksum) + else + merge_checksum(lock_name, checksum, existing) + end + end + end + + def register(spec, checksum) + return unless checksum + + register_checksum(spec.name_tuple.lock_name, checksum) + end + + def merge!(other) + other.store.each do |lock_name, checksums| + checksums.each do |_algo, checksum| + register_checksum(lock_name, checksum) + end + end + end + + def to_lock(spec) + lock_name = spec.name_tuple.lock_name + checksums = @store[lock_name] + if checksums + "#{lock_name} #{checksums.values.map(&:to_lock).sort.join(",")}" + else + lock_name + end + end + + private + + def register_checksum(lock_name, checksum) + @store_mutex.synchronize do + existing = fetch_checksum(lock_name, checksum.algo) + if existing + merge_checksum(lock_name, checksum, existing) + else + store_checksum(lock_name, checksum) + end + end + end + + def merge_checksum(lock_name, checksum, existing) + existing.merge!(checksum) || raise(ChecksumMismatchError.new(lock_name, existing, checksum)) + end + + def store_checksum(lock_name, checksum) + (@store[lock_name] ||= {})[checksum.algo] = checksum + end + + def fetch_checksum(lock_name, algo) + @store[lock_name]&.fetch(algo, nil) + end + end + end +end diff --git a/lib/bundler/ci_detector.rb b/lib/bundler/ci_detector.rb new file mode 100644 index 0000000000..e5fedbdea8 --- /dev/null +++ b/lib/bundler/ci_detector.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +module Bundler + module CIDetector + # NOTE: Any changes made here will need to be made to both lib/rubygems/ci_detector.rb and + # bundler/lib/bundler/ci_detector.rb (which are enforced duplicates). + # TODO: Drop that duplication once bundler drops support for RubyGems 3.4 + # + # ## Recognized CI providers, their signifiers, and the relevant docs ## + # + # Travis CI - CI, TRAVIS https://docs.travis-ci.com/user/environment-variables/#default-environment-variables + # Cirrus CI - CI, CIRRUS_CI https://cirrus-ci.org/guide/writing-tasks/#environment-variables + # Circle CI - CI, CIRCLECI https://circleci.com/docs/variables/#built-in-environment-variables + # Gitlab CI - CI, GITLAB_CI https://docs.gitlab.com/ee/ci/variables/ + # AppVeyor - CI, APPVEYOR https://www.appveyor.com/docs/environment-variables/ + # CodeShip - CI_NAME https://docs.cloudbees.com/docs/cloudbees-codeship/latest/pro-builds-and-configuration/environment-variables#_default_environment_variables + # dsari - CI, DSARI https://github.com/rfinnie/dsari#running + # Jenkins - BUILD_NUMBER https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables + # TeamCity - TEAMCITY_VERSION https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#Predefined+Server+Build+Parameters + # Appflow - CI_BUILD_ID https://ionic.io/docs/appflow/automation/environments#predefined-environments + # TaskCluster - TASKCLUSTER_ROOT_URL https://docs.taskcluster.net/docs/manual/design/env-vars + # Semaphore - CI, SEMAPHORE https://docs.semaphoreci.com/ci-cd-environment/environment-variables/ + # BuildKite - CI, BUILDKITE https://buildkite.com/docs/pipelines/environment-variables + # GoCD - GO_SERVER_URL https://docs.gocd.org/current/faq/dev_use_current_revision_in_build.html + # GH Actions - CI, GITHUB_ACTIONS https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables + # + # ### Some "standard" ENVs that multiple providers may set ### + # + # * CI - this is set by _most_ (but not all) CI providers now; it's approaching a standard. + # * CI_NAME - Not as frequently used, but some providers set this to specify their own name + + # Any of these being set is a reasonably reliable indicator that we are + # executing in a CI environment. + ENV_INDICATORS = [ + "CI", + "CI_NAME", + "CONTINUOUS_INTEGRATION", + "BUILD_NUMBER", + "CI_APP_ID", + "CI_BUILD_ID", + "CI_BUILD_NUMBER", + "RUN_ID", + "TASKCLUSTER_ROOT_URL", + ].freeze + + # For each CI, this env suffices to indicate that we're on _that_ CI's + # containers. (A few of them only supply a CI_NAME variable, which is also + # nice). And if they set "CI" but we can't tell which one they are, we also + # want to know that - a bare "ci" without another token tells us as much. + ENV_DESCRIPTORS = { + "TRAVIS" => "travis", + "CIRCLECI" => "circle", + "CIRRUS_CI" => "cirrus", + "DSARI" => "dsari", + "SEMAPHORE" => "semaphore", + "JENKINS_URL" => "jenkins", + "BUILDKITE" => "buildkite", + "GO_SERVER_URL" => "go", + "GITLAB_CI" => "gitlab", + "GITHUB_ACTIONS" => "github", + "TASKCLUSTER_ROOT_URL" => "taskcluster", + "CI" => "ci", + }.freeze + + def self.ci? + ENV_INDICATORS.any? {|var| ENV.include?(var) } + end + + def self.ci_strings + matching_names = ENV_DESCRIPTORS.select {|env, _| ENV[env] }.values + matching_names << ENV["CI_NAME"].downcase if ENV["CI_NAME"] + matching_names.reject(&:empty?).sort.uniq + end + end +end diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index dd91038d64..eb67668cd2 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -5,6 +5,7 @@ require_relative "vendored_thor" module Bundler class CLI < Thor require_relative "cli/common" + require_relative "cli/install" package_name "Bundler" @@ -69,7 +70,7 @@ module Bundler Bundler.settings.set_command_option_if_given :retry, options[:retry] current_cmd = args.last[:current_command].name - auto_install if AUTO_INSTALL_CMDS.include?(current_cmd) + Bundler.auto_install if AUTO_INSTALL_CMDS.include?(current_cmd) rescue UnknownArgumentError => e raise InvalidOption, e.message ensure @@ -80,10 +81,10 @@ module Bundler unprinted_warnings.each {|w| Bundler.ui.warn(w) } end - check_unknown_options!(:except => [:config, :exec]) + check_unknown_options!(except: [:config, :exec]) stop_on_unknown_option! :exec - desc "cli_help", "Prints a summary of bundler commands", :hide => true + desc "cli_help", "Prints a summary of bundler commands", hide: true def cli_help version Bundler.ui.info "\n" @@ -99,21 +100,23 @@ module Bundler shell.say "Bundler commands:\n\n" shell.say " Primary commands:\n" - shell.print_table(primary_commands, :indent => 4, :truncate => true) + shell.print_table(primary_commands, indent: 4, truncate: true) shell.say shell.say " Utilities:\n" - shell.print_table(utilities, :indent => 4, :truncate => true) + shell.print_table(utilities, indent: 4, truncate: true) shell.say self.class.send(:class_options_help, shell) end default_task(Bundler.feature_flag.default_cli_command) - class_option "no-color", :type => :boolean, :desc => "Disable colorization in output" - class_option "retry", :type => :numeric, :aliases => "-r", :banner => "NUM", - :desc => "Specify the number of times you wish to attempt network commands" - class_option "verbose", :type => :boolean, :desc => "Enable verbose output mode", :aliases => "-V" + class_option "no-color", type: :boolean, desc: "Disable colorization in output" + class_option "retry", type: :numeric, aliases: "-r", banner: "NUM", + desc: "Specify the number of times you wish to attempt network commands" + class_option "verbose", type: :boolean, desc: "Enable verbose output mode", aliases: "-V" def help(cli = nil) + cli = self.class.all_aliases[cli] if self.class.all_aliases[cli] + case cli when "gemfile" then command = "gemfile" when nil then command = "bundle" @@ -127,8 +130,8 @@ module Bundler if man_pages.include?(command) man_page = man_pages[command] - if Bundler.which("man") && man_path !~ %r{^file:/.+!/META-INF/jruby.home/.+} - Kernel.exec "man #{man_page}" + if Bundler.which("man") && !man_path.match?(%r{^file:/.+!/META-INF/jruby.home/.+}) + Kernel.exec("man", man_page) else puts File.read("#{man_path}/#{File.basename(man_page)}.ronn") end @@ -155,8 +158,8 @@ module Bundler Gemfile to a gem with a gemspec, the --gemspec option will automatically add each dependency listed in the gemspec file to the newly created Gemfile. D - method_option "gemspec", :type => :string, :banner => "Use the specified .gemspec to create the Gemfile" - method_option "gemfile", :type => :string, :banner => "Use the specified name for the gemfile instead of 'Gemfile'" + method_option "gemspec", type: :string, banner: "Use the specified .gemspec to create the Gemfile" + method_option "gemfile", type: :string, banner: "Use the specified name for the gemfile instead of 'Gemfile'" def init require_relative "cli/init" Init.new(options.dup).run @@ -168,12 +171,9 @@ module Bundler all gems are found, Bundler prints a success message and exits with a status of 0. If not, the first missing gem is listed and Bundler exits status 1. D - method_option "dry-run", :type => :boolean, :default => false, :banner => - "Lock the Gemfile" - method_option "gemfile", :type => :string, :banner => - "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?}" + method_option "dry-run", type: :boolean, default: false, banner: "Lock the Gemfile" + method_option "gemfile", type: :string, banner: "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?}" def check remembered_flag_deprecation("path") @@ -187,10 +187,14 @@ module Bundler 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. D - method_option "install", :type => :boolean, :banner => - "Runs 'bundle install' after removing the gems from the Gemfile" + method_option "install", type: :boolean, banner: "Runs 'bundle install' after removing the gems from the Gemfile" def remove(*gems) - SharedHelpers.major_deprecation(2, "The `--install` flag has been deprecated. `bundle install` is triggered by default.") if ARGV.include?("--install") + if ARGV.include?("--install") + message = "The `--install` flag has been deprecated. `bundle install` is triggered by default." + removed_message = "The `--install` flag has been removed. `bundle install` is triggered by default." + SharedHelpers.major_deprecation(2, message, removed_message: removed_message) + end + require_relative "cli/remove" Remove.new(gems, options).run end @@ -206,58 +210,40 @@ module Bundler If the bundle has already been installed, bundler will tell you so and then exit. D - method_option "binstubs", :type => :string, :lazy_default => "bin", :banner => - "Generate bin stubs for bundled gems to ./bin" - method_option "clean", :type => :boolean, :banner => - "Run bundle clean automatically after install" - method_option "deployment", :type => :boolean, :banner => - "Install using defaults tuned for deployment environments" - method_option "frozen", :type => :boolean, :banner => - "Do not allow the Gemfile.lock to be updated after this install" - method_option "full-index", :type => :boolean, :banner => - "Fall back to using the single-file index of all gems" - method_option "gemfile", :type => :string, :banner => - "Use the specified gemfile instead of Gemfile" - method_option "jobs", :aliases => "-j", :type => :numeric, :banner => - "Specify the number of jobs to run in parallel" - method_option "local", :type => :boolean, :banner => - "Do not attempt to fetch gems remotely and use the gem cache instead" - method_option "prefer-local", :type => :boolean, :banner => - "Only attempt to fetch gems remotely if not present locally, even if newer versions are available remotely" - method_option "no-cache", :type => :boolean, :banner => - "Don't update the existing gem cache." - method_option "redownload", :type => :boolean, :aliases => "--force", :banner => - "Force downloading every gem." - 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 "shebang", :type => :string, :banner => - "Specify a different shebang executable name than the default (usually 'ruby')" - method_option "standalone", :type => :array, :lazy_default => [], :banner => - "Make a bundle that can work without the Bundler runtime" - method_option "system", :type => :boolean, :banner => - "Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application" - method_option "trust-policy", :alias => "P", :type => :string, :banner => - "Gem trust policy (like gem install -P). Must be one of " + - Bundler.rubygems.security_policy_keys.join("|") - method_option "without", :type => :array, :banner => - "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." + method_option "binstubs", type: :string, lazy_default: "bin", banner: "Generate bin stubs for bundled gems to ./bin" + method_option "clean", type: :boolean, banner: "Run bundle clean automatically after install" + method_option "deployment", type: :boolean, banner: "Install using defaults tuned for deployment environments" + method_option "frozen", type: :boolean, banner: "Do not allow the Gemfile.lock to be updated after this install" + method_option "full-index", type: :boolean, banner: "Fall back to using the single-file index of all gems" + method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile" + method_option "jobs", aliases: "-j", type: :numeric, banner: "Specify the number of jobs to run in parallel" + method_option "local", type: :boolean, banner: "Do not attempt to fetch gems remotely and use the gem cache instead" + method_option "prefer-local", type: :boolean, banner: "Only attempt to fetch gems remotely if not present locally, even if newer versions are available remotely" + method_option "no-cache", type: :boolean, banner: "Don't update the existing gem cache." + method_option "redownload", type: :boolean, aliases: "--force", banner: "Force downloading every gem." + 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 "shebang", type: :string, banner: "Specify a different shebang executable name than the default (usually 'ruby')" + method_option "standalone", type: :array, lazy_default: [], banner: "Make a bundle that can work without the Bundler runtime" + method_option "system", type: :boolean, banner: "Install to the system location ($BUNDLE_PATH or $GEM_HOME) even if the bundle was previously installed somewhere else for this application" + method_option "trust-policy", alias: "P", type: :string, banner: "Gem trust policy (like gem install -P). Must be one of " + + Bundler.rubygems.security_policy_keys.join("|") + method_option "without", type: :array, banner: "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." def install SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force") - %w[clean deployment frozen no-prune path shebang system without with].each do |option| + %w[clean deployment frozen no-prune path shebang without with].each do |option| remembered_flag_deprecation(option) end + print_remembered_flag_deprecation("--system", "path.system", "true") if ARGV.include?("--system") + remembered_negative_flag_deprecation("no-deployment") require_relative "cli/install" - Bundler.settings.temporary(:no_install => false) do + Bundler.settings.temporary(no_install: false) do Install.new(options.dup).run end end @@ -270,44 +256,27 @@ module Bundler update when you have changed the Gemfile, or if you want to get the newest possible versions of the gems in the bundle. D - method_option "full-index", :type => :boolean, :banner => - "Fall back to using the single-file index of all gems" - method_option "gemfile", :type => :string, :banner => - "Use the specified gemfile instead of Gemfile" - method_option "group", :aliases => "-g", :type => :array, :banner => - "Update a specific group" - method_option "jobs", :aliases => "-j", :type => :numeric, :banner => - "Specify the number of jobs to run in parallel" - method_option "local", :type => :boolean, :banner => - "Do not attempt to fetch gems remotely and use the gem cache instead" - method_option "quiet", :type => :boolean, :banner => - "Only output warnings and errors." - method_option "source", :type => :array, :banner => - "Update a specific source (and all gems associated with it)" - method_option "redownload", :type => :boolean, :aliases => "--force", :banner => - "Force downloading every gem." - method_option "ruby", :type => :boolean, :banner => - "Update ruby specified in Gemfile.lock" - method_option "bundler", :type => :string, :lazy_default => "> 0.a", :banner => - "Update the locked version of bundler" - method_option "patch", :type => :boolean, :banner => - "Prefer updating only to next patch version" - method_option "minor", :type => :boolean, :banner => - "Prefer updating only to next minor version" - method_option "major", :type => :boolean, :banner => - "Prefer updating to next major version (default)" - method_option "pre", :type => :boolean, :banner => - "Always choose the highest allowed version when updating gems, regardless of prerelease status" - method_option "strict", :type => :boolean, :banner => - "Do not allow any gem to be updated past latest --patch | --minor | --major" - method_option "conservative", :type => :boolean, :banner => - "Use bundle install conservative update behavior and do not allow shared dependencies to be updated." - method_option "all", :type => :boolean, :banner => - "Update everything." + method_option "full-index", type: :boolean, banner: "Fall back to using the single-file index of all gems" + method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile" + method_option "group", aliases: "-g", type: :array, banner: "Update a specific group" + method_option "jobs", aliases: "-j", type: :numeric, banner: "Specify the number of jobs to run in parallel" + method_option "local", type: :boolean, banner: "Do not attempt to fetch gems remotely and use the gem cache instead" + method_option "quiet", type: :boolean, banner: "Only output warnings and errors." + method_option "source", type: :array, banner: "Update a specific source (and all gems associated with it)" + method_option "redownload", type: :boolean, aliases: "--force", banner: "Force downloading every gem." + method_option "ruby", type: :boolean, banner: "Update ruby specified in Gemfile.lock" + method_option "bundler", type: :string, lazy_default: "> 0.a", banner: "Update the locked version of bundler" + method_option "patch", type: :boolean, banner: "Prefer updating only to next patch version" + method_option "minor", type: :boolean, banner: "Prefer updating only to next minor version" + method_option "major", type: :boolean, banner: "Prefer updating to next major version (default)" + method_option "pre", type: :boolean, banner: "Always choose the highest allowed version when updating gems, regardless of prerelease status" + method_option "strict", type: :boolean, banner: "Do not allow any gem to be updated past latest --patch | --minor | --major" + method_option "conservative", type: :boolean, banner: "Use bundle install conservative update behavior and do not allow shared dependencies to be updated." + method_option "all", type: :boolean, banner: "Update everything." def update(*gems) SharedHelpers.major_deprecation(2, "The `--force` option has been renamed to `--redownload`") if ARGV.include?("--force") require_relative "cli/update" - Bundler.settings.temporary(:no_install => false) do + Bundler.settings.temporary(no_install: false) do Update.new(options, gems).run end end @@ -317,21 +286,25 @@ module Bundler Show lists the names and versions of all gems that are required by your Gemfile. Calling show with [GEM] will list the exact location of that gem on your machine. D - method_option "paths", :type => :boolean, - :banner => "List the paths of all gems that are required by your Gemfile." - method_option "outdated", :type => :boolean, - :banner => "Show verbose output including whether gems are outdated." + method_option "paths", type: :boolean, + banner: "List the paths of all gems that are required by your Gemfile." + method_option "outdated", type: :boolean, + banner: "Show verbose output including whether gems are outdated." def show(gem_name = nil) - SharedHelpers.major_deprecation(2, "the `--outdated` flag to `bundle show` was undocumented and will be removed without replacement") if ARGV.include?("--outdated") + if ARGV.include?("--outdated") + message = "the `--outdated` flag to `bundle show` was undocumented and will be removed without replacement" + removed_message = "the `--outdated` flag to `bundle show` was undocumented and has been removed without replacement" + SharedHelpers.major_deprecation(2, message, removed_message: removed_message) + end require_relative "cli/show" Show.new(options, gem_name).run end desc "list", "List all gems in the bundle" - method_option "name-only", :type => :boolean, :banner => "print only the gem names" - method_option "only-group", :type => :array, :default => [], :banner => "print gems from a given set of groups" - method_option "without-group", :type => :array, :default => [], :banner => "print all gems except from a given set of groups" - method_option "paths", :type => :boolean, :banner => "print the path to each gem in the bundle" + method_option "name-only", type: :boolean, banner: "print only the gem names" + method_option "only-group", type: :array, default: [], banner: "print gems from a given set of groups" + method_option "without-group", type: :array, default: [], banner: "print all gems except from a given set of groups" + method_option "paths", type: :boolean, banner: "print the path to each gem in the bundle" def list require_relative "cli/list" List.new(options).run @@ -340,8 +313,8 @@ module Bundler 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" - method_option "version", :type => :boolean, :banner => "Print gem version" + method_option "path", type: :boolean, banner: "Print full path to gem" + method_option "version", type: :boolean, banner: "Print gem version" def info(gem_name) require_relative "cli/info" Info.new(options, gem_name).run @@ -353,18 +326,12 @@ module Bundler or the --binstubs directory if one has been set. Calling binstubs with [GEM [GEM]] will create binstubs for all given gems. D - method_option "force", :type => :boolean, :default => false, :banner => - "Overwrite existing binstubs if they exist" - method_option "path", :type => :string, :lazy_default => "bin", :banner => - "Binstub destination directory (default bin)" - method_option "shebang", :type => :string, :banner => - "Specify a different shebang executable name than the default (usually 'ruby')" - method_option "standalone", :type => :boolean, :banner => - "Make binstubs that can work without the Bundler runtime" - method_option "all", :type => :boolean, :banner => - "Install binstubs for all gems" - method_option "all-platforms", :type => :boolean, :default => false, :banner => - "Install binstubs for all platforms" + method_option "force", type: :boolean, default: false, banner: "Overwrite existing binstubs if they exist" + method_option "path", type: :string, lazy_default: "bin", banner: "Binstub destination directory (default bin)" + method_option "shebang", type: :string, banner: "Specify a different shebang executable name than the default (usually 'ruby')" + method_option "standalone", type: :boolean, banner: "Make binstubs that can work without the Bundler runtime" + method_option "all", type: :boolean, banner: "Install binstubs for all gems" + method_option "all-platforms", type: :boolean, default: false, banner: "Install binstubs for all platforms" def binstubs(*gems) require_relative "cli/binstubs" Binstubs.new(options, gems).run @@ -374,19 +341,19 @@ module Bundler long_desc <<-D Adds the specified gem to Gemfile (if valid) and run 'bundle install' in one step. D - method_option "version", :aliases => "-v", :type => :string - method_option "group", :aliases => "-g", :type => :string - method_option "source", :aliases => "-s", :type => :string - method_option "require", :aliases => "-r", :type => :string, :banner => "Adds require path to gem. Provide false, or a path as a string." - method_option "path", :type => :string - method_option "git", :type => :string - method_option "github", :type => :string - method_option "branch", :type => :string - method_option "ref", :type => :string - method_option "skip-install", :type => :boolean, :banner => - "Adds gem to the Gemfile but does not install it" - method_option "optimistic", :type => :boolean, :banner => "Adds optimistic declaration of version to gem" - method_option "strict", :type => :boolean, :banner => "Adds strict declaration of version to gem" + method_option "version", aliases: "-v", type: :string + method_option "group", aliases: "-g", type: :string + method_option "source", aliases: "-s", type: :string + method_option "require", aliases: "-r", type: :string, banner: "Adds require path to gem. Provide false, or a path as a string." + method_option "path", type: :string + method_option "git", type: :string + method_option "github", type: :string + method_option "branch", type: :string + method_option "ref", type: :string + method_option "glob", type: :string, banner: "The location of a dependency's .gemspec, expanded within Ruby (single quotes recommended)" + method_option "skip-install", type: :boolean, banner: "Adds gem to the Gemfile but does not install it" + method_option "optimistic", type: :boolean, banner: "Adds optimistic declaration of version to gem" + method_option "strict", type: :boolean, banner: "Adds strict declaration of version to gem" def add(*gems) require_relative "cli/add" Add.new(options.dup, gems).run @@ -402,54 +369,45 @@ module Bundler For more information on patch level options (--major, --minor, --patch, --strict) see documentation on the same options on the update command. D - method_option "group", :type => :string, :banner => "List gems from a specific group" - method_option "groups", :type => :boolean, :banner => "List gems organized by groups" - method_option "local", :type => :boolean, :banner => - "Do not attempt to fetch gems remotely and use the gem cache instead" - method_option "pre", :type => :boolean, :banner => "Check for newer pre-release gems" - method_option "source", :type => :array, :banner => "Check against a specific source" - method_option "filter-strict", :type => :boolean, :aliases => "--strict", :banner => - "Only list newer versions allowed by your Gemfile requirements" - method_option "update-strict", :type => :boolean, :banner => - "Strict conservative resolution, do not allow any gem to be updated past latest --patch | --minor | --major" - method_option "minor", :type => :boolean, :banner => "Prefer updating only to next minor version" - method_option "major", :type => :boolean, :banner => "Prefer updating to next major version (default)" - method_option "patch", :type => :boolean, :banner => "Prefer updating only to next patch version" - method_option "filter-major", :type => :boolean, :banner => "Only list major newer versions" - method_option "filter-minor", :type => :boolean, :banner => "Only list minor newer versions" - method_option "filter-patch", :type => :boolean, :banner => "Only list patch newer versions" - method_option "parseable", :aliases => "--porcelain", :type => :boolean, :banner => - "Use minimal formatting for more parseable output" - method_option "only-explicit", :type => :boolean, :banner => - "Only list gems specified in your Gemfile, not their dependencies" + method_option "group", type: :string, banner: "List gems from a specific group" + method_option "groups", type: :boolean, banner: "List gems organized by groups" + method_option "local", type: :boolean, banner: "Do not attempt to fetch gems remotely and use the gem cache instead" + method_option "pre", type: :boolean, banner: "Check for newer pre-release gems" + method_option "source", type: :array, banner: "Check against a specific source" + method_option "filter-strict", type: :boolean, aliases: "--strict", banner: "Only list newer versions allowed by your Gemfile requirements" + method_option "update-strict", type: :boolean, banner: "Strict conservative resolution, do not allow any gem to be updated past latest --patch | --minor | --major" + method_option "minor", type: :boolean, banner: "Prefer updating only to next minor version" + method_option "major", type: :boolean, banner: "Prefer updating to next major version (default)" + method_option "patch", type: :boolean, banner: "Prefer updating only to next patch version" + method_option "filter-major", type: :boolean, banner: "Only list major newer versions" + method_option "filter-minor", type: :boolean, banner: "Only list minor newer versions" + method_option "filter-patch", type: :boolean, banner: "Only list patch newer versions" + method_option "parseable", aliases: "--porcelain", type: :boolean, banner: "Use minimal formatting for more parseable output" + method_option "only-explicit", type: :boolean, banner: "Only list gems specified in your Gemfile, not their dependencies" def outdated(*gems) require_relative "cli/outdated" Outdated.new(options, gems).run end 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" + 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)." - 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 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 bundle cache operation's install" + 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)." + 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 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 bundle cache operation's install" long_desc <<-D 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 @@ -457,17 +415,20 @@ 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") - - SharedHelpers.major_deprecation 2, - "The `--path` flag is deprecated because its semantics are unclear. " \ - "Use `bundle config cache_path` to configure the path of your cache of gems, " \ - "and `bundle config path` to configure the path where your gems are installed, " \ - "and stop using this flag" if ARGV.include?("--path") + print_remembered_flag_deprecation("--all", "cache_all", "true") if ARGV.include?("--all") + + if ARGV.include?("--path") + message = + "The `--path` flag is deprecated because its semantics are unclear. " \ + "Use `bundle config cache_path` to configure the path of your cache of gems, " \ + "and `bundle config path` to configure the path where your gems are installed, " \ + "and stop using this flag" + removed_message = + "The `--path` flag has been removed because its semantics were unclear. " \ + "Use `bundle config cache_path` to configure the path of your cache of gems, " \ + "and `bundle config path` to configure the path where your gems are installed." + SharedHelpers.major_deprecation 2, message, removed_message: removed_message + end require_relative "cli/cache" Cache.new(options).run @@ -476,8 +437,8 @@ module Bundler map aliases_for("cache") desc "exec [OPTIONS]", "Run the command in context of the bundle" - method_option :keep_file_descriptors, :type => :boolean, :default => true - method_option :gemfile, :type => :string, :required => false + method_option :keep_file_descriptors, type: :boolean, default: true + method_option :gemfile, type: :string, required: false long_desc <<-D Exec runs a command, providing it access to the gems in the bundle. While using bundle exec you can require and call the bundled gems as if they were installed @@ -485,7 +446,9 @@ module Bundler D def exec(*args) if ARGV.include?("--no-keep-file-descriptors") - SharedHelpers.major_deprecation(2, "The `--no-keep-file-descriptors` has been deprecated. `bundle exec` no longer mess with your file descriptors. Close them in the exec'd script if you need to") + message = "The `--no-keep-file-descriptors` has been deprecated. `bundle exec` no longer mess with your file descriptors. Close them in the exec'd script if you need to" + removed_message = "The `--no-keep-file-descriptors` has been removed. `bundle exec` no longer mess with your file descriptors. Close them in the exec'd script if you need to" + SharedHelpers.major_deprecation(2, message, removed_message: removed_message) end require_relative "cli/exec" @@ -510,7 +473,7 @@ module Bundler subcommand "config", Config desc "open GEM", "Opens the source directory of the given bundled gem" - method_option "path", :type => :string, :lazy_default => "", :banner => "Open relative path of the gem source." + method_option "path", type: :string, lazy_default: "", banner: "Open relative path of the gem source." def open(name) require_relative "cli/open" Open.new(options, name).run @@ -555,17 +518,17 @@ module Bundler end unless Bundler.feature_flag.bundler_3_mode? - desc "viz [OPTIONS]", "Generates a visual dependency graph", :hide => true + desc "viz [OPTIONS]", "Generates a visual dependency graph", hide: true long_desc <<-D Viz generates a PNG file of the current Gemfile as a dependency graph. Viz requires the ruby-graphviz gem (and its dependencies). The associated gems must also be installed via 'bundle install'. D - method_option :file, :type => :string, :default => "gem_graph", :aliases => "-f", :desc => "The name to use for the generated file. see format option" - method_option :format, :type => :string, :default => "png", :aliases => "-F", :desc => "This is output format option. Supported format is png, jpg, svg, dot ..." - method_option :requirements, :type => :boolean, :default => false, :aliases => "-R", :desc => "Set to show the version of each required dependency." - method_option :version, :type => :boolean, :default => false, :aliases => "-v", :desc => "Set to show each gem version." - method_option :without, :type => :array, :default => [], :aliases => "-W", :banner => "GROUP[ GROUP...]", :desc => "Exclude gems that are part of the specified named group." + method_option :file, type: :string, default: "gem_graph", aliases: "-f", desc: "The name to use for the generated file. see format option" + method_option :format, type: :string, default: "png", aliases: "-F", desc: "This is output format option. Supported format is png, jpg, svg, dot ..." + method_option :requirements, type: :boolean, default: false, aliases: "-R", desc: "Set to show the version of each required dependency." + method_option :version, type: :boolean, default: false, aliases: "-v", desc: "Set to show each gem version." + method_option :without, type: :array, default: [], aliases: "-W", banner: "GROUP[ GROUP...]", desc: "Exclude gems that are part of the specified named group." def viz SharedHelpers.major_deprecation 2, "The `viz` command has been renamed to `graph` and moved to a plugin. See https://github.com/rubygems/bundler-graph" require_relative "cli/viz" @@ -576,23 +539,23 @@ module Bundler old_gem = instance_method(:gem) 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 --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 => :string, :desc => "Generate the boilerplate for C extension code.", :enum => EXTENSIONS - 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 --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 :changelog, :type => :boolean, :desc => "Generate changelog file. Set a default with `bundle config set --global gem.changelog 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 --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, GitLab CI or CircleCI. Set a default with `bundle config set --global gem.ci (github|gitlab|circle)`" - method_option :linter, :type => :string, :lazy_default => Bundler.settings["gem.linter"] || "", - :desc => "Add a linter and code formatter, either RuboCop or Standard. Set a default with `bundle config set --global gem.linter (rubocop|standard)`" - method_option :github_username, :type => :string, :default => Bundler.settings["gem.github_username"], :banner => "Set your username on GitHub", :desc => "Fill in GitHub username on README so that you don't have to do it manually. Set a default with `bundle config set --global gem.github_username <your_username>`." + 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 --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: :string, desc: "Generate the boilerplate for C extension code.", enum: EXTENSIONS + 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 --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 :changelog, type: :boolean, desc: "Generate changelog file. Set a default with `bundle config set --global gem.changelog 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 --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, GitLab CI or CircleCI. Set a default with `bundle config set --global gem.ci (github|gitlab|circle)`" + method_option :linter, type: :string, lazy_default: Bundler.settings["gem.linter"] || "", + desc: "Add a linter and code formatter, either RuboCop or Standard. Set a default with `bundle config set --global gem.linter (rubocop|standard)`" + method_option :github_username, type: :string, default: Bundler.settings["gem.github_username"], banner: "Set your username on GitHub", desc: "Fill in GitHub username on README so that you don't have to do it manually. Set a default with `bundle config set --global gem.github_username <your_username>`." def gem(name) end @@ -623,29 +586,24 @@ module Bundler File.expand_path("templates", __dir__) end - desc "clean [OPTIONS]", "Cleans up unused gems in your bundler directory", :hide => true - method_option "dry-run", :type => :boolean, :default => false, :banner => - "Only print out changes, do not clean gems" - method_option "force", :type => :boolean, :default => false, :banner => - "Forces cleaning up unused gems even if Bundler is configured to use globally installed gems. As a consequence, removes all system gems except for the ones in the current application." + desc "clean [OPTIONS]", "Cleans up unused gems in your bundler directory", hide: true + method_option "dry-run", type: :boolean, default: false, banner: "Only print out changes, do not clean gems" + method_option "force", type: :boolean, default: false, banner: "Forces cleaning up unused gems even if Bundler is configured to use globally installed gems. As a consequence, removes all system gems except for the ones in the current application." def clean require_relative "cli/clean" Clean.new(options.dup).run end desc "platform [OPTIONS]", "Displays platform compatibility information" - method_option "ruby", :type => :boolean, :default => false, :banner => - "only display ruby related platform information" + method_option "ruby", type: :boolean, default: false, banner: "only display ruby related platform information" def platform require_relative "cli/platform" Platform.new(options).run end - desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile", :hide => true - method_option "source", :type => :string, :banner => - "Install gem from the given source" - method_option "group", :type => :string, :banner => - "Install gem into a bundler group" + desc "inject GEM VERSION", "Add the named gem, with version requirements, to the resolved Gemfile", hide: true + method_option "source", type: :string, banner: "Install gem from the given source" + method_option "group", type: :string, banner: "Install gem into a bundler group" def inject(name, version) SharedHelpers.major_deprecation 2, "The `inject` command has been replaced by the `add` command" require_relative "cli/inject" @@ -653,36 +611,21 @@ module Bundler end desc "lock", "Creates a lockfile without installing" - method_option "update", :type => :array, :lazy_default => true, :banner => - "ignore the existing lockfile, update all gems by default, or update list of given gems" - method_option "local", :type => :boolean, :default => false, :banner => - "do not attempt to fetch remote gemspecs and use the local gem cache only" - method_option "print", :type => :boolean, :default => false, :banner => - "print the lockfile to STDOUT instead of writing to the file system" - method_option "gemfile", :type => :string, :banner => - "Use the specified gemfile instead of Gemfile" - method_option "lockfile", :type => :string, :default => nil, :banner => - "the path the lockfile should be written to" - method_option "full-index", :type => :boolean, :default => false, :banner => - "Fall back to using the single-file index of all gems" - method_option "add-platform", :type => :array, :default => [], :banner => - "Add a new platform to the lockfile" - method_option "remove-platform", :type => :array, :default => [], :banner => - "Remove a platform from the lockfile" - method_option "patch", :type => :boolean, :banner => - "If updating, prefer updating only to next patch version" - method_option "minor", :type => :boolean, :banner => - "If updating, prefer updating only to next minor version" - method_option "major", :type => :boolean, :banner => - "If updating, prefer updating to next major version (default)" - method_option "pre", :type => :boolean, :banner => - "If updating, always choose the highest allowed version, regardless of prerelease status" - method_option "strict", :type => :boolean, :banner => - "If updating, do not allow any gem to be updated past latest --patch | --minor | --major" - method_option "conservative", :type => :boolean, :banner => - "If updating, use bundle install conservative update behavior and do not allow shared dependencies to be updated" - method_option "bundler", :type => :string, :lazy_default => "> 0.a", :banner => - "Update the locked version of bundler" + method_option "update", type: :array, lazy_default: true, banner: "ignore the existing lockfile, update all gems by default, or update list of given gems" + method_option "local", type: :boolean, default: false, banner: "do not attempt to fetch remote gemspecs and use the local gem cache only" + method_option "print", type: :boolean, default: false, banner: "print the lockfile to STDOUT instead of writing to the file system" + method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile" + method_option "lockfile", type: :string, default: nil, banner: "the path the lockfile should be written to" + method_option "full-index", type: :boolean, default: false, banner: "Fall back to using the single-file index of all gems" + method_option "add-platform", type: :array, default: [], banner: "Add a new platform to the lockfile" + method_option "remove-platform", type: :array, default: [], banner: "Remove a platform from the lockfile" + method_option "patch", type: :boolean, banner: "If updating, prefer updating only to next patch version" + method_option "minor", type: :boolean, banner: "If updating, prefer updating only to next minor version" + method_option "major", type: :boolean, banner: "If updating, prefer updating to next major version (default)" + method_option "pre", type: :boolean, banner: "If updating, always choose the highest allowed version, regardless of prerelease status" + method_option "strict", type: :boolean, banner: "If updating, do not allow any gem to be updated past latest --patch | --minor | --major" + method_option "conservative", type: :boolean, banner: "If updating, use bundle install conservative update behavior and do not allow shared dependencies to be updated" + method_option "bundler", type: :string, lazy_default: "> 0.a", banner: "Update the locked version of bundler" def lock require_relative "cli/lock" Lock.new(options).run @@ -699,10 +642,8 @@ module Bundler missing dependencies are detected, Bundler prints them and exits status 1. Otherwise, Bundler prints a success message and exits with a status of 0. D - method_option "gemfile", :type => :string, :banner => - "Use the specified gemfile instead of Gemfile" - method_option "quiet", :type => :boolean, :banner => - "Only output warnings and errors." + method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile" + method_option "quiet", type: :boolean, banner: "Only output warnings and errors." def doctor require_relative "cli/doctor" Doctor.new(options).run @@ -722,7 +663,9 @@ module Bundler D def pristine(*gems) require_relative "cli/pristine" - Pristine.new(gems).run + Bundler.settings.temporary(no_install: false) do + Pristine.new(gems).run + end end if Bundler.feature_flag.plugins? @@ -743,7 +686,6 @@ module Bundler 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 @@ -764,7 +706,9 @@ module Bundler # when deprecated version of `--ext` is called # print out deprecation warning and pretend `--ext=c` was provided if deprecated_ext_value?(arguments) - SharedHelpers.major_deprecation 2, "Extensions can now be generated using C or Rust, so `--ext` with no arguments has been deprecated. Please select a language, e.g. `--ext=rust` to generate a Rust extension. This gem will now be generated as if `--ext=c` was used." + message = "Extensions can now be generated using C or Rust, so `--ext` with no arguments has been deprecated. Please select a language, e.g. `--ext=rust` to generate a Rust extension. This gem will now be generated as if `--ext=c` was used." + removed_message = "Extensions can now be generated using C or Rust, so `--ext` with no arguments has been removed. Please select a language, e.g. `--ext=rust` to generate a Rust extension." + SharedHelpers.major_deprecation 2, message, removed_message: removed_message arguments[arguments.index("--ext")] = "--ext=c" end end @@ -794,26 +738,6 @@ module Bundler private - # Automatically invoke `bundle install` and resume if - # Bundler.settings[:auto_install] exists. This is set through config cmd - # `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 - # `Installer` that'll keep a reference to the old one instead. - def auto_install - return unless Bundler.settings[:auto_install] - - begin - Bundler.definition.specs - rescue GemNotFound - Bundler.ui.info "Automatically installing missing gems." - Bundler.reset! - invoke :install, [] - Bundler.reset! - end - end - def current_command _, _, config = @_initializer config[:current_command] @@ -843,13 +767,10 @@ module Bundler return unless SharedHelpers.md5_available? - latest = Fetcher::CompactIndex. - new(nil, Source::Rubygems::Remote.new(Bundler::URI("https://rubygems.org")), nil). - send(:compact_index_client). - instance_variable_get(:@cache). - dependencies("bundler"). - map {|d| Gem::Version.new(d.first) }. - max + require_relative "vendored_uri" + remote = Source::Rubygems::Remote.new(Gem::URI("https://rubygems.org")) + cache_path = Bundler.user_cache.join("compact_index", remote.cache_slug) + latest = Bundler::CompactIndexClient.new(cache_path).latest_version("bundler") return unless latest current = Gem::Version.new(VERSION) @@ -883,12 +804,23 @@ module Bundler value = options[name] value = value.join(" ").to_s if option.type == :array + value = "'#{value}'" unless option.type == :boolean - Bundler::SharedHelpers.major_deprecation 2, + print_remembered_flag_deprecation(flag_name, name.tr("-", "_"), value) + end + + def print_remembered_flag_deprecation(flag_name, option_name, option_value) + message = "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 --local #{name.tr("-", "_")} " \ - "'#{value}'`, and stop using this flag" + "do in future versions. Instead please use `bundle config set #{option_name} " \ + "#{option_value}`, and stop using this flag" + removed_message = + "The `#{flag_name}` flag has been removed because it relied on being " \ + "remembered across bundler invocations, which bundler will no longer " \ + "do. Instead please use `bundle config set #{option_name} " \ + "#{option_value}`, and stop using this flag" + Bundler::SharedHelpers.major_deprecation 2, message, removed_message: removed_message end end end diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index 08fa6547fb..002d9e1d33 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -28,9 +28,9 @@ module Bundler dependencies = gems.map {|g| Bundler::Dependency.new(g, version, options) } Injector.inject(dependencies, - :conservative_versioning => options[:version].nil?, # Perform conservative versioning only when version is not specified - :optimistic => options[:optimistic], - :strict => options[:strict]) + conservative_versioning: options[:version].nil?, # Perform conservative versioning only when version is not specified + optimistic: options[:optimistic], + strict: options[:strict]) end def validate_options! diff --git a/lib/bundler/cli/binstubs.rb b/lib/bundler/cli/binstubs.rb index fc2fad47a5..8ce138df96 100644 --- a/lib/bundler/cli/binstubs.rb +++ b/lib/bundler/cli/binstubs.rb @@ -17,9 +17,9 @@ module Bundler installer = Installer.new(Bundler.root, Bundler.definition) installer_opts = { - :force => options[:force], - :binstubs_cmd => true, - :all_platforms => options["all-platforms"], + force: options[:force], + binstubs_cmd: true, + all_platforms: options["all-platforms"], } if options[:all] @@ -45,7 +45,7 @@ module Bundler next end - Bundler.settings.temporary(:path => (Bundler.settings[:path] || Bundler.root)) do + Bundler.settings.temporary(path: Bundler.settings[:path] || Bundler.root) do installer.generate_standalone_bundler_executable_stubs(spec, installer_opts) end else diff --git a/lib/bundler/cli/cache.rb b/lib/bundler/cli/cache.rb index c8698ed7e3..2e63a16ec3 100644 --- a/lib/bundler/cli/cache.rb +++ b/lib/bundler/cli/cache.rb @@ -19,7 +19,7 @@ module Bundler # 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.settings.temporary(cache_all_platforms: options["all-platforms"]) do Bundler.load.cache(custom_path) end end diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb index cc1f37f0c3..33d31cdd27 100644 --- a/lib/bundler/cli/check.rb +++ b/lib/bundler/cli/check.rb @@ -29,10 +29,10 @@ module Bundler Bundler.ui.warn "Install missing gems with `bundle install`" exit 1 elsif !Bundler.default_lockfile.file? && Bundler.frozen_bundle? - Bundler.ui.error "This bundle has been frozen, but there is no #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} present" + Bundler.ui.error "This bundle has been frozen, but there is no #{SharedHelpers.relative_lockfile_path} present" exit 1 else - Bundler.load.lock(:preserve_unknown_sections => true) unless options[:"dry-run"] + Bundler.load.lock(preserve_unknown_sections: true) unless options[:"dry-run"] Bundler.ui.info "The Gemfile's dependencies are satisfied" end end diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index d654406f65..7ef6deb2cf 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -54,9 +54,12 @@ module Bundler Bundler.definition.specs.each do |spec| return spec if spec.name == name - specs << spec if regexp && spec.name =~ regexp + specs << spec if regexp && spec.name.match?(regexp) end + default_spec = default_gem_spec(name) + specs << default_spec if default_spec + case specs.count when 0 dep_in_other_group = Bundler.definition.current_dependencies.find {|dep|dep.name == name } @@ -75,6 +78,11 @@ module Bundler raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies) end + def self.default_gem_spec(name) + gem_spec = Gem::Specification.find_all_by_name(name).last + gem_spec if gem_spec&.default_gem? + end + def self.ask_for_spec_from(specs) specs.each_with_index do |spec, index| Bundler.ui.info "#{index.succ} : #{spec.name}", true diff --git a/lib/bundler/cli/config.rb b/lib/bundler/cli/config.rb index e1222c75dd..77b502fe60 100644 --- a/lib/bundler/cli/config.rb +++ b/lib/bundler/cli/config.rb @@ -2,17 +2,17 @@ module Bundler class CLI::Config < Thor - class_option :parseable, :type => :boolean, :banner => "Use minimal formatting for more parseable output" + class_option :parseable, type: :boolean, banner: "Use minimal formatting for more parseable output" def self.scope_options - method_option :global, :type => :boolean, :banner => "Only change the global config" - method_option :local, :type => :boolean, :banner => "Only change the local config" + method_option :global, type: :boolean, banner: "Only change the global config" + method_option :local, type: :boolean, banner: "Only change the local config" end private_class_method :scope_options - desc "base NAME [VALUE]", "The Bundler 1 config interface", :hide => true + desc "base NAME [VALUE]", "The Bundler 1 config interface", hide: true scope_options - method_option :delete, :type => :boolean, :banner => "delete" + method_option :delete, type: :boolean, banner: "delete" def base(name = nil, *value) new_args = if ARGV.size == 1 @@ -25,8 +25,9 @@ module Bundler ["config", "get", ARGV[1]] end - SharedHelpers.major_deprecation 3, - "Using the `config` command without a subcommand [list, get, set, unset] is deprecated and will be removed in the future. Use `bundle #{new_args.join(" ")}` instead." + message = "Using the `config` command without a subcommand [list, get, set, unset] is deprecated and will be removed in the future. Use `bundle #{new_args.join(" ")}` instead." + removed_message = "Using the `config` command without a subcommand [list, get, set, unset] is has been removed. Use `bundle #{new_args.join(" ")}` instead." + SharedHelpers.major_deprecation 3, message, removed_message: removed_message Base.new(options, name, value, self).run end diff --git a/lib/bundler/cli/console.rb b/lib/bundler/cli/console.rb index 1eb8ea8254..840cf14fd7 100644 --- a/lib/bundler/cli/console.rb +++ b/lib/bundler/cli/console.rb @@ -9,8 +9,9 @@ module Bundler end def run - Bundler::SharedHelpers.major_deprecation 2, "bundle console will be replaced " \ - "by `bin/console` generated by `bundle gem <name>`" + message = "bundle console will be replaced by `bin/console` generated by `bundle gem <name>`" + removed_message = "bundle console has been replaced by `bin/console` generated by `bundle gem <name>`" + Bundler::SharedHelpers.major_deprecation 2, message, removed_message: removed_message group ? Bundler.require(:default, *group.split(" ").map!(&:to_sym)) : Bundler.require ARGV.clear diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index e299a5a8c2..1f6fc93c16 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -6,8 +6,8 @@ require "fiddle" module Bundler class CLI::Doctor - DARWIN_REGEX = /\s+(.+) \(compatibility /.freeze - LDD_REGEX = /\t\S+ => (\S+) \(\S+\)/.freeze + DARWIN_REGEX = /\s+(.+) \(compatibility / + LDD_REGEX = /\t\S+ => (\S+) \(\S+\)/ attr_reader :options diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index 42b602a055..f81cd5d2c4 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -12,7 +12,7 @@ module Bundler @options = options @cmd = args.shift @args = args - @args << { :close_others => !options.keep_file_descriptors? } unless Bundler.current_ruby.jruby? + @args << { close_others: !options.keep_file_descriptors? } unless Bundler.current_ruby.jruby? end def run diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb index 7f1200f4a0..b6571d0e86 100644 --- a/lib/bundler/cli/gem.rb +++ b/lib/bundler/cli/gem.rb @@ -11,7 +11,7 @@ module Bundler class CLI::Gem TEST_FRAMEWORK_VERSIONS = { "rspec" => "3.0", - "minitest" => "5.0", + "minitest" => "5.16", "test-unit" => "3.0", }.freeze @@ -32,7 +32,6 @@ module Bundler validate_ext_name if @extension validate_rust_builder_rubygems_version if @extension == "rust" - travis_removal_info end def run @@ -59,23 +58,23 @@ module Bundler end config = { - :name => name, - :underscored_name => underscored_name, - :namespaced_path => namespaced_path, - :makefile_path => "#{underscored_name}/#{underscored_name}", - :constant_name => constant_name, - :constant_array => constant_array, - :author => git_author_name.empty? ? "TODO: Write your name" : git_author_name, - :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email, - :test => options[:test], - :ext => extension, - :exe => options[:exe], - :bundler_version => bundler_dependency_version, - :git => use_git, - :github_username => github_username.empty? ? "[USERNAME]" : github_username, - :required_ruby_version => required_ruby_version, - :rust_builder_required_rubygems_version => rust_builder_required_rubygems_version, - :minitest_constant_name => minitest_constant_name, + name: name, + underscored_name: underscored_name, + namespaced_path: namespaced_path, + makefile_path: "#{underscored_name}/#{underscored_name}", + constant_name: constant_name, + constant_array: constant_array, + author: git_author_name.empty? ? "TODO: Write your name" : git_author_name, + email: git_user_email.empty? ? "TODO: Write your email address" : git_user_email, + test: options[:test], + ext: extension, + exe: options[:exe], + bundler_version: bundler_dependency_version, + git: use_git, + github_username: github_username.empty? ? "[USERNAME]" : github_username, + required_ruby_version: required_ruby_version, + rust_builder_required_rubygems_version: rust_builder_required_rubygems_version, + minitest_constant_name: minitest_constant_name, } ensure_safe_gem_name(name, constant_array) @@ -137,10 +136,13 @@ module Bundler case config[:ci] when "github" templates.merge!("github/workflows/main.yml.tt" => ".github/workflows/main.yml") + config[:ci_config_path] = ".github " when "gitlab" templates.merge!("gitlab-ci.yml.tt" => ".gitlab-ci.yml") + config[:ci_config_path] = ".gitlab-ci.yml " when "circle" templates.merge!("circleci/config.yml.tt" => ".circleci/config.yml") + config[:ci_config_path] = ".circleci " end if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?", @@ -233,9 +235,7 @@ module Bundler end if use_git - Dir.chdir(target) do - `git add .` - end + IO.popen(%w[git add .], { chdir: target }, &:read) end # Open gemspec in editor @@ -348,7 +348,7 @@ module Bundler Bundler.ui.confirm "Do you want to add a code linter and formatter to your gem? " \ "Supported Linters:\n" \ "* RuboCop: https://rubocop.org\n" \ - "* Standard: https://github.com/testdouble/standard\n" \ + "* Standard: https://github.com/standardrb/standard\n" \ "\n" Bundler.ui.info hint_text("linter") @@ -379,15 +379,20 @@ module Bundler def deprecated_rubocop_option if !options[:rubocop].nil? if options[:rubocop] - Bundler::SharedHelpers.major_deprecation 2, "--rubocop is deprecated, use --linter=rubocop" + Bundler::SharedHelpers.major_deprecation 2, + "--rubocop is deprecated, use --linter=rubocop", + removed_message: "--rubocop has been removed, use --linter=rubocop" "rubocop" else - Bundler::SharedHelpers.major_deprecation 2, "--no-rubocop is deprecated, use --linter" + Bundler::SharedHelpers.major_deprecation 2, + "--no-rubocop is deprecated, use --linter", + removed_message: "--no-rubocop has been removed, use --linter" false end elsif !Bundler.settings["gem.rubocop"].nil? Bundler::SharedHelpers.major_deprecation 2, - "config gem.rubocop is deprecated; we've updated your config to use gem.linter instead" + "config gem.rubocop is deprecated; we've updated your config to use gem.linter instead", + removed_message: "config gem.rubocop has been removed; we've updated your config to use gem.linter instead" Bundler.settings["gem.rubocop"] ? "rubocop" : false end end @@ -431,7 +436,7 @@ module Bundler end def required_ruby_version - "2.6.0" + "3.0.0" end def rubocop_version @@ -442,19 +447,6 @@ module Bundler "1.3" end - # TODO: remove at next minor release - def travis_removal_info - if options[:ci] == "travis" - Bundler.ui.error "Support for Travis CI was removed from gem skeleton generator." - exit 1 - end - - if Bundler.settings["gem.ci"] == "travis" - Bundler.ui.error "Support for Travis CI was removed from gem skeleton generator, but it is present in bundle config. Please configure another provider using `bundle config set gem.ci SERVICE` (where SERVICE is one of github/gitlab/circle) or unset configuration using `bundle config unset gem.ci`." - exit 1 - end - end - def validate_rust_builder_rubygems_version if Gem::Version.new(rust_builder_required_rubygems_version) > Gem.rubygems_version Bundler.ui.error "Your RubyGems version (#{Gem.rubygems_version}) is too old to build Rust extension. Please update your RubyGems using `gem update --system` or any other way and try again." diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 36c7a58f12..8f34956aca 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -25,19 +25,8 @@ module Bundler private - def spec_for_gem(gem_name) - spec = Bundler.definition.specs.find {|s| s.name == gem_name } - spec || default_gem_spec(gem_name) || Bundler::CLI::Common.select_spec(gem_name, :regex_match) - end - - def default_gem_spec(gem_name) - return unless Gem::Specification.respond_to?(:find_all_by_name) - gem_spec = Gem::Specification.find_all_by_name(gem_name).last - return gem_spec if gem_spec&.default_gem? - end - - def spec_not_found(gem_name) - raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(gem_name, Bundler.definition.dependencies) + def spec_for_gem(name) + Bundler::CLI::Common.select_spec(name, :regex_match) end def print_gem_version(spec) diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index c71bcf159f..a233d5d2e5 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -14,7 +14,7 @@ module Bundler Bundler.self_manager.install_locked_bundler_and_restart_with_it_if_needed - Bundler::SharedHelpers.set_env "RB_USER_INSTALL", "1" if Bundler::FREEBSD + Bundler::SharedHelpers.set_env "RB_USER_INSTALL", "1" if Gem.freebsd_platform? # Disable color in deployment mode Bundler.ui.shell = Thor::Shell::Basic.new if options[:deployment] @@ -28,8 +28,8 @@ module Bundler flag = "--deployment flag" if options[:deployment] flag ||= "--frozen flag" if options[:frozen] flag ||= "deployment setting" - raise ProductionError, "The #{flag} requires a #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}. Please make " \ - "sure you have checked your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} into version control " \ + raise ProductionError, "The #{flag} requires a lockfile. Please make " \ + "sure you have checked your #{SharedHelpers.relative_lockfile_path} into version control " \ "before deploying." end @@ -51,7 +51,8 @@ module Bundler if options["binstubs"] Bundler::SharedHelpers.major_deprecation 2, - "The --binstubs option will be removed in favor of `bundle binstubs --all`" + "The --binstubs option will be removed in favor of `bundle binstubs --all`", + removed_message: "The --binstubs option have been removed in favor of `bundle binstubs --all`" end Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins? @@ -61,7 +62,7 @@ module Bundler installer = Installer.install(Bundler.root, definition, options) - Bundler.settings.temporary(:cache_all_platforms => options[:local] ? false : Bundler.settings[:cache_all_platforms]) do + Bundler.settings.temporary(cache_all_platforms: options[:local] ? false : Bundler.settings[:cache_all_platforms]) do Bundler.load.cache(nil, options[:local]) if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle? end @@ -95,7 +96,7 @@ module Bundler def warn_if_root return if Bundler.settings[:silence_root_warning] || Gem.win_platform? || !Process.uid.zero? Bundler.ui.warn "Don't run Bundler as root. Installing your bundle as root " \ - "will break this application for all non-root users on this machine.", :wrap => true + "will break this application for all non-root users on this machine.", wrap: true end def dependencies_count_for(definition) @@ -148,7 +149,7 @@ module Bundler Bundler.settings.set_command_option_if_given :path, options[:path] if options["standalone"] && Bundler.settings[:path].nil? && !options["local"] - Bundler.settings.temporary(:path_relative_to_cwd => false) do + Bundler.settings.temporary(path_relative_to_cwd: false) do Bundler.settings.set_command_option :path, "bundle" end end diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb index cb3ed27138..dac3d2a09a 100644 --- a/lib/bundler/cli/lock.rb +++ b/lib/bundler/cli/lock.rb @@ -26,42 +26,46 @@ module Bundler if update.is_a?(Array) # unlocking specific gems Bundler::CLI::Common.ensure_all_gems_in_lockfile!(update) - update = { :gems => update, :conservative => conservative } + update = { gems: update, conservative: conservative } elsif update && conservative - update = { :conservative => conservative } + update = { conservative: conservative } elsif update && bundler - update = { :bundler => bundler } + update = { bundler: bundler } end - definition = Bundler.definition(update) - Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options) if options[:update] + file = options[:lockfile] + file = file ? Pathname.new(file).expand_path : Bundler.default_lockfile - options["remove-platform"].each do |platform| - definition.remove_platform(platform) - end + Bundler.settings.temporary(frozen: false) do + definition = Bundler.definition(update, file) + + Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update] - options["add-platform"].each do |platform_string| - platform = Gem::Platform.new(platform_string) - if platform.to_s == "unknown" - Bundler.ui.warn "The platform `#{platform_string}` is unknown to RubyGems " \ - "and adding it will likely lead to resolution errors" + options["remove-platform"].each do |platform| + definition.remove_platform(platform) end - definition.add_platform(platform) - end - if definition.platforms.empty? - raise InvalidOption, "Removing all platforms from the bundle is not allowed" - end + options["add-platform"].each do |platform_string| + platform = Gem::Platform.new(platform_string) + if platform.to_s == "unknown" + Bundler.ui.warn "The platform `#{platform_string}` is unknown to RubyGems " \ + "and adding it will likely lead to resolution errors" + end + definition.add_platform(platform) + end + + if definition.platforms.empty? + raise InvalidOption, "Removing all platforms from the bundle is not allowed" + end - definition.resolve_remotely! unless options[:local] + definition.resolve_remotely! unless options[:local] - if print - puts definition.to_lock - else - file = options[:lockfile] - file = file ? File.expand_path(file) : Bundler.default_lockfile - puts "Writing lockfile to #{file}" - definition.lock(file) + if print + puts definition.to_lock + else + puts "Writing lockfile to #{file}" + definition.lock + end end Bundler.ui.level = previous_ui_level diff --git a/lib/bundler/cli/open.rb b/lib/bundler/cli/open.rb index 8522ec92d6..f24693b843 100644 --- a/lib/bundler/cli/open.rb +++ b/lib/bundler/cli/open.rb @@ -18,13 +18,11 @@ module Bundler Bundler.ui.info "Unable to open #{name} because it's a default gem, so the directory it would normally be installed to does not exist." else root_path = spec.full_gem_path - Dir.chdir(root_path) do - require "shellwords" - command = Shellwords.split(editor) << File.join([root_path, path].compact) - Bundler.with_original_env do - system(*command) - end || Bundler.ui.info("Could not run '#{command.join(" ")}'") - end + require "shellwords" + command = Shellwords.split(editor) << File.join([root_path, path].compact) + Bundler.with_original_env do + system(*command, { chdir: root_path }) + end || Bundler.ui.info("Could not run '#{command.join(" ")}'") end end end diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 68c701aefb..ec42e631bb 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -41,12 +41,12 @@ module Bundler # We're doing a full update Bundler.definition(true) else - Bundler.definition(:gems => gems, :sources => sources) + Bundler.definition(gems: gems, sources: sources) end Bundler::CLI::Common.configure_gem_version_promoter( Bundler.definition, - options.merge(:strict => @strict) + options.merge(strict: @strict) ) definition_resolution = proc do @@ -90,10 +90,10 @@ module Bundler end outdated_gems << { - :active_spec => active_spec, - :current_spec => current_spec, - :dependency => dependency, - :groups => groups, + active_spec: active_spec, + current_spec: current_spec, + dependency: dependency, + groups: groups, } end diff --git a/lib/bundler/cli/plugin.rb b/lib/bundler/cli/plugin.rb index fe3f4412fa..fd61ef0d95 100644 --- a/lib/bundler/cli/plugin.rb +++ b/lib/bundler/cli/plugin.rb @@ -5,20 +5,15 @@ module Bundler class CLI::Plugin < Thor desc "install PLUGINS", "Install the plugin from the source" long_desc <<-D - Install plugins either from the rubygems source provided (with --source option) or from a git source provided with --git (for remote repos) or --local_git (for local repos). If no sources are provided, it uses Gem.sources + Install plugins either from the rubygems source provided (with --source option), from a git source provided with --git, or a local path provided with --path. If no sources are provided, it uses Gem.sources D - method_option "source", :type => :string, :default => nil, :banner => - "URL of the RubyGems source to fetch the plugin from" - method_option "version", :type => :string, :default => nil, :banner => - "The version of the plugin to fetch" - method_option "git", :type => :string, :default => nil, :banner => - "URL of the git repo to fetch from" - method_option "local_git", :type => :string, :default => nil, :banner => - "Path of the local git repo to fetch from" - method_option "branch", :type => :string, :default => nil, :banner => - "The git branch to checkout" - method_option "ref", :type => :string, :default => nil, :banner => - "The git revision to check out" + method_option "source", type: :string, default: nil, banner: "URL of the RubyGems source to fetch the plugin from" + method_option "version", type: :string, default: nil, banner: "The version of the plugin to fetch" + method_option "git", type: :string, default: nil, banner: "URL of the git repo to fetch from" + method_option "local_git", type: :string, default: nil, banner: "Path of the local git repo to fetch from (deprecated)" + method_option "branch", type: :string, default: nil, banner: "The git branch to checkout" + method_option "ref", type: :string, default: nil, banner: "The git revision to check out" + method_option "path", type: :string, default: nil, banner: "Path of a local gem to directly use" def install(*plugins) Bundler::Plugin.install(plugins, options) end @@ -27,8 +22,7 @@ module Bundler long_desc <<-D Uninstall given list of plugins. To uninstall all the plugins, use -all option. D - method_option "all", :type => :boolean, :default => nil, :banner => - "Uninstall all the installed plugins. If no plugin is installed, then it does nothing." + method_option "all", type: :boolean, default: nil, banner: "Uninstall all the installed plugins. If no plugin is installed, then it does nothing." def uninstall(*plugins) Bundler::Plugin.uninstall(plugins, options) end diff --git a/lib/bundler/cli/pristine.rb b/lib/bundler/cli/pristine.rb index d6654f8053..e0d7452c44 100644 --- a/lib/bundler/cli/pristine.rb +++ b/lib/bundler/cli/pristine.rb @@ -12,40 +12,48 @@ module Bundler definition.validate_runtime! installer = Bundler::Installer.new(Bundler.root, definition) - Bundler.load.specs.each do |spec| - next if spec.name == "bundler" # Source::Rubygems doesn't install bundler - next if !@gems.empty? && !@gems.include?(spec.name) - - gem_name = "#{spec.name} (#{spec.version}#{spec.git_version})" - gem_name += " (#{spec.platform})" if !spec.platform.nil? && spec.platform != Gem::Platform::RUBY - - case source = spec.source - when Source::Rubygems - cached_gem = spec.cache_file - unless File.exist?(cached_gem) - Bundler.ui.error("Failed to pristine #{gem_name}. Cached gem #{cached_gem} does not exist.") + ProcessLock.lock do + installed_specs = definition.specs.reject do |spec| + next if spec.name == "bundler" # Source::Rubygems doesn't install bundler + next if !@gems.empty? && !@gems.include?(spec.name) + + gem_name = "#{spec.name} (#{spec.version}#{spec.git_version})" + gem_name += " (#{spec.platform})" if !spec.platform.nil? && spec.platform != Gem::Platform::RUBY + + case source = spec.source + when Source::Rubygems + cached_gem = spec.cache_file + unless File.exist?(cached_gem) + Bundler.ui.error("Failed to pristine #{gem_name}. Cached gem #{cached_gem} does not exist.") + next + end + + FileUtils.rm_rf spec.full_gem_path + when Source::Git + if source.local? + Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is locally overridden.") + next + end + + source.remote! + if extension_cache_path = source.extension_cache_path(spec) + FileUtils.rm_rf extension_cache_path + end + FileUtils.rm_rf spec.extension_dir + FileUtils.rm_rf spec.full_gem_path + else + Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is sourced from local path.") next end - FileUtils.rm_rf spec.full_gem_path - when Source::Git - if source.local? - Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is locally overridden.") - next - end + true + end.map(&:name) - source.remote! - if extension_cache_path = source.extension_cache_path(spec) - FileUtils.rm_rf extension_cache_path - end - FileUtils.rm_rf spec.extension_dir - FileUtils.rm_rf spec.full_gem_path - else - Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is sourced from local path.") - next - end - - Bundler::GemInstaller.new(spec, installer, false, 0, true).install_from_spec + jobs = installer.send(:installation_parallelization, {}) + pristine_count = definition.specs.count - installed_specs.count + # allow a pristining a single gem to skip the parallel worker + jobs = [jobs, pristine_count].min + ParallelInstaller.call(installer, definition.specs, jobs, false, true, skip: installed_specs) end end end diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index b49182655b..985e8db051 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -35,7 +35,7 @@ module Bundler if full_update if conservative - Bundler.definition(:conservative => conservative) + Bundler.definition(conservative: conservative) else Bundler.definition(true) end @@ -51,9 +51,9 @@ module Bundler gems.concat(deps.map(&:name)) end - Bundler.definition(:gems => gems, :sources => sources, :ruby => options[:ruby], - :conservative => conservative, - :bundler => update_bundler) + Bundler.definition(gems: gems, sources: sources, ruby: options[:ruby], + conservative: conservative, + bundler: update_bundler) end Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options) @@ -63,6 +63,7 @@ module Bundler opts = options.dup opts["update"] = true opts["local"] = options[:local] + opts["force"] = options[:redownload] Bundler.settings.set_command_option_if_given :jobs, opts["jobs"] @@ -70,7 +71,7 @@ module Bundler if locked_gems = Bundler.definition.locked_gems previous_locked_info = locked_gems.specs.reduce({}) do |h, s| - h[s.name] = { :spec => s, :version => s.version, :source => s.source.identifier } + h[s.name] = { spec: s, version: s.version, source: s.source.identifier } h end end diff --git a/lib/bundler/compact_index_client.rb b/lib/bundler/compact_index_client.rb index 127a50e810..692d68e579 100644 --- a/lib/bundler/compact_index_client.rb +++ b/lib/bundler/compact_index_client.rb @@ -4,8 +4,44 @@ require "pathname" require "set" module Bundler + # The CompactIndexClient is responsible for fetching and parsing the compact index. + # + # The compact index is a set of caching optimized files that are used to fetch gem information. + # The files are: + # - names: a list of all gem names + # - versions: a list of all gem versions + # - info/[gem]: a list of all versions of a gem + # + # The client is instantiated with: + # - `directory`: the root directory where the cache files are stored. + # - `fetcher`: (optional) an object that responds to #call(uri_path, headers) and returns an http response. + # If the `fetcher` is not provided, the client will only read cached files from disk. + # + # The client is organized into: + # - `Updater`: updates the cached files on disk using the fetcher. + # - `Cache`: calls the updater, caches files, read and return them from disk + # - `Parser`: parses the compact index file data + # - `CacheFile`: a concurrency safe file reader/writer that verifies checksums + # + # The client is intended to optimize memory usage and performance. + # It is called 100s or 1000s of times, parsing files with hundreds of thousands of lines. + # It may be called concurrently without global interpreter lock in some Rubies. + # As a result, some methods may look more complex than necessary to save memory or time. class CompactIndexClient + # NOTE: MD5 is here not because we expect a server to respond with it, but + # because we use it to generate the etag on first request during the upgrade + # to the compact index client that uses opaque etags saved to files. + # Remove once 2.5.0 has been out for a while. + SUPPORTED_DIGESTS = { "sha-256" => :SHA256, "md5" => :MD5 }.freeze DEBUG_MUTEX = Thread::Mutex.new + + # info returns an Array of INFO Arrays. Each INFO Array has the following indices: + INFO_NAME = 0 + INFO_VERSION = 1 + INFO_PLATFORM = 2 + INFO_DEPS = 3 + INFO_REQS = 4 + def self.debug return unless ENV["DEBUG_COMPACT_INDEX"] DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") } @@ -14,106 +50,48 @@ module Bundler class Error < StandardError; end require_relative "compact_index_client/cache" + require_relative "compact_index_client/cache_file" + require_relative "compact_index_client/parser" require_relative "compact_index_client/updater" - attr_reader :directory - - def initialize(directory, fetcher) - @directory = Pathname.new(directory) - @updater = Updater.new(fetcher) - @cache = Cache.new(@directory) - @endpoints = Set.new - @info_checksums_by_name = {} - @parsed_checksums = false - @mutex = Thread::Mutex.new - end - - def execution_mode=(block) - Bundler::CompactIndexClient.debug { "execution_mode=" } - @endpoints = Set.new - - @execution_mode = block - end - - # @return [Lambda] A lambda that takes an array of inputs and a block, and - # maps the inputs with the block in parallel. - # - def execution_mode - @execution_mode || sequentially - end - - def sequential_execution_mode! - self.execution_mode = sequentially - end - - def sequentially - @sequentially ||= lambda do |inputs, &blk| - inputs.map(&blk) - end + def initialize(directory, fetcher = nil) + @cache = Cache.new(directory, fetcher) + @parser = Parser.new(@cache) end def names - Bundler::CompactIndexClient.debug { "/names" } - update(@cache.names_path, "names") - @cache.names + Bundler::CompactIndexClient.debug { "names" } + @parser.names end def versions - Bundler::CompactIndexClient.debug { "/versions" } - update(@cache.versions_path, "versions") - versions, @info_checksums_by_name = @cache.versions - versions + Bundler::CompactIndexClient.debug { "versions" } + @parser.versions end def dependencies(names) Bundler::CompactIndexClient.debug { "dependencies(#{names})" } - execution_mode.call(names) do |name| - update_info(name) - @cache.dependencies(name).map {|d| d.unshift(name) } - end.flatten(1) + names.map {|name| info(name) } end - def update_and_parse_checksums! - Bundler::CompactIndexClient.debug { "update_and_parse_checksums!" } - return @info_checksums_by_name if @parsed_checksums - update(@cache.versions_path, "versions") - @info_checksums_by_name = @cache.checksums - @parsed_checksums = true - end - - private - - def update(local_path, remote_path) - Bundler::CompactIndexClient.debug { "update(#{local_path}, #{remote_path})" } - unless synchronize { @endpoints.add?(remote_path) } - Bundler::CompactIndexClient.debug { "already fetched #{remote_path}" } - return - end - @updater.update(local_path, url(remote_path)) + def info(name) + Bundler::CompactIndexClient.debug { "info(#{names})" } + @parser.info(name) end - def update_info(name) - Bundler::CompactIndexClient.debug { "update_info(#{name})" } - path = @cache.info_path(name) - checksum = @updater.checksum_for_file(path) - unless existing = @info_checksums_by_name[name] - Bundler::CompactIndexClient.debug { "skipping updating info for #{name} since it is missing from versions" } - return - end - if checksum == existing - Bundler::CompactIndexClient.debug { "skipping updating info for #{name} since the versions checksum matches the local checksum" } - return - end - Bundler::CompactIndexClient.debug { "updating info for #{name} since the versions checksum #{existing} != the local checksum #{checksum}" } - update(path, "info/#{name}") + def latest_version(name) + Bundler::CompactIndexClient.debug { "latest_version(#{name})" } + @parser.info(name).map {|d| Gem::Version.new(d[INFO_VERSION]) }.max end - def url(path) - path + def available? + Bundler::CompactIndexClient.debug { "available?" } + @parser.available? end - def synchronize - @mutex.synchronize { yield } + def reset! + Bundler::CompactIndexClient.debug { "reset!" } + @cache.reset! end end end diff --git a/lib/bundler/compact_index_client/cache.rb b/lib/bundler/compact_index_client/cache.rb index 0b43581c11..bedd7f8028 100644 --- a/lib/bundler/compact_index_client/cache.rb +++ b/lib/bundler/compact_index_client/cache.rb @@ -7,94 +7,89 @@ module Bundler class Cache attr_reader :directory - def initialize(directory) + def initialize(directory, fetcher = nil) @directory = Pathname.new(directory).expand_path - info_roots.each do |dir| - SharedHelpers.filesystem_access(dir) do - FileUtils.mkdir_p(dir) - end - end - end + @updater = Updater.new(fetcher) if fetcher + @mutex = Thread::Mutex.new + @endpoints = Set.new - def names - lines(names_path) + @info_root = mkdir("info") + @special_characters_info_root = mkdir("info-special-characters") + @info_etag_root = mkdir("info-etags") end - def names_path - directory.join("names") + def names + fetch("names", names_path, names_etag_path) end def versions - versions_by_name = Hash.new {|hash, key| hash[key] = [] } - info_checksums_by_name = {} - - lines(versions_path).each do |line| - name, versions_string, info_checksum = line.split(" ", 3) - info_checksums_by_name[name] = info_checksum || "" - versions_string.split(",").each do |version| - if version.start_with?("-") - version = version[1..-1].split("-", 2).unshift(name) - versions_by_name[name].delete(version) - else - version = version.split("-", 2).unshift(name) - versions_by_name[name] << version - end - end - end - - [versions_by_name, info_checksums_by_name] - end - - def versions_path - directory.join("versions") + fetch("versions", versions_path, versions_etag_path) end - def checksums - checksums = {} + def info(name, remote_checksum = nil) + path = info_path(name) - lines(versions_path).each do |line| - name, _, checksum = line.split(" ", 3) - checksums[name] = checksum + if remote_checksum && remote_checksum != SharedHelpers.checksum_for_file(path, :MD5) + fetch("info/#{name}", path, info_etag_path(name)) + else + Bundler::CompactIndexClient.debug { "update skipped info/#{name} (#{remote_checksum ? "versions index checksum is nil" : "versions index checksum matches local"})" } + read(path) end - - checksums end - def dependencies(name) - lines(info_path(name)).map do |line| - parse_gem(line) - end + def reset! + @mutex.synchronize { @endpoints.clear } end + private + + def names_path = directory.join("names") + def names_etag_path = directory.join("names.etag") + def versions_path = directory.join("versions") + def versions_etag_path = directory.join("versions.etag") + def info_path(name) name = name.to_s + # TODO: converge this into the info_root by hashing all filenames like info_etag_path if /[^a-z0-9_-]/.match?(name) name += "-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}" - info_roots.last.join(name) + @special_characters_info_root.join(name) else - info_roots.first.join(name) + @info_root.join(name) end end - private + def info_etag_path(name) + name = name.to_s + @info_etag_root.join("#{name}-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}") + end + + def mkdir(name) + directory.join(name).tap do |dir| + SharedHelpers.filesystem_access(dir) do + FileUtils.mkdir_p(dir) + end + end + end + + def fetch(remote_path, path, etag_path) + if already_fetched?(remote_path) + Bundler::CompactIndexClient.debug { "already fetched #{remote_path}" } + else + Bundler::CompactIndexClient.debug { "fetching #{remote_path}" } + @updater&.update(remote_path, path, etag_path) + end - def lines(path) - return [] unless path.file? - lines = SharedHelpers.filesystem_access(path, :read, &:read).split("\n") - header = lines.index("---") - header ? lines[header + 1..-1] : lines + read(path) end - def parse_gem(line) - @dependency_parser ||= GemParser.new - @dependency_parser.parse(line) + def already_fetched?(remote_path) + @mutex.synchronize { !@endpoints.add?(remote_path) } end - def info_roots - [ - directory.join("info"), - directory.join("info-special-characters"), - ] + def read(path) + return unless path.file? + SharedHelpers.filesystem_access(path, :read, &:read) end end end diff --git a/lib/bundler/compact_index_client/cache_file.rb b/lib/bundler/compact_index_client/cache_file.rb new file mode 100644 index 0000000000..299d683438 --- /dev/null +++ b/lib/bundler/compact_index_client/cache_file.rb @@ -0,0 +1,148 @@ +# frozen_string_literal: true + +require_relative "../vendored_fileutils" +require "rubygems/package" + +module Bundler + class CompactIndexClient + # write cache files in a way that is robust to concurrent modifications + # if digests are given, the checksums will be verified + class CacheFile + DEFAULT_FILE_MODE = 0o644 + private_constant :DEFAULT_FILE_MODE + + class Error < RuntimeError; end + class ClosedError < Error; end + + class DigestMismatchError < Error + def initialize(digests, expected_digests) + super "Calculated checksums #{digests.inspect} did not match expected #{expected_digests.inspect}." + end + end + + # Initialize with a copy of the original file, then yield the instance. + def self.copy(path, &block) + new(path) do |file| + file.initialize_digests + + SharedHelpers.filesystem_access(path, :read) do + path.open("rb") do |s| + file.open {|f| IO.copy_stream(s, f) } + end + end + + yield file + end + end + + # Write data to a temp file, then replace the original file with it verifying the digests if given. + def self.write(path, data, digests = nil) + return unless data + new(path) do |file| + file.digests = digests + file.write(data) + end + end + + attr_reader :original_path, :path + + def initialize(original_path, &block) + @original_path = original_path + @perm = original_path.file? ? original_path.stat.mode : DEFAULT_FILE_MODE + @path = original_path.sub(/$/, ".#{$$}.tmp") + return unless block_given? + begin + yield self + ensure + close + end + end + + def size + path.size + end + + # initialize the digests using CompactIndexClient::SUPPORTED_DIGESTS, or a subset based on keys. + def initialize_digests(keys = nil) + @digests = keys ? SUPPORTED_DIGESTS.slice(*keys) : SUPPORTED_DIGESTS.dup + @digests.transform_values! {|algo_class| SharedHelpers.digest(algo_class).new } + end + + # reset the digests so they don't contain any previously read data + def reset_digests + @digests&.each_value(&:reset) + end + + # set the digests that will be verified at the end + def digests=(expected_digests) + @expected_digests = expected_digests + + if @expected_digests.nil? + @digests = nil + elsif @digests + @digests = @digests.slice(*@expected_digests.keys) + else + initialize_digests(@expected_digests.keys) + end + end + + def digests? + @digests&.any? + end + + # Open the temp file for writing, reusing original permissions, yielding the IO object. + def open(write_mode = "wb", perm = @perm, &block) + raise ClosedError, "Cannot reopen closed file" if @closed + SharedHelpers.filesystem_access(path, :write) do + path.open(write_mode, perm) do |f| + yield digests? ? Gem::Package::DigestIO.new(f, @digests) : f + end + end + end + + # Returns false without appending when no digests since appending is too error prone to do without digests. + def append(data) + return false unless digests? + open("a") {|f| f.write data } + verify && commit + end + + def write(data) + reset_digests + open {|f| f.write data } + commit! + end + + def commit! + verify || raise(DigestMismatchError.new(@base64digests, @expected_digests)) + commit + end + + # Verify the digests, returning true on match, false on mismatch. + def verify + return true unless @expected_digests && digests? + @base64digests = @digests.transform_values!(&:base64digest) + @digests = nil + @base64digests.all? {|algo, digest| @expected_digests[algo] == digest } + end + + # Replace the original file with the temp file without verifying digests. + # The file is permanently closed. + def commit + raise ClosedError, "Cannot commit closed file" if @closed + SharedHelpers.filesystem_access(original_path, :write) do + FileUtils.mv(path, original_path) + end + @closed = true + end + + # Remove the temp file without replacing the original file. + # The file is permanently closed. + def close + return if @closed + FileUtils.remove_file(path) if @path&.file? + @closed = true + end + end + end +end diff --git a/lib/bundler/compact_index_client/gem_parser.rb b/lib/bundler/compact_index_client/gem_parser.rb index e7bf4c6001..60a1817607 100644 --- a/lib/bundler/compact_index_client/gem_parser.rb +++ b/lib/bundler/compact_index_client/gem_parser.rb @@ -6,12 +6,15 @@ module Bundler GemParser = Gem::Resolver::APISet::GemParser else class GemParser + EMPTY_ARRAY = [].freeze + private_constant :EMPTY_ARRAY + def parse(line) version_and_platform, rest = line.split(" ", 2) version, platform = version_and_platform.split("-", 2) - dependencies, requirements = rest.split("|", 2).map {|s| s.split(",") } if rest - dependencies = dependencies ? dependencies.map {|d| parse_dependency(d) } : [] - requirements = requirements ? requirements.map {|d| parse_dependency(d) } : [] + dependencies, requirements = rest.split("|", 2).map! {|s| s.split(",") } if rest + dependencies = dependencies ? dependencies.map! {|d| parse_dependency(d) } : EMPTY_ARRAY + requirements = requirements ? requirements.map! {|d| parse_dependency(d) } : EMPTY_ARRAY [version, platform, dependencies, requirements] end @@ -20,6 +23,7 @@ module Bundler def parse_dependency(string) dependency = string.split(":") dependency[-1] = dependency[-1].split("&") if dependency.size > 1 + dependency[0] = -dependency[0] dependency end end diff --git a/lib/bundler/compact_index_client/parser.rb b/lib/bundler/compact_index_client/parser.rb new file mode 100644 index 0000000000..3a0dec4907 --- /dev/null +++ b/lib/bundler/compact_index_client/parser.rb @@ -0,0 +1,111 @@ +# frozen_string_literal: true + +module Bundler + class CompactIndexClient + class Parser + # `compact_index` - an object responding to #names, #versions, #info(name, checksum), + # returning the file contents as a string + def initialize(compact_index) + @compact_index = compact_index + @info_checksums = nil + @versions_by_name = nil + @available = nil + @gem_parser = nil + @versions_data = nil + end + + def names + lines(@compact_index.names) + end + + def versions + @versions_by_name ||= Hash.new {|hash, key| hash[key] = [] } + @info_checksums = {} + + lines(@compact_index.versions).each do |line| + name, versions_string, checksum = line.split(" ", 3) + @info_checksums[name] = checksum || "" + versions_string.split(",") do |version| + delete = version.delete_prefix!("-") + version = version.split("-", 2).unshift(name) + if delete + @versions_by_name[name].delete(version) + else + @versions_by_name[name] << version + end + end + end + + @versions_by_name + end + + def info(name) + data = @compact_index.info(name, info_checksum(name)) + lines(data).map {|line| gem_parser.parse(line).unshift(name) } + end + + # parse the last, most recently updated line of the versions file to determine availability + def available? + return @available unless @available.nil? + return @available = false unless versions_data&.size&.nonzero? + + line_end = versions_data.size - 1 + return @available = false if versions_data[line_end] != "\n" + + line_start = versions_data.rindex("\n", line_end - 1) + line_start ||= -1 # allow a single line versions file + + @available = !split_last_word(versions_data, line_start + 1, line_end).nil? + end + + private + + # Search for a line starting with gem name, then return last space-separated word (the checksum) + def info_checksum(name) + return unless versions_data + return unless (line_start = rindex_of_gem(name)) + return unless (line_end = versions_data.index("\n", line_start)) + split_last_word(versions_data, line_start, line_end) + end + + def gem_parser + @gem_parser ||= GemParser.new + end + + def versions_data + @versions_data ||= begin + data = @compact_index.versions + strip_header!(data) if data + data.freeze + end + end + + def rindex_of_gem(name) + if (pos = versions_data.rindex("\n#{name} ")) + pos + 1 + elsif versions_data.start_with?("#{name} ") + 0 + end + end + + # This is similar to `string.split(" ").last` but it avoids allocating extra objects. + def split_last_word(string, line_start, line_end) + return unless line_start < line_end && line_start >= 0 + word_start = string.rindex(" ", line_end).to_i + 1 + return if word_start < line_start + string[word_start, line_end - word_start] + end + + def lines(string) + return [] if string.nil? || string.empty? + strip_header!(string) + string.split("\n") + end + + def strip_header!(string) + header_end = string.index("---\n") + string.slice!(0, header_end + 4) if header_end + end + end + end +end diff --git a/lib/bundler/compact_index_client/updater.rb b/lib/bundler/compact_index_client/updater.rb index 0f7bf9bb50..88c7146900 100644 --- a/lib/bundler/compact_index_client/updater.rb +++ b/lib/bundler/compact_index_client/updater.rb @@ -1,20 +1,11 @@ # frozen_string_literal: true -require_relative "../vendored_fileutils" - module Bundler class CompactIndexClient class Updater - class MisMatchedChecksumError < Error - def initialize(path, server_checksum, local_checksum) - @path = path - @server_checksum = server_checksum - @local_checksum = local_checksum - end - - def message - "The checksum of /#{@path} does not match the checksum provided by the server! Something is wrong " \ - "(local checksum is #{@local_checksum.inspect}, was expecting #{@server_checksum.inspect})." + class MismatchedChecksumError < Error + def initialize(path, message) + super "The checksum of /#{path} does not match the checksum provided by the server! Something is wrong. #{message}" end end @@ -22,95 +13,91 @@ module Bundler @fetcher = fetcher end - def update(local_path, remote_path, retrying = nil) - headers = {} - - local_temp_path = local_path.sub(/$/, ".#{$$}") - local_temp_path = local_temp_path.sub(/$/, ".retrying") if retrying - local_temp_path = local_temp_path.sub(/$/, ".tmp") - - # first try to fetch any new bytes on the existing file - if retrying.nil? && local_path.file? - copy_file local_path, local_temp_path + def update(remote_path, local_path, etag_path) + append(remote_path, local_path, etag_path) || replace(remote_path, local_path, etag_path) + rescue CacheFile::DigestMismatchError => e + raise MismatchedChecksumError.new(remote_path, e.message) + rescue Zlib::GzipFile::Error + raise Bundler::HTTPError + end - headers["If-None-Match"] = etag_for(local_temp_path) - headers["Range"] = - if local_temp_path.size.nonzero? - # Subtract a byte to ensure the range won't be empty. - # Avoids 416 (Range Not Satisfiable) responses. - "bytes=#{local_temp_path.size - 1}-" - else - "bytes=#{local_temp_path.size}-" - end - end + private - response = @fetcher.call(remote_path, headers) - return nil if response.is_a?(Net::HTTPNotModified) + def append(remote_path, local_path, etag_path) + return false unless local_path.file? && local_path.size.nonzero? - content = response.body + CacheFile.copy(local_path) do |file| + etag = etag_path.read.tap(&:chomp!) if etag_path.file? - etag = (response["ETag"] || "").gsub(%r{\AW/}, "") - correct_response = SharedHelpers.filesystem_access(local_temp_path) do - if response.is_a?(Net::HTTPPartialContent) && local_temp_path.size.nonzero? - local_temp_path.open("a") {|f| f << slice_body(content, 1..-1) } + # Subtract a byte to ensure the range won't be empty. + # Avoids 416 (Range Not Satisfiable) responses. + response = @fetcher.call(remote_path, request_headers(etag, file.size - 1)) + break true if response.is_a?(Gem::Net::HTTPNotModified) - etag_for(local_temp_path) == etag + file.digests = parse_digests(response) + # server may ignore Range and return the full response + if response.is_a?(Gem::Net::HTTPPartialContent) + break false unless file.append(response.body.byteslice(1..-1)) else - local_temp_path.open("wb") {|f| f << content } - - etag.length.zero? || etag_for(local_temp_path) == etag + file.write(response.body) end + CacheFile.write(etag_path, etag_from_response(response)) + true end + end - if correct_response - SharedHelpers.filesystem_access(local_path) do - FileUtils.mv(local_temp_path, local_path) - end - return nil - end - - if retrying - raise MisMatchedChecksumError.new(remote_path, etag, etag_for(local_temp_path)) - end + # request without range header to get the full file or a 304 Not Modified + def replace(remote_path, local_path, etag_path) + etag = etag_path.read.tap(&:chomp!) if etag_path.file? + response = @fetcher.call(remote_path, request_headers(etag)) + return true if response.is_a?(Gem::Net::HTTPNotModified) + CacheFile.write(local_path, response.body, parse_digests(response)) + CacheFile.write(etag_path, etag_from_response(response)) + end - update(local_path, remote_path, :retrying) - rescue Zlib::GzipFile::Error - raise Bundler::HTTPError - ensure - FileUtils.remove_file(local_temp_path) if File.exist?(local_temp_path) + def request_headers(etag, range_start = nil) + headers = {} + headers["Range"] = "bytes=#{range_start}-" if range_start + headers["If-None-Match"] = %("#{etag}") if etag + headers end - def etag_for(path) - sum = checksum_for_file(path) - sum ? %("#{sum}") : nil + def etag_for_request(etag_path) + etag_path.read.tap(&:chomp!) if etag_path.file? end - def slice_body(body, range) - body.byteslice(range) + def etag_from_response(response) + return unless response["ETag"] + etag = response["ETag"].delete_prefix("W/") + return if etag.delete_prefix!('"') && !etag.delete_suffix!('"') + etag end - def checksum_for_file(path) - return nil unless path.file? - # This must use File.read instead of Digest.file().hexdigest - # because we need to preserve \n line endings on windows when calculating - # the checksum - SharedHelpers.filesystem_access(path, :read) do - SharedHelpers.digest(:MD5).hexdigest(File.read(path)) + # Unwraps and returns a Hash of digest algorithms and base64 values + # according to RFC 8941 Structured Field Values for HTTP. + # https://www.rfc-editor.org/rfc/rfc8941#name-parsing-a-byte-sequence + # Ignores unsupported algorithms. + def parse_digests(response) + return unless header = response["Repr-Digest"] || response["Digest"] + digests = {} + header.split(",") do |param| + algorithm, value = param.split("=", 2) + algorithm.strip! + algorithm.downcase! + next unless SUPPORTED_DIGESTS.key?(algorithm) + next unless value = byte_sequence(value) + digests[algorithm] = value end + digests.empty? ? nil : digests end - private - - def copy_file(source, dest) - SharedHelpers.filesystem_access(source, :read) do - File.open(source, "r") do |s| - SharedHelpers.filesystem_access(dest, :write) do - File.open(dest, "wb", s.stat.mode) do |f| - IO.copy_stream(s, f) - end - end - end - end + # Unwrap surrounding colons (byte sequence) + # The wrapping characters must be matched or we return nil. + # Also handles quotes because right now rubygems.org sends them. + def byte_sequence(value) + return if value.delete_prefix!(":") && !value.delete_suffix!(":") + return if value.delete_prefix!('"') && !value.delete_suffix!('"') + value end end end diff --git a/lib/bundler/constants.rb b/lib/bundler/constants.rb index 8dd8a53815..9564771e78 100644 --- a/lib/bundler/constants.rb +++ b/lib/bundler/constants.rb @@ -1,7 +1,14 @@ # frozen_string_literal: true +require "rbconfig" + module Bundler WINDOWS = RbConfig::CONFIG["host_os"] =~ /(msdos|mswin|djgpp|mingw)/ + deprecate_constant :WINDOWS + FREEBSD = RbConfig::CONFIG["host_os"].to_s.include?("bsd") - NULL = WINDOWS ? "NUL" : "/dev/null" + deprecate_constant :FREEBSD + + NULL = File::NULL + deprecate_constant :NULL end diff --git a/lib/bundler/current_ruby.rb b/lib/bundler/current_ruby.rb index 1d2d8ff2fb..93e0c401c0 100644 --- a/lib/bundler/current_ruby.rb +++ b/lib/bundler/current_ruby.rb @@ -43,7 +43,7 @@ module Bundler ].freeze def ruby? - return true if Bundler::GemHelpers.generic_local_platform == Gem::Platform::RUBY + return true if Bundler::GemHelpers.generic_local_platform_is_ruby? !windows? && (RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx" || RUBY_ENGINE == "maglev" || RUBY_ENGINE == "truffleruby") end diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 1444cc2b0a..6cf1f9a255 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -18,7 +18,8 @@ module Bundler :platforms, :ruby_version, :lockfile, - :gemfiles + :gemfiles, + :locked_checksums ) # Given a gemfile and lockfile creates a Bundler definition @@ -68,7 +69,6 @@ module Bundler @sources = sources @unlock = unlock @optional_groups = optional_groups - @remote = false @prefer_local = false @specs = nil @ruby_version = ruby_version @@ -76,22 +76,27 @@ module Bundler @lockfile = lockfile @lockfile_contents = String.new + @locked_bundler_version = nil - @locked_ruby_version = nil + @resolved_bundler_version = nil + + @locked_ruby_version = nil @new_platform = nil @removed_platform = nil - if lockfile && File.exist?(lockfile) + if lockfile_exists? @lockfile_contents = Bundler.read_file(lockfile) @locked_gems = LockfileParser.new(@lockfile_contents) @locked_platforms = @locked_gems.platforms @platforms = @locked_platforms.dup @locked_bundler_version = @locked_gems.bundler_version @locked_ruby_version = @locked_gems.ruby_version + @originally_locked_deps = @locked_gems.dependencies @originally_locked_specs = SpecSet.new(@locked_gems.specs) + @locked_checksums = @locked_gems.checksums if unlock != true - @locked_deps = @locked_gems.dependencies + @locked_deps = @originally_locked_deps @locked_specs = @originally_locked_specs @locked_sources = @locked_gems.sources else @@ -106,9 +111,11 @@ module Bundler @locked_gems = nil @locked_deps = {} @locked_specs = SpecSet.new([]) + @originally_locked_deps = {} @originally_locked_specs = @locked_specs @locked_sources = [] @locked_platforms = [] + @locked_checksums = nil end locked_gem_sources = @locked_sources.select {|s| s.is_a?(Source::Rubygems) } @@ -124,7 +131,7 @@ module Bundler @sources.merged_gem_lockfile_sections!(locked_gem_sources.first) end - @unlock[:sources] ||= [] + @sources_to_unlock = @unlock.delete(:sources) || [] @unlock[:ruby] ||= if @ruby_version && locked_ruby_version_object @ruby_version.diff(locked_ruby_version_object) end @@ -136,17 +143,19 @@ module Bundler @path_changes = converge_paths @source_changes = converge_sources + @explicit_unlocks = @unlock.delete(:gems) || [] + if @unlock[:conservative] - @unlock[:gems] ||= @dependencies.map(&:name) + @gems_to_unlock = @explicit_unlocks.any? ? @explicit_unlocks : @dependencies.map(&:name) else - eager_unlock = (@unlock[:gems] || []).map {|name| Dependency.new(name, ">= 0") } - @unlock[:gems] = @locked_specs.for(eager_unlock, false, platforms).map(&:name).uniq + eager_unlock = @explicit_unlocks.map {|name| Dependency.new(name, ">= 0") } + @gems_to_unlock = @locked_specs.for(eager_unlock, false, platforms).map(&:name).uniq end @dependency_changes = converge_dependencies @local_changes = converge_locals - @incomplete_lockfile = check_missing_lockfile_specs + check_lockfile end def gem_version_promoter @@ -154,37 +163,24 @@ module Bundler end def resolve_only_locally! - @remote = false sources.local_only! resolve end def resolve_with_cache! + sources.local! sources.cached! resolve end def resolve_remotely! - @remote = true + sources.cached! sources.remote! resolve end - def resolution_mode=(options) - if options["local"] - @remote = false - else - @remote = true - @prefer_local = options["prefer-local"] - end - end - - def setup_sources_for_resolve - if @remote == false - sources.cached! - else - sources.remote! - end + def prefer_local! + @prefer_local = true end # For given dependency list returns a SpecSet with Gemspec of all the required @@ -217,8 +213,8 @@ module Bundler rescue BundlerError => e @resolve = nil @resolver = nil + @resolution_packages = nil @specs = nil - @gem_version_promoter = nil Bundler.ui.debug "The definition is missing dependencies, failed to resolve & materialize locally (#{e})" true @@ -233,8 +229,17 @@ module Bundler end def current_dependencies + filter_relevant(dependencies) + end + + def current_locked_dependencies + filter_relevant(locked_dependencies) + end + + def filter_relevant(dependencies) + platforms_array = [generic_local_platform].freeze dependencies.select do |d| - d.should_include? && !d.gem_platforms([generic_local_platform]).empty? + d.should_include? && !d.gem_platforms(platforms_array).empty? end end @@ -258,9 +263,15 @@ module Bundler def dependencies_for(groups) groups.map!(&:to_sym) - current_dependencies.reject do |d| - (d.groups & groups).empty? + deps = current_dependencies # always returns a new array + deps.select! do |d| + if RUBY_VERSION >= "3.1" + d.groups.intersect?(groups) + else + !(d.groups & groups).empty? + end end + deps end # Resolve all the dependencies specified in Gemfile. It ensures that @@ -272,7 +283,7 @@ module Bundler @resolve ||= if Bundler.frozen_bundle? Bundler.ui.debug "Frozen, using resolution from the lockfile" @locked_specs - elsif !unlocking? && nothing_changed? + elsif no_resolve_needed? if deleted_deps.any? Bundler.ui.debug "Some dependencies were deleted, using a subset of the resolution from the lockfile" SpecSet.new(filter_specs(@locked_specs, @dependencies - deleted_deps)) @@ -285,7 +296,12 @@ module Bundler end end else - Bundler.ui.debug "Found changes from the lockfile, re-resolving dependencies because #{change_reason}" + if lockfile_exists? + Bundler.ui.debug "Found changes from the lockfile, re-resolving dependencies because #{change_reason}" + else + Bundler.ui.debug "Resolving dependencies because there's no lockfile" + end + start_resolution end end @@ -298,34 +314,26 @@ module Bundler dependencies.map(&:groups).flatten.uniq end - def lock(file, preserve_unknown_sections = false) - return if Definition.no_lock - - contents = to_lock - - # Convert to \r\n if the existing lock has them - # i.e., Windows with `git config core.autocrlf=true` - contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match?("\r\n") - - if @locked_bundler_version - locked_major = @locked_bundler_version.segments.first - current_major = Bundler.gem_version.segments.first - - updating_major = locked_major < current_major - end + def lock(file_or_preserve_unknown_sections = false, preserve_unknown_sections_or_unused = false) + if [true, false, nil].include?(file_or_preserve_unknown_sections) + target_lockfile = lockfile || Bundler.default_lockfile + preserve_unknown_sections = file_or_preserve_unknown_sections + else + target_lockfile = file_or_preserve_unknown_sections + preserve_unknown_sections = preserve_unknown_sections_or_unused - preserve_unknown_sections ||= !updating_major && (Bundler.frozen_bundle? || !(unlocking? || @unlocking_bundler)) + suggestion = if target_lockfile == lockfile + "To fix this warning, remove it from the `Definition#lock` call." + else + "Instead, instantiate a new definition passing `#{target_lockfile}`, and call `lock` without a file argument on that definition" + end - return if file && File.exist?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections) + msg = "`Definition#lock` was passed a target file argument. #{suggestion}" - if Bundler.frozen_bundle? - Bundler.ui.error "Cannot write a changed lockfile while frozen." - return + Bundler::SharedHelpers.major_deprecation 2, msg end - SharedHelpers.filesystem_access(file) do |p| - File.open(p, "wb") {|f| f.puts(contents) } - end + write_lock(target_lockfile, preserve_unknown_sections) end def locked_ruby_version @@ -349,25 +357,16 @@ module Bundler end end + def bundler_version_to_lock + @resolved_bundler_version || Bundler.gem_version + end + def to_lock require_relative "lockfile_generator" LockfileGenerator.generate(self) end def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false) - msg = String.new - msg << "You are trying to install in deployment mode after changing\n" \ - "your Gemfile. Run `bundle install` elsewhere and add the\n" \ - "updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control." - - unless explicit_flag - suggested_command = unless Bundler.settings.locations("frozen").keys.include?(:env) - "bundle config set frozen false" - end - msg << "\n\nIf this is a development machine, remove the #{Bundler.default_gemfile} " \ - "freeze \nby running `#{suggested_command}`." if suggested_command - end - added = [] deleted = [] changed = [] @@ -381,32 +380,36 @@ module Bundler deleted.concat deleted_deps.map {|d| "* #{pretty_dep(d)}" } if deleted_deps.any? both_sources = Hash.new {|h, k| h[k] = [] } - @dependencies.each {|d| both_sources[d.name][0] = d } - - locked_dependencies.each do |d| - next if !Bundler.feature_flag.bundler_3_mode? && @locked_specs[d.name].empty? - - both_sources[d.name][1] = d - end + current_dependencies.each {|d| both_sources[d.name][0] = d } + current_locked_dependencies.each {|d| both_sources[d.name][1] = d } both_sources.each do |name, (dep, lock_dep)| next if dep.nil? || lock_dep.nil? - gemfile_source = dep.source || sources.default_source - lock_source = lock_dep.source || sources.default_source + gemfile_source = dep.source || default_source + lock_source = lock_dep.source || default_source next if lock_source.include?(gemfile_source) - gemfile_source_name = dep.source ? gemfile_source.identifier : "no specified source" - lockfile_source_name = lock_dep.source ? lock_source.identifier : "no specified source" + gemfile_source_name = dep.source ? gemfile_source.to_gemfile : "no specified source" + lockfile_source_name = lock_dep.source ? lock_source.to_gemfile : "no specified source" changed << "* #{name} from `#{lockfile_source_name}` to `#{gemfile_source_name}`" end reason = change_reason - msg << "\n\n#{reason.split(", ").map(&:capitalize).join("\n")}" unless reason.strip.empty? + msg = String.new + msg << "#{reason.capitalize.strip}, but the lockfile can't be updated because frozen mode is set" msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any? msg << "\n\nYou have deleted from the Gemfile:\n" << deleted.join("\n") if deleted.any? msg << "\n\nYou have changed in the Gemfile:\n" << changed.join("\n") if changed.any? - msg << "\n" + msg << "\n\nRun `bundle install` elsewhere and add the updated #{SharedHelpers.relative_gemfile_path} to version control.\n" + + unless explicit_flag + suggested_command = unless Bundler.settings.locations("frozen").keys.include?(:env) + "bundle config set frozen false" + end + msg << "If this is a development machine, remove the #{SharedHelpers.relative_lockfile_path} " \ + "freeze by running `#{suggested_command}`." if suggested_command + end raise ProductionError, msg if added.any? || deleted.any? || changed.any? || !nothing_changed? end @@ -445,8 +448,8 @@ module Bundler return if current_platform_locked? raise ProductionError, "Your bundle only supports platforms #{@platforms.map(&:to_s)} " \ - "but your local platform is #{Bundler.local_platform}. " \ - "Add the current platform to the lockfile with\n`bundle lock --add-platform #{Bundler.local_platform}` and try again." + "but your local platform is #{local_platform}. " \ + "Add the current platform to the lockfile with\n`bundle lock --add-platform #{local_platform}` and try again." end def add_platform(platform) @@ -471,7 +474,21 @@ module Bundler private :sources def nothing_changed? - !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@incomplete_lockfile + return false unless lockfile_exists? + + !@source_changes && + !@dependency_changes && + !@new_platform && + !@path_changes && + !@local_changes && + !@missing_lockfile_dep && + !@unlocking_bundler && + !@locked_spec_with_missing_deps && + !@locked_spec_with_invalid_deps + end + + def no_resolve_needed? + !unlocking? && nothing_changed? end def unlocking? @@ -480,20 +497,75 @@ module Bundler private + def should_add_extra_platforms? + !lockfile_exists? && generic_local_platform_is_ruby? && !Bundler.settings[:force_ruby_platform] + end + + def lockfile_exists? + file_exists?(lockfile) + end + + def file_exists?(file) + file && File.exist?(file) + end + + def write_lock(file, preserve_unknown_sections) + return if Definition.no_lock + + contents = to_lock + + # Convert to \r\n if the existing lock has them + # i.e., Windows with `git config core.autocrlf=true` + contents.gsub!(/\n/, "\r\n") if @lockfile_contents.match?("\r\n") + + if @locked_bundler_version + locked_major = @locked_bundler_version.segments.first + current_major = bundler_version_to_lock.segments.first + + updating_major = locked_major < current_major + end + + preserve_unknown_sections ||= !updating_major && (Bundler.frozen_bundle? || !(unlocking? || @unlocking_bundler)) + + if file_exists?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections) + return if Bundler.frozen_bundle? + SharedHelpers.filesystem_access(file) { FileUtils.touch(file) } + return + end + + if Bundler.frozen_bundle? + Bundler.ui.error "Cannot write a changed lockfile while frozen." + return + end + + SharedHelpers.filesystem_access(file) do |p| + File.open(p, "wb") {|f| f.puts(contents) } + end + end + def resolver @resolver ||= Resolver.new(resolution_packages, gem_version_promoter) end def expanded_dependencies - dependencies + metadata_dependencies + dependencies_with_bundler + metadata_dependencies + end + + def dependencies_with_bundler + return dependencies unless @unlocking_bundler + return dependencies if dependencies.map(&:name).include?("bundler") + + [Dependency.new("bundler", @unlocking_bundler)] + dependencies end def resolution_packages @resolution_packages ||= begin last_resolve = converge_locked_specs - remove_ruby_from_platforms_if_necessary!(current_dependencies) - packages = Resolver::Base.new(source_requirements, expanded_dependencies, last_resolve, @platforms, :locked_specs => @originally_locked_specs, :unlock => @unlock[:gems], :prerelease => gem_version_promoter.pre?) - additional_base_requirements_for_resolve(packages, last_resolve) + remove_invalid_platforms!(current_dependencies) + packages = Resolver::Base.new(source_requirements, expanded_dependencies, last_resolve, @platforms, locked_specs: @originally_locked_specs, unlock: @gems_to_unlock, prerelease: gem_version_promoter.pre?) + packages = additional_base_requirements_to_prevent_downgrades(packages, last_resolve) + packages = additional_base_requirements_to_force_updates(packages) + packages end end @@ -508,7 +580,7 @@ module Bundler if missing_specs.any? missing_specs.each do |s| locked_gem = @locked_specs[s.name].last - next if locked_gem.nil? || locked_gem.version != s.version || !@remote + next if locked_gem.nil? || locked_gem.version != s.version || sources.local_mode? raise GemNotFound, "Your bundle is locked to #{locked_gem} from #{locked_gem.source}, but that version can " \ "no longer be found in that source. That means the author of #{locked_gem} has removed it. " \ "You'll need to update your bundle to a version other than #{locked_gem} that hasn't been " \ @@ -527,7 +599,7 @@ module Bundler break if incomplete_specs.empty? Bundler.ui.debug("The lockfile does not have all gems needed for the current platform though, Bundler will still re-resolve dependencies") - setup_sources_for_resolve + sources.remote! resolution_packages.delete(incomplete_specs) @resolve = start_resolution specs = resolve.materialize(dependencies) @@ -549,9 +621,14 @@ module Bundler end def start_resolution - result = resolver.start + result = SpecSet.new(resolver.start) + + @resolved_bundler_version = result.find {|spec| spec.name == "bundler" }&.version + @platforms = result.add_extra_platforms!(platforms) if should_add_extra_platforms? - SpecSet.new(SpecSet.new(result).for(dependencies, false, @platforms)) + result.complete_platforms!(platforms) + + SpecSet.new(result.for(dependencies, false, @platforms)) end def precompute_source_requirements_for_indirect_dependencies? @@ -572,7 +649,7 @@ module Bundler end def current_ruby_platform_locked? - return false unless generic_local_platform == Gem::Platform::RUBY + return false unless generic_local_platform_is_ruby? return false if Bundler.settings[:force_ruby_platform] && !@platforms.include?(Gem::Platform::RUBY) current_platform_locked? @@ -580,7 +657,7 @@ module Bundler def current_platform_locked? @platforms.any? do |bundle_platform| - MatchPlatform.platforms_match?(bundle_platform, Bundler.local_platform) + MatchPlatform.platforms_match?(bundle_platform, local_platform) end end @@ -592,14 +669,18 @@ module Bundler def change_reason if unlocking? - unlock_reason = @unlock.reject {|_k, v| Array(v).empty? }.map do |k, v| - if v == true - k.to_s - else - v = Array(v) - "#{k}: (#{v.join(", ")})" - end - end.join(", ") + unlock_targets = if @gems_to_unlock.any? + ["gems", @gems_to_unlock] + elsif @sources_to_unlock.any? + ["sources", @sources_to_unlock] + end + + unlock_reason = if unlock_targets + "#{unlock_targets.first}: (#{unlock_targets.last.join(", ")})" + else + @unlock[:ruby] ? "ruby" : "" + end + return "bundler is unlocking #{unlock_reason}" end [ @@ -608,7 +689,10 @@ module Bundler [@new_platform, "you added a new platform to your gemfile"], [@path_changes, "the gemspecs for path gems changed"], [@local_changes, "the gemspecs for git local gems changed"], - [@incomplete_lockfile, "your lock file is missing some gems"], + [@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""], + [@unlocking_bundler, "an update to the version of Bundler itself was requested"], + [@locked_spec_with_missing_deps, "your lock file includes \"#{@locked_spec_with_missing_deps}\" but not some of its dependencies"], + [@locked_spec_with_invalid_deps, "your lockfile does not satisfy dependencies of \"#{@locked_spec_with_invalid_deps}\""], ].select(&:first).map(&:last).join(", ") end @@ -635,8 +719,7 @@ module Bundler locked_index = Index.new locked_index.use(@locked_specs.select {|s| source.can_lock?(s) }) - # order here matters, since Index#== is checking source.specs.include?(locked_index) - locked_index != source.specs + !locked_index.subset?(source.specs) rescue PathError, GitError => e Bundler.ui.debug "Assuming that #{source} has not changed since fetching its specs errored (#{e})" false @@ -652,7 +735,7 @@ module Bundler spec = @dependencies.find {|s| s.name == k } source = spec&.source if source&.respond_to?(:local_override!) - source.unlock! if @unlock[:gems].include?(spec.name) + source.unlock! if @gems_to_unlock.include?(spec.name) locals << [source, source.local_override!(v)] end end @@ -660,22 +743,39 @@ module Bundler sources_with_changes = locals.select do |source, changed| changed || specs_changed?(source) end.map(&:first) - !sources_with_changes.each {|source| @unlock[:sources] << source.name }.empty? + !sources_with_changes.each {|source| @sources_to_unlock << source.name }.empty? end - def check_missing_lockfile_specs - all_locked_specs = @locked_specs.map(&:name) << "bundler" + def check_lockfile + @missing_lockfile_dep = nil + + @locked_spec_with_invalid_deps = nil + @locked_spec_with_missing_deps = nil - missing = @locked_specs.select do |s| - s.dependencies.any? {|dep| !all_locked_specs.include?(dep.name) } + missing = [] + invalid = [] + + @locked_specs.each do |s| + validation = @locked_specs.validate_deps(s) + + missing << s if validation == :missing + invalid << s if validation == :invalid end if missing.any? @locked_specs.delete(missing) - true - else - false + @locked_spec_with_missing_deps = missing.first.name + elsif !@dependency_changes + @missing_lockfile_dep = current_dependencies.find do |d| + @locked_specs[d.name].empty? && d.name != "bundler" + end&.name + end + + if invalid.any? + @locked_specs.delete(invalid) + + @locked_spec_with_invalid_deps = invalid.first.name end end @@ -710,12 +810,17 @@ module Bundler changes = sources.replace_sources!(@locked_sources) sources.all_sources.each do |source| + # has to be done separately, because we want to keep the locked checksum + # store for a source, even when doing a full update + if @locked_checksums && @locked_gems && locked_source = @locked_gems.sources.find {|s| s == source && !s.equal?(source) } + source.checksum_store.merge!(locked_source.checksum_store) + end # If the source is unlockable and the current command allows an unlock of # the source (for example, you are doing a `bundle update <foo>` of a git-pinned # gem), unlock it. For git sources, this means to unlock the revision, which # will cause the `ref` used to be the most recent for the branch (or master) if # an explicit `ref` is not used. - if source.respond_to?(:unlock!) && @unlock[:sources].include?(source.name) + if source.respond_to?(:unlock!) && @sources_to_unlock.include?(source.name) source.unlock! changes = true end @@ -732,9 +837,7 @@ module Bundler dep.source = sources.get(dep.source) end - next if unlocking? - - unless locked_dep = @locked_deps[dep.name] + unless locked_dep = @originally_locked_deps[dep.name] changes = true next end @@ -761,7 +864,7 @@ module Bundler def converge_locked_specs converged = converge_specs(@locked_specs) - resolve = SpecSet.new(converged.reject {|s| @unlock[:gems].include?(s.name) }) + resolve = SpecSet.new(converged.reject {|s| @gems_to_unlock.include?(s.name) }) diff = nil @@ -780,37 +883,38 @@ module Bundler def converge_specs(specs) converged = [] - - deps = @dependencies.select do |dep| - specs[dep].any? {|s| s.satisfies?(dep) && (!dep.source || s.source.include?(dep.source)) } - end + deps = [] @specs_that_changed_sources = [] specs.each do |s| + name = s.name dep = @dependencies.find {|d| s.satisfies?(d) } + lockfile_source = s.source - # Replace the locked dependency's source with the equivalent source from the Gemfile - s.source = if dep&.source - gemfile_source = dep.source - lockfile_source = s.source + if dep + gemfile_source = dep.source || default_source @specs_that_changed_sources << s if gemfile_source != lockfile_source + deps << dep if !dep.source || lockfile_source.include?(dep.source) + @gems_to_unlock << name if lockfile_source.include?(dep.source) && lockfile_source != gemfile_source - gemfile_source + # Replace the locked dependency's source with the equivalent source from the Gemfile + s.source = gemfile_source else - sources.get_with_fallback(s.source) + # Replace the locked dependency's source with the default source, if the locked source is no longer in the Gemfile + s.source = default_source unless sources.get(lockfile_source) end - next if @unlock[:sources].include?(s.source.name) + next if @sources_to_unlock.include?(s.source.name) # Path sources have special logic if s.source.instance_of?(Source::Path) || s.source.instance_of?(Source::Gemspec) new_specs = begin s.source.specs - rescue PathError, GitError + rescue PathError # if we won't need the source (according to the lockfile), - # don't error if the path/git source isn't available + # don't error if the path source isn't available next if specs. for(requested_dependencies, false). none? {|locked_spec| locked_spec.source == s.source } @@ -824,12 +928,12 @@ module Bundler else # If the spec is no longer in the path source, unlock it. This # commonly happens if the version changed in the gemspec - @unlock[:gems] << s.name + @gems_to_unlock << name end end - if dep.nil? && requested_dependencies.find {|d| s.name == d.name } - @unlock[:gems] << s.name + if dep.nil? && requested_dependencies.find {|d| name == d.name } + @gems_to_unlock << s.name else converged << s end @@ -840,7 +944,7 @@ module Bundler def metadata_dependencies @metadata_dependencies ||= [ - Dependency.new("Ruby\0", Gem.ruby_version), + Dependency.new("Ruby\0", Bundler::RubyVersion.system.gem_version), Dependency.new("RubyGems\0", Gem::VERSION), ] end @@ -852,20 +956,32 @@ module Bundler source_requirements = if precompute_source_requirements_for_indirect_dependencies? all_requirements = source_map.all_requirements all_requirements = pin_locally_available_names(all_requirements) if @prefer_local - { :default => sources.default_source }.merge(all_requirements) + { default: default_source }.merge(all_requirements) else - { :default => Source::RubygemsAggregate.new(sources, source_map) }.merge(source_map.direct_requirements) + { default: Source::RubygemsAggregate.new(sources, source_map) }.merge(source_map.direct_requirements) end - source_requirements.merge!(source_map.locked_requirements) unless @remote + source_requirements.merge!(source_map.locked_requirements) if nothing_changed? metadata_dependencies.each do |dep| source_requirements[dep.name] = sources.metadata_source end - source_requirements[:default_bundler] = source_requirements["bundler"] || sources.default_source - source_requirements["bundler"] = sources.metadata_source # needs to come last to override + + default_bundler_source = source_requirements["bundler"] || default_source + + if @unlocking_bundler + default_bundler_source.add_dependency_names("bundler") + else + source_requirements[:default_bundler] = default_bundler_source + source_requirements["bundler"] = sources.metadata_source # needs to come last to override + end + verify_changed_sources! source_requirements end + def default_source + sources.default_source + end + def verify_changed_sources! @specs_that_changed_sources.each do |s| if s.source.specs.search(s.name).empty? @@ -894,7 +1010,7 @@ module Bundler current == proposed end - def additional_base_requirements_for_resolve(resolution_packages, last_resolve) + def additional_base_requirements_to_prevent_downgrades(resolution_packages, last_resolve) return resolution_packages unless @locked_gems && !sources.expired_sources?(@locked_gems.sources) converge_specs(@originally_locked_specs - last_resolve).each do |locked_spec| next if locked_spec.source.is_a?(Source::Path) @@ -903,16 +1019,39 @@ module Bundler resolution_packages end - def remove_ruby_from_platforms_if_necessary!(dependencies) - return if Bundler.frozen_bundle? || - Bundler.local_platform == Gem::Platform::RUBY || - !platforms.include?(Gem::Platform::RUBY) || - (@new_platform && platforms.last == Gem::Platform::RUBY) || + def additional_base_requirements_to_force_updates(resolution_packages) + return resolution_packages if @explicit_unlocks.empty? + full_update = dup_for_full_unlock.resolve + @explicit_unlocks.each do |name| + version = full_update[name].first&.version + resolution_packages.base_requirements[name] = Gem::Requirement.new("= #{version}") if version + end + resolution_packages + end + + def dup_for_full_unlock + unlocked_definition = self.class.new(@lockfile, @dependencies, @sources, true, @ruby_version, @optional_groups, @gemfiles) + unlocked_definition.gem_version_promoter.tap do |gvp| + gvp.level = gem_version_promoter.level + gvp.strict = gem_version_promoter.strict + gvp.pre = gem_version_promoter.pre + end + unlocked_definition + end + + def remove_invalid_platforms!(dependencies) + return if Bundler.frozen_bundle? + + platforms.reverse_each do |platform| + next if local_platform == platform || + (@new_platform && platforms.last == platform) || + @path_changes || @dependency_changes || - !@originally_locked_specs.incomplete_ruby_specs?(dependencies) + !@originally_locked_specs.incomplete_for_platform?(dependencies, platform) - remove_platform(Gem::Platform::RUBY) - add_current_platform + remove_platform(platform) + add_current_platform if platform == Gem::Platform::RUBY + end end def source_map diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 21a4564dcc..2a4f72fe55 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -7,21 +7,21 @@ require_relative "rubygems_ext" module Bundler class Dependency < Gem::Dependency attr_reader :autorequire - attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref + attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref, :glob - ALL_RUBY_VERSIONS = ((18..27).to_a + (30..33).to_a).freeze + ALL_RUBY_VERSIONS = (18..27).to_a.concat((30..34).to_a).freeze PLATFORM_MAP = { - :ruby => [Gem::Platform::RUBY, ALL_RUBY_VERSIONS], - :mri => [Gem::Platform::RUBY, ALL_RUBY_VERSIONS], - :rbx => [Gem::Platform::RUBY], - :truffleruby => [Gem::Platform::RUBY], - :jruby => [Gem::Platform::JAVA, [18, 19]], - :windows => [Gem::Platform::WINDOWS, ALL_RUBY_VERSIONS], + ruby: [Gem::Platform::RUBY, ALL_RUBY_VERSIONS], + mri: [Gem::Platform::RUBY, ALL_RUBY_VERSIONS], + rbx: [Gem::Platform::RUBY], + truffleruby: [Gem::Platform::RUBY], + jruby: [Gem::Platform::JAVA, [18, 19]], + windows: [Gem::Platform::WINDOWS, ALL_RUBY_VERSIONS], # deprecated - :mswin => [Gem::Platform::MSWIN, ALL_RUBY_VERSIONS], - :mswin64 => [Gem::Platform::MSWIN64, ALL_RUBY_VERSIONS - [18]], - :mingw => [Gem::Platform::MINGW, ALL_RUBY_VERSIONS], - :x64_mingw => [Gem::Platform::X64_MINGW, ALL_RUBY_VERSIONS - [18, 19]], + mswin: [Gem::Platform::MSWIN, ALL_RUBY_VERSIONS], + mswin64: [Gem::Platform::MSWIN64, ALL_RUBY_VERSIONS - [18]], + mingw: [Gem::Platform::MINGW, ALL_RUBY_VERSIONS], + x64_mingw: [Gem::Platform::X64_MINGW, ALL_RUBY_VERSIONS - [18, 19]], }.each_with_object({}) do |(platform, spec), hash| hash[platform] = spec[0] spec[1]&.each {|version| hash[:"#{platform}_#{version}"] = spec[0] } @@ -39,6 +39,7 @@ module Bundler @github = options["github"] @branch = options["branch"] @ref = options["ref"] + @glob = options["glob"] @platforms = Array(options["platforms"]) @env = options["env"] @should_include = options.fetch("should_include", true) @@ -48,10 +49,13 @@ module Bundler @autorequire = Array(options["require"] || []) if options.key?("require") end + RUBY_PLATFORM_ARRAY = [Gem::Platform::RUBY].freeze + private_constant :RUBY_PLATFORM_ARRAY + # Returns the platforms this dependency is valid for, in the same order as # passed in the `valid_platforms` parameter def gem_platforms(valid_platforms) - return [Gem::Platform::RUBY] if force_ruby_platform + return RUBY_PLATFORM_ARRAY if force_ruby_platform return valid_platforms if @platforms.empty? valid_platforms.select {|p| expanded_platforms.include?(GemHelpers.generic(p)) } @@ -65,6 +69,10 @@ module Bundler @should_include && current_env? && current_platform? end + def gemspec_dev_dep? + type == :development + end + def current_env? return true unless @env if @env.is_a?(Hash) diff --git a/lib/bundler/digest.rb b/lib/bundler/digest.rb index 148e9f7788..2c6d971f1b 100644 --- a/lib/bundler/digest.rb +++ b/lib/bundler/digest.rb @@ -50,7 +50,7 @@ module Bundler words.map!.with_index {|word, index| SHA1_MASK & (word + mutated[index]) } end - words.pack("N*").unpack("H*").first + words.pack("N*").unpack1("H*") end private diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 03c80a408c..6af80fb31f 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -18,9 +18,10 @@ module Bundler VALID_KEYS = %w[group groups git path glob name branch ref tag require submodules platform platforms type source install_if gemfile force_ruby_platform].freeze - GITHUB_PULL_REQUEST_URL = %r{\Ahttps://github\.com/([A-Za-z0-9_\-\.]+/[A-Za-z0-9_\-\.]+)/pull/(\d+)\z}.freeze + GITHUB_PULL_REQUEST_URL = %r{\Ahttps://github\.com/([A-Za-z0-9_\-\.]+/[A-Za-z0-9_\-\.]+)/pull/(\d+)\z} + GITLAB_MERGE_REQUEST_URL = %r{\Ahttps://gitlab\.com/([A-Za-z0-9_\-\./]+)/-/merge_requests/(\d+)\z} - attr_reader :gemspecs + attr_reader :gemspecs, :gemfile attr_accessor :dependencies def initialize @@ -46,7 +47,7 @@ module Bundler @gemfile = expanded_gemfile_path @gemfiles << expanded_gemfile_path contents ||= Bundler.read_file(@gemfile.to_s) - instance_eval(contents.dup.tap {|x| x.untaint if RUBY_VERSION < "2.7" }, gemfile.to_s, 1) + instance_eval(contents, @gemfile.to_s, 1) rescue Exception => e # rubocop:disable Lint/RescueException message = "There was an error " \ "#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \ @@ -76,11 +77,11 @@ module Bundler @gemspecs << spec - gem spec.name, :name => spec.name, :path => path, :glob => glob + gem spec.name, name: spec.name, path: path, glob: glob group(development_group) do spec.development_dependencies.each do |dep| - gem dep.name, *(dep.requirement.as_list + [:type => :development]) + gem dep.name, *(dep.requirement.as_list + [type: :development]) end end when 0 @@ -102,39 +103,51 @@ module Bundler # if there's already a dependency with this name we try to prefer one if current = @dependencies.find {|d| d.name == dep.name } - deleted_dep = @dependencies.delete(current) if current.type == :development + if current.requirement != dep.requirement + current_requirement_open = current.requirements_list.include?(">= 0") - unless deleted_dep - if current.requirement != dep.requirement - return if dep.type == :development + gemspec_dep = [dep, current].find(&:gemspec_dev_dep?) + if gemspec_dep + gemfile_dep = [dep, current].find(&:runtime?) + unless current_requirement_open + Bundler.ui.warn "A gemspec development dependency (#{gemspec_dep.name}, #{gemspec_dep.requirement}) is being overridden by a Gemfile dependency (#{gemfile_dep.name}, #{gemfile_dep.requirement}).\n" \ + "This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement\n" + end + else update_prompt = "" if File.basename(@gemfile) == Injector::INJECTED_GEMS - if dep.requirements_list.include?(">= 0") && !current.requirements_list.include?(">= 0") + if dep.requirements_list.include?(">= 0") && !current_requirement_open update_prompt = ". Gem already added" else update_prompt = ". If you want to update the gem version, run `bundle update #{current.name}`" - update_prompt += ". You may also need to change the version requirement specified in the Gemfile if it's too restrictive." unless current.requirements_list.include?(">= 0") + update_prompt += ". You may also need to change the version requirement specified in the Gemfile if it's too restrictive." unless current_requirement_open end end raise GemfileError, "You cannot specify the same gem twice with different version requirements.\n" \ - "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \ - "#{update_prompt}" - elsif current.source != dep.source - return if dep.type == :development - raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \ - "You specified that #{dep.name} (#{dep.requirement}) should come from " \ - "#{current.source || "an unspecified source"} and #{dep.source}\n" - else - Bundler.ui.warn "Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once.\n" \ - "You should probably keep only one of them.\n" \ - "Remove any duplicate entries and specify the gem only once.\n" \ - "While it's not a problem now, it could cause errors if you change the version of one of them later." + "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \ + "#{update_prompt}" end end + + # Always prefer the dependency from the Gemfile + if current.gemspec_dev_dep? + @dependencies.delete(current) + elsif dep.gemspec_dev_dep? + return + elsif current.source != dep.source + raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \ + "You specified that #{dep.name} (#{dep.requirement}) should come from " \ + "#{current.source || "an unspecified source"} and #{dep.source}\n" + else + Bundler.ui.warn "Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once.\n" \ + "You should probably keep only one of them.\n" \ + "Remove any duplicate entries and specify the gem only once.\n" \ + "While it's not a problem now, it could cause errors if you change the version of one of them later." + end end @dependencies << dep @@ -296,6 +309,20 @@ module Bundler repo_name ||= user_name "https://#{user_name}@bitbucket.org/#{user_name}/#{repo_name}.git" end + + git_source(:gitlab) do |repo_name| + if repo_name =~ GITLAB_MERGE_REQUEST_URL + { + "git" => "https://gitlab.com/#{$1}.git", + "branch" => nil, + "ref" => "refs/merge-requests/#{$2}/head", + "tag" => nil, + } + else + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + "https://gitlab.com/#{repo_name}.git" + end + end end def with_source(source) @@ -397,13 +424,11 @@ module Bundler end def validate_keys(command, opts, valid_keys) - invalid_keys = opts.keys - valid_keys - - git_source = opts.keys & @git_sources.keys.map(&:to_s) - if opts["branch"] && !(opts["git"] || opts["github"] || git_source.any?) + if opts["branch"] && !(opts["git"] || opts["github"] || (opts.keys & @git_sources.keys.map(&:to_s)).any?) raise GemfileError, %(The `branch` option for `#{command}` is not allowed. Only gems with a git source can specify a branch) end + invalid_keys = opts.keys - valid_keys return true unless invalid_keys.any? message = String.new @@ -422,9 +447,13 @@ module Bundler def normalize_source(source) case source when :gemcutter, :rubygems, :rubyforge - Bundler::SharedHelpers.major_deprecation 2, "The source :#{source} is deprecated because HTTP " \ - "requests are insecure.\nPlease change your source to 'https://" \ - "rubygems.org' if possible, or 'http://rubygems.org' if not." + message = + "The source :#{source} is deprecated because HTTP requests are insecure.\n" \ + "Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not." + removed_message = + "The source :#{source} is disallowed because HTTP requests are insecure.\n" \ + "Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not." + Bundler::SharedHelpers.major_deprecation 2, message, removed_message: removed_message "http://rubygems.org" when String source @@ -469,10 +498,17 @@ module Bundler "should come from that source" raise GemfileEvalError, msg else - Bundler::SharedHelpers.major_deprecation 2, "Your Gemfile contains multiple global sources. " \ + message = + "Your Gemfile contains multiple global sources. " \ "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." + removed_message = + "Your Gemfile contains multiple global sources. " \ + "Using `source` more than once without a block is a security risk, and " \ + "may result in installing unexpected gems. To resolve this error, use " \ + "a block to indicate which gems should come from the secondary source." + Bundler::SharedHelpers.major_deprecation 2, message, removed_message: removed_message end end diff --git a/lib/bundler/endpoint_specification.rb b/lib/bundler/endpoint_specification.rb index 863544b1f9..87cb352efa 100644 --- a/lib/bundler/endpoint_specification.rb +++ b/lib/bundler/endpoint_specification.rb @@ -94,7 +94,7 @@ module Bundler def _local_specification return unless @loaded_from && File.exist?(local_specification_path) - eval(File.read(local_specification_path)).tap do |spec| + eval(File.read(local_specification_path), nil, local_specification_path).tap do |spec| spec.loaded_from = @loaded_from end end @@ -125,7 +125,11 @@ module Bundler next unless v case k.to_s when "checksum" - @checksum = v.last + begin + @checksum = Checksum.from_api(v.last, @spec_fetcher.uri) + rescue ArgumentError => e + raise ArgumentError, "Invalid checksum for #{full_name}: #{e.message}" + end when "rubygems" @required_rubygems_version = Gem::Requirement.new(v) when "ruby" diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 4f8b6f605d..f6cb198e38 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -40,11 +40,11 @@ module Bundler out << "\n## Gemfile\n" gemfiles.each do |gemfile| - out << "\n### #{Pathname.new(gemfile).relative_path_from(SharedHelpers.pwd)}\n\n" + out << "\n### #{SharedHelpers.relative_path_to(gemfile)}\n\n" out << "```ruby\n" << read_file(gemfile).chomp << "\n```\n" end - out << "\n### #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}\n\n" + out << "\n### #{SharedHelpers.relative_path_to(Bundler.default_lockfile)}\n\n" out << "```\n" << read_file(Bundler.default_lockfile).chomp << "\n```\n" end diff --git a/lib/bundler/environment_preserver.rb b/lib/bundler/environment_preserver.rb index 57013f5d50..444ab6fd37 100644 --- a/lib/bundler/environment_preserver.rb +++ b/lib/bundler/environment_preserver.rb @@ -19,14 +19,7 @@ module Bundler BUNDLER_PREFIX = "BUNDLER_ORIG_" def self.from_env - new(env_to_hash(ENV), BUNDLER_KEYS) - end - - def self.env_to_hash(env) - to_hash = env.to_hash - return to_hash unless Gem.win_platform? - - to_hash.each_with_object({}) {|(k,v), a| a[k.upcase] = v } + new(ENV.to_hash, BUNDLER_KEYS) end # @param env [Hash] @@ -39,18 +32,7 @@ module Bundler # Replaces `ENV` with the bundler environment variables backed up def replace_with_backup - unless Gem.win_platform? - ENV.replace(backup) - return - end - - # Fallback logic for Windows below to workaround - # https://bugs.ruby-lang.org/issues/16798. Can be dropped once all - # supported rubies include the fix for that. - - ENV.clear - - backup.each {|k, v| ENV[k] = v } + ENV.replace(backup) end # @return [Hash] @@ -58,9 +40,9 @@ module Bundler env = @original.clone @keys.each do |key| value = env[key] - if !value.nil? && !value.empty? + if !value.nil? env[@prefix + key] ||= value - elsif value.nil? + else env[@prefix + key] ||= INTENTIONALLY_NIL end end @@ -72,7 +54,7 @@ module Bundler env = @original.clone @keys.each do |key| value_original = env[@prefix + key] - next if value_original.nil? || value_original.empty? + next if value_original.nil? if value_original == INTENTIONALLY_NIL env.delete(key) else diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb index 5839fc6a73..c29b1bfed8 100644 --- a/lib/bundler/errors.rb +++ b/lib/bundler/errors.rb @@ -52,6 +52,49 @@ module Bundler class GemfileEvalError < GemfileError; end class MarshalError < StandardError; end + class ChecksumMismatchError < SecurityError + def initialize(lock_name, existing, checksum) + @lock_name = lock_name + @existing = existing + @checksum = checksum + end + + def message + <<~MESSAGE + Bundler found mismatched checksums. This is a potential security risk. + #{@lock_name} #{@existing.to_lock} + from #{@existing.sources.join("\n and ")} + #{@lock_name} #{@checksum.to_lock} + from #{@checksum.sources.join("\n and ")} + + #{mismatch_resolution_instructions} + To ignore checksum security warnings, disable checksum validation with + `bundle config set --local disable_checksum_validation true` + MESSAGE + end + + def mismatch_resolution_instructions + removable, remote = [@existing, @checksum].partition(&:removable?) + case removable.size + when 0 + msg = +"Mismatched checksums each have an authoritative source:\n" + msg << " 1. #{@existing.sources.reject(&:removable?).map(&:to_s).join(" and ")}\n" + msg << " 2. #{@checksum.sources.reject(&:removable?).map(&:to_s).join(" and ")}\n" + msg << "You may need to alter your Gemfile sources to resolve this issue.\n" + when 1 + msg = +"If you trust #{remote.first.sources.first}, to resolve this issue you can:\n" + msg << removable.first.removal_instructions + when 2 + msg = +"To resolve this issue you can either:\n" + msg << @checksum.removal_instructions + msg << "or if you are sure that the new checksum from #{@checksum.sources.first} is correct:\n" + msg << @existing.removal_instructions + end + end + + status_code(37) + end + class PermissionError < BundlerError def initialize(path, permission_type = :write) @path = path @@ -172,4 +215,33 @@ module Bundler status_code(36) end + + class InsecureInstallPathError < BundlerError + def initialize(path) + @path = path + end + + def message + "The installation path is insecure. Bundler cannot continue.\n" \ + "#{@path} is world-writable (without sticky bit).\n" \ + "Bundler cannot safely replace gems in world-writeable directories due to potential vulnerabilities.\n" \ + "Please change the permissions of this directory or choose a different install path." + end + + status_code(38) + end + + class CorruptBundlerInstallError < BundlerError + def initialize(loaded_spec) + @loaded_spec = loaded_spec + end + + def message + "The running version of Bundler (#{Bundler::VERSION}) does not match the version of the specification installed for it (#{@loaded_spec.version}). " \ + "This can be caused by reinstalling Ruby without removing previous installation, leaving around an upgraded default version of Bundler. " \ + "Reinstalling Ruby from scratch should fix the problem." + end + + status_code(39) + end end diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index 983de3137c..ab2189f7f0 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -37,7 +37,6 @@ module Bundler settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") } settings_flag(:print_only_version_number) { bundler_3_mode? } settings_flag(:setup_makes_kernel_gem_public) { !bundler_3_mode? } - settings_flag(:suppress_install_using_messages) { bundler_3_mode? } settings_flag(:update_requires_all_flag) { bundler_4_mode? } settings_option(:default_cli_command) { bundler_3_mode? ? :cli_help : :install } diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb index e12c15af8a..6288b22dcd 100644 --- a/lib/bundler/fetcher.rb +++ b/lib/bundler/fetcher.rb @@ -1,14 +1,15 @@ # frozen_string_literal: true require_relative "vendored_persistent" +require_relative "vendored_timeout" require "cgi" require "securerandom" require "zlib" -require "rubygems/request" module Bundler # Handles all the fetching with the rubygems server class Fetcher + autoload :Base, File.expand_path("fetcher/base", __dir__) autoload :CompactIndex, File.expand_path("fetcher/compact_index", __dir__) autoload :Downloader, File.expand_path("fetcher/downloader", __dir__) autoload :Dependency, File.expand_path("fetcher/dependency", __dir__) @@ -61,6 +62,16 @@ module Bundler end end + # This error is raised if HTTP authentication is correct, but lacks + # necessary permissions. + class AuthenticationForbiddenError < HTTPError + def initialize(remote_uri) + remote_uri = filter_uri(remote_uri) + super "Access token could not be authenticated for #{remote_uri}.\n" \ + "Make sure it's valid and has the necessary scopes configured." + end + end + # Exceptions classes that should bypass retry attempts. If your password didn't work the # first time, it's not going to the third time. NET_ERRORS = [:HTTPBadGateway, :HTTPBadRequest, :HTTPFailedDependency, @@ -70,9 +81,9 @@ module Bundler :HTTPRequestURITooLong, :HTTPUnauthorized, :HTTPUnprocessableEntity, :HTTPUnsupportedMediaType, :HTTPVersionNotSupported].freeze FAIL_ERRORS = begin - fail_errors = [AuthenticationRequiredError, BadAuthenticationError, FallbackError] + fail_errors = [AuthenticationRequiredError, BadAuthenticationError, AuthenticationForbiddenError, FallbackError, SecurityError] fail_errors << Gem::Requirement::BadRequirementError - fail_errors.concat(NET_ERRORS.map {|e| Net.const_get(e) }) + fail_errors.concat(NET_ERRORS.map {|e| Gem::Net.const_get(e) }) end.freeze class << self @@ -84,6 +95,7 @@ module Bundler self.max_retries = Bundler.settings[:retry] # How many retries for the API call def initialize(remote) + @cis = nil @remote = remote Socket.do_not_reverse_lookup = true @@ -99,15 +111,17 @@ module Bundler spec -= [nil, "ruby", ""] spec_file_name = "#{spec.join "-"}.gemspec" - uri = Bundler::URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz") - if uri.scheme == "file" - path = Bundler.rubygems.correct_for_windows_path(uri.path) + uri = Gem::URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz") + spec = if uri.scheme == "file" + path = Gem::Util.correct_for_windows_path(uri.path) Bundler.safe_load_marshal Bundler.rubygems.inflate(Gem.read_binary(path)) elsif cached_spec_path = gemspec_cached_path(spec_file_name) Bundler.load_gemspec(cached_spec_path) else Bundler.safe_load_marshal Bundler.rubygems.inflate(downloader.fetch(uri).body) end + raise MarshalError, "is #{spec.inspect}" unless spec.is_a?(Gem::Specification) + spec rescue MarshalError raise HTTPError, "Gemspec #{spec} contained invalid data.\n" \ "Your network or your gem server is probably having issues right now." @@ -124,20 +138,11 @@ module Bundler def specs(gem_names, source) index = Bundler::Index.new - if Bundler::Fetcher.disable_endpoint - @use_api = false - specs = fetchers.last.specs(gem_names) - else - specs = [] - @fetchers = fetchers.drop_while do |f| - !f.available? || (f.api_fetcher? && !gem_names) || !specs = f.specs(gem_names) - end - @use_api = false if fetchers.none?(&:api_fetcher?) - end - - specs.each do |name, version, platform, dependencies, metadata| + fetch_specs(gem_names).each do |name, version, platform, dependencies, metadata| spec = if dependencies - EndpointSpecification.new(name, version, platform, self, dependencies, metadata) + EndpointSpecification.new(name, version, platform, self, dependencies, metadata).tap do |es| + source.checksum_store.replace(es, es.checksum) + end else RemoteSpecification.new(name, version, platform, self) end @@ -148,22 +153,10 @@ module Bundler index rescue CertificateFailureError - Bundler.ui.info "" if gem_names && use_api # newline after dots + Bundler.ui.info "" if gem_names && api_fetcher? # newline after dots raise end - def use_api - return @use_api if defined?(@use_api) - - fetchers.shift until fetchers.first.available? - - @use_api = if remote_uri.scheme == "file" || Bundler::Fetcher.disable_endpoint - false - else - fetchers.first.api_fetcher? - end - end - def user_agent @user_agent ||= begin ruby = Bundler::RubyVersion.system @@ -199,10 +192,6 @@ module Bundler end end - def fetchers - @fetchers ||= FETCHERS.map {|f| f.new(downloader, @remote, uri) } - end - def http_proxy return unless uri = connection.proxy_uri uri.to_s @@ -212,25 +201,49 @@ module Bundler "#<#{self.class}:0x#{object_id} uri=#{uri}>" end + def api_fetcher? + fetchers.first.api_fetcher? + end + + def gem_remote_fetcher + @gem_remote_fetcher ||= begin + require_relative "fetcher/gem_remote_fetcher" + fetcher = GemRemoteFetcher.new Gem.configuration[:http_proxy] + fetcher.headers["User-Agent"] = user_agent + fetcher.headers["X-Gemfile-Source"] = @remote.original_uri.to_s if @remote.original_uri + fetcher + end + end + private - FETCHERS = [CompactIndex, Dependency, Index].freeze + def available_fetchers + if Bundler::Fetcher.disable_endpoint + [Index] + elsif remote_uri.scheme == "file" + Bundler.ui.debug("Using a local server, bundler won't use the CompactIndex API") + [Index] + else + [CompactIndex, Dependency, Index] + end + end + + def fetchers + @fetchers ||= available_fetchers.map {|f| f.new(downloader, @remote, uri, gem_remote_fetcher) }.drop_while {|f| !f.available? } + end + + def fetch_specs(gem_names) + fetchers.reject!(&:api_fetcher?) unless gem_names + fetchers.reject! do |f| + specs = f.specs(gem_names) + return specs if specs + true + end + [] + end def cis - env_cis = { - "TRAVIS" => "travis", - "CIRCLECI" => "circle", - "SEMAPHORE" => "semaphore", - "JENKINS_URL" => "jenkins", - "BUILDBOX" => "buildbox", - "GO_SERVER_URL" => "go", - "SNAP_CI" => "snap", - "GITLAB_CI" => "gitlab", - "GITHUB_ACTIONS" => "github", - "CI_NAME" => ENV["CI_NAME"], - "CI" => "ci", - } - env_cis.find_all {|env, _| ENV[env] }.map {|_, ci| ci } + @cis ||= Bundler::CIDetector.ci_strings end def connection @@ -240,9 +253,9 @@ module Bundler Bundler.settings[:ssl_client_cert] raise SSLError if needs_ssl && !defined?(OpenSSL::SSL) - con = PersistentHTTP.new :name => "bundler", :proxy => :ENV + con = Gem::Net::HTTP::Persistent.new name: "bundler", proxy: :ENV if gem_proxy = Gem.configuration[:http_proxy] - con.proxy = Bundler::URI.parse(gem_proxy) if gem_proxy != :no_proxy + con.proxy = Gem::URI.parse(gem_proxy) if gem_proxy != :no_proxy end if remote_uri.scheme == "https" @@ -275,10 +288,10 @@ module Bundler end HTTP_ERRORS = [ - Timeout::Error, EOFError, SocketError, Errno::ENETDOWN, Errno::ENETUNREACH, + Gem::Timeout::Error, EOFError, SocketError, Errno::ENETDOWN, Errno::ENETUNREACH, Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EAGAIN, - Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, - PersistentHTTP::Error, Zlib::BufError, Errno::EHOSTUNREACH + Gem::Net::HTTPBadResponse, Gem::Net::HTTPHeaderSyntaxError, Gem::Net::ProtocolError, + Gem::Net::HTTP::Persistent::Error, Zlib::BufError, Errno::EHOSTUNREACH ].freeze def bundler_cert_store @@ -294,6 +307,7 @@ module Bundler end else store.set_default_paths + require "rubygems/request" Gem::Request.get_cert_files.each {|c| store.add_file c } end store diff --git a/lib/bundler/fetcher/base.rb b/lib/bundler/fetcher/base.rb index 62cc75add8..cfec2f8e94 100644 --- a/lib/bundler/fetcher/base.rb +++ b/lib/bundler/fetcher/base.rb @@ -6,12 +6,14 @@ module Bundler attr_reader :downloader attr_reader :display_uri attr_reader :remote + attr_reader :gem_remote_fetcher - def initialize(downloader, remote, display_uri) + def initialize(downloader, remote, display_uri, gem_remote_fetcher) raise "Abstract class" if self.class == Base @downloader = downloader @remote = remote @display_uri = display_uri + @gem_remote_fetcher = gem_remote_fetcher end def remote_uri @@ -38,9 +40,9 @@ module Bundler private - def log_specs(debug_msg) + def log_specs(&block) if Bundler.ui.debug? - Bundler.ui.debug debug_msg + Bundler.ui.debug yield else Bundler.ui.info ".", false end diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index 674d2b49f1..6e5656d26a 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -4,8 +4,6 @@ require_relative "base" require_relative "../worker" module Bundler - autoload :CompactIndexClient, File.expand_path("../compact_index_client", __dir__) - class Fetcher class CompactIndex < Base def self.compact_index_request(method_name) @@ -13,9 +11,9 @@ module Bundler undef_method(method_name) define_method(method_name) do |*args, &blk| method.bind(self).call(*args, &blk) - rescue NetworkDownError, CompactIndexClient::Updater::MisMatchedChecksumError => e + rescue NetworkDownError, CompactIndexClient::Updater::MismatchedChecksumError => e raise HTTPError, e.message - rescue AuthenticationRequiredError + rescue AuthenticationRequiredError, BadAuthenticationError # Fail since we got a 401 from the server. raise rescue HTTPError => e @@ -35,16 +33,9 @@ module Bundler remaining_gems = gem_names.dup until remaining_gems.empty? - log_specs "Looking up gems #{remaining_gems.inspect}" - - deps = begin - parallel_compact_index_client.dependencies(remaining_gems) - rescue TooManyRequestsError - @bundle_worker&.stop - @bundle_worker = nil # reset it. Not sure if necessary - serial_compact_index_client.dependencies(remaining_gems) - end - next_gems = deps.map {|d| d[3].map(&:first).flatten(1) }.flatten(1).uniq + log_specs { "Looking up gems #{remaining_gems.inspect}" } + deps = fetch_gem_infos(remaining_gems).flatten(1) + next_gems = deps.flat_map {|d| d[CompactIndexClient::INFO_DEPS].flat_map(&:first) }.uniq deps.each {|dep| gem_info << dep } complete_gems.concat(deps.map(&:first)).uniq! remaining_gems = next_gems - complete_gems @@ -60,13 +51,9 @@ module Bundler Bundler.ui.debug("FIPS mode is enabled, bundler can't use the CompactIndex API") return nil end - if fetch_uri.scheme == "file" - Bundler.ui.debug("Using a local server, bundler won't use the CompactIndex API") - return false - end # Read info file checksums out of /versions, so we can know if gems are up to date - compact_index_client.update_and_parse_checksums! - rescue CompactIndexClient::Updater::MisMatchedChecksumError => e + compact_index_client.available? + rescue CompactIndexClient::Updater::MismatchedChecksumError => e Bundler.ui.debug(e.message) nil end @@ -85,20 +72,20 @@ module Bundler end end - def parallel_compact_index_client - compact_index_client.execution_mode = lambda do |inputs, &blk| - func = lambda {|object, _index| blk.call(object) } - worker = bundle_worker(func) - inputs.each {|input| worker.enq(input) } - inputs.map { worker.deq } - end - - compact_index_client + def fetch_gem_infos(names) + in_parallel(names) {|name| compact_index_client.info(name) } + rescue TooManyRequestsError # rubygems.org is rate limiting us, slow down. + @bundle_worker&.stop + @bundle_worker = nil # reset it. Not sure if necessary + compact_index_client.reset! + names.map {|name| compact_index_client.info(name) } end - def serial_compact_index_client - compact_index_client.sequential_execution_mode! - compact_index_client + def in_parallel(inputs, &blk) + func = lambda {|object, _index| blk.call(object) } + worker = bundle_worker(func) + inputs.each {|input| worker.enq(input) } + inputs.map { worker.deq } end def bundle_worker(func = nil) @@ -125,7 +112,7 @@ module Bundler rescue NetworkDownError => e raise unless Bundler.feature_flag.allow_offline_install? && headers["If-None-Match"] ui.warn "Using the cached data for the new index because of a network error: #{e}" - Net::HTTPNotModified.new(nil, nil, nil) + Gem::Net::HTTPNotModified.new(nil, nil, nil) end end end diff --git a/lib/bundler/fetcher/dependency.rb b/lib/bundler/fetcher/dependency.rb index 18b606abb6..0b807c9a4b 100644 --- a/lib/bundler/fetcher/dependency.rb +++ b/lib/bundler/fetcher/dependency.rb @@ -24,7 +24,7 @@ module Bundler def specs(gem_names, full_dependency_list = [], last_spec_list = []) query_list = gem_names.uniq - full_dependency_list - log_specs "Query List: #{query_list.inspect}" + log_specs { "Query List: #{query_list.inspect}" } return last_spec_list if query_list.empty? diff --git a/lib/bundler/fetcher/downloader.rb b/lib/bundler/fetcher/downloader.rb index 28d33f1aed..868b39b959 100644 --- a/lib/bundler/fetcher/downloader.rb +++ b/lib/bundler/fetcher/downloader.rb @@ -20,31 +20,35 @@ module Bundler Bundler.ui.debug("HTTP #{response.code} #{response.message} #{filtered_uri}") case response - when Net::HTTPSuccess, Net::HTTPNotModified + when Gem::Net::HTTPSuccess, Gem::Net::HTTPNotModified response - when Net::HTTPRedirection - new_uri = Bundler::URI.parse(response["location"]) + when Gem::Net::HTTPRedirection + new_uri = Gem::URI.parse(response["location"]) if new_uri.host == uri.host new_uri.user = uri.user new_uri.password = uri.password end fetch(new_uri, headers, counter + 1) - when Net::HTTPRequestedRangeNotSatisfiable + when Gem::Net::HTTPRequestedRangeNotSatisfiable new_headers = headers.dup new_headers.delete("Range") new_headers["Accept-Encoding"] = "gzip" fetch(uri, new_headers) - when Net::HTTPRequestEntityTooLarge + when Gem::Net::HTTPRequestEntityTooLarge raise FallbackError, response.body - when Net::HTTPTooManyRequests + when Gem::Net::HTTPTooManyRequests raise TooManyRequestsError, response.body - when Net::HTTPUnauthorized + when Gem::Net::HTTPUnauthorized raise BadAuthenticationError, uri.host if uri.userinfo raise AuthenticationRequiredError, uri.host - when Net::HTTPNotFound - raise FallbackError, "Net::HTTPNotFound: #{filtered_uri}" + when Gem::Net::HTTPForbidden + raise AuthenticationForbiddenError, uri.host + when Gem::Net::HTTPNotFound + raise FallbackError, "Gem::Net::HTTPNotFound: #{filtered_uri}" else - raise HTTPError, "#{response.class}#{": #{response.body}" unless response.body.empty?}" + message = "Gem::#{response.class.name.gsub(/\AGem::/, "")}" + message += ": #{response.body}" unless response.body.empty? + raise HTTPError, message end end @@ -54,7 +58,7 @@ module Bundler filtered_uri = URICredentialsFilter.credential_filtered_uri(uri) Bundler.ui.debug "HTTP GET #{filtered_uri}" - req = Net::HTTP::Get.new uri.request_uri, headers + req = Gem::Net::HTTP::Get.new uri.request_uri, headers if uri.user user = CGI.unescape(uri.user) password = uri.password ? CGI.unescape(uri.password) : nil diff --git a/lib/bundler/fetcher/gem_remote_fetcher.rb b/lib/bundler/fetcher/gem_remote_fetcher.rb new file mode 100644 index 0000000000..3fc7b68263 --- /dev/null +++ b/lib/bundler/fetcher/gem_remote_fetcher.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require "rubygems/remote_fetcher" + +module Bundler + class Fetcher + class GemRemoteFetcher < Gem::RemoteFetcher + def request(*args) + super do |req| + req.delete("User-Agent") if headers["User-Agent"] + yield req if block_given? + end + end + end + end +end diff --git a/lib/bundler/fetcher/index.rb b/lib/bundler/fetcher/index.rb index 6bb9fcc193..6e37e1e5d1 100644 --- a/lib/bundler/fetcher/index.rb +++ b/lib/bundler/fetcher/index.rb @@ -6,7 +6,7 @@ module Bundler class Fetcher class Index < Base def specs(_gem_names) - Bundler.rubygems.fetch_all_remote_specs(remote) + Bundler.rubygems.fetch_all_remote_specs(remote, gem_remote_fetcher) rescue Gem::RemoteFetcher::FetchError => e case e.message when /certificate verify failed/ @@ -15,8 +15,7 @@ module Bundler raise BadAuthenticationError, remote_uri if remote_uri.userinfo raise AuthenticationRequiredError, remote_uri when /403/ - raise BadAuthenticationError, remote_uri if remote_uri.userinfo - raise AuthenticationRequiredError, remote_uri + raise AuthenticationForbiddenError, remote_uri else raise HTTPError, "Could not fetch specs from #{display_uri} due to underlying error <#{e.message}>" end diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb index b66a046d37..e61ed64450 100644 --- a/lib/bundler/friendly_errors.rb +++ b/lib/bundler/friendly_errors.rb @@ -32,7 +32,7 @@ module Bundler if Bundler.ui.debug? Bundler.ui.trace error else - Bundler.ui.error error.message, :wrap => true + Bundler.ui.error error.message, wrap: true end when Thor::Error Bundler.ui.error error.message @@ -40,7 +40,7 @@ module Bundler Bundler.ui.error "\nQuitting..." Bundler.ui.trace error when Gem::InvalidSpecificationException - Bundler.ui.error error.message, :wrap => true + Bundler.ui.error error.message, wrap: true when SystemExit when *[defined?(Java::JavaLang::OutOfMemoryError) && Java::JavaLang::OutOfMemoryError].compact Bundler.ui.error "\nYour JVM has run out of memory, and Bundler cannot continue. " \ diff --git a/lib/bundler/gem_helper.rb b/lib/bundler/gem_helper.rb index dcf759cded..5ce0ef6280 100644 --- a/lib/bundler/gem_helper.rb +++ b/lib/bundler/gem_helper.rb @@ -47,7 +47,7 @@ module Bundler built_gem_path = build_gem end - desc "Generate SHA512 checksum if #{name}-#{version}.gem into the checksums directory." + desc "Generate SHA512 checksum of #{name}-#{version}.gem into the checksums directory." task "build:checksum" => "build" do build_checksum(built_gem_path) end @@ -215,7 +215,7 @@ module Bundler def sh_with_status(cmd, &block) Bundler.ui.debug(cmd) SharedHelpers.chdir(base) do - outbuf = IO.popen(cmd, :err => [:child, :out], &:read) + outbuf = IO.popen(cmd, err: [:child, :out], &:read) status = $? block&.call(outbuf) if status.success? [outbuf, status] diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb index 2e6d788f9c..de007523ec 100644 --- a/lib/bundler/gem_helpers.rb +++ b/lib/bundler/gem_helpers.rb @@ -34,6 +34,11 @@ module Bundler end module_function :local_platform + def generic_local_platform_is_ruby? + generic_local_platform == Gem::Platform::RUBY + end + module_function :generic_local_platform_is_ruby? + def platform_specificity_match(spec_platform, user_platform) spec_platform = Gem::Platform.new(spec_platform) @@ -48,6 +53,13 @@ module Bundler end module_function :select_best_platform_match + def force_ruby_platform(specs) + matching = specs.select {|spec| spec.match_platform(Gem::Platform::RUBY) && spec.force_ruby_platform! } + + sort_best_platform_match(matching, Gem::Platform::RUBY) + end + module_function :force_ruby_platform + def sort_best_platform_match(matching, platform) exact = matching.select {|spec| spec.platform == platform } return exact if exact.any? @@ -107,8 +119,6 @@ module Bundler def same_deps(spec, exemplary_spec) same_runtime_deps = spec.dependencies.sort == exemplary_spec.dependencies.sort - return same_runtime_deps unless spec.is_a?(Gem::Specification) && exemplary_spec.is_a?(Gem::Specification) - same_metadata_deps = spec.required_ruby_version == exemplary_spec.required_ruby_version && spec.required_rubygems_version == exemplary_spec.required_rubygems_version same_runtime_deps && same_metadata_deps end diff --git a/lib/bundler/gem_version_promoter.rb b/lib/bundler/gem_version_promoter.rb index d281f46eeb..ecc65b4956 100644 --- a/lib/bundler/gem_version_promoter.rb +++ b/lib/bundler/gem_version_promoter.rb @@ -45,17 +45,37 @@ module Bundler # Given a Resolver::Package and an Array of Specifications of available # versions for a gem, this method will return the Array of Specifications - # sorted (and possibly truncated if strict is true) in an order to give - # preference to the current level (:major, :minor or :patch) when resolution - # is deciding what versions best resolve all dependencies in the bundle. + # sorted in an order to give preference to the current level (:major, :minor + # or :patch) when resolution is deciding what versions best resolve all + # dependencies in the bundle. # @param package [Resolver::Package] The package being resolved. # @param specs [Specification] An array of Specifications for the package. - # @return [Specification] A new instance of the Specification Array sorted and - # possibly filtered. + # @return [Specification] A new instance of the Specification Array sorted. def sort_versions(package, specs) - specs = filter_dep_specs(specs, package) if strict + locked_version = package.locked_version + + result = specs.sort do |a, b| + unless package.prerelease_specified? || pre? + a_pre = a.prerelease? + b_pre = b.prerelease? - sort_dep_specs(specs, package) + next 1 if a_pre && !b_pre + next -1 if b_pre && !a_pre + end + + if major? || locked_version.nil? + b <=> a + elsif either_version_older_than_locked?(a, b, locked_version) + b <=> a + elsif segments_do_not_match?(a, b, :major) + a <=> b + elsif !minor? && segments_do_not_match?(a, b, :minor) + a <=> b + else + b <=> a + end + end + post_sort(result, package.unlock?, locked_version) end # @return [bool] Convenience method for testing value of level variable. @@ -73,9 +93,18 @@ module Bundler pre == true end - private + # Given a Resolver::Package and an Array of Specifications of available + # versions for a gem, this method will truncate the Array if strict + # is true. That means filtering out downgrades from the version currently + # locked, and filtering out upgrades that go past the selected level (major, + # minor, or patch). + # @param package [Resolver::Package] The package being resolved. + # @param specs [Specification] An array of Specifications for the package. + # @return [Specification] A new instance of the Specification Array + # truncated. + def filter_versions(package, specs) + return specs unless strict - def filter_dep_specs(specs, package) locked_version = package.locked_version return specs if locked_version.nil? || major? @@ -89,35 +118,10 @@ module Bundler end end - def sort_dep_specs(specs, package) - locked_version = package.locked_version - - result = specs.sort do |a, b| - unless package.prerelease_specified? || pre? - a_pre = a.prerelease? - b_pre = b.prerelease? - - next -1 if a_pre && !b_pre - next 1 if b_pre && !a_pre - end - - if major? - a <=> b - elsif either_version_older_than_locked?(a, b, locked_version) - a <=> b - elsif segments_do_not_match?(a, b, :major) - b <=> a - elsif !minor? && segments_do_not_match?(a, b, :minor) - b <=> a - else - a <=> b - end - end - post_sort(result, package.unlock?, locked_version) - end + private def either_version_older_than_locked?(a, b, locked_version) - locked_version && (a.version < locked_version || b.version < locked_version) + a.version < locked_version || b.version < locked_version end def segments_do_not_match?(a, b, level) @@ -133,13 +137,13 @@ module Bundler if unlock || locked_version.nil? result else - move_version_to_end(result, locked_version) + move_version_to_beginning(result, locked_version) end end - def move_version_to_end(result, version) + def move_version_to_beginning(result, version) move, keep = result.partition {|s| s.version.to_s == version.to_s } - keep.concat(move) + move.concat(keep) end end end diff --git a/lib/bundler/graph.rb b/lib/bundler/graph.rb index 3c008e63e3..b22b17a453 100644 --- a/lib/bundler/graph.rb +++ b/lib/bundler/graph.rb @@ -84,7 +84,7 @@ module Bundler else raise ArgumentError, "2nd argument is invalid" end - label.nil? ? {} : { :label => label } + label.nil? ? {} : { label: label } end def spec_for_dependency(dependency) @@ -103,7 +103,7 @@ module Bundler end def g - @g ||= ::GraphViz.digraph(@graph_name, :concentrate => true, :normalize => true, :nodesep => 0.55) do |g| + @g ||= ::GraphViz.digraph(@graph_name, concentrate: true, normalize: true, nodesep: 0.55) do |g| g.edge[:weight] = 2 g.edge[:fontname] = g.node[:fontname] = "Arial, Helvetica, SansSerif" g.edge[:fontsize] = 12 @@ -114,10 +114,10 @@ module Bundler @groups.each do |group| g.add_nodes( group, { - :style => "filled", - :fillcolor => "#B9B9D5", - :shape => "box3d", - :fontsize => 16, + style: "filled", + fillcolor: "#B9B9D5", + shape: "box3d", + fontsize: 16, }.merge(@node_options[group]) ) end @@ -125,8 +125,8 @@ module Bundler @relations.each do |parent, children| children.each do |child| if @groups.include?(parent) - g.add_nodes(child, { :style => "filled", :fillcolor => "#B9B9D5" }.merge(@node_options[child])) - g.add_edges(parent, child, { :constraint => false }.merge(@edge_options["#{parent}_#{child}"])) + g.add_nodes(child, { style: "filled", fillcolor: "#B9B9D5" }.merge(@node_options[child])) + g.add_edges(parent, child, { constraint: false }.merge(@edge_options["#{parent}_#{child}"])) else g.add_nodes(child, @node_options[child]) g.add_edges(parent, child, @edge_options["#{parent}_#{child}"]) @@ -135,7 +135,7 @@ module Bundler end if @output_format.to_s == "debug" - $stdout.puts g.output :none => String + $stdout.puts g.output none: String Bundler.ui.info "debugging bundle viz..." else begin diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb index b8c599f63a..df46facc88 100644 --- a/lib/bundler/index.rb +++ b/lib/bundler/index.rb @@ -10,8 +10,8 @@ module Bundler i end - attr_reader :specs, :all_specs, :sources - protected :specs, :all_specs + attr_reader :specs, :duplicates, :sources + protected :specs, :duplicates RUBY = "ruby" NULL = "\0" @@ -19,21 +19,21 @@ module Bundler def initialize @sources = [] @cache = {} - @specs = Hash.new {|h, k| h[k] = {} } - @all_specs = Hash.new {|h, k| h[k] = EMPTY_SEARCH } + @specs = {} + @duplicates = {} end def initialize_copy(o) @sources = o.sources.dup @cache = {} - @specs = Hash.new {|h, k| h[k] = {} } - @all_specs = Hash.new {|h, k| h[k] = EMPTY_SEARCH } + @specs = {} + @duplicates = {} o.specs.each do |name, hash| @specs[name] = hash.dup end - o.all_specs.each do |name, array| - @all_specs[name] = array.dup + o.duplicates.each do |name, array| + @duplicates[name] = array.dup end end @@ -46,12 +46,11 @@ module Bundler true end - def search_all(name) - all_matches = local_search(name) + @all_specs[name] - @sources.each do |source| - all_matches.concat(source.search_all(name)) - end - all_matches + def search_all(name, &blk) + return enum_for(:search_all, name) unless blk + specs_by_name(name).each(&blk) + @duplicates[name]&.each(&blk) + @sources.each {|source| source.search_all(name, &blk) } end # Search this index's specs, and any source indexes that this index knows @@ -61,11 +60,14 @@ module Bundler return results unless @sources.any? @sources.each do |source| - results.concat(source.search(query)) + results = safe_concat(results, source.search(query)) end - results.uniq(&:full_name) + results.uniq!(&:full_name) unless results.empty? # avoid modifying frozen EMPTY_SEARCH + results end + alias_method :[], :search + def local_search(query) case query when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification then search_by_spec(query) @@ -76,12 +78,10 @@ module Bundler end end - alias_method :[], :search - - def <<(spec) - @specs[spec.name][spec.full_name] = spec - spec + def add(spec) + (@specs[spec.name] ||= {}).store(spec.full_name, spec) end + alias_method :<<, :add def each(&blk) return enum_for(:each) unless blk @@ -115,15 +115,25 @@ module Bundler names.uniq end - def use(other, override_dupes = false) + # Combines indexes proritizing existing specs, like `Hash#reverse_merge!` + # Duplicate specs found in `other` are stored in `@duplicates`. + def use(other) return unless other - other.each do |s| - if (dupes = search_by_spec(s)) && !dupes.empty? - # safe to << since it's a new array when it has contents - @all_specs[s.name] = dupes << s - next unless override_dupes + other.each do |spec| + exist?(spec) ? add_duplicate(spec) : add(spec) + end + self + end + + # Combines indexes proritizing specs from `other`, like `Hash#merge!` + # Duplicate specs found in `self` are saved in `@duplicates`. + def merge!(other) + return unless other + other.each do |spec| + if existing = find_by_spec(spec) + add_duplicate(existing) end - self << s + add spec end self end @@ -135,8 +145,7 @@ module Bundler end # Whether all the specs in self are in other - # TODO: rename to #include? - def ==(other) + def subset?(other) all? do |spec| other_spec = other[spec].first other_spec && dependencies_eql?(spec, other_spec) && spec.source == other_spec.source @@ -157,19 +166,40 @@ module Bundler private + def safe_concat(a, b) + return a if b.empty? + return b if a.empty? + a.concat(b) + end + + def add_duplicate(spec) + (@duplicates[spec.name] ||= []) << spec + end + def specs_by_name_and_version(name, version) - specs_by_name(name).select {|spec| spec.version == version } + results = @specs[name]&.values + return EMPTY_SEARCH unless results + results.select! {|spec| spec.version == version } + results end def specs_by_name(name) - @specs[name].values + @specs[name]&.values || EMPTY_SEARCH end EMPTY_SEARCH = [].freeze def search_by_spec(spec) - spec = @specs[spec.name][spec.full_name] + spec = find_by_spec(spec) spec ? [spec] : EMPTY_SEARCH end + + def find_by_spec(spec) + @specs[spec.name]&.fetch(spec.full_name, nil) + end + + def exist?(spec) + @specs[spec.name]&.key?(spec.full_name) + end end end diff --git a/lib/bundler/injector.rb b/lib/bundler/injector.rb index cb644a7f69..879b481339 100644 --- a/lib/bundler/injector.rb +++ b/lib/bundler/injector.rb @@ -29,7 +29,7 @@ module Bundler end # temporarily unfreeze - Bundler.settings.temporary(:deployment => false, :frozen => false) do + Bundler.settings.temporary(deployment: false, frozen: false) do # evaluate the Gemfile we have now builder = Dsl.new builder.eval_gemfile(gemfile_path) @@ -50,7 +50,7 @@ module Bundler append_to(gemfile_path, build_gem_lines(@options[:conservative_versioning])) if @deps.any? # since we resolved successfully, write out the lockfile - @definition.lock(Bundler.default_lockfile) + @definition.lock # invalidate the cached Bundler.definition Bundler.reset_paths! @@ -86,7 +86,7 @@ module Bundler segments = version.segments seg_end_index = version >= Gem::Version.new("1.0") ? 1 : 2 - prerelease_suffix = version.to_s.gsub(version.release.to_s, "") if version.prerelease? + prerelease_suffix = version.to_s.delete_prefix(version.release.to_s) if version.prerelease? "#{version_prefix}#{segments[0..seg_end_index].join(".")}#{prerelease_suffix}" end @@ -120,9 +120,10 @@ module Bundler github = ", :github => \"#{d.github}\"" unless d.github.nil? branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil? ref = ", :ref => \"#{d.ref}\"" unless d.ref.nil? + glob = ", :glob => \"#{d.glob}\"" unless d.glob.nil? require_path = ", :require => #{convert_autorequire(d.autorequire)}" unless d.autorequire.nil? - %(gem #{name}#{requirement}#{group}#{source}#{path}#{git}#{github}#{branch}#{ref}#{require_path}) + %(gem #{name}#{requirement}#{group}#{source}#{path}#{git}#{github}#{branch}#{ref}#{glob}#{require_path}) end.join("\n") end diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb index 5c184f67a1..ae4ccf2138 100644 --- a/lib/bundler/inline.rb +++ b/lib/bundler/inline.rb @@ -48,14 +48,14 @@ def gemfile(install = false, options = {}, &gemfile) builder.instance_eval(&gemfile) builder.check_primary_source_safety - Bundler.settings.temporary(:deployment => false, :frozen => false) do + Bundler.settings.temporary(deployment: false, frozen: false) do definition = builder.to_definition(nil, true) def definition.lock(*); end definition.validate_runtime! if install || definition.missing_specs? - Bundler.settings.temporary(:inline => true, :no_install => false) do - installer = Bundler::Installer.install(Bundler.root, definition, :system => true) + Bundler.settings.temporary(inline: true, no_install: false) do + installer = Bundler::Installer.install(Bundler.root, definition, system: true) installer.post_install_messages.each do |name, message| Bundler.ui.info "Post-install message from #{name}:\n#{message}" end diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 59b6a6ad22..256f0be348 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -81,7 +81,7 @@ module Bundler if resolve_if_needed(options) ensure_specs_are_compatible! - load_plugins + Bundler.load_plugins(@definition) options.delete(:jobs) else options[:jobs] = 1 # to avoid the overhead of Bundler::Worker @@ -136,12 +136,12 @@ module Bundler mode = Gem.win_platform? ? "wb:UTF-8" : "w" require "erb" - content = ERB.new(template, :trim_mode => "-").result(binding) + content = ERB.new(template, trim_mode: "-").result(binding) - File.write(binstub_path, content, :mode => mode, :perm => 0o777 & ~File.umask) + File.write(binstub_path, content, mode: mode, perm: 0o777 & ~File.umask) if Gem.win_platform? || options[:all_platforms] prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n" - File.write("#{binstub_path}.cmd", prefix + content, :mode => mode) + File.write("#{binstub_path}.cmd", prefix + content, mode: mode) end end @@ -179,12 +179,12 @@ module Bundler mode = Gem.win_platform? ? "wb:UTF-8" : "w" require "erb" - content = ERB.new(template, :trim_mode => "-").result(binding) + content = ERB.new(template, trim_mode: "-").result(binding) - File.write("#{bin_path}/#{executable}", content, :mode => mode, :perm => 0o755) + File.write("#{bin_path}/#{executable}", content, mode: mode, perm: 0o755) if Gem.win_platform? || options[:all_platforms] prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n" - File.write("#{bin_path}/#{executable}.cmd", prefix + content, :mode => mode) + File.write("#{bin_path}/#{executable}.cmd", prefix + content, mode: mode) end end end @@ -213,20 +213,6 @@ module Bundler Bundler.settings.processor_count end - def load_plugins - Bundler.rubygems.load_plugins - - requested_path_gems = @definition.requested_specs.select {|s| s.source.is_a?(Source::Path) } - path_plugin_files = requested_path_gems.map do |spec| - Bundler.rubygems.spec_matches_for_glob(spec, "rubygems_plugin#{Bundler.rubygems.suffix_pattern}") - rescue TypeError - error_message = "#{spec.name} #{spec.version} has an invalid gemspec" - raise Gem::InvalidSpecificationException, error_message - end.flatten - Bundler.rubygems.load_plugin_files(path_plugin_files) - Bundler.rubygems.load_env_plugins - end - def ensure_specs_are_compatible! @definition.specs.each do |spec| unless spec.matches_current_ruby? @@ -249,19 +235,19 @@ module Bundler # returns whether or not a re-resolve was needed def resolve_if_needed(options) - @definition.resolution_mode = options - - if !@definition.unlocking? && !options["force"] && !Bundler.settings[:inline] && Bundler.default_lockfile.file? - return false if @definition.nothing_changed? && !@definition.missing_specs? + @definition.prefer_local! if options["prefer-local"] + + if options["local"] || (@definition.no_resolve_needed? && !@definition.missing_specs?) + @definition.resolve_with_cache! + false + else + @definition.resolve_remotely! + true end - - @definition.setup_sources_for_resolve - - true end - def lock(opts = {}) - @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) + def lock + @definition.lock end end end diff --git a/lib/bundler/installer/gem_installer.rb b/lib/bundler/installer/gem_installer.rb index c855c7afa0..a7770eb7e0 100644 --- a/lib/bundler/installer/gem_installer.rb +++ b/lib/bundler/installer/gem_installer.rb @@ -17,11 +17,11 @@ module Bundler Bundler.ui.debug "#{worker}: #{spec.name} (#{spec.version}) from #{spec.loaded_from}" generate_executable_stubs [true, post_install_message] - rescue Bundler::InstallHookError, Bundler::SecurityError, Bundler::APIResponseMismatchError + rescue Bundler::InstallHookError, Bundler::SecurityError, Bundler::APIResponseMismatchError, Bundler::InsecureInstallPathError raise rescue Errno::ENOSPC [false, out_of_space_message] - rescue Bundler::BundlerError, Gem::InstallError, Bundler::APIResponseInvalidDependenciesError => e + rescue Bundler::BundlerError, Gem::InstallError => e [false, specific_failure_message(e)] end @@ -53,10 +53,9 @@ module Bundler def install spec.source.install( spec, - :force => force, - :ensure_builtin_gems_cached => standalone, - :build_args => Array(spec_settings), - :previous_spec => previous_spec, + force: force, + build_args: Array(spec_settings), + previous_spec: previous_spec, ) end @@ -77,7 +76,7 @@ module Bundler if Bundler.settings[:bin] && standalone installer.generate_standalone_bundler_executable_stubs(spec) elsif Bundler.settings[:bin] - installer.generate_bundler_executable_stubs(spec, :force => true) + installer.generate_bundler_executable_stubs(spec, force: true) end end end diff --git a/lib/bundler/installer/parallel_installer.rb b/lib/bundler/installer/parallel_installer.rb index 83a381f592..e745088f81 100644 --- a/lib/bundler/installer/parallel_installer.rb +++ b/lib/bundler/installer/parallel_installer.rb @@ -42,8 +42,7 @@ module Bundler # Checks installed dependencies against spec's dependencies to make # sure needed dependencies have been installed. - def dependencies_installed?(all_specs) - installed_specs = all_specs.select(&:installed?).map(&:name) + def dependencies_installed?(installed_specs) dependencies.all? {|d| installed_specs.include? d.name } end @@ -63,20 +62,23 @@ module Bundler end end - def self.call(*args) - new(*args).call + def self.call(*args, **kwargs) + new(*args, **kwargs).call end attr_reader :size - def initialize(installer, all_specs, size, standalone, force) + def initialize(installer, all_specs, size, standalone, force, skip: nil) @installer = installer @size = size @standalone = standalone @force = force @specs = all_specs.map {|s| SpecInstallation.new(s) } + @specs.each do |spec_install| + spec_install.state = :installed if skip.include?(spec_install.name) + end if skip @spec_set = all_specs - @rake = @specs.find {|s| s.name == "rake" } + @rake = @specs.find {|s| s.name == "rake" unless s.installed? } end def call @@ -91,38 +93,12 @@ module Bundler install_serially end - check_for_unmet_dependencies - handle_error if failed_specs.any? @specs ensure worker_pool&.stop end - def check_for_unmet_dependencies - unmet_dependencies = @specs.map do |s| - [ - s, - s.dependencies.reject {|dep| @specs.any? {|spec| dep.matches_spec?(spec.spec) } }, - ] - end.reject {|a| a.last.empty? } - return if unmet_dependencies.empty? - - warning = [] - warning << "Your lockfile doesn't include a valid resolution." - warning << "You can fix this by regenerating your lockfile or manually editing the bad locked gems to a version that satisfies all dependencies." - warning << "The unmet dependencies are:" - - unmet_dependencies.each do |spec, unmet_spec_dependencies| - unmet_spec_dependencies.each do |unmet_spec_dependency| - found = @specs.find {|s| s.name == unmet_spec_dependency.name && !unmet_spec_dependency.matches_spec?(s.spec) } - warning << "* #{unmet_spec_dependency}, dependency of #{spec.full_name}, unsatisfied by #{found.full_name}" - end - end - - Bundler.ui.warn(warning.join("\n")) - end - private def failed_specs @@ -209,8 +185,14 @@ module Bundler # previously installed specifications. We continue until all specs # are installed. def enqueue_specs - @specs.select(&:ready_to_enqueue?).each do |spec| - if spec.dependencies_installed? @specs + installed_specs = {} + @specs.each do |spec| + next unless spec.installed? + installed_specs[spec.name] = true + end + + @specs.each do |spec| + if spec.ready_to_enqueue? && spec.dependencies_installed?(installed_specs) spec.state = :enqueued worker_pool.enq spec end diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index 2a8c9a432d..5331df2e95 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -12,6 +12,7 @@ module Bundler end File.open File.join(bundler_path, "setup.rb"), "w" do |file| file.puts "require 'rbconfig'" + file.puts prevent_gem_activation file.puts define_path_helpers file.puts reverse_rubygems_kernel_mixin paths.each do |path| @@ -55,13 +56,26 @@ module Bundler if spec.source.instance_of?(Source::Path) && spec.source.path.absolute? full_path else - Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s + SharedHelpers.relative_path_to(full_path, from: Bundler.root.join(bundler_path)) end rescue TypeError error_message = "#{spec.name} #{spec.version} has an invalid gemspec" raise Gem::InvalidSpecificationException.new(error_message) end + def prevent_gem_activation + <<~'END' + module Kernel + remove_method(:gem) if private_method_defined?(:gem) + + def gem(*) + end + + private :gem + end + END + end + def define_path_helpers <<~'END' unless defined?(Gem) @@ -87,8 +101,7 @@ module Bundler if Gem.respond_to?(:discover_gems_on_require=) Gem.discover_gems_on_require = false else - kernel = (class << ::Kernel; self; end) - [kernel, ::Kernel].each do |k| + [::Kernel.singleton_class, ::Kernel].each do |k| if k.private_method_defined?(:gem_original_require) private_require = k.private_method_defined?(:require) k.send(:remove_method, :require) diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index c9b161dc0e..8669e021c2 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -4,16 +4,29 @@ require_relative "force_platform" module Bundler class LazySpecification + include MatchMetadata include MatchPlatform include ForcePlatform - attr_reader :name, :version, :dependencies, :platform - attr_accessor :source, :remote, :force_ruby_platform + attr_reader :name, :version, :platform + attr_accessor :source, :remote, :force_ruby_platform, :dependencies, :required_ruby_version, :required_rubygems_version + + alias_method :runtime_dependencies, :dependencies + + def self.from_spec(s) + lazy_spec = new(s.name, s.version, s.platform, s.source) + lazy_spec.dependencies = s.dependencies + lazy_spec.required_ruby_version = s.required_ruby_version + lazy_spec.required_rubygems_version = s.required_rubygems_version + lazy_spec + end def initialize(name, version, platform, source = nil) @name = name @version = version @dependencies = [] + @required_ruby_version = Gem::Requirement.default + @required_rubygems_version = Gem::Requirement.default @platform = platform || Gem::Platform::RUBY @source = source @force_ruby_platform = default_force_ruby_platform @@ -27,6 +40,14 @@ module Bundler end end + def lock_name + @lock_name ||= name_tuple.lock_name + end + + def name_tuple + Gem::NameTuple.new(@name, @version, @platform) + end + def ==(other) full_name == other.full_name end @@ -61,12 +82,7 @@ module Bundler def to_lock out = String.new - - if platform == Gem::Platform::RUBY - out << " #{name} (#{version})\n" - else - out << " #{name} (#{version}-#{platform})\n" - end + out << " #{lock_name}\n" dependencies.sort_by(&:to_s).uniq.each do |dep| next if dep.type == :development @@ -89,7 +105,7 @@ module Bundler installable_candidates = GemHelpers.select_best_platform_match(matching_specs, target_platform) - specification = __materialize__(installable_candidates, :fallback_to_non_installable => false) + specification = __materialize__(installable_candidates, fallback_to_non_installable: false) return specification unless specification.nil? if target_platform != platform @@ -109,9 +125,7 @@ module Bundler # bad gem. def __materialize__(candidates, fallback_to_non_installable: Bundler.frozen_bundle?) search = candidates.reverse.find do |spec| - spec.is_a?(StubSpecification) || - (spec.matches_current_ruby? && - spec.matches_current_rubygems?) + spec.is_a?(StubSpecification) || spec.matches_current_metadata? end if search.nil? && fallback_to_non_installable search = candidates.last @@ -122,11 +136,7 @@ module Bundler end def to_s - @to_s ||= if platform == Gem::Platform::RUBY - "#{name} (#{version})" - else - "#{name} (#{version}-#{platform})" - end + lock_name end def git_version @@ -134,6 +144,10 @@ module Bundler " #{source.revision[0..6]}" end + def force_ruby_platform! + @force_ruby_platform = true + end + private def use_exact_resolved_specifications? diff --git a/lib/bundler/lockfile_generator.rb b/lib/bundler/lockfile_generator.rb index a7ee026f67..a646d00ee1 100644 --- a/lib/bundler/lockfile_generator.rb +++ b/lib/bundler/lockfile_generator.rb @@ -19,6 +19,7 @@ module Bundler add_sources add_platforms add_dependencies + add_checksums add_locked_ruby_version add_bundled_with @@ -65,13 +66,21 @@ module Bundler end end + def add_checksums + return unless definition.locked_checksums + checksums = definition.resolve.map do |spec| + spec.source.checksum_store.to_lock(spec) + end + add_section("CHECKSUMS", checksums) + end + def add_locked_ruby_version return unless locked_ruby_version = definition.locked_ruby_version add_section("RUBY VERSION", locked_ruby_version.to_s) end def add_bundled_with - add_section("BUNDLED WITH", Bundler::VERSION) + add_section("BUNDLED WITH", definition.bundler_version_to_lock.to_s) end def add_section(name, value) diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index 7360a36752..1e11621e55 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -2,10 +2,41 @@ module Bundler class LockfileParser - attr_reader :sources, :dependencies, :specs, :platforms, :bundler_version, :ruby_version + class Position + attr_reader :line, :column + def initialize(line, column) + @line = line + @column = column + end + + def advance!(string) + lines = string.count("\n") + if lines > 0 + @line += lines + @column = string.length - string.rindex("\n") + else + @column += string.length + end + end + + def to_s + "#{line}:#{column}" + end + end + + attr_reader( + :sources, + :dependencies, + :specs, + :platforms, + :bundler_version, + :ruby_version, + :checksums, + ) BUNDLED = "BUNDLED WITH" DEPENDENCIES = "DEPENDENCIES" + CHECKSUMS = "CHECKSUMS" PLATFORMS = "PLATFORMS" RUBY = "RUBY VERSION" GIT = "GIT" @@ -13,7 +44,7 @@ module Bundler PATH = "PATH" PLUGIN = "PLUGIN SOURCE" SPECS = " specs:" - OPTIONS = /^ ([a-z]+): (.*)$/i.freeze + OPTIONS = /^ ([a-z]+): (.*)$/i SOURCE = [GIT, GEM, PATH, PLUGIN].freeze SECTIONS_BY_VERSION_INTRODUCED = { @@ -21,15 +52,18 @@ module Bundler Gem::Version.create("1.10") => [BUNDLED].freeze, Gem::Version.create("1.12") => [RUBY].freeze, Gem::Version.create("1.13") => [PLUGIN].freeze, + Gem::Version.create("2.5.0") => [CHECKSUMS].freeze, }.freeze - KNOWN_SECTIONS = SECTIONS_BY_VERSION_INTRODUCED.values.flatten.freeze + KNOWN_SECTIONS = SECTIONS_BY_VERSION_INTRODUCED.values.flatten!.freeze ENVIRONMENT_VERSION_SECTIONS = [BUNDLED, RUBY].freeze deprecate_constant(:ENVIRONMENT_VERSION_SECTIONS) def self.sections_in_lockfile(lockfile_contents) - lockfile_contents.scan(/^\w[\w ]*$/).uniq + sections = lockfile_contents.scan(/^\w[\w ]*$/) + sections.uniq! + sections end def self.unknown_sections_in_lockfile(lockfile_contents) @@ -38,7 +72,7 @@ module Bundler def self.sections_to_ignore(base_version = nil) base_version &&= base_version.release - base_version ||= Gem::Version.create("1.0".dup) + base_version ||= Gem::Version.create("1.0") attributes = [] SECTIONS_BY_VERSION_INTRODUCED.each do |version, introduced| next if version <= base_version @@ -61,37 +95,53 @@ module Bundler @platforms = [] @sources = [] @dependencies = {} - @state = nil + @parse_method = nil @specs = {} + @lockfile_path = begin + SharedHelpers.relative_lockfile_path + rescue GemfileNotFound + "Gemfile.lock" + end + @pos = Position.new(1, 1) if lockfile.match?(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/) - raise LockfileError, "Your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} contains merge conflicts.\n" \ - "Run `git checkout HEAD -- #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` first to get a clean lock." + raise LockfileError, "Your #{@lockfile_path} contains merge conflicts.\n" \ + "Run `git checkout HEAD -- #{@lockfile_path}` first to get a clean lock." end - lockfile.split(/(?:\r?\n)+/).each do |line| + lockfile.split(/((?:\r?\n)+)/) do |line| + # split alternates between the line and the following whitespace + next @pos.advance!(line) if line.match?(/^\s*$/) + if SOURCE.include?(line) - @state = :source + @parse_method = :parse_source parse_source(line) elsif line == DEPENDENCIES - @state = :dependency + @parse_method = :parse_dependency + elsif line == CHECKSUMS + # This is a temporary solution to make this feature disabled by default + # for all gemfiles that don't already explicitly include the feature. + @checksums = true + @parse_method = :parse_checksum elsif line == PLATFORMS - @state = :platform + @parse_method = :parse_platform elsif line == RUBY - @state = :ruby + @parse_method = :parse_ruby elsif line == BUNDLED - @state = :bundled_with + @parse_method = :parse_bundled_with elsif /^[^\s]/.match?(line) - @state = nil - elsif @state - send("parse_#{@state}", line) + @parse_method = nil + elsif @parse_method + send(@parse_method, line) end + @pos.advance!(line) end - @specs = @specs.values.sort_by(&:full_name) + @specs = @specs.values.sort_by!(&:full_name) rescue ArgumentError => e Bundler.ui.debug(e) - raise LockfileError, "Your lockfile is unreadable. Run `rm #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` " \ - "and then `bundle install` to generate a new lockfile." + raise LockfileError, "Your lockfile is unreadable. Run `rm #{@lockfile_path}` " \ + "and then `bundle install` to generate a new lockfile. The error occurred while " \ + "evaluating #{@lockfile_path}:#{@pos}" end def may_include_redundant_platform_specific_gems? @@ -110,21 +160,9 @@ module Bundler def parse_source(line) case line when SPECS - case @type - when PATH - @current_source = TYPES[@type].from_lock(@opts) - @sources << @current_source - when GIT - @current_source = TYPES[@type].from_lock(@opts) - @sources << @current_source - when GEM - @opts["remotes"] = Array(@opts.delete("remote")).reverse - @current_source = TYPES[@type].from_lock(@opts) - @sources << @current_source - when PLUGIN - @current_source = Plugin.source_from_lock(@opts) - @sources << @current_source - end + return unless TYPES.key?(@type) + @current_source = TYPES[@type].from_lock(@opts) + @sources << @current_source when OPTIONS value = $2 value = true if value == "true" @@ -154,18 +192,19 @@ module Bundler (?:#{space}\(([^-]*) # Space, followed by version (?:-(.*))?\))? # Optional platform (!)? # Optional pinned marker + (?:#{space}([^ ]+))? # Optional checksum $ # Line end - /xo.freeze + /xo def parse_dependency(line) return unless line =~ NAME_VERSION spaces = $1 return unless spaces.size == 2 - name = $2 + name = -$2 version = $3 pinned = $5 - version = version.split(",").map(&:strip) if version + version = version.split(",").each(&:strip!) if version dep = Bundler::Dependency.new(name, version) @@ -186,23 +225,47 @@ module Bundler @dependencies[dep.name] = dep end - def parse_spec(line) + def parse_checksum(line) return unless line =~ NAME_VERSION + spaces = $1 + return unless spaces.size == 2 + checksums = $6 + return unless checksums name = $2 version = $3 platform = $4 + version = Gem::Version.new(version) + platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY + full_name = Gem::NameTuple.new(name, version, platform).full_name + return unless spec = @specs[full_name] + + checksums.split(",") do |lock_checksum| + column = line.index(lock_checksum) + 1 + checksum = Checksum.from_lock(lock_checksum, "#{@lockfile_path}:#{@pos.line}:#{column}") + spec.source.checksum_store.register(spec, checksum) + end + end + + def parse_spec(line) + return unless line =~ NAME_VERSION + spaces = $1 + name = -$2 + version = $3 + if spaces.size == 4 + # only load platform for non-dependency (spec) line + platform = $4 + version = Gem::Version.new(version) platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY - @current_spec = LazySpecification.new(name, version, platform) - @current_spec.source = @current_source + @current_spec = LazySpecification.new(name, version, platform, @current_source) @current_source.add_dependency_names(name) @specs[@current_spec.full_name] = @current_spec elsif spaces.size == 6 - version = version.split(",").map(&:strip) if version + version = version.split(",").each(&:strip!) if version dep = Gem::Dependency.new(name, version) @current_spec.dependencies << dep end @@ -213,13 +276,14 @@ module Bundler end def parse_bundled_with(line) - line = line.strip + line.strip! return unless Gem::Version.correct?(line) @bundler_version = Gem::Version.create(line) end def parse_ruby(line) - @ruby_version = line.strip + line.strip! + @ruby_version = line end end end diff --git a/lib/bundler/man/bundle-add.1 b/lib/bundler/man/bundle-add.1 index 0e21c75506..56a3b6f85c 100644 --- a/lib/bundler/man/bundle-add.1 +++ b/lib/bundler/man/bundle-add.1 @@ -1,81 +1,58 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-ADD" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-ADD" "1" "May 2024" "" .SH "NAME" \fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install -. .SH "SYNOPSIS" \fBbundle add\fR \fIGEM_NAME\fR [\-\-group=GROUP] [\-\-version=VERSION] [\-\-source=SOURCE] [\-\-path=PATH] [\-\-git=GIT] [\-\-github=GITHUB] [\-\-branch=BRANCH] [\-\-ref=REF] [\-\-skip\-install] [\-\-strict] [\-\-optimistic] -. .SH "DESCRIPTION" Adds the named gem to the Gemfile and run \fBbundle install\fR\. \fBbundle install\fR can be avoided by using the flag \fB\-\-skip\-install\fR\. -. .P Example: -. .P bundle add rails -. .P bundle add rails \-\-version "< 3\.0, > 1\.1" -. .P bundle add rails \-\-version "~> 5\.0\.0" \-\-source "https://gems\.example\.com" \-\-group "development" -. .P bundle add rails \-\-skip\-install -. .P bundle add rails \-\-group "development, test" -. .SH "OPTIONS" -. .TP \fB\-\-version\fR, \fB\-v\fR Specify version requirements(s) for the added gem\. -. .TP \fB\-\-group\fR, \fB\-g\fR Specify the group(s) for the added gem\. Multiple groups should be separated by commas\. -. .TP \fB\-\-source\fR, \fB\-s\fR Specify the source for the added gem\. -. .TP \fB\-\-require\fR, \fB\-r\fR Adds require path to gem\. Provide false, or a path as a string\. -. .TP \fB\-\-path\fR Specify the file system path for the added gem\. -. .TP \fB\-\-git\fR Specify the git source for the added gem\. -. .TP \fB\-\-github\fR Specify the github source for the added gem\. -. .TP \fB\-\-branch\fR Specify the git branch for the added gem\. -. .TP \fB\-\-ref\fR Specify the git ref for the added gem\. -. .TP \fB\-\-skip\-install\fR Adds the gem to the Gemfile but does not install it\. -. .TP \fB\-\-optimistic\fR Adds optimistic declaration of version\. -. .TP \fB\-\-strict\fR Adds strict declaration of version\. diff --git a/lib/bundler/man/bundle-binstubs.1 b/lib/bundler/man/bundle-binstubs.1 index 2774e9d28a..4ec301951f 100644 --- a/lib/bundler/man/bundle-binstubs.1 +++ b/lib/bundler/man/bundle-binstubs.1 @@ -1,41 +1,29 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-BINSTUBS" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-BINSTUBS" "1" "May 2024" "" .SH "NAME" \fBbundle\-binstubs\fR \- Install the binstubs of the listed gems -. .SH "SYNOPSIS" \fBbundle binstubs\fR \fIGEM_NAME\fR [\-\-force] [\-\-path PATH] [\-\-standalone] -. .SH "DESCRIPTION" Binstubs are scripts that wrap around executables\. Bundler creates a small Ruby file (a binstub) that loads Bundler, runs the command, and puts it into \fBbin/\fR\. Binstubs are a shortcut\-or alternative\- to always using \fBbundle exec\fR\. This gives you a file that can be run directly, and one that will always run the correct gem version used by the application\. -. .P For example, if you run \fBbundle binstubs rspec\-core\fR, Bundler will create the file \fBbin/rspec\fR\. That file will contain enough code to load Bundler, tell it to load the bundled gems, and then run rspec\. -. .P This command generates binstubs for executables in \fBGEM_NAME\fR\. Binstubs are put into \fBbin\fR, or the \fB\-\-path\fR directory if one has been set\. Calling binstubs with [GEM [GEM]] will create binstubs for all given gems\. -. .SH "OPTIONS" -. .TP \fB\-\-force\fR Overwrite existing binstubs if they exist\. -. .TP \fB\-\-path\fR The location to install the specified binstubs to\. This defaults to \fBbin\fR\. -. .TP \fB\-\-standalone\fR Makes binstubs that can work without depending on Rubygems or Bundler at runtime\. -. .TP \fB\-\-shebang\fR -Specify a different shebang executable name than the default (default \'ruby\') -. +Specify a different shebang executable name than the default (default 'ruby') .TP \fB\-\-all\fR Create binstubs for all gems in the bundle\. diff --git a/lib/bundler/man/bundle-cache.1 b/lib/bundler/man/bundle-cache.1 index 67a8fdd14d..e2da1269e6 100644 --- a/lib/bundler/man/bundle-cache.1 +++ b/lib/bundler/man/bundle-cache.1 @@ -1,61 +1,40 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-CACHE" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-CACHE" "1" "May 2024" "" .SH "NAME" \fBbundle\-cache\fR \- Package your needed \fB\.gem\fR files into your application -. .SH "SYNOPSIS" \fBbundle cache\fR -. .P alias: \fBpackage\fR, \fBpack\fR -. .SH "DESCRIPTION" Copy all of the \fB\.gem\fR files needed to run the application into the \fBvendor/cache\fR directory\. In the future, when running \fBbundle install(1)\fR \fIbundle\-install\.1\.html\fR, use the gems in the cache in preference to the ones on \fBrubygems\.org\fR\. -. .SH "GIT AND PATH GEMS" The \fBbundle cache\fR command can also package \fB:git\fR and \fB:path\fR dependencies besides \.gem files\. This needs to be explicitly enabled via the \fB\-\-all\fR option\. Once used, the \fB\-\-all\fR option will be remembered\. -. .SH "SUPPORT FOR MULTIPLE PLATFORMS" When using gems that have different packages for different platforms, Bundler supports caching of gems for other platforms where the Gemfile has been resolved (i\.e\. present in the lockfile) in \fBvendor/cache\fR\. This needs to be enabled via the \fB\-\-all\-platforms\fR option\. This setting will be remembered in your local bundler configuration\. -. .SH "REMOTE FETCHING" By default, if you run \fBbundle install(1)\fR \fIbundle\-install\.1\.html\fR after running bundle cache(1) \fIbundle\-cache\.1\.html\fR, bundler will still connect to \fBrubygems\.org\fR to check whether a platform\-specific gem exists for any of the gems in \fBvendor/cache\fR\. -. .P For instance, consider this Gemfile(5): -. .IP "" 4 -. .nf - source "https://rubygems\.org" gem "nokogiri" -. .fi -. .IP "" 0 -. .P If you run \fBbundle cache\fR under C Ruby, bundler will retrieve the version of \fBnokogiri\fR for the \fB"ruby"\fR platform\. If you deploy to JRuby and run \fBbundle install\fR, bundler is forced to check to see whether a \fB"java"\fR platformed \fBnokogiri\fR exists\. -. .P Even though the \fBnokogiri\fR gem for the Ruby platform is \fItechnically\fR acceptable on JRuby, it has a C extension that does not run on JRuby\. As a result, bundler will, by default, still connect to \fBrubygems\.org\fR to check whether it has a version of one of your gems more specific to your platform\. -. .P This problem is also not limited to the \fB"java"\fR platform\. A similar (common) problem can happen when developing on Windows and deploying to Linux, or even when developing on OSX and deploying to Linux\. -. .P If you know for sure that the gems packaged in \fBvendor/cache\fR are appropriate for the platform you are on, you can run \fBbundle install \-\-local\fR to skip checking for more appropriate gems, and use the ones in \fBvendor/cache\fR\. -. .P One way to be sure that you have the right platformed versions of all your gems is to run \fBbundle cache\fR on an identical machine and check in the gems\. For instance, you can run \fBbundle cache\fR on an identical staging box during your staging process, and check in the \fBvendor/cache\fR before deploying to production\. -. .P By default, bundle cache(1) \fIbundle\-cache\.1\.html\fR fetches and also installs the gems to the default location\. To package the dependencies to \fBvendor/cache\fR without installing them to the local install location, you can run \fBbundle cache \-\-no\-install\fR\. -. .SH "HISTORY" In Bundler 2\.1, \fBcache\fR took in the functionalities of \fBpackage\fR and now \fBpackage\fR and \fBpack\fR are aliases of \fBcache\fR\. diff --git a/lib/bundler/man/bundle-check.1 b/lib/bundler/man/bundle-check.1 index 7679945c48..dee1af1326 100644 --- a/lib/bundler/man/bundle-check.1 +++ b/lib/bundler/man/bundle-check.1 @@ -1,30 +1,23 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-CHECK" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-CHECK" "1" "May 2024" "" .SH "NAME" \fBbundle\-check\fR \- Verifies if dependencies are satisfied by installed gems -. .SH "SYNOPSIS" \fBbundle check\fR [\-\-dry\-run] [\-\-gemfile=FILE] [\-\-path=PATH] -. .SH "DESCRIPTION" \fBcheck\fR searches the local machine for each of the gems requested in the Gemfile\. If all gems are found, Bundler prints a success message and exits with a status of 0\. -. .P If not, the first missing gem is listed and Bundler exits status 1\. -. +.P +If the lockfile needs to be updated then it will be resolved using the gems installed on the local machine, if they satisfy the requirements\. .SH "OPTIONS" -. .TP \fB\-\-dry\-run\fR Locks the [\fBGemfile(5)\fR][Gemfile(5)] before running the command\. -. .TP \fB\-\-gemfile\fR Use the specified gemfile instead of the [\fBGemfile(5)\fR][Gemfile(5)]\. -. .TP \fB\-\-path\fR Specify a different path than the system default (\fB$BUNDLE_PATH\fR or \fB$GEM_HOME\fR)\. Bundler will remember this value for future installs on this machine\. diff --git a/lib/bundler/man/bundle-check.1.ronn b/lib/bundler/man/bundle-check.1.ronn index f2846b8ff2..eb3ff1daf9 100644 --- a/lib/bundler/man/bundle-check.1.ronn +++ b/lib/bundler/man/bundle-check.1.ronn @@ -15,6 +15,9 @@ a status of 0. If not, the first missing gem is listed and Bundler exits status 1. +If the lockfile needs to be updated then it will be resolved using the gems +installed on the local machine, if they satisfy the requirements. + ## OPTIONS * `--dry-run`: diff --git a/lib/bundler/man/bundle-clean.1 b/lib/bundler/man/bundle-clean.1 index 2eb745698c..7c7f9b5c77 100644 --- a/lib/bundler/man/bundle-clean.1 +++ b/lib/bundler/man/bundle-clean.1 @@ -1,23 +1,16 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-CLEAN" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-CLEAN" "1" "May 2024" "" .SH "NAME" \fBbundle\-clean\fR \- Cleans up unused gems in your bundler directory -. .SH "SYNOPSIS" \fBbundle clean\fR [\-\-dry\-run] [\-\-force] -. .SH "DESCRIPTION" This command will remove all unused gems in your bundler directory\. This is useful when you have made many changes to your gem dependencies\. -. .SH "OPTIONS" -. .TP \fB\-\-dry\-run\fR Print the changes, but do not clean the unused gems\. -. .TP \fB\-\-force\fR Forces cleaning up unused gems even if Bundler is configured to use globally installed gems\. As a consequence, removes all system gems except for the ones in the current application\. diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1 index 493b57e1de..2de52ee375 100644 --- a/lib/bundler/man/bundle-config.1 +++ b/lib/bundler/man/bundle-config.1 @@ -1,515 +1,319 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-CONFIG" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-CONFIG" "1" "May 2024" "" .SH "NAME" \fBbundle\-config\fR \- Set bundler configuration options -. .SH "SYNOPSIS" \fBbundle config\fR list -. .br \fBbundle config\fR [get] NAME -. .br \fBbundle config\fR [set] NAME VALUE -. .br \fBbundle config\fR unset NAME -. .SH "DESCRIPTION" -This command allows you to interact with Bundler\'s configuration system\. -. +This command allows you to interact with Bundler's configuration system\. .P Bundler loads configuration settings in this order: -. .IP "1." 4 Local config (\fB<project_root>/\.bundle/config\fR or \fB$BUNDLE_APP_CONFIG/config\fR) -. .IP "2." 4 Environmental variables (\fBENV\fR) -. .IP "3." 4 Global config (\fB~/\.bundle/config\fR) -. .IP "4." 4 Bundler default config -. .IP "" 0 -. .P Executing \fBbundle config list\fR will print a list of all bundler configuration for the current bundle, and where that configuration was set\. -. .P Executing \fBbundle config get <name>\fR will print the value of that configuration setting, and where it was set\. -. .P Executing \fBbundle config set <name> <value>\fR defaults to setting \fBlocal\fR configuration if executing from within a local application, otherwise it will set \fBglobal\fR configuration\. See \fB\-\-local\fR and \fB\-\-global\fR options below\. -. .P Executing \fBbundle config set \-\-local <name> <value>\fR will set that configuration in the directory for the local application\. The configuration will be stored in \fB<project_root>/\.bundle/config\fR\. If \fBBUNDLE_APP_CONFIG\fR is set, the configuration will be stored in \fB$BUNDLE_APP_CONFIG/config\fR\. -. .P Executing \fBbundle config set \-\-global <name> <value>\fR will set that configuration to the value specified for all bundles executed as the current user\. The configuration will be stored in \fB~/\.bundle/config\fR\. If \fIname\fR already is set, \fIname\fR will be overridden and user will be warned\. -. .P Executing \fBbundle config unset <name>\fR will delete the configuration in both local and global sources\. -. .P Executing \fBbundle config unset \-\-global <name>\fR will delete the configuration only from the user configuration\. -. .P Executing \fBbundle config unset \-\-local <name>\fR will delete the configuration only from the local application\. -. .P Executing bundle with the \fBBUNDLE_IGNORE_CONFIG\fR environment variable set will cause it to ignore all configuration\. -. .SH "REMEMBERING OPTIONS" -Flags passed to \fBbundle install\fR or the Bundler runtime, such as \fB\-\-path foo\fR or \fB\-\-without production\fR, are remembered between commands and saved to your local application\'s configuration (normally, \fB\./\.bundle/config\fR)\. -. +Flags passed to \fBbundle install\fR or the Bundler runtime, such as \fB\-\-path foo\fR or \fB\-\-without production\fR, are remembered between commands and saved to your local application's configuration (normally, \fB\./\.bundle/config\fR)\. .P -However, this will be changed in bundler 3, so it\'s better not to rely on this behavior\. If these options must be remembered, it\'s better to set them using \fBbundle config\fR (e\.g\., \fBbundle config set \-\-local path foo\fR)\. -. +However, this will be changed in bundler 3, so it's better not to rely on this behavior\. If these options must be remembered, it's better to set them using \fBbundle config\fR (e\.g\., \fBbundle config set \-\-local path foo\fR)\. .P The options that can be configured are: -. .TP \fBbin\fR -Creates a directory (defaults to \fB~/bin\fR) and place any executables from the gem there\. These executables run in Bundler\'s context\. If used, you might add this directory to your environment\'s \fBPATH\fR variable\. For instance, if the \fBrails\fR gem comes with a \fBrails\fR executable, this flag will create a \fBbin/rails\fR executable that ensures that all referred dependencies will be resolved using the bundled gems\. -. +Creates a directory (defaults to \fB~/bin\fR) and place any executables from the gem there\. These executables run in Bundler's context\. If used, you might add this directory to your environment's \fBPATH\fR variable\. For instance, if the \fBrails\fR gem comes with a \fBrails\fR executable, this flag will create a \fBbin/rails\fR executable that ensures that all referred dependencies will be resolved using the bundled gems\. .TP \fBdeployment\fR -In deployment mode, Bundler will \'roll\-out\' the bundle for \fBproduction\fR use\. Please check carefully if you want to have this option enabled in \fBdevelopment\fR or \fBtest\fR environments\. -. +In deployment mode, Bundler will 'roll\-out' the bundle for \fBproduction\fR use\. Please check carefully if you want to have this option enabled in \fBdevelopment\fR or \fBtest\fR environments\. .TP \fBonly\fR A space\-separated list of groups to install only gems of the specified groups\. -. .TP \fBpath\fR -The location to install the specified gems to\. This defaults to Rubygems\' setting\. Bundler shares this location with Rubygems, \fBgem install \.\.\.\fR will have gem installed there, too\. Therefore, gems installed without a \fB\-\-path \.\.\.\fR setting will show up by calling \fBgem list\fR\. Accordingly, gems installed to other locations will not get listed\. -. +The location to install the specified gems to\. This defaults to Rubygems' setting\. Bundler shares this location with Rubygems, \fBgem install \|\.\|\.\|\.\fR will have gem installed there, too\. Therefore, gems installed without a \fB\-\-path \|\.\|\.\|\.\fR setting will show up by calling \fBgem list\fR\. Accordingly, gems installed to other locations will not get listed\. .TP \fBwithout\fR A space\-separated list of groups referencing gems to skip during installation\. -. .TP \fBwith\fR A space\-separated list of \fBoptional\fR groups referencing gems to include during installation\. -. .SH "BUILD OPTIONS" You can use \fBbundle config\fR to give Bundler the flags to pass to the gem installer every time bundler tries to install a particular gem\. -. .P A very common example, the \fBmysql\fR gem, requires Snow Leopard users to pass configuration flags to \fBgem install\fR to specify where to find the \fBmysql_config\fR executable\. -. .IP "" 4 -. .nf - gem install mysql \-\- \-\-with\-mysql\-config=/usr/local/mysql/bin/mysql_config -. .fi -. .IP "" 0 -. .P Since the specific location of that executable can change from machine to machine, you can specify these flags on a per\-machine basis\. -. .IP "" 4 -. .nf - bundle config set \-\-global build\.mysql \-\-with\-mysql\-config=/usr/local/mysql/bin/mysql_config -. .fi -. .IP "" 0 -. .P After running this command, every time bundler needs to install the \fBmysql\fR gem, it will pass along the flags you specified\. -. .SH "CONFIGURATION KEYS" Configuration keys in bundler have two forms: the canonical form and the environment variable form\. -. .P -For instance, passing the \fB\-\-without\fR flag to bundle install(1) \fIbundle\-install\.1\.html\fR prevents Bundler from installing certain groups specified in the Gemfile(5)\. Bundler persists this value in \fBapp/\.bundle/config\fR so that calls to \fBBundler\.setup\fR do not try to find gems from the \fBGemfile\fR that you didn\'t install\. Additionally, subsequent calls to bundle install(1) \fIbundle\-install\.1\.html\fR remember this setting and skip those groups\. -. +For instance, passing the \fB\-\-without\fR flag to bundle install(1) \fIbundle\-install\.1\.html\fR prevents Bundler from installing certain groups specified in the Gemfile(5)\. Bundler persists this value in \fBapp/\.bundle/config\fR so that calls to \fBBundler\.setup\fR do not try to find gems from the \fBGemfile\fR that you didn't install\. Additionally, subsequent calls to bundle install(1) \fIbundle\-install\.1\.html\fR remember this setting and skip those groups\. .P The canonical form of this configuration is \fB"without"\fR\. To convert the canonical form to the environment variable form, capitalize it, and prepend \fBBUNDLE_\fR\. The environment variable form of \fB"without"\fR is \fBBUNDLE_WITHOUT\fR\. -. .P Any periods in the configuration keys must be replaced with two underscores when setting it via environment variables\. The configuration key \fBlocal\.rack\fR becomes the environment variable \fBBUNDLE_LOCAL__RACK\fR\. -. .SH "LIST OF AVAILABLE KEYS" The following is a list of all configuration keys and their purpose\. You can learn more about their operation in bundle install(1) \fIbundle\-install\.1\.html\fR\. -. -.IP "\(bu" 4 -\fBallow_deployment_source_credential_changes\fR (\fBBUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES\fR): When in deployment mode, allow changing the credentials to a gem\'s source\. Ex: \fBhttps://some\.host\.com/gems/path/\fR \-> \fBhttps://user_name:password@some\.host\.com/gems/path\fR -. .IP "\(bu" 4 \fBallow_offline_install\fR (\fBBUNDLE_ALLOW_OFFLINE_INSTALL\fR): Allow Bundler to use cached data when installing without network access\. -. .IP "\(bu" 4 \fBauto_clean_without_path\fR (\fBBUNDLE_AUTO_CLEAN_WITHOUT_PATH\fR): Automatically run \fBbundle clean\fR after installing when an explicit \fBpath\fR has not been set and Bundler is not installing into the system gems\. -. .IP "\(bu" 4 \fBauto_install\fR (\fBBUNDLE_AUTO_INSTALL\fR): Automatically run \fBbundle install\fR when gems are missing\. -. .IP "\(bu" 4 \fBbin\fR (\fBBUNDLE_BIN\fR): Install executables from gems in the bundle to the specified directory\. Defaults to \fBfalse\fR\. -. .IP "\(bu" 4 \fBcache_all\fR (\fBBUNDLE_CACHE_ALL\fR): Cache all gems, including path and git gems\. This needs to be explicitly configured on bundler 1 and bundler 2, but will be the default on bundler 3\. -. .IP "\(bu" 4 \fBcache_all_platforms\fR (\fBBUNDLE_CACHE_ALL_PLATFORMS\fR): Cache gems for all platforms\. -. .IP "\(bu" 4 \fBcache_path\fR (\fBBUNDLE_CACHE_PATH\fR): The directory that bundler will place cached gems in when running \fBbundle package\fR, and that bundler will look in when installing gems\. Defaults to \fBvendor/cache\fR\. -. .IP "\(bu" 4 \fBclean\fR (\fBBUNDLE_CLEAN\fR): Whether Bundler should run \fBbundle clean\fR automatically after \fBbundle install\fR\. -. .IP "\(bu" 4 \fBconsole\fR (\fBBUNDLE_CONSOLE\fR): The console that \fBbundle console\fR starts\. Defaults to \fBirb\fR\. -. .IP "\(bu" 4 \fBdefault_install_uses_path\fR (\fBBUNDLE_DEFAULT_INSTALL_USES_PATH\fR): Whether a \fBbundle install\fR without an explicit \fB\-\-path\fR argument defaults to installing gems in \fB\.bundle\fR\. -. .IP "\(bu" 4 \fBdeployment\fR (\fBBUNDLE_DEPLOYMENT\fR): Disallow changes to the \fBGemfile\fR\. When the \fBGemfile\fR is changed and the lockfile has not been updated, running Bundler commands will be blocked\. -. .IP "\(bu" 4 \fBdisable_checksum_validation\fR (\fBBUNDLE_DISABLE_CHECKSUM_VALIDATION\fR): Allow installing gems even if they do not match the checksum provided by RubyGems\. -. .IP "\(bu" 4 \fBdisable_exec_load\fR (\fBBUNDLE_DISABLE_EXEC_LOAD\fR): Stop Bundler from using \fBload\fR to launch an executable in\-process in \fBbundle exec\fR\. -. .IP "\(bu" 4 \fBdisable_local_branch_check\fR (\fBBUNDLE_DISABLE_LOCAL_BRANCH_CHECK\fR): Allow Bundler to use a local git override without a branch specified in the Gemfile\. -. .IP "\(bu" 4 \fBdisable_local_revision_check\fR (\fBBUNDLE_DISABLE_LOCAL_REVISION_CHECK\fR): Allow Bundler to use a local git override without checking if the revision present in the lockfile is present in the repository\. -. .IP "\(bu" 4 -\fBdisable_shared_gems\fR (\fBBUNDLE_DISABLE_SHARED_GEMS\fR): Stop Bundler from accessing gems installed to RubyGems\' normal location\. -. +\fBdisable_shared_gems\fR (\fBBUNDLE_DISABLE_SHARED_GEMS\fR): Stop Bundler from accessing gems installed to RubyGems' normal location\. .IP "\(bu" 4 \fBdisable_version_check\fR (\fBBUNDLE_DISABLE_VERSION_CHECK\fR): Stop Bundler from checking if a newer Bundler version is available on rubygems\.org\. -. .IP "\(bu" 4 -\fBforce_ruby_platform\fR (\fBBUNDLE_FORCE_RUBY_PLATFORM\fR): Ignore the current machine\'s platform and install only \fBruby\fR platform gems\. As a result, gems with native extensions will be compiled from source\. -. +\fBforce_ruby_platform\fR (\fBBUNDLE_FORCE_RUBY_PLATFORM\fR): Ignore the current machine's platform and install only \fBruby\fR platform gems\. As a result, gems with native extensions will be compiled from source\. .IP "\(bu" 4 \fBfrozen\fR (\fBBUNDLE_FROZEN\fR): Disallow changes to the \fBGemfile\fR\. When the \fBGemfile\fR is changed and the lockfile has not been updated, running Bundler commands will be blocked\. Defaults to \fBtrue\fR when \fB\-\-deployment\fR is used\. -. .IP "\(bu" 4 \fBgem\.github_username\fR (\fBBUNDLE_GEM__GITHUB_USERNAME\fR): Sets a GitHub username or organization to be used in \fBREADME\fR file when you create a new gem via \fBbundle gem\fR command\. It can be overridden by passing an explicit \fB\-\-github\-username\fR flag to \fBbundle gem\fR\. -. .IP "\(bu" 4 \fBgem\.push_key\fR (\fBBUNDLE_GEM__PUSH_KEY\fR): Sets the \fB\-\-key\fR parameter for \fBgem push\fR when using the \fBrake release\fR command with a private gemstash server\. -. .IP "\(bu" 4 \fBgemfile\fR (\fBBUNDLE_GEMFILE\fR): The name of the file that bundler should use as the \fBGemfile\fR\. This location of this file also sets the root of the project, which is used to resolve relative paths in the \fBGemfile\fR, among other things\. By default, bundler will search up from the current working directory until it finds a \fBGemfile\fR\. -. .IP "\(bu" 4 \fBglobal_gem_cache\fR (\fBBUNDLE_GLOBAL_GEM_CACHE\fR): Whether Bundler should cache all gems globally, rather than locally to the installing Ruby installation\. -. .IP "\(bu" 4 \fBignore_funding_requests\fR (\fBBUNDLE_IGNORE_FUNDING_REQUESTS\fR): When set, no funding requests will be printed\. -. .IP "\(bu" 4 \fBignore_messages\fR (\fBBUNDLE_IGNORE_MESSAGES\fR): When set, no post install messages will be printed\. To silence a single gem, use dot notation like \fBignore_messages\.httparty true\fR\. -. .IP "\(bu" 4 \fBinit_gems_rb\fR (\fBBUNDLE_INIT_GEMS_RB\fR): Generate a \fBgems\.rb\fR instead of a \fBGemfile\fR when running \fBbundle init\fR\. -. .IP "\(bu" 4 \fBjobs\fR (\fBBUNDLE_JOBS\fR): The number of gems Bundler can install in parallel\. Defaults to the number of available processors\. -. .IP "\(bu" 4 \fBno_install\fR (\fBBUNDLE_NO_INSTALL\fR): Whether \fBbundle package\fR should skip installing gems\. -. .IP "\(bu" 4 \fBno_prune\fR (\fBBUNDLE_NO_PRUNE\fR): Whether Bundler should leave outdated gems unpruned when caching\. -. .IP "\(bu" 4 \fBonly\fR (\fBBUNDLE_ONLY\fR): A space\-separated list of groups to install only gems of the specified groups\. -. .IP "\(bu" 4 \fBpath\fR (\fBBUNDLE_PATH\fR): The location on disk where all gems in your bundle will be located regardless of \fB$GEM_HOME\fR or \fB$GEM_PATH\fR values\. Bundle gems not found in this location will be installed by \fBbundle install\fR\. Defaults to \fBGem\.dir\fR\. When \-\-deployment is used, defaults to vendor/bundle\. -. .IP "\(bu" 4 \fBpath\.system\fR (\fBBUNDLE_PATH__SYSTEM\fR): Whether Bundler will install gems into the default system path (\fBGem\.dir\fR)\. -. .IP "\(bu" 4 \fBpath_relative_to_cwd\fR (\fBBUNDLE_PATH_RELATIVE_TO_CWD\fR) Makes \fB\-\-path\fR relative to the CWD instead of the \fBGemfile\fR\. -. .IP "\(bu" 4 -\fBplugins\fR (\fBBUNDLE_PLUGINS\fR): Enable Bundler\'s experimental plugin system\. -. +\fBplugins\fR (\fBBUNDLE_PLUGINS\fR): Enable Bundler's experimental plugin system\. .IP "\(bu" 4 \fBprefer_patch\fR (BUNDLE_PREFER_PATCH): Prefer updating only to next patch version during updates\. Makes \fBbundle update\fR calls equivalent to \fBbundler update \-\-patch\fR\. -. .IP "\(bu" 4 \fBprint_only_version_number\fR (\fBBUNDLE_PRINT_ONLY_VERSION_NUMBER\fR): Print only version number from \fBbundler \-\-version\fR\. -. .IP "\(bu" 4 \fBredirect\fR (\fBBUNDLE_REDIRECT\fR): The number of redirects allowed for network requests\. Defaults to \fB5\fR\. -. .IP "\(bu" 4 \fBretry\fR (\fBBUNDLE_RETRY\fR): The number of times to retry failed network requests\. Defaults to \fB3\fR\. -. .IP "\(bu" 4 \fBsetup_makes_kernel_gem_public\fR (\fBBUNDLE_SETUP_MAKES_KERNEL_GEM_PUBLIC\fR): Have \fBBundler\.setup\fR make the \fBKernel#gem\fR method public, even though RubyGems declares it as private\. -. .IP "\(bu" 4 \fBshebang\fR (\fBBUNDLE_SHEBANG\fR): The program name that should be invoked for generated binstubs\. Defaults to the ruby install name used to generate the binstub\. -. .IP "\(bu" 4 \fBsilence_deprecations\fR (\fBBUNDLE_SILENCE_DEPRECATIONS\fR): Whether Bundler should silence deprecation warnings for behavior that will be changed in the next major version\. -. .IP "\(bu" 4 \fBsilence_root_warning\fR (\fBBUNDLE_SILENCE_ROOT_WARNING\fR): Silence the warning Bundler prints when installing gems as root\. -. .IP "\(bu" 4 \fBssl_ca_cert\fR (\fBBUNDLE_SSL_CA_CERT\fR): Path to a designated CA certificate file or folder containing multiple certificates for trusted CAs in PEM format\. -. .IP "\(bu" 4 \fBssl_client_cert\fR (\fBBUNDLE_SSL_CLIENT_CERT\fR): Path to a designated file containing a X\.509 client certificate and key in PEM format\. -. .IP "\(bu" 4 \fBssl_verify_mode\fR (\fBBUNDLE_SSL_VERIFY_MODE\fR): The SSL verification mode Bundler uses when making HTTPS requests\. Defaults to verify peer\. -. -.IP "\(bu" 4 -\fBsuppress_install_using_messages\fR (\fBBUNDLE_SUPPRESS_INSTALL_USING_MESSAGES\fR): Avoid printing \fBUsing \.\.\.\fR messages during installation when the version of a gem has not changed\. -. .IP "\(bu" 4 \fBsystem_bindir\fR (\fBBUNDLE_SYSTEM_BINDIR\fR): The location where RubyGems installs binstubs\. Defaults to \fBGem\.bindir\fR\. -. .IP "\(bu" 4 \fBtimeout\fR (\fBBUNDLE_TIMEOUT\fR): The seconds allowed before timing out for network requests\. Defaults to \fB10\fR\. -. .IP "\(bu" 4 \fBupdate_requires_all_flag\fR (\fBBUNDLE_UPDATE_REQUIRES_ALL_FLAG\fR): Require passing \fB\-\-all\fR to \fBbundle update\fR when everything should be updated, and disallow passing no options to \fBbundle update\fR\. -. .IP "\(bu" 4 \fBuser_agent\fR (\fBBUNDLE_USER_AGENT\fR): The custom user agent fragment Bundler includes in API requests\. -. +.IP "\(bu" 4 +\fBversion\fR (\fBBUNDLE_VERSION\fR): The version of Bundler to use when running under Bundler environment\. Defaults to \fBlockfile\fR\. You can also specify \fBsystem\fR or \fBx\.y\.z\fR\. \fBlockfile\fR will use the Bundler version specified in the \fBGemfile\.lock\fR, \fBsystem\fR will use the system version of Bundler, and \fBx\.y\.z\fR will use the specified version of Bundler\. .IP "\(bu" 4 \fBwith\fR (\fBBUNDLE_WITH\fR): A \fB:\fR\-separated list of groups whose gems bundler should install\. -. .IP "\(bu" 4 \fBwithout\fR (\fBBUNDLE_WITHOUT\fR): A \fB:\fR\-separated list of groups whose gems bundler should not install\. -. .IP "" 0 -. .P In general, you should set these settings per\-application by using the applicable flag to the bundle install(1) \fIbundle\-install\.1\.html\fR or bundle cache(1) \fIbundle\-cache\.1\.html\fR command\. -. .P You can set them globally either via environment variables or \fBbundle config\fR, whichever is preferable for your setup\. If you use both, environment variables will take preference over global settings\. -. .SH "LOCAL GIT REPOS" Bundler also allows you to work against a git repository locally instead of using the remote version\. This can be achieved by setting up a local override: -. .IP "" 4 -. .nf - bundle config set \-\-local local\.GEM_NAME /path/to/local/git/repository -. .fi -. .IP "" 0 -. .P For example, in order to use a local Rack repository, a developer could call: -. .IP "" 4 -. .nf - bundle config set \-\-local local\.rack ~/Work/git/rack -. .fi -. .IP "" 0 -. .P -Now instead of checking out the remote git repository, the local override will be used\. Similar to a path source, every time the local git repository change, changes will be automatically picked up by Bundler\. This means a commit in the local git repo will update the revision in the \fBGemfile\.lock\fR to the local git repo revision\. This requires the same attention as git submodules\. Before pushing to the remote, you need to ensure the local override was pushed, otherwise you may point to a commit that only exists in your local machine\. You\'ll also need to CGI escape your usernames and passwords as well\. -. +Now instead of checking out the remote git repository, the local override will be used\. Similar to a path source, every time the local git repository change, changes will be automatically picked up by Bundler\. This means a commit in the local git repo will update the revision in the \fBGemfile\.lock\fR to the local git repo revision\. This requires the same attention as git submodules\. Before pushing to the remote, you need to ensure the local override was pushed, otherwise you may point to a commit that only exists in your local machine\. You'll also need to CGI escape your usernames and passwords as well\. .P -Bundler does many checks to ensure a developer won\'t work with invalid references\. Particularly, we force a developer to specify a branch in the \fBGemfile\fR in order to use this feature\. If the branch specified in the \fBGemfile\fR and the current branch in the local git repository do not match, Bundler will abort\. This ensures that a developer is always working against the correct branches, and prevents accidental locking to a different branch\. -. +Bundler does many checks to ensure a developer won't work with invalid references\. Particularly, we force a developer to specify a branch in the \fBGemfile\fR in order to use this feature\. If the branch specified in the \fBGemfile\fR and the current branch in the local git repository do not match, Bundler will abort\. This ensures that a developer is always working against the correct branches, and prevents accidental locking to a different branch\. .P Finally, Bundler also ensures that the current revision in the \fBGemfile\.lock\fR exists in the local git repository\. By doing this, Bundler forces you to fetch the latest changes in the remotes\. -. .SH "MIRRORS OF GEM SOURCES" Bundler supports overriding gem sources with mirrors\. This allows you to configure rubygems\.org as the gem source in your Gemfile while still using your mirror to fetch gems\. -. .IP "" 4 -. .nf - bundle config set \-\-global mirror\.SOURCE_URL MIRROR_URL -. .fi -. .IP "" 0 -. .P For example, to use a mirror of https://rubygems\.org hosted at https://example\.org: -. .IP "" 4 -. .nf - bundle config set \-\-global mirror\.https://rubygems\.org https://example\.org -. .fi -. .IP "" 0 -. .P Each mirror also provides a fallback timeout setting\. If the mirror does not respond within the fallback timeout, Bundler will try to use the original server instead of the mirror\. -. .IP "" 4 -. .nf - bundle config set \-\-global mirror\.SOURCE_URL\.fallback_timeout TIMEOUT -. .fi -. .IP "" 0 -. .P For example, to fall back to rubygems\.org after 3 seconds: -. .IP "" 4 -. .nf - bundle config set \-\-global mirror\.https://rubygems\.org\.fallback_timeout 3 -. .fi -. .IP "" 0 -. .P The default fallback timeout is 0\.1 seconds, but the setting can currently only accept whole seconds (for example, 1, 15, or 30)\. -. .SH "CREDENTIALS FOR GEM SOURCES" Bundler allows you to configure credentials for any gem source, which allows you to avoid putting secrets into your Gemfile\. -. .IP "" 4 -. .nf - bundle config set \-\-global SOURCE_HOSTNAME USERNAME:PASSWORD -. .fi -. .IP "" 0 -. .P For example, to save the credentials of user \fBclaudette\fR for the gem source at \fBgems\.longerous\.com\fR, you would run: -. .IP "" 4 -. .nf - bundle config set \-\-global gems\.longerous\.com claudette:s00pers3krit -. .fi -. .IP "" 0 -. .P Or you can set the credentials as an environment variable like this: -. .IP "" 4 -. .nf - export BUNDLE_GEMS__LONGEROUS__COM="claudette:s00pers3krit" -. .fi -. .IP "" 0 -. .P For gems with a git source with HTTP(S) URL you can specify credentials like so: -. .IP "" 4 -. .nf - bundle config set \-\-global https://github\.com/rubygems/rubygems\.git username:password -. .fi -. .IP "" 0 -. .P Or you can set the credentials as an environment variable like so: -. .IP "" 4 -. .nf - export BUNDLE_GITHUB__COM=username:password -. .fi -. .IP "" 0 -. .P This is especially useful for private repositories on hosts such as GitHub, where you can use personal OAuth tokens: -. .IP "" 4 -. .nf - export BUNDLE_GITHUB__COM=abcd0123generatedtoken:x\-oauth\-basic -. .fi -. .IP "" 0 -. .P Note that any configured credentials will be redacted by informative commands such as \fBbundle config list\fR or \fBbundle config get\fR, unless you use the \fB\-\-parseable\fR flag\. This is to avoid unintentionally leaking credentials when copy\-pasting bundler output\. -. .P Also note that to guarantee a sane mapping between valid environment variable names and valid host names, bundler makes the following transformations: -. .IP "\(bu" 4 -Any \fB\-\fR characters in a host name are mapped to a triple dash (\fB___\fR) in the corresponding environment variable\. -. +Any \fB\-\fR characters in a host name are mapped to a triple underscore (\fB___\fR) in the corresponding environment variable\. .IP "\(bu" 4 -Any \fB\.\fR characters in a host name are mapped to a double dash (\fB__\fR) in the corresponding environment variable\. -. +Any \fB\.\fR characters in a host name are mapped to a double underscore (\fB__\fR) in the corresponding environment variable\. .IP "" 0 -. .P -This means that if you have a gem server named \fBmy\.gem\-host\.com\fR, you\'ll need to use the \fBBUNDLE_MY__GEM___HOST__COM\fR variable to configure credentials for it through ENV\. -. +This means that if you have a gem server named \fBmy\.gem\-host\.com\fR, you'll need to use the \fBBUNDLE_MY__GEM___HOST__COM\fR variable to configure credentials for it through ENV\. .SH "CONFIGURE BUNDLER DIRECTORIES" -Bundler\'s home, config, cache and plugin directories are able to be configured through environment variables\. The default location for Bundler\'s home directory is \fB~/\.bundle\fR, which all directories inherit from by default\. The following outlines the available environment variables and their default values -. +Bundler's home, cache and plugin directories and config file can be configured through environment variables\. The default location for Bundler's home directory is \fB~/\.bundle\fR, which all directories inherit from by default\. The following outlines the available environment variables and their default values .IP "" 4 -. .nf - BUNDLE_USER_HOME : $HOME/\.bundle BUNDLE_USER_CACHE : $BUNDLE_USER_HOME/cache BUNDLE_USER_CONFIG : $BUNDLE_USER_HOME/config BUNDLE_USER_PLUGIN : $BUNDLE_USER_HOME/plugin -. .fi -. .IP "" 0 diff --git a/lib/bundler/man/bundle-config.1.ronn b/lib/bundler/man/bundle-config.1.ronn index bc8b27cf89..1a0ec2a5dc 100644 --- a/lib/bundler/man/bundle-config.1.ronn +++ b/lib/bundler/man/bundle-config.1.ronn @@ -137,9 +137,6 @@ the environment variable `BUNDLE_LOCAL__RACK`. The following is a list of all configuration keys and their purpose. You can learn more about their operation in [bundle install(1)](bundle-install.1.html). -* `allow_deployment_source_credential_changes` (`BUNDLE_ALLOW_DEPLOYMENT_SOURCE_CREDENTIAL_CHANGES`): - When in deployment mode, allow changing the credentials to a gem's source. - Ex: `https://some.host.com/gems/path/` -> `https://user_name:password@some.host.com/gems/path` * `allow_offline_install` (`BUNDLE_ALLOW_OFFLINE_INSTALL`): Allow Bundler to use cached data when installing without network access. * `auto_clean_without_path` (`BUNDLE_AUTO_CLEAN_WITHOUT_PATH`): @@ -265,9 +262,6 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html). * `ssl_verify_mode` (`BUNDLE_SSL_VERIFY_MODE`): The SSL verification mode Bundler uses when making HTTPS requests. Defaults to verify peer. -* `suppress_install_using_messages` (`BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES`): - Avoid printing `Using ...` messages during installation when the version of - a gem has not changed. * `system_bindir` (`BUNDLE_SYSTEM_BINDIR`): The location where RubyGems installs binstubs. Defaults to `Gem.bindir`. * `timeout` (`BUNDLE_TIMEOUT`): @@ -277,6 +271,12 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html). and disallow passing no options to `bundle update`. * `user_agent` (`BUNDLE_USER_AGENT`): The custom user agent fragment Bundler includes in API requests. +* `version` (`BUNDLE_VERSION`): + The version of Bundler to use when running under Bundler environment. + Defaults to `lockfile`. You can also specify `system` or `x.y.z`. + `lockfile` will use the Bundler version specified in the `Gemfile.lock`, + `system` will use the system version of Bundler, and `x.y.z` will use + the specified version of Bundler. * `with` (`BUNDLE_WITH`): A `:`-separated list of groups whose gems bundler should install. * `without` (`BUNDLE_WITHOUT`): @@ -385,10 +385,10 @@ copy-pasting bundler output. Also note that to guarantee a sane mapping between valid environment variable names and valid host names, bundler makes the following transformations: -* Any `-` characters in a host name are mapped to a triple dash (`___`) in the +* Any `-` characters in a host name are mapped to a triple underscore (`___`) in the corresponding environment variable. -* Any `.` characters in a host name are mapped to a double dash (`__`) in the +* Any `.` characters in a host name are mapped to a double underscore (`__`) in the corresponding environment variable. This means that if you have a gem server named `my.gem-host.com`, you'll need to @@ -397,7 +397,7 @@ through ENV. ## CONFIGURE BUNDLER DIRECTORIES -Bundler's home, config, cache and plugin directories are able to be configured +Bundler's home, cache and plugin directories and config file can be configured through environment variables. The default location for Bundler's home directory is `~/.bundle`, which all directories inherit from by default. The following outlines the available environment variables and their default values diff --git a/lib/bundler/man/bundle-console.1 b/lib/bundler/man/bundle-console.1 index ff239004bf..dca18ec43d 100644 --- a/lib/bundler/man/bundle-console.1 +++ b/lib/bundler/man/bundle-console.1 @@ -1,53 +1,35 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-CONSOLE" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-CONSOLE" "1" "May 2024" "" .SH "NAME" \fBbundle\-console\fR \- Deprecated way to open an IRB session with the bundle pre\-loaded -. .SH "SYNOPSIS" \fBbundle console\fR [GROUP] -. .SH "DESCRIPTION" Starts an interactive Ruby console session in the context of the current bundle\. -. .P If no \fBGROUP\fR is specified, all gems in the \fBdefault\fR group in the Gemfile(5) \fIhttps://bundler\.io/man/gemfile\.5\.html\fR are preliminarily loaded\. -. .P If \fBGROUP\fR is specified, all gems in the given group in the Gemfile in addition to the gems in \fBdefault\fR group are loaded\. Even if the given group does not exist in the Gemfile, IRB console starts without any warning or error\. -. .P The environment variable \fBBUNDLE_CONSOLE\fR or \fBbundle config set console\fR can be used to change the shell from the following: -. .IP "\(bu" 4 \fBirb\fR (default) -. .IP "\(bu" 4 \fBpry\fR (https://github\.com/pry/pry) -. .IP "\(bu" 4 \fBripl\fR (https://github\.com/cldwalker/ripl) -. .IP "" 0 -. .P \fBbundle console\fR uses irb by default\. An alternative Pry or Ripl can be used with \fBbundle console\fR by adjusting the \fBconsole\fR Bundler setting\. Also make sure that \fBpry\fR or \fBripl\fR is in your Gemfile\. -. .SH "EXAMPLE" -. .nf - $ bundle config set console pry $ bundle console -Resolving dependencies\.\.\. +Resolving dependencies\|\.\|\.\|\. [1] pry(main)> -. .fi -. .SH "NOTES" This command was deprecated in Bundler 2\.1 and will be removed in 3\.0\. Use \fBbin/console\fR script, which can be generated by \fBbundle gem <NAME>\fR\. -. .SH "SEE ALSO" Gemfile(5) \fIhttps://bundler\.io/man/gemfile\.5\.html\fR diff --git a/lib/bundler/man/bundle-doctor.1 b/lib/bundler/man/bundle-doctor.1 index e463b67477..6489cc07f7 100644 --- a/lib/bundler/man/bundle-doctor.1 +++ b/lib/bundler/man/bundle-doctor.1 @@ -1,44 +1,30 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-DOCTOR" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-DOCTOR" "1" "May 2024" "" .SH "NAME" \fBbundle\-doctor\fR \- Checks the bundle for common problems -. .SH "SYNOPSIS" \fBbundle doctor\fR [\-\-quiet] [\-\-gemfile=GEMFILE] -. .SH "DESCRIPTION" Checks your Gemfile and gem environment for common problems\. If issues are detected, Bundler prints them and exits status 1\. Otherwise, Bundler prints a success message and exits status 0\. -. .P Examples of common problems caught by bundle\-doctor include: -. .IP "\(bu" 4 Invalid Bundler settings -. .IP "\(bu" 4 Mismatched Ruby versions -. .IP "\(bu" 4 Mismatched platforms -. .IP "\(bu" 4 Uninstalled gems -. .IP "\(bu" 4 Missing dependencies -. .IP "" 0 -. .SH "OPTIONS" -. .TP \fB\-\-quiet\fR Only output warnings and errors\. -. .TP \fB\-\-gemfile=<gemfile>\fR -The location of the Gemfile(5) which Bundler should use\. This defaults to a Gemfile(5) in the current working directory\. In general, Bundler will assume that the location of the Gemfile(5) is also the project\'s root and will try to find \fBGemfile\.lock\fR and \fBvendor/cache\fR relative to this location\. +The location of the Gemfile(5) which Bundler should use\. This defaults to a Gemfile(5) in the current working directory\. In general, Bundler will assume that the location of the Gemfile(5) is also the project's root and will try to find \fBGemfile\.lock\fR and \fBvendor/cache\fR relative to this location\. diff --git a/lib/bundler/man/bundle-exec.1 b/lib/bundler/man/bundle-exec.1 index 9e9efe8b6d..1548d29670 100644 --- a/lib/bundler/man/bundle-exec.1 +++ b/lib/bundler/man/bundle-exec.1 @@ -1,165 +1,104 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-EXEC" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-EXEC" "1" "May 2024" "" .SH "NAME" \fBbundle\-exec\fR \- Execute a command in the context of the bundle -. .SH "SYNOPSIS" \fBbundle exec\fR [\-\-keep\-file\-descriptors] \fIcommand\fR -. .SH "DESCRIPTION" This command executes the command, making all gems specified in the [\fBGemfile(5)\fR][Gemfile(5)] available to \fBrequire\fR in Ruby programs\. -. .P Essentially, if you would normally have run something like \fBrspec spec/my_spec\.rb\fR, and you want to use the gems specified in the [\fBGemfile(5)\fR][Gemfile(5)] and installed via bundle install(1) \fIbundle\-install\.1\.html\fR, you should run \fBbundle exec rspec spec/my_spec\.rb\fR\. -. .P -Note that \fBbundle exec\fR does not require that an executable is available on your shell\'s \fB$PATH\fR\. -. +Note that \fBbundle exec\fR does not require that an executable is available on your shell's \fB$PATH\fR\. .SH "OPTIONS" -. .TP \fB\-\-keep\-file\-descriptors\fR -Exec in Ruby 2\.0 began discarding non\-standard file descriptors\. When this flag is passed, exec will revert to the 1\.9 behaviour of passing all file descriptors to the new process\. -. +Passes all file descriptors to the new processes\. Default is true from bundler version 2\.2\.26\. Setting it to false is now deprecated\. .SH "BUNDLE INSTALL \-\-BINSTUBS" If you use the \fB\-\-binstubs\fR flag in bundle install(1) \fIbundle\-install\.1\.html\fR, Bundler will automatically create a directory (which defaults to \fBapp_root/bin\fR) containing all of the executables available from gems in the bundle\. -. .P After using \fB\-\-binstubs\fR, \fBbin/rspec spec/my_spec\.rb\fR is identical to \fBbundle exec rspec spec/my_spec\.rb\fR\. -. .SH "ENVIRONMENT MODIFICATIONS" \fBbundle exec\fR makes a number of changes to the shell environment, then executes the command you specify in full\. -. .IP "\(bu" 4 -make sure that it\'s still possible to shell out to \fBbundle\fR from inside a command invoked by \fBbundle exec\fR (using \fB$BUNDLE_BIN_PATH\fR) -. +make sure that it's still possible to shell out to \fBbundle\fR from inside a command invoked by \fBbundle exec\fR (using \fB$BUNDLE_BIN_PATH\fR) .IP "\(bu" 4 put the directory containing executables (like \fBrails\fR, \fBrspec\fR, \fBrackup\fR) for your bundle on \fB$PATH\fR -. .IP "\(bu" 4 make sure that if bundler is invoked in the subshell, it uses the same \fBGemfile\fR (by setting \fBBUNDLE_GEMFILE\fR) -. .IP "\(bu" 4 add \fB\-rbundler/setup\fR to \fB$RUBYOPT\fR, which makes sure that Ruby programs invoked in the subshell can see the gems in the bundle -. .IP "" 0 -. .P It also modifies Rubygems: -. .IP "\(bu" 4 disallow loading additional gems not in the bundle -. .IP "\(bu" 4 -modify the \fBgem\fR method to be a no\-op if a gem matching the requirements is in the bundle, and to raise a \fBGem::LoadError\fR if it\'s not -. +modify the \fBgem\fR method to be a no\-op if a gem matching the requirements is in the bundle, and to raise a \fBGem::LoadError\fR if it's not .IP "\(bu" 4 Define \fBGem\.refresh\fR to be a no\-op, since the source index is always frozen when using bundler, and to prevent gems from the system leaking into the environment -. .IP "\(bu" 4 Override \fBGem\.bin_path\fR to use the gems in the bundle, making system executables work -. .IP "\(bu" 4 Add all gems in the bundle into Gem\.loaded_specs -. .IP "" 0 -. .P -Finally, \fBbundle exec\fR also implicitly modifies \fBGemfile\.lock\fR if the lockfile and the Gemfile do not match\. Bundler needs the Gemfile to determine things such as a gem\'s groups, \fBautorequire\fR, and platforms, etc\., and that information isn\'t stored in the lockfile\. The Gemfile and lockfile must be synced in order to \fBbundle exec\fR successfully, so \fBbundle exec\fR updates the lockfile beforehand\. -. +Finally, \fBbundle exec\fR also implicitly modifies \fBGemfile\.lock\fR if the lockfile and the Gemfile do not match\. Bundler needs the Gemfile to determine things such as a gem's groups, \fBautorequire\fR, and platforms, etc\., and that information isn't stored in the lockfile\. The Gemfile and lockfile must be synced in order to \fBbundle exec\fR successfully, so \fBbundle exec\fR updates the lockfile beforehand\. .SS "Loading" By default, when attempting to \fBbundle exec\fR to a file with a ruby shebang, Bundler will \fBKernel\.load\fR that file instead of using \fBKernel\.exec\fR\. For the vast majority of cases, this is a performance improvement\. In a rare few cases, this could cause some subtle side\-effects (such as dependence on the exact contents of \fB$0\fR or \fB__FILE__\fR) and the optimization can be disabled by enabling the \fBdisable_exec_load\fR setting\. -. .SS "Shelling out" -Any Ruby code that opens a subshell (like \fBsystem\fR, backticks, or \fB%x{}\fR) will automatically use the current Bundler environment\. If you need to shell out to a Ruby command that is not part of your current bundle, use the \fBwith_unbundled_env\fR method with a block\. Any subshells created inside the block will be given the environment present before Bundler was activated\. For example, Homebrew commands run Ruby, but don\'t work inside a bundle: -. +Any Ruby code that opens a subshell (like \fBsystem\fR, backticks, or \fB%x{}\fR) will automatically use the current Bundler environment\. If you need to shell out to a Ruby command that is not part of your current bundle, use the \fBwith_unbundled_env\fR method with a block\. Any subshells created inside the block will be given the environment present before Bundler was activated\. For example, Homebrew commands run Ruby, but don't work inside a bundle: .IP "" 4 -. .nf - Bundler\.with_unbundled_env do `brew install wget` end -. .fi -. .IP "" 0 -. .P Using \fBwith_unbundled_env\fR is also necessary if you are shelling out to a different bundle\. Any Bundler commands run in a subshell will inherit the current Gemfile, so commands that need to run in the context of a different bundle also need to use \fBwith_unbundled_env\fR\. -. .IP "" 4 -. .nf - Bundler\.with_unbundled_env do Dir\.chdir "/other/bundler/project" do `bundle exec \./script` end end -. .fi -. .IP "" 0 -. .P Bundler provides convenience helpers that wrap \fBsystem\fR and \fBexec\fR, and they can be used like this: -. .IP "" 4 -. .nf - -Bundler\.clean_system(\'brew install wget\') -Bundler\.clean_exec(\'brew install wget\') -. +Bundler\.clean_system('brew install wget') +Bundler\.clean_exec('brew install wget') .fi -. .IP "" 0 -. .SH "RUBYGEMS PLUGINS" At present, the Rubygems plugin system requires all files named \fBrubygems_plugin\.rb\fR on the load path of \fIany\fR installed gem when any Ruby code requires \fBrubygems\.rb\fR\. This includes executables installed into the system, like \fBrails\fR, \fBrackup\fR, and \fBrspec\fR\. -. .P Since Rubygems plugins can contain arbitrary Ruby code, they commonly end up activating themselves or their dependencies\. -. .P For instance, the \fBgemcutter 0\.5\fR gem depended on \fBjson_pure\fR\. If you had that version of gemcutter installed (even if you \fIalso\fR had a newer version without this problem), Rubygems would activate \fBgemcutter 0\.5\fR and \fBjson_pure <latest>\fR\. -. .P If your Gemfile(5) also contained \fBjson_pure\fR (or a gem with a dependency on \fBjson_pure\fR), the latest version on your system might conflict with the version in your Gemfile(5), or the snapshot version in your \fBGemfile\.lock\fR\. -. .P If this happens, bundler will say: -. .IP "" 4 -. .nf - You have already activated json_pure 1\.4\.6 but your Gemfile requires json_pure 1\.4\.3\. Consider using bundle exec\. -. .fi -. .IP "" 0 -. .P In this situation, you almost certainly want to remove the underlying gem with the problematic gem plugin\. In general, the authors of these plugins (in this case, the \fBgemcutter\fR gem) have released newer versions that are more careful in their plugins\. -. .P You can find a list of all the gems containing gem plugins by running -. .IP "" 4 -. .nf - -ruby \-e "puts Gem\.find_files(\'rubygems_plugin\.rb\')" -. +ruby \-e "puts Gem\.find_files('rubygems_plugin\.rb')" .fi -. .IP "" 0 -. .P -At the very least, you should remove all but the newest version of each gem plugin, and also remove all gem plugins that you aren\'t using (\fBgem uninstall gem_name\fR)\. +At the very least, you should remove all but the newest version of each gem plugin, and also remove all gem plugins that you aren't using (\fBgem uninstall gem_name\fR)\. diff --git a/lib/bundler/man/bundle-exec.1.ronn b/lib/bundler/man/bundle-exec.1.ronn index 05948095e2..9d5b559f26 100644 --- a/lib/bundler/man/bundle-exec.1.ronn +++ b/lib/bundler/man/bundle-exec.1.ronn @@ -21,9 +21,8 @@ available on your shell's `$PATH`. ## OPTIONS * `--keep-file-descriptors`: - Exec in Ruby 2.0 began discarding non-standard file descriptors. When this - flag is passed, exec will revert to the 1.9 behaviour of passing all file - descriptors to the new process. + Passes all file descriptors to the new processes. Default is true from + bundler version 2.2.26. Setting it to false is now deprecated. ## BUNDLE INSTALL --BINSTUBS diff --git a/lib/bundler/man/bundle-gem.1 b/lib/bundler/man/bundle-gem.1 index ea64871fb6..5df7b0ef2f 100644 --- a/lib/bundler/man/bundle-gem.1 +++ b/lib/bundler/man/bundle-gem.1 @@ -1,105 +1,69 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-GEM" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-GEM" "1" "May 2024" "" .SH "NAME" \fBbundle\-gem\fR \- Generate a project skeleton for creating a rubygem -. .SH "SYNOPSIS" \fBbundle gem\fR \fIGEM_NAME\fR \fIOPTIONS\fR -. .SH "DESCRIPTION" Generates a directory named \fBGEM_NAME\fR with a \fBRakefile\fR, \fBGEM_NAME\.gemspec\fR, and other supporting files and directories that can be used to develop a rubygem with that name\. -. .P Run \fBrake \-T\fR in the resulting project for a list of Rake tasks that can be used to test and publish the gem to rubygems\.org\. -. .P -The generated project skeleton can be customized with OPTIONS, as explained below\. Note that these options can also be specified via Bundler\'s global configuration file using the following names: -. +The generated project skeleton can be customized with OPTIONS, as explained below\. Note that these options can also be specified via Bundler's global configuration file using the following names: .IP "\(bu" 4 \fBgem\.coc\fR -. .IP "\(bu" 4 \fBgem\.mit\fR -. .IP "\(bu" 4 \fBgem\.test\fR -. .IP "" 0 -. .SH "OPTIONS" -. .IP "\(bu" 4 \fB\-\-exe\fR or \fB\-b\fR or \fB\-\-bin\fR: Specify that Bundler should create a binary executable (as \fBexe/GEM_NAME\fR) in the generated rubygem project\. This binary will also be added to the \fBGEM_NAME\.gemspec\fR manifest\. This behavior is disabled by default\. -. .IP "\(bu" 4 \fB\-\-no\-exe\fR: Do not create a binary (overrides \fB\-\-exe\fR specified in the global config)\. -. .IP "\(bu" 4 -\fB\-\-coc\fR: Add a \fBCODE_OF_CONDUCT\.md\fR file to the root of the generated project\. If this option is unspecified, an interactive prompt will be displayed and the answer will be saved in Bundler\'s global config for future \fBbundle gem\fR use\. -. +\fB\-\-coc\fR: Add a \fBCODE_OF_CONDUCT\.md\fR file to the root of the generated project\. If this option is unspecified, an interactive prompt will be displayed and the answer will be saved in Bundler's global config for future \fBbundle gem\fR use\. .IP "\(bu" 4 \fB\-\-no\-coc\fR: Do not create a \fBCODE_OF_CONDUCT\.md\fR (overrides \fB\-\-coc\fR specified in the global config)\. -. .IP "\(bu" 4 \fB\-\-ext=c\fR, \fB\-\-ext=rust\fR Add boilerplate for C or Rust (currently magnus \fIhttps://docs\.rs/magnus\fR based) extension code to the generated project\. This behavior is disabled by default\. -. .IP "\(bu" 4 \fB\-\-no\-ext\fR: Do not add extension code (overrides \fB\-\-ext\fR specified in the global config)\. -. .IP "\(bu" 4 -\fB\-\-mit\fR: Add an MIT license to a \fBLICENSE\.txt\fR file in the root of the generated project\. Your name from the global git config is used for the copyright statement\. If this option is unspecified, an interactive prompt will be displayed and the answer will be saved in Bundler\'s global config for future \fBbundle gem\fR use\. -. +\fB\-\-mit\fR: Add an MIT license to a \fBLICENSE\.txt\fR file in the root of the generated project\. Your name from the global git config is used for the copyright statement\. If this option is unspecified, an interactive prompt will be displayed and the answer will be saved in Bundler's global config for future \fBbundle gem\fR use\. .IP "\(bu" 4 \fB\-\-no\-mit\fR: Do not create a \fBLICENSE\.txt\fR (overrides \fB\-\-mit\fR specified in the global config)\. -. .IP "\(bu" 4 \fB\-t\fR, \fB\-\-test=minitest\fR, \fB\-\-test=rspec\fR, \fB\-\-test=test\-unit\fR: Specify the test framework that Bundler should use when generating the project\. Acceptable values are \fBminitest\fR, \fBrspec\fR and \fBtest\-unit\fR\. The \fBGEM_NAME\.gemspec\fR will be configured and a skeleton test/spec directory will be created based on this option\. Given no option is specified: -. .IP -When Bundler is configured to generate tests, this defaults to Bundler\'s global config setting \fBgem\.test\fR\. -. +When Bundler is configured to generate tests, this defaults to Bundler's global config setting \fBgem\.test\fR\. .IP When Bundler is configured to not generate tests, an interactive prompt will be displayed and the answer will be used for the current rubygem project\. -. .IP -When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler\'s global config for future \fBbundle gem\fR use\. -. +When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler's global config for future \fBbundle gem\fR use\. .IP "\(bu" 4 \fB\-\-ci\fR, \fB\-\-ci=github\fR, \fB\-\-ci=gitlab\fR, \fB\-\-ci=circle\fR: Specify the continuous integration service that Bundler should use when generating the project\. Acceptable values are \fBgithub\fR, \fBgitlab\fR and \fBcircle\fR\. A configuration file will be generated in the project directory\. Given no option is specified: -. .IP -When Bundler is configured to generate CI files, this defaults to Bundler\'s global config setting \fBgem\.ci\fR\. -. +When Bundler is configured to generate CI files, this defaults to Bundler's global config setting \fBgem\.ci\fR\. .IP When Bundler is configured to not generate CI files, an interactive prompt will be displayed and the answer will be used for the current rubygem project\. -. .IP -When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler\'s global config for future \fBbundle gem\fR use\. -. +When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler's global config for future \fBbundle gem\fR use\. .IP "\(bu" 4 -\fB\-\-linter\fR, \fB\-\-linter=rubocop\fR, \fB\-\-linter=standard\fR: Specify the linter and code formatter that Bundler should add to the project\'s development dependencies\. Acceptable values are \fBrubocop\fR and \fBstandard\fR\. A configuration file will be generated in the project directory\. Given no option is specified: -. +\fB\-\-linter\fR, \fB\-\-linter=rubocop\fR, \fB\-\-linter=standard\fR: Specify the linter and code formatter that Bundler should add to the project's development dependencies\. Acceptable values are \fBrubocop\fR and \fBstandard\fR\. A configuration file will be generated in the project directory\. Given no option is specified: .IP -When Bundler is configured to add a linter, this defaults to Bundler\'s global config setting \fBgem\.linter\fR\. -. +When Bundler is configured to add a linter, this defaults to Bundler's global config setting \fBgem\.linter\fR\. .IP When Bundler is configured not to add a linter, an interactive prompt will be displayed and the answer will be used for the current rubygem project\. -. .IP -When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler\'s global config for future \fBbundle gem\fR use\. -. +When Bundler is unconfigured, an interactive prompt will be displayed and the answer will be saved in Bundler's global config for future \fBbundle gem\fR use\. .IP "\(bu" 4 \fB\-e\fR, \fB\-\-edit[=EDITOR]\fR: Open the resulting GEM_NAME\.gemspec in EDITOR, or the default editor if not specified\. The default is \fB$BUNDLER_EDITOR\fR, \fB$VISUAL\fR, or \fB$EDITOR\fR\. -. .IP "" 0 -. .SH "SEE ALSO" -. .IP "\(bu" 4 bundle config(1) \fIbundle\-config\.1\.html\fR -. .IP "" 0 diff --git a/lib/bundler/man/bundle-help.1 b/lib/bundler/man/bundle-help.1 index a3b059ea07..a3e7c7770d 100644 --- a/lib/bundler/man/bundle-help.1 +++ b/lib/bundler/man/bundle-help.1 @@ -1,13 +1,9 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-HELP" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-HELP" "1" "May 2024" "" .SH "NAME" \fBbundle\-help\fR \- Displays detailed help for each subcommand -. .SH "SYNOPSIS" \fBbundle help\fR [COMMAND] -. .SH "DESCRIPTION" Displays detailed help for the given subcommand\. You can specify a single \fBCOMMAND\fR at the same time\. When \fBCOMMAND\fR is omitted, help for \fBhelp\fR command will be displayed\. diff --git a/lib/bundler/man/bundle-info.1 b/lib/bundler/man/bundle-info.1 index 5af60c6a77..a3d7ff0988 100644 --- a/lib/bundler/man/bundle-info.1 +++ b/lib/bundler/man/bundle-info.1 @@ -1,19 +1,13 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-INFO" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-INFO" "1" "May 2024" "" .SH "NAME" \fBbundle\-info\fR \- Show information for the given gem in your bundle -. .SH "SYNOPSIS" -\fBbundle info\fR [GEM] [\-\-path] -. +\fBbundle info\fR [GEM_NAME] [\-\-path] .SH "DESCRIPTION" -Print the basic information about the provided GEM such as homepage, version, path and summary\. -. +Given a gem name present in your bundle, print the basic information about it such as homepage, version, path and summary\. .SH "OPTIONS" -. .TP \fB\-\-path\fR Print the path of the given gem diff --git a/lib/bundler/man/bundle-info.1.ronn b/lib/bundler/man/bundle-info.1.ronn index 47e457aa3c..cecdeb564f 100644 --- a/lib/bundler/man/bundle-info.1.ronn +++ b/lib/bundler/man/bundle-info.1.ronn @@ -3,13 +3,13 @@ bundle-info(1) -- Show information for the given gem in your bundle ## SYNOPSIS -`bundle info` [GEM] +`bundle info` [GEM_NAME] [--path] ## DESCRIPTION -Print the basic information about the provided GEM such as homepage, version, -path and summary. +Given a gem name present in your bundle, print the basic information about it + such as homepage, version, path and summary. ## OPTIONS diff --git a/lib/bundler/man/bundle-init.1 b/lib/bundler/man/bundle-init.1 index e93b4fd5e9..a0edaaa18f 100644 --- a/lib/bundler/man/bundle-init.1 +++ b/lib/bundler/man/bundle-init.1 @@ -1,29 +1,20 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-INIT" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-INIT" "1" "May 2024" "" .SH "NAME" \fBbundle\-init\fR \- Generates a Gemfile into the current working directory -. .SH "SYNOPSIS" \fBbundle init\fR [\-\-gemspec=FILE] -. .SH "DESCRIPTION" Init generates a default [\fBGemfile(5)\fR][Gemfile(5)] in the current working directory\. When adding a [\fBGemfile(5)\fR][Gemfile(5)] to a gem with a gemspec, the \fB\-\-gemspec\fR option will automatically add each dependency listed in the gemspec file to the newly created [\fBGemfile(5)\fR][Gemfile(5)]\. -. .SH "OPTIONS" -. .TP \fB\-\-gemspec\fR Use the specified \.gemspec to create the [\fBGemfile(5)\fR][Gemfile(5)] -. .TP \fB\-\-gemfile\fR Use the specified name for the gemfile instead of \fBGemfile\fR -. .SH "FILES" Included in the default [\fBGemfile(5)\fR][Gemfile(5)] generated is the line \fB# frozen_string_literal: true\fR\. This is a magic comment supported for the first time in Ruby 2\.3\. The presence of this line results in all string literals in the file being implicitly frozen\. -. .SH "SEE ALSO" Gemfile(5) \fIhttps://bundler\.io/man/gemfile\.5\.html\fR diff --git a/lib/bundler/man/bundle-inject.1 b/lib/bundler/man/bundle-inject.1 index 657d5ef4a7..7a1038206e 100644 --- a/lib/bundler/man/bundle-inject.1 +++ b/lib/bundler/man/bundle-inject.1 @@ -1,36 +1,23 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-INJECT" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-INJECT" "1" "May 2024" "" .SH "NAME" \fBbundle\-inject\fR \- Add named gem(s) with version requirements to Gemfile -. .SH "SYNOPSIS" \fBbundle inject\fR [GEM] [VERSION] -. .SH "DESCRIPTION" Adds the named gem(s) with their version requirements to the resolved [\fBGemfile(5)\fR][Gemfile(5)]\. -. .P -This command will add the gem to both your [\fBGemfile(5)\fR][Gemfile(5)] and Gemfile\.lock if it isn\'t listed yet\. -. +This command will add the gem to both your [\fBGemfile(5)\fR][Gemfile(5)] and Gemfile\.lock if it isn't listed yet\. .P Example: -. .IP "" 4 -. .nf - bundle install -bundle inject \'rack\' \'> 0\' -. +bundle inject 'rack' '> 0' .fi -. .IP "" 0 -. .P -This will inject the \'rack\' gem with a version greater than 0 in your [\fBGemfile(5)\fR][Gemfile(5)] and Gemfile\.lock\. -. +This will inject the 'rack' gem with a version greater than 0 in your [\fBGemfile(5)\fR][Gemfile(5)] and Gemfile\.lock\. .P The \fBbundle inject\fR command was deprecated in Bundler 2\.1 and will be removed in Bundler 3\.0\. diff --git a/lib/bundler/man/bundle-install.1 b/lib/bundler/man/bundle-install.1 index 8f144692f3..cc46a03b7f 100644 --- a/lib/bundler/man/bundle-install.1 +++ b/lib/bundler/man/bundle-install.1 @@ -1,313 +1,215 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-INSTALL" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-INSTALL" "1" "May 2024" "" .SH "NAME" \fBbundle\-install\fR \- Install the dependencies specified in your Gemfile -. .SH "SYNOPSIS" -\fBbundle install\fR [\-\-binstubs[=DIRECTORY]] [\-\-clean] [\-\-deployment] [\-\-frozen] [\-\-full\-index] [\-\-gemfile=GEMFILE] [\-\-jobs=NUMBER] [\-\-local] [\-\-no\-cache] [\-\-no\-prune] [\-\-path PATH] [\-\-quiet] [\-\-redownload] [\-\-retry=NUMBER] [\-\-shebang] [\-\-standalone[=GROUP[ GROUP\.\.\.]]] [\-\-system] [\-\-trust\-policy=POLICY] [\-\-with=GROUP[ GROUP\.\.\.]] [\-\-without=GROUP[ GROUP\.\.\.]] -. +\fBbundle install\fR [\-\-binstubs[=DIRECTORY]] [\-\-clean] [\-\-deployment] [\-\-frozen] [\-\-full\-index] [\-\-gemfile=GEMFILE] [\-\-jobs=NUMBER] [\-\-local] [\-\-no\-cache] [\-\-no\-prune] [\-\-path PATH] [\-\-prefer\-local] [\-\-quiet] [\-\-redownload] [\-\-retry=NUMBER] [\-\-shebang] [\-\-standalone[=GROUP[ GROUP\|\.\|\.\|\.]]] [\-\-system] [\-\-trust\-policy=POLICY] [\-\-with=GROUP[ GROUP\|\.\|\.\|\.]] [\-\-without=GROUP[ GROUP\|\.\|\.\|\.]] .SH "DESCRIPTION" Install the gems specified in your Gemfile(5)\. If this is the first time you run bundle install (and a \fBGemfile\.lock\fR does not exist), Bundler will fetch all remote sources, resolve dependencies and install all needed gems\. -. .P If a \fBGemfile\.lock\fR does exist, and you have not updated your Gemfile(5), Bundler will fetch all remote sources, but use the dependencies specified in the \fBGemfile\.lock\fR instead of resolving dependencies\. -. .P If a \fBGemfile\.lock\fR does exist, and you have updated your Gemfile(5), Bundler will use the dependencies in the \fBGemfile\.lock\fR for all gems that you did not update, but will re\-resolve the dependencies of gems that you did update\. You can find more information about this update process below under \fICONSERVATIVE UPDATING\fR\. -. .SH "OPTIONS" The \fB\-\-clean\fR, \fB\-\-deployment\fR, \fB\-\-frozen\fR, \fB\-\-no\-prune\fR, \fB\-\-path\fR, \fB\-\-shebang\fR, \fB\-\-system\fR, \fB\-\-without\fR and \fB\-\-with\fR options are deprecated because they only make sense if they are applied to every subsequent \fBbundle install\fR run automatically and that requires \fBbundler\fR to silently remember them\. Since \fBbundler\fR will no longer remember CLI flags in future versions, \fBbundle config\fR (see bundle\-config(1)) should be used to apply them permanently\. -. .TP \fB\-\-binstubs[=<directory>]\fR Binstubs are scripts that wrap around executables\. Bundler creates a small Ruby file (a binstub) that loads Bundler, runs the command, and puts it in \fBbin/\fR\. This lets you link the binstub inside of an application to the exact gem version the application needs\. -. .IP -Creates a directory (defaults to \fB~/bin\fR) and places any executables from the gem there\. These executables run in Bundler\'s context\. If used, you might add this directory to your environment\'s \fBPATH\fR variable\. For instance, if the \fBrails\fR gem comes with a \fBrails\fR executable, this flag will create a \fBbin/rails\fR executable that ensures that all referred dependencies will be resolved using the bundled gems\. -. +Creates a directory (defaults to \fB~/bin\fR) and places any executables from the gem there\. These executables run in Bundler's context\. If used, you might add this directory to your environment's \fBPATH\fR variable\. For instance, if the \fBrails\fR gem comes with a \fBrails\fR executable, this flag will create a \fBbin/rails\fR executable that ensures that all referred dependencies will be resolved using the bundled gems\. .TP \fB\-\-clean\fR -On finishing the installation Bundler is going to remove any gems not present in the current Gemfile(5)\. Don\'t worry, gems currently in use will not be removed\. -. +On finishing the installation Bundler is going to remove any gems not present in the current Gemfile(5)\. Don't worry, gems currently in use will not be removed\. .IP This option is deprecated in favor of the \fBclean\fR setting\. -. .TP \fB\-\-deployment\fR -In \fIdeployment mode\fR, Bundler will \'roll\-out\' the bundle for production or CI use\. Please check carefully if you want to have this option enabled in your development environment\. -. +In \fIdeployment mode\fR, Bundler will 'roll\-out' the bundle for production or CI use\. Please check carefully if you want to have this option enabled in your development environment\. .IP This option is deprecated in favor of the \fBdeployment\fR setting\. -. .TP \fB\-\-redownload\fR Force download every gem, even if the required versions are already available locally\. -. .TP \fB\-\-frozen\fR Do not allow the Gemfile\.lock to be updated after this install\. Exits non\-zero if there are going to be changes to the Gemfile\.lock\. -. .IP This option is deprecated in favor of the \fBfrozen\fR setting\. -. .TP \fB\-\-full\-index\fR -Bundler will not call Rubygems\' API endpoint (default) but download and cache a (currently big) index file of all gems\. Performance can be improved for large bundles that seldom change by enabling this option\. -. +Bundler will not call Rubygems' API endpoint (default) but download and cache a (currently big) index file of all gems\. Performance can be improved for large bundles that seldom change by enabling this option\. .TP \fB\-\-gemfile=<gemfile>\fR -The location of the Gemfile(5) which Bundler should use\. This defaults to a Gemfile(5) in the current working directory\. In general, Bundler will assume that the location of the Gemfile(5) is also the project\'s root and will try to find \fBGemfile\.lock\fR and \fBvendor/cache\fR relative to this location\. -. +The location of the Gemfile(5) which Bundler should use\. This defaults to a Gemfile(5) in the current working directory\. In general, Bundler will assume that the location of the Gemfile(5) is also the project's root and will try to find \fBGemfile\.lock\fR and \fBvendor/cache\fR relative to this location\. .TP \fB\-\-jobs=[<number>]\fR, \fB\-j[<number>]\fR The maximum number of parallel download and install jobs\. The default is the number of available processors\. -. .TP \fB\-\-local\fR -Do not attempt to connect to \fBrubygems\.org\fR\. Instead, Bundler will use the gems already present in Rubygems\' cache or in \fBvendor/cache\fR\. Note that if an appropriate platform\-specific gem exists on \fBrubygems\.org\fR it will not be found\. -. +Do not attempt to connect to \fBrubygems\.org\fR\. Instead, Bundler will use the gems already present in Rubygems' cache or in \fBvendor/cache\fR\. Note that if an appropriate platform\-specific gem exists on \fBrubygems\.org\fR it will not be found\. .TP \fB\-\-prefer\-local\fR -Force using locally installed gems, or gems already present in Rubygems\' cache or in \fBvendor/cache\fR, when resolving, even if newer versions are available remotely\. Only attempt to connect to \fBrubygems\.org\fR for gems that are not present locally\. -. +Force using locally installed gems, or gems already present in Rubygems' cache or in \fBvendor/cache\fR, when resolving, even if newer versions are available remotely\. Only attempt to connect to \fBrubygems\.org\fR for gems that are not present locally\. .TP \fB\-\-no\-cache\fR Do not update the cache in \fBvendor/cache\fR with the newly bundled gems\. This does not remove any gems in the cache but keeps the newly bundled gems from being cached during the install\. -. .TP \fB\-\-no\-prune\fR -Don\'t remove stale gems from the cache when the installation finishes\. -. +Don't remove stale gems from the cache when the installation finishes\. .IP This option is deprecated in favor of the \fBno_prune\fR setting\. -. .TP \fB\-\-path=<path>\fR -The location to install the specified gems to\. This defaults to Rubygems\' setting\. Bundler shares this location with Rubygems, \fBgem install \.\.\.\fR will have gem installed there, too\. Therefore, gems installed without a \fB\-\-path \.\.\.\fR setting will show up by calling \fBgem list\fR\. Accordingly, gems installed to other locations will not get listed\. -. +The location to install the specified gems to\. This defaults to Rubygems' setting\. Bundler shares this location with Rubygems, \fBgem install \|\.\|\.\|\.\fR will have gem installed there, too\. Therefore, gems installed without a \fB\-\-path \|\.\|\.\|\.\fR setting will show up by calling \fBgem list\fR\. Accordingly, gems installed to other locations will not get listed\. .IP This option is deprecated in favor of the \fBpath\fR setting\. -. .TP \fB\-\-quiet\fR Do not print progress information to the standard output\. Instead, Bundler will exit using a status code (\fB$?\fR)\. -. .TP \fB\-\-retry=[<number>]\fR Retry failed network or git requests for \fInumber\fR times\. -. .TP \fB\-\-shebang=<ruby\-executable>\fR Uses the specified ruby executable (usually \fBruby\fR) to execute the scripts created with \fB\-\-binstubs\fR\. In addition, if you use \fB\-\-binstubs\fR together with \fB\-\-shebang jruby\fR these executables will be changed to execute \fBjruby\fR instead\. -. .IP This option is deprecated in favor of the \fBshebang\fR setting\. -. .TP \fB\-\-standalone[=<list>]\fR -Makes a bundle that can work without depending on Rubygems or Bundler at runtime\. A space separated list of groups to install has to be specified\. Bundler creates a directory named \fBbundle\fR and installs the bundle there\. It also generates a \fBbundle/bundler/setup\.rb\fR file to replace Bundler\'s own setup in the manner required\. Using this option implicitly sets \fBpath\fR, which is a [remembered option][REMEMBERED OPTIONS]\. -. +Makes a bundle that can work without depending on Rubygems or Bundler at runtime\. A space separated list of groups to install has to be specified\. Bundler creates a directory named \fBbundle\fR and installs the bundle there\. It also generates a \fBbundle/bundler/setup\.rb\fR file to replace Bundler's own setup in the manner required\. Using this option implicitly sets \fBpath\fR, which is a [remembered option][REMEMBERED OPTIONS]\. .TP \fB\-\-system\fR -Installs the gems specified in the bundle to the system\'s Rubygems location\. This overrides any previous configuration of \fB\-\-path\fR\. -. +Installs the gems specified in the bundle to the system's Rubygems location\. This overrides any previous configuration of \fB\-\-path\fR\. .IP This option is deprecated in favor of the \fBsystem\fR setting\. -. .TP \fB\-\-trust\-policy=[<policy>]\fR Apply the Rubygems security policy \fIpolicy\fR, where policy is one of \fBHighSecurity\fR, \fBMediumSecurity\fR, \fBLowSecurity\fR, \fBAlmostNoSecurity\fR, or \fBNoSecurity\fR\. For more details, please see the Rubygems signing documentation linked below in \fISEE ALSO\fR\. -. .TP \fB\-\-with=<list>\fR A space\-separated list of groups referencing gems to install\. If an optional group is given it is installed\. If a group is given that is in the remembered list of groups given to \-\-without, it is removed from that list\. -. .IP This option is deprecated in favor of the \fBwith\fR setting\. -. .TP \fB\-\-without=<list>\fR A space\-separated list of groups referencing gems to skip during installation\. If a group is given that is in the remembered list of groups given to \-\-with, it is removed from that list\. -. .IP This option is deprecated in favor of the \fBwithout\fR setting\. -. .SH "DEPLOYMENT MODE" -Bundler\'s defaults are optimized for development\. To switch to defaults optimized for deployment and for CI, use the \fB\-\-deployment\fR flag\. Do not activate deployment mode on development machines, as it will cause an error when the Gemfile(5) is modified\. -. +Bundler's defaults are optimized for development\. To switch to defaults optimized for deployment and for CI, use the \fB\-\-deployment\fR flag\. Do not activate deployment mode on development machines, as it will cause an error when the Gemfile(5) is modified\. .IP "1." 4 A \fBGemfile\.lock\fR is required\. -. .IP To ensure that the same versions of the gems you developed with and tested with are also used in deployments, a \fBGemfile\.lock\fR is required\. -. .IP This is mainly to ensure that you remember to check your \fBGemfile\.lock\fR into version control\. -. .IP "2." 4 The \fBGemfile\.lock\fR must be up to date -. .IP In development, you can modify your Gemfile(5) and re\-run \fBbundle install\fR to \fIconservatively update\fR your \fBGemfile\.lock\fR snapshot\. -. .IP In deployment, your \fBGemfile\.lock\fR should be up\-to\-date with changes made in your Gemfile(5)\. -. .IP "3." 4 Gems are installed to \fBvendor/bundle\fR not your default system location -. .IP -In development, it\'s convenient to share the gems used in your application with other applications and other scripts that run on the system\. -. +In development, it's convenient to share the gems used in your application with other applications and other scripts that run on the system\. .IP In deployment, isolation is a more important default\. In addition, the user deploying the application may not have permission to install gems to the system, or the web server may not have permission to read them\. -. .IP As a result, \fBbundle install \-\-deployment\fR installs gems to the \fBvendor/bundle\fR directory in the application\. This may be overridden using the \fB\-\-path\fR option\. -. .IP "" 0 -. .SH "INSTALLING GROUPS" By default, \fBbundle install\fR will install all gems in all groups in your Gemfile(5), except those declared for a different platform\. -. .P However, you can explicitly tell Bundler to skip installing certain groups with the \fB\-\-without\fR option\. This option takes a space\-separated list of groups\. -. .P While the \fB\-\-without\fR option will skip \fIinstalling\fR the gems in the specified groups, it will still \fIdownload\fR those gems and use them to resolve the dependencies of every gem in your Gemfile(5)\. -. .P This is so that installing a different set of groups on another machine (such as a production server) will not change the gems and versions that you have already developed and tested against\. -. .P \fBBundler offers a rock\-solid guarantee that the third\-party code you are running in development and testing is also the third\-party code you are running in production\. You can choose to exclude some of that code in different environments, but you will never be caught flat\-footed by different versions of third\-party code being used in different environments\.\fR -. .P For a simple illustration, consider the following Gemfile(5): -. .IP "" 4 -. .nf +source 'https://rubygems\.org' -source \'https://rubygems\.org\' - -gem \'sinatra\' +gem 'sinatra' group :production do - gem \'rack\-perftools\-profiler\' + gem 'rack\-perftools\-profiler' end -. .fi -. .IP "" 0 -. .P In this case, \fBsinatra\fR depends on any version of Rack (\fB>= 1\.0\fR), while \fBrack\-perftools\-profiler\fR depends on 1\.x (\fB~> 1\.0\fR)\. -. .P When you run \fBbundle install \-\-without production\fR in development, we look at the dependencies of \fBrack\-perftools\-profiler\fR as well\. That way, you do not spend all your time developing against Rack 2\.0, using new APIs unavailable in Rack 1\.x, only to have Bundler switch to Rack 1\.2 when the \fBproduction\fR group \fIis\fR used\. -. .P This should not cause any problems in practice, because we do not attempt to \fBinstall\fR the gems in the excluded groups, and only evaluate as part of the dependency resolution process\. -. .P This also means that you cannot include different versions of the same gem in different groups, because doing so would result in different sets of dependencies used in development and production\. Because of the vagaries of the dependency resolution process, this usually affects more than the gems you list in your Gemfile(5), and can (surprisingly) radically change the gems you are using\. -. .SH "THE GEMFILE\.LOCK" When you run \fBbundle install\fR, Bundler will persist the full names and versions of all gems that you used (including dependencies of the gems specified in the Gemfile(5)) into a file called \fBGemfile\.lock\fR\. -. .P Bundler uses this file in all subsequent calls to \fBbundle install\fR, which guarantees that you always use the same exact code, even as your application moves across machines\. -. .P Because of the way dependency resolution works, even a seemingly small change (for instance, an update to a point\-release of a dependency of a gem in your Gemfile(5)) can result in radically different gems being needed to satisfy all dependencies\. -. .P As a result, you \fBSHOULD\fR check your \fBGemfile\.lock\fR into version control, in both applications and gems\. If you do not, every machine that checks out your repository (including your production server) will resolve all dependencies again, which will result in different versions of third\-party code being used if \fBany\fR of the gems in the Gemfile(5) or any of their dependencies have been updated\. -. .P When Bundler first shipped, the \fBGemfile\.lock\fR was included in the \fB\.gitignore\fR file included with generated gems\. Over time, however, it became clear that this practice forces the pain of broken dependencies onto new contributors, while leaving existing contributors potentially unaware of the problem\. Since \fBbundle install\fR is usually the first step towards a contribution, the pain of broken dependencies would discourage new contributors from contributing\. As a result, we have revised our guidance for gem authors to now recommend checking in the lock for gems\. -. .SH "CONSERVATIVE UPDATING" When you make a change to the Gemfile(5) and then run \fBbundle install\fR, Bundler will update only the gems that you modified\. -. .P In other words, if a gem that you \fBdid not modify\fR worked before you called \fBbundle install\fR, it will continue to use the exact same versions of all dependencies as it used before the update\. -. .P -Let\'s take a look at an example\. Here\'s your original Gemfile(5): -. +Let's take a look at an example\. Here's your original Gemfile(5): .IP "" 4 -. .nf +source 'https://rubygems\.org' -source \'https://rubygems\.org\' - -gem \'actionpack\', \'2\.3\.8\' -gem \'activemerchant\' -. +gem 'actionpack', '2\.3\.8' +gem 'activemerchant' .fi -. .IP "" 0 -. .P In this case, both \fBactionpack\fR and \fBactivemerchant\fR depend on \fBactivesupport\fR\. The \fBactionpack\fR gem depends on \fBactivesupport 2\.3\.8\fR and \fBrack ~> 1\.1\.0\fR, while the \fBactivemerchant\fR gem depends on \fBactivesupport >= 2\.3\.2\fR, \fBbraintree >= 2\.0\.0\fR, and \fBbuilder >= 2\.0\.0\fR\. -. .P When the dependencies are first resolved, Bundler will select \fBactivesupport 2\.3\.8\fR, which satisfies the requirements of both gems in your Gemfile(5)\. -. .P Next, you modify your Gemfile(5) to: -. .IP "" 4 -. .nf +source 'https://rubygems\.org' -source \'https://rubygems\.org\' - -gem \'actionpack\', \'3\.0\.0\.rc\' -gem \'activemerchant\' -. +gem 'actionpack', '3\.0\.0\.rc' +gem 'activemerchant' .fi -. .IP "" 0 -. .P The \fBactionpack 3\.0\.0\.rc\fR gem has a number of new dependencies, and updates the \fBactivesupport\fR dependency to \fB= 3\.0\.0\.rc\fR and the \fBrack\fR dependency to \fB~> 1\.2\.1\fR\. -. .P When you run \fBbundle install\fR, Bundler notices that you changed the \fBactionpack\fR gem, but not the \fBactivemerchant\fR gem\. It evaluates the gems currently being used to satisfy its requirements: -. .TP \fBactivesupport 2\.3\.8\fR also used to satisfy a dependency in \fBactivemerchant\fR, which is not being updated -. .TP \fBrack ~> 1\.1\.0\fR not currently being used to satisfy another dependency -. .P Because you did not explicitly ask to update \fBactivemerchant\fR, you would not expect it to suddenly stop working after updating \fBactionpack\fR\. However, satisfying the new \fBactivesupport 3\.0\.0\.rc\fR dependency of actionpack requires updating one of its dependencies\. -. .P Even though \fBactivemerchant\fR declares a very loose dependency that theoretically matches \fBactivesupport 3\.0\.0\.rc\fR, Bundler treats gems in your Gemfile(5) that have not changed as an atomic unit together with their dependencies\. In this case, the \fBactivemerchant\fR dependency is treated as \fBactivemerchant 1\.7\.1 + activesupport 2\.3\.8\fR, so \fBbundle install\fR will report that it cannot update \fBactionpack\fR\. -. .P To explicitly update \fBactionpack\fR, including its dependencies which other gems in the Gemfile(5) still depend on, run \fBbundle update actionpack\fR (see \fBbundle update(1)\fR)\. -. .P \fBSummary\fR: In general, after making a change to the Gemfile(5) , you should first try to run \fBbundle install\fR, which will guarantee that no other gem in the Gemfile(5) is impacted by the change\. If that does not work, run bundle update(1) \fIbundle\-update\.1\.html\fR\. -. .SH "SEE ALSO" -. .IP "\(bu" 4 -Gem install docs \fIhttp://guides\.rubygems\.org/rubygems\-basics/#installing\-gems\fR -. +Gem install docs \fIhttps://guides\.rubygems\.org/rubygems\-basics/#installing\-gems\fR .IP "\(bu" 4 -Rubygems signing docs \fIhttp://guides\.rubygems\.org/security/\fR -. +Rubygems signing docs \fIhttps://guides\.rubygems\.org/security/\fR .IP "" 0 diff --git a/lib/bundler/man/bundle-install.1.ronn b/lib/bundler/man/bundle-install.1.ronn index be9ed0f974..ed8169de05 100644 --- a/lib/bundler/man/bundle-install.1.ronn +++ b/lib/bundler/man/bundle-install.1.ronn @@ -14,6 +14,7 @@ bundle-install(1) -- Install the dependencies specified in your Gemfile [--no-cache] [--no-prune] [--path PATH] + [--prefer-local] [--quiet] [--redownload] [--retry=NUMBER] @@ -378,5 +379,5 @@ does not work, run [bundle update(1)](bundle-update.1.html). ## SEE ALSO -* [Gem install docs](http://guides.rubygems.org/rubygems-basics/#installing-gems) -* [Rubygems signing docs](http://guides.rubygems.org/security/) +* [Gem install docs](https://guides.rubygems.org/rubygems-basics/#installing-gems) +* [Rubygems signing docs](https://guides.rubygems.org/security/) diff --git a/lib/bundler/man/bundle-list.1 b/lib/bundler/man/bundle-list.1 index f24f62dd38..21723608cc 100644 --- a/lib/bundler/man/bundle-list.1 +++ b/lib/bundler/man/bundle-list.1 @@ -1,49 +1,34 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-LIST" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-LIST" "1" "May 2024" "" .SH "NAME" \fBbundle\-list\fR \- List all the gems in the bundle -. .SH "SYNOPSIS" -\fBbundle list\fR [\-\-name\-only] [\-\-paths] [\-\-without\-group=GROUP[ GROUP\.\.\.]] [\-\-only\-group=GROUP[ GROUP\.\.\.]] -. +\fBbundle list\fR [\-\-name\-only] [\-\-paths] [\-\-without\-group=GROUP[ GROUP\|\.\|\.\|\.]] [\-\-only\-group=GROUP[ GROUP\|\.\|\.\|\.]] .SH "DESCRIPTION" Prints a list of all the gems in the bundle including their version\. -. .P Example: -. .P bundle list \-\-name\-only -. .P bundle list \-\-paths -. .P bundle list \-\-without\-group test -. .P bundle list \-\-only\-group dev -. .P bundle list \-\-only\-group dev test \-\-paths -. .SH "OPTIONS" -. .TP \fB\-\-name\-only\fR Print only the name of each gem\. -. .TP \fB\-\-paths\fR Print the path to each gem in the bundle\. -. .TP \fB\-\-without\-group=<list>\fR A space\-separated list of groups of gems to skip during printing\. -. .TP \fB\-\-only\-group=<list>\fR A space\-separated list of groups of gems to print\. diff --git a/lib/bundler/man/bundle-lock.1 b/lib/bundler/man/bundle-lock.1 index 55d1035d77..8b81b7732f 100644 --- a/lib/bundler/man/bundle-lock.1 +++ b/lib/bundler/man/bundle-lock.1 @@ -1,84 +1,60 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-LOCK" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-LOCK" "1" "May 2024" "" .SH "NAME" \fBbundle\-lock\fR \- Creates / Updates a lockfile without installing -. .SH "SYNOPSIS" \fBbundle lock\fR [\-\-update] [\-\-local] [\-\-print] [\-\-lockfile=PATH] [\-\-full\-index] [\-\-add\-platform] [\-\-remove\-platform] [\-\-patch] [\-\-minor] [\-\-major] [\-\-strict] [\-\-conservative] -. .SH "DESCRIPTION" Lock the gems specified in Gemfile\. -. .SH "OPTIONS" -. .TP \fB\-\-update=<*gems>\fR Ignores the existing lockfile\. Resolve then updates lockfile\. Taking a list of gems or updating all gems if no list is given\. -. .TP \fB\-\-local\fR -Do not attempt to connect to \fBrubygems\.org\fR\. Instead, Bundler will use the gems already present in Rubygems\' cache or in \fBvendor/cache\fR\. Note that if a appropriate platform\-specific gem exists on \fBrubygems\.org\fR it will not be found\. -. +Do not attempt to connect to \fBrubygems\.org\fR\. Instead, Bundler will use the gems already present in Rubygems' cache or in \fBvendor/cache\fR\. Note that if a appropriate platform\-specific gem exists on \fBrubygems\.org\fR it will not be found\. .TP \fB\-\-print\fR Prints the lockfile to STDOUT instead of writing to the file system\. -. .TP \fB\-\-lockfile=<path>\fR The path where the lockfile should be written to\. -. .TP \fB\-\-full\-index\fR Fall back to using the single\-file index of all gems\. -. .TP \fB\-\-add\-platform\fR Add a new platform to the lockfile, re\-resolving for the addition of that platform\. -. .TP \fB\-\-remove\-platform\fR Remove a platform from the lockfile\. -. .TP \fB\-\-patch\fR If updating, prefer updating only to next patch version\. -. .TP \fB\-\-minor\fR If updating, prefer updating only to next minor version\. -. .TP \fB\-\-major\fR If updating, prefer updating to next major version (default)\. -. .TP \fB\-\-strict\fR If updating, do not allow any gem to be updated past latest \-\-patch | \-\-minor | \-\-major\. -. .TP \fB\-\-conservative\fR If updating, use bundle install conservative update behavior and do not allow shared dependencies to be updated\. -. .SH "UPDATING ALL GEMS" If you run \fBbundle lock\fR with \fB\-\-update\fR option without list of gems, bundler will ignore any previously installed gems and resolve all dependencies again based on the latest versions of all gems available in the sources\. -. .SH "UPDATING A LIST OF GEMS" Sometimes, you want to update a single gem in the Gemfile(5), and leave the rest of the gems that you specified locked to the versions in the \fBGemfile\.lock\fR\. -. .P For instance, you only want to update \fBnokogiri\fR, run \fBbundle lock \-\-update nokogiri\fR\. -. .P Bundler will update \fBnokogiri\fR and any of its dependencies, but leave the rest of the gems that you specified locked to the versions in the \fBGemfile\.lock\fR\. -. .SH "SUPPORTING OTHER PLATFORMS" -If you want your bundle to support platforms other than the one you\'re running locally, you can run \fBbundle lock \-\-add\-platform PLATFORM\fR to add PLATFORM to the lockfile, force bundler to re\-resolve and consider the new platform when picking gems, all without needing to have a machine that matches PLATFORM handy to install those platform\-specific gems on\. -. +If you want your bundle to support platforms other than the one you're running locally, you can run \fBbundle lock \-\-add\-platform PLATFORM\fR to add PLATFORM to the lockfile, force bundler to re\-resolve and consider the new platform when picking gems, all without needing to have a machine that matches PLATFORM handy to install those platform\-specific gems on\. .P For a full explanation of gem platforms, see \fBgem help platform\fR\. -. .SH "PATCH LEVEL OPTIONS" See bundle update(1) \fIbundle\-update\.1\.html\fR for details\. diff --git a/lib/bundler/man/bundle-open.1 b/lib/bundler/man/bundle-open.1 index ff44d1224f..41a8804a09 100644 --- a/lib/bundler/man/bundle-open.1 +++ b/lib/bundler/man/bundle-open.1 @@ -1,51 +1,31 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-OPEN" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-OPEN" "1" "May 2024" "" .SH "NAME" \fBbundle\-open\fR \- Opens the source directory for a gem in your bundle -. .SH "SYNOPSIS" \fBbundle open\fR [GEM] [\-\-path=PATH] -. .SH "DESCRIPTION" Opens the source directory of the provided GEM in your editor\. -. .P For this to work the \fBEDITOR\fR or \fBBUNDLER_EDITOR\fR environment variable has to be set\. -. .P Example: -. .IP "" 4 -. .nf - -bundle open \'rack\' -. +bundle open 'rack' .fi -. .IP "" 0 -. .P -Will open the source directory for the \'rack\' gem in your bundle\. -. +Will open the source directory for the 'rack' gem in your bundle\. .IP "" 4 -. .nf - -bundle open \'rack\' \-\-path \'README\.md\' -. +bundle open 'rack' \-\-path 'README\.md' .fi -. .IP "" 0 -. .P -Will open the README\.md file of the \'rack\' gem source in your bundle\. -. +Will open the README\.md file of the 'rack' gem source in your bundle\. .SH "OPTIONS" -. .TP \fB\-\-path\fR Specify GEM source relative path to open\. diff --git a/lib/bundler/man/bundle-outdated.1 b/lib/bundler/man/bundle-outdated.1 index 8455b71b45..838fce45cd 100644 --- a/lib/bundler/man/bundle-outdated.1 +++ b/lib/bundler/man/bundle-outdated.1 @@ -1,148 +1,100 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-OUTDATED" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-OUTDATED" "1" "May 2024" "" .SH "NAME" \fBbundle\-outdated\fR \- List installed gems with newer versions available -. .SH "SYNOPSIS" \fBbundle outdated\fR [GEM] [\-\-local] [\-\-pre] [\-\-source] [\-\-strict] [\-\-parseable | \-\-porcelain] [\-\-group=GROUP] [\-\-groups] [\-\-patch|\-\-minor|\-\-major] [\-\-filter\-major] [\-\-filter\-minor] [\-\-filter\-patch] [\-\-only\-explicit] -. .SH "DESCRIPTION" Outdated lists the names and versions of gems that have a newer version available in the given source\. Calling outdated with [GEM [GEM]] will only check for newer versions of the given gems\. Prerelease gems are ignored by default\. If your gems are up to date, Bundler will exit with a status of 0\. Otherwise, it will exit 1\. -. .SH "OPTIONS" -. .TP \fB\-\-local\fR Do not attempt to fetch gems remotely and use the gem cache instead\. -. .TP \fB\-\-pre\fR Check for newer pre\-release gems\. -. .TP \fB\-\-source\fR Check against a specific source\. -. .TP \fB\-\-strict\fR Only list newer versions allowed by your Gemfile requirements, also respecting conservative update flags (\-\-patch, \-\-minor, \-\-major)\. -. .TP \fB\-\-parseable\fR, \fB\-\-porcelain\fR Use minimal formatting for more parseable output\. -. .TP \fB\-\-group\fR List gems from a specific group\. -. .TP \fB\-\-groups\fR List gems organized by groups\. -. .TP \fB\-\-minor\fR Prefer updating only to next minor version\. -. .TP \fB\-\-major\fR Prefer updating to next major version (default)\. -. .TP \fB\-\-patch\fR Prefer updating only to next patch version\. -. .TP \fB\-\-filter\-major\fR Only list major newer versions\. -. .TP \fB\-\-filter\-minor\fR Only list minor newer versions\. -. .TP \fB\-\-filter\-patch\fR Only list patch newer versions\. -. .TP \fB\-\-only\-explicit\fR Only list gems specified in your Gemfile, not their dependencies\. -. .SH "PATCH LEVEL OPTIONS" See bundle update(1) \fIbundle\-update\.1\.html\fR for details\. -. .SH "FILTERING OUTPUT" The 3 filtering options do not affect the resolution of versions, merely what versions are shown in the output\. -. .P If the regular output shows the following: -. .IP "" 4 -. .nf - -* faker (newest 1\.6\.6, installed 1\.6\.5, requested ~> 1\.4) in groups "development, test" -* hashie (newest 3\.4\.6, installed 1\.2\.0, requested = 1\.2\.0) in groups "default" -* headless (newest 2\.3\.1, installed 2\.2\.3) in groups "test" -. +* Gem Current Latest Requested Groups +* faker 1\.6\.5 1\.6\.6 ~> 1\.4 development, test +* hashie 1\.2\.0 3\.4\.6 = 1\.2\.0 default +* headless 2\.2\.3 2\.3\.1 = 2\.2\.3 test .fi -. .IP "" 0 -. .P \fB\-\-filter\-major\fR would only show: -. .IP "" 4 -. .nf - -* hashie (newest 3\.4\.6, installed 1\.2\.0, requested = 1\.2\.0) in groups "default" -. +* Gem Current Latest Requested Groups +* hashie 1\.2\.0 3\.4\.6 = 1\.2\.0 default .fi -. .IP "" 0 -. .P \fB\-\-filter\-minor\fR would only show: -. .IP "" 4 -. .nf - -* headless (newest 2\.3\.1, installed 2\.2\.3) in groups "test" -. +* Gem Current Latest Requested Groups +* headless 2\.2\.3 2\.3\.1 = 2\.2\.3 test .fi -. .IP "" 0 -. .P \fB\-\-filter\-patch\fR would only show: -. .IP "" 4 -. .nf - -* faker (newest 1\.6\.6, installed 1\.6\.5, requested ~> 1\.4) in groups "development, test" -. +* Gem Current Latest Requested Groups +* faker 1\.6\.5 1\.6\.6 ~> 1\.4 development, test .fi -. .IP "" 0 -. .P Filter options can be combined\. \fB\-\-filter\-minor\fR and \fB\-\-filter\-patch\fR would show: -. .IP "" 4 -. .nf - -* faker (newest 1\.6\.6, installed 1\.6\.5, requested ~> 1\.4) in groups "development, test" -* headless (newest 2\.3\.1, installed 2\.2\.3) in groups "test" -. +* Gem Current Latest Requested Groups +* faker 1\.6\.5 1\.6\.6 ~> 1\.4 development, test .fi -. .IP "" 0 -. .P Combining all three \fBfilter\fR options would be the same result as providing none of them\. diff --git a/lib/bundler/man/bundle-outdated.1.ronn b/lib/bundler/man/bundle-outdated.1.ronn index 04096ffbb6..4ac65d0532 100644 --- a/lib/bundler/man/bundle-outdated.1.ronn +++ b/lib/bundler/man/bundle-outdated.1.ronn @@ -78,25 +78,29 @@ in the output. If the regular output shows the following: - * faker (newest 1.6.6, installed 1.6.5, requested ~> 1.4) in groups "development, test" - * hashie (newest 3.4.6, installed 1.2.0, requested = 1.2.0) in groups "default" - * headless (newest 2.3.1, installed 2.2.3) in groups "test" + * Gem Current Latest Requested Groups + * faker 1.6.5 1.6.6 ~> 1.4 development, test + * hashie 1.2.0 3.4.6 = 1.2.0 default + * headless 2.2.3 2.3.1 = 2.2.3 test `--filter-major` would only show: - * hashie (newest 3.4.6, installed 1.2.0, requested = 1.2.0) in groups "default" + * Gem Current Latest Requested Groups + * hashie 1.2.0 3.4.6 = 1.2.0 default `--filter-minor` would only show: - * headless (newest 2.3.1, installed 2.2.3) in groups "test" + * Gem Current Latest Requested Groups + * headless 2.2.3 2.3.1 = 2.2.3 test `--filter-patch` would only show: - * faker (newest 1.6.6, installed 1.6.5, requested ~> 1.4) in groups "development, test" + * Gem Current Latest Requested Groups + * faker 1.6.5 1.6.6 ~> 1.4 development, test Filter options can be combined. `--filter-minor` and `--filter-patch` would show: - * faker (newest 1.6.6, installed 1.6.5, requested ~> 1.4) in groups "development, test" - * headless (newest 2.3.1, installed 2.2.3) in groups "test" + * Gem Current Latest Requested Groups + * faker 1.6.5 1.6.6 ~> 1.4 development, test Combining all three `filter` options would be the same result as providing none of them. diff --git a/lib/bundler/man/bundle-platform.1 b/lib/bundler/man/bundle-platform.1 index 2794878719..0dbce7a7a4 100644 --- a/lib/bundler/man/bundle-platform.1 +++ b/lib/bundler/man/bundle-platform.1 @@ -1,41 +1,27 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-PLATFORM" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-PLATFORM" "1" "May 2024" "" .SH "NAME" \fBbundle\-platform\fR \- Displays platform compatibility information -. .SH "SYNOPSIS" \fBbundle platform\fR [\-\-ruby] -. .SH "DESCRIPTION" \fBplatform\fR displays information from your Gemfile, Gemfile\.lock, and Ruby VM about your platform\. -. .P For instance, using this Gemfile(5): -. .IP "" 4 -. .nf - source "https://rubygems\.org" ruby "3\.1\.2" gem "rack" -. .fi -. .IP "" 0 -. .P If you run \fBbundle platform\fR on Ruby 3\.1\.2, it displays the following output: -. .IP "" 4 -. .nf - Your platform is: x86_64\-linux Your app has gems that work on these platforms: @@ -48,24 +34,16 @@ Your Gemfile specifies a Ruby version requirement: * ruby 3\.1\.2 Your current platform satisfies the Ruby version requirement\. -. .fi -. .IP "" 0 -. .P -\fBplatform\fR lists all the platforms in your \fBGemfile\.lock\fR as well as the \fBruby\fR directive if applicable from your Gemfile(5)\. It also lets you know if the \fBruby\fR directive requirement has been met\. If \fBruby\fR directive doesn\'t match the running Ruby VM, it tells you what part does not\. -. +\fBplatform\fR lists all the platforms in your \fBGemfile\.lock\fR as well as the \fBruby\fR directive if applicable from your Gemfile(5)\. It also lets you know if the \fBruby\fR directive requirement has been met\. If \fBruby\fR directive doesn't match the running Ruby VM, it tells you what part does not\. .SH "OPTIONS" -. .TP \fB\-\-ruby\fR -It will display the ruby directive information, so you don\'t have to parse it from the Gemfile(5)\. -. +It will display the ruby directive information, so you don't have to parse it from the Gemfile(5)\. .SH "SEE ALSO" -. .IP "\(bu" 4 bundle\-lock(1) \fIbundle\-lock\.1\.html\fR -. .IP "" 0 diff --git a/lib/bundler/man/bundle-plugin.1 b/lib/bundler/man/bundle-plugin.1 index 39d3dfa04e..1290abb3ba 100644 --- a/lib/bundler/man/bundle-plugin.1 +++ b/lib/bundler/man/bundle-plugin.1 @@ -1,81 +1,58 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-PLUGIN" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-PLUGIN" "1" "May 2024" "" .SH "NAME" \fBbundle\-plugin\fR \- Manage Bundler plugins -. .SH "SYNOPSIS" -\fBbundle plugin\fR install PLUGINS [\-\-source=\fISOURCE\fR] [\-\-version=\fIversion\fR] [\-\-git|\-\-local_git=\fIgit\-url\fR] [\-\-branch=\fIbranch\fR|\-\-ref=\fIrev\fR] -. +\fBbundle plugin\fR install PLUGINS [\-\-source=\fISOURCE\fR] [\-\-version=\fIversion\fR] [\-\-git=\fIgit\-url\fR] [\-\-branch=\fIbranch\fR|\-\-ref=\fIrev\fR] [\-\-path=\fIpath\fR] .br \fBbundle plugin\fR uninstall PLUGINS -. .br \fBbundle plugin\fR list -. .br \fBbundle plugin\fR help [COMMAND] -. .SH "DESCRIPTION" You can install, uninstall, and list plugin(s) with this command to extend functionalities of Bundler\. -. .SH "SUB\-COMMANDS" -. .SS "install" Install the given plugin(s)\. -. -.IP "\(bu" 4 -\fBbundle plugin install bundler\-graph\fR: Install bundler\-graph gem from RubyGems\.org\. The global source, specified in source in Gemfile is ignored\. -. -.IP "\(bu" 4 -\fBbundle plugin install bundler\-graph \-\-source https://example\.com\fR: Install bundler\-graph gem from example\.com\. The global source, specified in source in Gemfile is not considered\. -. -.IP "\(bu" 4 -\fBbundle plugin install bundler\-graph \-\-version 0\.2\.1\fR: You can specify the version of the gem via \fB\-\-version\fR\. -. -.IP "\(bu" 4 -\fBbundle plugin install bundler\-graph \-\-git https://github\.com/rubygems/bundler\-graph\fR: Install bundler\-graph gem from Git repository\. \fB\-\-git\fR can be replaced with \fB\-\-local\-git\fR\. You cannot use both \fB\-\-git\fR and \fB\-\-local\-git\fR\. You can use standard Git URLs like: -. -.IP "\(bu" 4 +.TP +\fBbundle plugin install bundler\-graph\fR +Install bundler\-graph gem from globally configured sources (defaults to RubyGems\.org)\. The global source, specified in source in Gemfile is ignored\. +.TP +\fBbundle plugin install bundler\-graph \-\-source https://example\.com\fR +Install bundler\-graph gem from example\.com\. The global source, specified in source in Gemfile is not considered\. +.TP +\fBbundle plugin install bundler\-graph \-\-version 0\.2\.1\fR +You can specify the version of the gem via \fB\-\-version\fR\. +.TP +\fBbundle plugin install bundler\-graph \-\-git https://github\.com/rubygems/bundler\-graph\fR +Install bundler\-graph gem from Git repository\. You can use standard Git URLs like: +.IP \fBssh://[user@]host\.xz[:port]/path/to/repo\.git\fR -. -.IP "\(bu" 4 +.br \fBhttp[s]://host\.xz[:port]/path/to/repo\.git\fR -. -.IP "\(bu" 4 +.br \fB/path/to/repo\fR -. -.IP "\(bu" 4 +.br \fBfile:///path/to/repo\fR -. -.IP "" 0 -. .IP -When you specify \fB\-\-git\fR/\fB\-\-local\-git\fR, you can use \fB\-\-branch\fR or \fB\-\-ref\fR to specify any branch, tag, or commit hash (revision) to use\. When you specify both, only the latter is used\. -. -.IP "" 0 -. +When you specify \fB\-\-git\fR, you can use \fB\-\-branch\fR or \fB\-\-ref\fR to specify any branch, tag, or commit hash (revision) to use\. +.TP +\fBbundle plugin install bundler\-graph \-\-path \.\./bundler\-graph\fR +Install bundler\-graph gem from a local path\. .SS "uninstall" Uninstall the plugin(s) specified in PLUGINS\. -. .SS "list" List the installed plugins and available commands\. -. .P No options\. -. .SS "help" Describe subcommands or one specific subcommand\. -. .P No options\. -. .SH "SEE ALSO" -. .IP "\(bu" 4 How to write a Bundler plugin \fIhttps://bundler\.io/guides/bundler_plugins\.html\fR -. .IP "" 0 diff --git a/lib/bundler/man/bundle-plugin.1.ronn b/lib/bundler/man/bundle-plugin.1.ronn index 4f234eeba7..b0a34660ea 100644 --- a/lib/bundler/man/bundle-plugin.1.ronn +++ b/lib/bundler/man/bundle-plugin.1.ronn @@ -4,7 +4,8 @@ bundle-plugin(1) -- Manage Bundler plugins ## SYNOPSIS `bundle plugin` install PLUGINS [--source=<SOURCE>] [--version=<version>] - [--git|--local_git=<git-url>] [--branch=<branch>|--ref=<rev>]<br> + [--git=<git-url>] [--branch=<branch>|--ref=<rev>] + [--path=<path>]<br> `bundle plugin` uninstall PLUGINS<br> `bundle plugin` list<br> `bundle plugin` help [COMMAND] @@ -20,7 +21,7 @@ You can install, uninstall, and list plugin(s) with this command to extend funct Install the given plugin(s). * `bundle plugin install bundler-graph`: - Install bundler-graph gem from RubyGems.org. The global source, specified in source in Gemfile is ignored. + Install bundler-graph gem from globally configured sources (defaults to RubyGems.org). The global source, specified in source in Gemfile is ignored. * `bundle plugin install bundler-graph --source https://example.com`: Install bundler-graph gem from example.com. The global source, specified in source in Gemfile is not considered. @@ -29,14 +30,17 @@ Install the given plugin(s). You can specify the version of the gem via `--version`. * `bundle plugin install bundler-graph --git https://github.com/rubygems/bundler-graph`: - Install bundler-graph gem from Git repository. `--git` can be replaced with `--local-git`. You cannot use both `--git` and `--local-git`. You can use standard Git URLs like: + Install bundler-graph gem from Git repository. You can use standard Git URLs like: - * `ssh://[user@]host.xz[:port]/path/to/repo.git` - * `http[s]://host.xz[:port]/path/to/repo.git` - * `/path/to/repo` - * `file:///path/to/repo` + `ssh://[user@]host.xz[:port]/path/to/repo.git`<br> + `http[s]://host.xz[:port]/path/to/repo.git`<br> + `/path/to/repo`<br> + `file:///path/to/repo` - When you specify `--git`/`--local-git`, you can use `--branch` or `--ref` to specify any branch, tag, or commit hash (revision) to use. When you specify both, only the latter is used. + When you specify `--git`, you can use `--branch` or `--ref` to specify any branch, tag, or commit hash (revision) to use. + +* `bundle plugin install bundler-graph --path ../bundler-graph`: + Install bundler-graph gem from a local path. ### uninstall diff --git a/lib/bundler/man/bundle-pristine.1 b/lib/bundler/man/bundle-pristine.1 index f42c7ce156..bf4a7cd323 100644 --- a/lib/bundler/man/bundle-pristine.1 +++ b/lib/bundler/man/bundle-pristine.1 @@ -1,34 +1,23 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-PRISTINE" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-PRISTINE" "1" "May 2024" "" .SH "NAME" \fBbundle\-pristine\fR \- Restores installed gems to their pristine condition -. .SH "SYNOPSIS" \fBbundle pristine\fR -. .SH "DESCRIPTION" \fBpristine\fR restores the installed gems in the bundle to their pristine condition using the local gem cache from RubyGems\. For git gems, a forced checkout will be performed\. -. .P -For further explanation, \fBbundle pristine\fR ignores unpacked files on disk\. In other words, this command utilizes the local \fB\.gem\fR cache or the gem\'s git repository as if one were installing from scratch\. -. +For further explanation, \fBbundle pristine\fR ignores unpacked files on disk\. In other words, this command utilizes the local \fB\.gem\fR cache or the gem's git repository as if one were installing from scratch\. .P -Note: the Bundler gem cannot be restored to its original state with \fBpristine\fR\. One also cannot use \fBbundle pristine\fR on gems with a \'path\' option in the Gemfile, because bundler has no original copy it can restore from\. -. +Note: the Bundler gem cannot be restored to its original state with \fBpristine\fR\. One also cannot use \fBbundle pristine\fR on gems with a 'path' option in the Gemfile, because bundler has no original copy it can restore from\. .P When is it practical to use \fBbundle pristine\fR? -. .P It comes in handy when a developer is debugging a gem\. \fBbundle pristine\fR is a great way to get rid of experimental changes to a gem that one may not want\. -. .P Why use \fBbundle pristine\fR over \fBgem pristine \-\-all\fR? -. .P Both commands are very similar\. For context: \fBbundle pristine\fR, without arguments, cleans all gems from the lockfile\. Meanwhile, \fBgem pristine \-\-all\fR cleans all installed gems for that Ruby version\. -. .P If a developer forgets which gems in their project they might have been debugging, the Rubygems \fBgem pristine [GEMNAME]\fR command may be inconvenient\. One can avoid waiting for \fBgem pristine \-\-all\fR, and instead run \fBbundle pristine\fR\. diff --git a/lib/bundler/man/bundle-remove.1 b/lib/bundler/man/bundle-remove.1 index b18d80554d..c3c96b416d 100644 --- a/lib/bundler/man/bundle-remove.1 +++ b/lib/bundler/man/bundle-remove.1 @@ -1,31 +1,21 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-REMOVE" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-REMOVE" "1" "May 2024" "" .SH "NAME" \fBbundle\-remove\fR \- Removes gems from the Gemfile -. .SH "SYNOPSIS" -\fBbundle remove [GEM [GEM \.\.\.]] [\-\-install]\fR -. +\fBbundle remove [GEM [GEM \|\.\|\.\|\.]] [\-\-install]\fR .SH "DESCRIPTION" Removes the given gems from the Gemfile while ensuring that the resulting Gemfile is still valid\. If a gem cannot be removed, a warning is printed\. If a gem is already absent from the Gemfile, and error is raised\. -. .SH "OPTIONS" -. .TP \fB\-\-install\fR Runs \fBbundle install\fR after the given gems have been removed from the Gemfile, which ensures that both the lockfile and the installed gems on disk are also updated to remove the given gem(s)\. -. .P Example: -. .P bundle remove rails -. .P bundle remove rails rack -. .P bundle remove rails rack \-\-install diff --git a/lib/bundler/man/bundle-show.1 b/lib/bundler/man/bundle-show.1 index efd9ccb0e0..c054875efd 100644 --- a/lib/bundler/man/bundle-show.1 +++ b/lib/bundler/man/bundle-show.1 @@ -1,22 +1,15 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-SHOW" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-SHOW" "1" "May 2024" "" .SH "NAME" \fBbundle\-show\fR \- Shows all the gems in your bundle, or the path to a gem -. .SH "SYNOPSIS" \fBbundle show\fR [GEM] [\-\-paths] -. .SH "DESCRIPTION" Without the [GEM] option, \fBshow\fR will print a list of the names and versions of all gems that are required by your [\fBGemfile(5)\fR][Gemfile(5)], sorted by name\. -. .P Calling show with [GEM] will list the exact location of that gem on your machine\. -. .SH "OPTIONS" -. .TP \fB\-\-paths\fR List the paths of all gems that are required by your [\fBGemfile(5)\fR][Gemfile(5)], sorted by gem name\. diff --git a/lib/bundler/man/bundle-update.1 b/lib/bundler/man/bundle-update.1 index c67c44ff86..acd80ec75c 100644 --- a/lib/bundler/man/bundle-update.1 +++ b/lib/bundler/man/bundle-update.1 @@ -1,114 +1,81 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-UPDATE" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-UPDATE" "1" "May 2024" "" .SH "NAME" \fBbundle\-update\fR \- Update your gems to the latest available versions -. .SH "SYNOPSIS" \fBbundle update\fR \fI*gems\fR [\-\-all] [\-\-group=NAME] [\-\-source=NAME] [\-\-local] [\-\-ruby] [\-\-bundler[=VERSION]] [\-\-full\-index] [\-\-jobs=JOBS] [\-\-quiet] [\-\-patch|\-\-minor|\-\-major] [\-\-redownload] [\-\-strict] [\-\-conservative] -. .SH "DESCRIPTION" Update the gems specified (all gems, if \fB\-\-all\fR flag is used), ignoring the previously installed gems specified in the \fBGemfile\.lock\fR\. In general, you should use bundle install(1) \fIbundle\-install\.1\.html\fR to install the same exact gems and versions across machines\. -. .P You would use \fBbundle update\fR to explicitly update the version of a gem\. -. .SH "OPTIONS" -. .TP \fB\-\-all\fR Update all gems specified in Gemfile\. -. .TP \fB\-\-group=<name>\fR, \fB\-g=[<name>]\fR Only update the gems in the specified group\. For instance, you can update all gems in the development group with \fBbundle update \-\-group development\fR\. You can also call \fBbundle update rails \-\-group test\fR to update the rails gem and all gems in the test group, for example\. -. .TP \fB\-\-source=<name>\fR The name of a \fB:git\fR or \fB:path\fR source used in the Gemfile(5)\. For instance, with a \fB:git\fR source of \fBhttp://github\.com/rails/rails\.git\fR, you would call \fBbundle update \-\-source rails\fR -. .TP \fB\-\-local\fR Do not attempt to fetch gems remotely and use the gem cache instead\. -. .TP \fB\-\-ruby\fR Update the locked version of Ruby to the current version of Ruby\. -. .TP \fB\-\-bundler\fR Update the locked version of bundler to the invoked bundler version\. -. .TP \fB\-\-full\-index\fR Fall back to using the single\-file index of all gems\. -. .TP \fB\-\-jobs=[<number>]\fR, \fB\-j[<number>]\fR Specify the number of jobs to run in parallel\. The default is the number of available processors\. -. .TP \fB\-\-retry=[<number>]\fR Retry failed network or git requests for \fInumber\fR times\. -. .TP \fB\-\-quiet\fR Only output warnings and errors\. -. .TP \fB\-\-redownload\fR Force downloading every gem\. -. .TP \fB\-\-patch\fR Prefer updating only to next patch version\. -. .TP \fB\-\-minor\fR Prefer updating only to next minor version\. -. .TP \fB\-\-major\fR Prefer updating to next major version (default)\. -. .TP \fB\-\-strict\fR Do not allow any gem to be updated past latest \fB\-\-patch\fR | \fB\-\-minor\fR | \fB\-\-major\fR\. -. .TP \fB\-\-conservative\fR Use bundle install conservative update behavior and do not allow indirect dependencies to be updated\. -. .SH "UPDATING ALL GEMS" If you run \fBbundle update \-\-all\fR, bundler will ignore any previously installed gems and resolve all dependencies again based on the latest versions of all gems available in the sources\. -. .P Consider the following Gemfile(5): -. .IP "" 4 -. .nf - source "https://rubygems\.org" gem "rails", "3\.0\.0\.rc" gem "nokogiri" -. .fi -. .IP "" 0 -. .P When you run bundle install(1) \fIbundle\-install\.1\.html\fR the first time, bundler will resolve all of the dependencies, all the way down, and install what you need: -. .IP "" 4 -. .nf - -Fetching gem metadata from https://rubygems\.org/\.\.\.\.\.\.\.\.\. -Resolving dependencies\.\.\. +Fetching gem metadata from https://rubygems\.org/\|\.\|\.\|\.\|\.\|\.\|\.\|\.\|\.\|\. +Resolving dependencies\|\.\|\.\|\. Installing builder 2\.1\.2 Installing abstract 1\.0\.0 Installing rack 1\.2\.8 @@ -138,55 +105,36 @@ Installing nokogiri 1\.6\.5 Bundle complete! 2 Gemfile dependencies, 26 gems total\. Use `bundle show [gemname]` to see where a bundled gem is installed\. -. .fi -. .IP "" 0 -. .P As you can see, even though you have two gems in the Gemfile(5), your application needs 26 different gems in order to run\. Bundler remembers the exact versions it installed in \fBGemfile\.lock\fR\. The next time you run bundle install(1) \fIbundle\-install\.1\.html\fR, bundler skips the dependency resolution and installs the same gems as it installed last time\. -. .P -After checking in the \fBGemfile\.lock\fR into version control and cloning it on another machine, running bundle install(1) \fIbundle\-install\.1\.html\fR will \fIstill\fR install the gems that you installed last time\. You don\'t need to worry that a new release of \fBerubis\fR or \fBmail\fR changes the gems you use\. -. +After checking in the \fBGemfile\.lock\fR into version control and cloning it on another machine, running bundle install(1) \fIbundle\-install\.1\.html\fR will \fIstill\fR install the gems that you installed last time\. You don't need to worry that a new release of \fBerubis\fR or \fBmail\fR changes the gems you use\. .P However, from time to time, you might want to update the gems you are using to the newest versions that still match the gems in your Gemfile(5)\. -. .P To do this, run \fBbundle update \-\-all\fR, which will ignore the \fBGemfile\.lock\fR, and resolve all the dependencies again\. Keep in mind that this process can result in a significantly different set of the 25 gems, based on the requirements of new gems that the gem authors released since the last time you ran \fBbundle update \-\-all\fR\. -. .SH "UPDATING A LIST OF GEMS" Sometimes, you want to update a single gem in the Gemfile(5), and leave the rest of the gems that you specified locked to the versions in the \fBGemfile\.lock\fR\. -. .P For instance, in the scenario above, imagine that \fBnokogiri\fR releases version \fB1\.4\.4\fR, and you want to update it \fIwithout\fR updating Rails and all of its dependencies\. To do this, run \fBbundle update nokogiri\fR\. -. .P Bundler will update \fBnokogiri\fR and any of its dependencies, but leave alone Rails and its dependencies\. -. .SH "OVERLAPPING DEPENDENCIES" Sometimes, multiple gems declared in your Gemfile(5) are satisfied by the same second\-level dependency\. For instance, consider the case of \fBthin\fR and \fBrack\-perftools\-profiler\fR\. -. .IP "" 4 -. .nf - source "https://rubygems\.org" gem "thin" gem "rack\-perftools\-profiler" -. .fi -. .IP "" 0 -. .P The \fBthin\fR gem depends on \fBrack >= 1\.0\fR, while \fBrack\-perftools\-profiler\fR depends on \fBrack ~> 1\.0\fR\. If you run bundle install, you get: -. .IP "" 4 -. .nf - Fetching source index for https://rubygems\.org/ Installing daemons (1\.1\.0) Installing eventmachine (0\.12\.10) with native extensions @@ -196,199 +144,132 @@ Installing rack (1\.2\.1) Installing rack\-perftools_profiler (0\.0\.2) Installing thin (1\.2\.7) with native extensions Using bundler (1\.0\.0\.rc\.3) -. .fi -. .IP "" 0 -. .P -In this case, the two gems have their own set of dependencies, but they share \fBrack\fR in common\. If you run \fBbundle update thin\fR, bundler will update \fBdaemons\fR, \fBeventmachine\fR and \fBrack\fR, which are dependencies of \fBthin\fR, but not \fBopen4\fR or \fBperftools\.rb\fR, which are dependencies of \fBrack\-perftools_profiler\fR\. Note that \fBbundle update thin\fR will update \fBrack\fR even though it\'s \fIalso\fR a dependency of \fBrack\-perftools_profiler\fR\. -. +In this case, the two gems have their own set of dependencies, but they share \fBrack\fR in common\. If you run \fBbundle update thin\fR, bundler will update \fBdaemons\fR, \fBeventmachine\fR and \fBrack\fR, which are dependencies of \fBthin\fR, but not \fBopen4\fR or \fBperftools\.rb\fR, which are dependencies of \fBrack\-perftools_profiler\fR\. Note that \fBbundle update thin\fR will update \fBrack\fR even though it's \fIalso\fR a dependency of \fBrack\-perftools_profiler\fR\. .P In short, by default, when you update a gem using \fBbundle update\fR, bundler will update all dependencies of that gem, including those that are also dependencies of another gem\. -. .P To prevent updating indirect dependencies, prior to version 1\.14 the only option was the \fBCONSERVATIVE UPDATING\fR behavior in bundle install(1) \fIbundle\-install\.1\.html\fR: -. .P In this scenario, updating the \fBthin\fR version manually in the Gemfile(5), and then running bundle install(1) \fIbundle\-install\.1\.html\fR will only update \fBdaemons\fR and \fBeventmachine\fR, but not \fBrack\fR\. For more information, see the \fBCONSERVATIVE UPDATING\fR section of bundle install(1) \fIbundle\-install\.1\.html\fR\. -. .P Starting with 1\.14, specifying the \fB\-\-conservative\fR option will also prevent indirect dependencies from being updated\. -. .SH "PATCH LEVEL OPTIONS" Version 1\.14 introduced 4 patch\-level options that will influence how gem versions are resolved\. One of the following options can be used: \fB\-\-patch\fR, \fB\-\-minor\fR or \fB\-\-major\fR\. \fB\-\-strict\fR can be added to further influence resolution\. -. .TP \fB\-\-patch\fR Prefer updating only to next patch version\. -. .TP \fB\-\-minor\fR Prefer updating only to next minor version\. -. .TP \fB\-\-major\fR Prefer updating to next major version (default)\. -. .TP \fB\-\-strict\fR Do not allow any gem to be updated past latest \fB\-\-patch\fR | \fB\-\-minor\fR | \fB\-\-major\fR\. -. .P -When Bundler is resolving what versions to use to satisfy declared requirements in the Gemfile or in parent gems, it looks up all available versions, filters out any versions that don\'t satisfy the requirement, and then, by default, sorts them from newest to oldest, considering them in that order\. -. +When Bundler is resolving what versions to use to satisfy declared requirements in the Gemfile or in parent gems, it looks up all available versions, filters out any versions that don't satisfy the requirement, and then, by default, sorts them from newest to oldest, considering them in that order\. .P Providing one of the patch level options (e\.g\. \fB\-\-patch\fR) changes the sort order of the satisfying versions, causing Bundler to consider the latest \fB\-\-patch\fR or \fB\-\-minor\fR version available before other versions\. Note that versions outside the stated patch level could still be resolved to if necessary to find a suitable dependency graph\. -. .P -For example, if gem \'foo\' is locked at 1\.0\.2, with no gem requirement defined in the Gemfile, and versions 1\.0\.3, 1\.0\.4, 1\.1\.0, 1\.1\.1, 2\.0\.0 all exist, the default order of preference by default (\fB\-\-major\fR) will be "2\.0\.0, 1\.1\.1, 1\.1\.0, 1\.0\.4, 1\.0\.3, 1\.0\.2"\. -. +For example, if gem 'foo' is locked at 1\.0\.2, with no gem requirement defined in the Gemfile, and versions 1\.0\.3, 1\.0\.4, 1\.1\.0, 1\.1\.1, 2\.0\.0 all exist, the default order of preference by default (\fB\-\-major\fR) will be "2\.0\.0, 1\.1\.1, 1\.1\.0, 1\.0\.4, 1\.0\.3, 1\.0\.2"\. .P If the \fB\-\-patch\fR option is used, the order of preference will change to "1\.0\.4, 1\.0\.3, 1\.0\.2, 1\.1\.1, 1\.1\.0, 2\.0\.0"\. -. .P If the \fB\-\-minor\fR option is used, the order of preference will change to "1\.1\.1, 1\.1\.0, 1\.0\.4, 1\.0\.3, 1\.0\.2, 2\.0\.0"\. -. .P Combining the \fB\-\-strict\fR option with any of the patch level options will remove any versions beyond the scope of the patch level option, to ensure that no gem is updated that far\. -. .P To continue the previous example, if both \fB\-\-patch\fR and \fB\-\-strict\fR options are used, the available versions for resolution would be "1\.0\.4, 1\.0\.3, 1\.0\.2"\. If \fB\-\-minor\fR and \fB\-\-strict\fR are used, it would be "1\.1\.1, 1\.1\.0, 1\.0\.4, 1\.0\.3, 1\.0\.2"\. -. .P -Gem requirements as defined in the Gemfile will still be the first determining factor for what versions are available\. If the gem requirement for \fBfoo\fR in the Gemfile is \'~> 1\.0\', that will accomplish the same thing as providing the \fB\-\-minor\fR and \fB\-\-strict\fR options\. -. +Gem requirements as defined in the Gemfile will still be the first determining factor for what versions are available\. If the gem requirement for \fBfoo\fR in the Gemfile is '~> 1\.0', that will accomplish the same thing as providing the \fB\-\-minor\fR and \fB\-\-strict\fR options\. .SH "PATCH LEVEL EXAMPLES" Given the following gem specifications: -. .IP "" 4 -. .nf - foo 1\.4\.3, requires: ~> bar 2\.0 foo 1\.4\.4, requires: ~> bar 2\.0 foo 1\.4\.5, requires: ~> bar 2\.1 foo 1\.5\.0, requires: ~> bar 2\.1 foo 1\.5\.1, requires: ~> bar 3\.0 bar with versions 2\.0\.3, 2\.0\.4, 2\.1\.0, 2\.1\.1, 3\.0\.0 -. .fi -. .IP "" 0 -. .P Gemfile: -. .IP "" 4 -. .nf - -gem \'foo\' -. +gem 'foo' .fi -. .IP "" 0 -. .P Gemfile\.lock: -. .IP "" 4 -. .nf - foo (1\.4\.3) bar (~> 2\.0) bar (2\.0\.3) -. .fi -. .IP "" 0 -. .P Cases: -. .IP "" 4 -. .nf - # Command Line Result \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- -1 bundle update \-\-patch \'foo 1\.4\.5\', \'bar 2\.1\.1\' -2 bundle update \-\-patch foo \'foo 1\.4\.5\', \'bar 2\.1\.1\' -3 bundle update \-\-minor \'foo 1\.5\.1\', \'bar 3\.0\.0\' -4 bundle update \-\-minor \-\-strict \'foo 1\.5\.0\', \'bar 2\.1\.1\' -5 bundle update \-\-patch \-\-strict \'foo 1\.4\.4\', \'bar 2\.0\.4\' -. +1 bundle update \-\-patch 'foo 1\.4\.5', 'bar 2\.1\.1' +2 bundle update \-\-patch foo 'foo 1\.4\.5', 'bar 2\.1\.1' +3 bundle update \-\-minor 'foo 1\.5\.1', 'bar 3\.0\.0' +4 bundle update \-\-minor \-\-strict 'foo 1\.5\.0', 'bar 2\.1\.1' +5 bundle update \-\-patch \-\-strict 'foo 1\.4\.4', 'bar 2\.0\.4' .fi -. .IP "" 0 -. .P In case 1, bar is upgraded to 2\.1\.1, a minor version increase, because the dependency from foo 1\.4\.5 required it\. -. .P -In case 2, only foo is requested to be unlocked, but bar is also allowed to move because it\'s not a declared dependency in the Gemfile\. -. +In case 2, only foo is requested to be unlocked, but bar is also allowed to move because it's not a declared dependency in the Gemfile\. .P In case 3, bar goes up a whole major release, because a minor increase is preferred now for foo, and when it goes to 1\.5\.1, it requires 3\.0\.0 of bar\. -. .P -In case 4, foo is preferred up to a minor version, but 1\.5\.1 won\'t work because the \-\-strict flag removes bar 3\.0\.0 from consideration since it\'s a major increment\. -. +In case 4, foo is preferred up to a minor version, but 1\.5\.1 won't work because the \-\-strict flag removes bar 3\.0\.0 from consideration since it's a major increment\. .P In case 5, both foo and bar have any minor or major increments removed from consideration because of the \-\-strict flag, so the most they can move is up to 1\.4\.4 and 2\.0\.4\. -. .SH "RECOMMENDED WORKFLOW" In general, when working with an application managed with bundler, you should use the following workflow: -. .IP "\(bu" 4 After you create your Gemfile(5) for the first time, run -. .IP $ bundle install -. .IP "\(bu" 4 Check the resulting \fBGemfile\.lock\fR into version control -. .IP $ git add Gemfile\.lock -. .IP "\(bu" 4 When checking out this repository on another development machine, run -. .IP $ bundle install -. .IP "\(bu" 4 When checking out this repository on a deployment machine, run -. .IP $ bundle install \-\-deployment -. .IP "\(bu" 4 After changing the Gemfile(5) to reflect a new or update dependency, run -. .IP $ bundle install -. .IP "\(bu" 4 Make sure to check the updated \fBGemfile\.lock\fR into version control -. .IP $ git add Gemfile\.lock -. .IP "\(bu" 4 If bundle install(1) \fIbundle\-install\.1\.html\fR reports a conflict, manually update the specific gems that you changed in the Gemfile(5) -. .IP $ bundle update rails thin -. .IP "\(bu" 4 If you want to update all the gems to the latest possible versions that still match the gems listed in the Gemfile(5), run -. .IP $ bundle update \-\-all -. .IP "" 0 diff --git a/lib/bundler/man/bundle-version.1 b/lib/bundler/man/bundle-version.1 index 9a3820f3e6..44eaf92224 100644 --- a/lib/bundler/man/bundle-version.1 +++ b/lib/bundler/man/bundle-version.1 @@ -1,35 +1,22 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-VERSION" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-VERSION" "1" "May 2024" "" .SH "NAME" \fBbundle\-version\fR \- Prints Bundler version information -. .SH "SYNOPSIS" \fBbundle version\fR -. .SH "DESCRIPTION" Prints Bundler version information\. -. .SH "OPTIONS" No options\. -. .SH "EXAMPLE" Print the version of Bundler with build date and commit hash of the in the Git source\. -. .IP "" 4 -. .nf - bundle version -. .fi -. .IP "" 0 -. .P shows \fBBundler version 2\.3\.21 (2022\-08\-24 commit d54be5fdd8)\fR for example\. -. .P cf\. \fBbundle \-\-version\fR shows \fBBundler version 2\.3\.21\fR\. diff --git a/lib/bundler/man/bundle-viz.1 b/lib/bundler/man/bundle-viz.1 index 3a07010309..77b902214c 100644 --- a/lib/bundler/man/bundle-viz.1 +++ b/lib/bundler/man/bundle-viz.1 @@ -1,41 +1,29 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE\-VIZ" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE\-VIZ" "1" "May 2024" "" .SH "NAME" \fBbundle\-viz\fR \- Generates a visual dependency graph for your Gemfile -. .SH "SYNOPSIS" \fBbundle viz\fR [\-\-file=FILE] [\-\-format=FORMAT] [\-\-requirements] [\-\-version] [\-\-without=GROUP GROUP] -. .SH "DESCRIPTION" \fBviz\fR generates a PNG file of the current \fBGemfile(5)\fR as a dependency graph\. \fBviz\fR requires the ruby\-graphviz gem (and its dependencies)\. -. .P The associated gems must also be installed via \fBbundle install(1)\fR \fIbundle\-install\.1\.html\fR\. -. .P \fBviz\fR command was deprecated in Bundler 2\.2\. Use bundler\-graph plugin \fIhttps://github\.com/rubygems/bundler\-graph\fR instead\. -. .SH "OPTIONS" -. .TP \fB\-\-file\fR, \fB\-f\fR The name to use for the generated file\. See \fB\-\-format\fR option -. .TP \fB\-\-format\fR, \fB\-F\fR -This is output format option\. Supported format is png, jpg, svg, dot \.\.\. -. +This is output format option\. Supported format is png, jpg, svg, dot \|\.\|\.\|\. .TP \fB\-\-requirements\fR, \fB\-R\fR Set to show the version of each required dependency\. -. .TP \fB\-\-version\fR, \fB\-v\fR Set to show each gem version\. -. .TP \fB\-\-without\fR, \fB\-W\fR Exclude gems that are part of the specified named group\. diff --git a/lib/bundler/man/bundle.1 b/lib/bundler/man/bundle.1 index 873ba566b1..199d1ce9fd 100644 --- a/lib/bundler/man/bundle.1 +++ b/lib/bundler/man/bundle.1 @@ -1,141 +1,102 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "BUNDLE" "1" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "BUNDLE" "1" "May 2024" "" .SH "NAME" \fBbundle\fR \- Ruby Dependency Management -. .SH "SYNOPSIS" \fBbundle\fR COMMAND [\-\-no\-color] [\-\-verbose] [ARGS] -. .SH "DESCRIPTION" -Bundler manages an \fBapplication\'s dependencies\fR through its entire life across many machines systematically and repeatably\. -. +Bundler manages an \fBapplication's dependencies\fR through its entire life across many machines systematically and repeatably\. .P See the bundler website \fIhttps://bundler\.io\fR for information on getting started, and Gemfile(5) for more information on the \fBGemfile\fR format\. -. .SH "OPTIONS" -. .TP \fB\-\-no\-color\fR Print all output without color -. .TP \fB\-\-retry\fR, \fB\-r\fR Specify the number of times you wish to attempt network commands -. .TP \fB\-\-verbose\fR, \fB\-V\fR Print out additional logging information -. .SH "BUNDLE COMMANDS" We divide \fBbundle\fR subcommands into primary commands and utilities: -. .SH "PRIMARY COMMANDS" -. .TP \fBbundle install(1)\fR \fIbundle\-install\.1\.html\fR Install the gems specified by the \fBGemfile\fR or \fBGemfile\.lock\fR -. .TP \fBbundle update(1)\fR \fIbundle\-update\.1\.html\fR Update dependencies to their latest versions -. .TP \fBbundle cache(1)\fR \fIbundle\-cache\.1\.html\fR Package the \.gem files required by your application into the \fBvendor/cache\fR directory (aliases: \fBbundle package\fR, \fBbundle pack\fR) -. .TP \fBbundle exec(1)\fR \fIbundle\-exec\.1\.html\fR Execute a script in the current bundle -. .TP \fBbundle config(1)\fR \fIbundle\-config\.1\.html\fR Specify and read configuration options for Bundler -. .TP \fBbundle help(1)\fR \fIbundle\-help\.1\.html\fR Display detailed help for each subcommand -. .SH "UTILITIES" -. .TP \fBbundle add(1)\fR \fIbundle\-add\.1\.html\fR Add the named gem to the Gemfile and run \fBbundle install\fR -. .TP \fBbundle binstubs(1)\fR \fIbundle\-binstubs\.1\.html\fR Generate binstubs for executables in a gem -. .TP \fBbundle check(1)\fR \fIbundle\-check\.1\.html\fR Determine whether the requirements for your application are installed and available to Bundler -. .TP \fBbundle show(1)\fR \fIbundle\-show\.1\.html\fR Show the source location of a particular gem in the bundle -. .TP \fBbundle outdated(1)\fR \fIbundle\-outdated\.1\.html\fR Show all of the outdated gems in the current bundle -. .TP \fBbundle console(1)\fR (deprecated) Start an IRB session in the current bundle -. .TP \fBbundle open(1)\fR \fIbundle\-open\.1\.html\fR Open an installed gem in the editor -. .TP \fBbundle lock(1)\fR \fIbundle\-lock\.1\.html\fR Generate a lockfile for your dependencies -. .TP \fBbundle viz(1)\fR \fIbundle\-viz\.1\.html\fR (deprecated) Generate a visual representation of your dependencies -. .TP \fBbundle init(1)\fR \fIbundle\-init\.1\.html\fR Generate a simple \fBGemfile\fR, placed in the current directory -. .TP \fBbundle gem(1)\fR \fIbundle\-gem\.1\.html\fR Create a simple gem, suitable for development with Bundler -. .TP \fBbundle platform(1)\fR \fIbundle\-platform\.1\.html\fR Display platform compatibility information -. .TP \fBbundle clean(1)\fR \fIbundle\-clean\.1\.html\fR Clean up unused gems in your Bundler directory -. .TP \fBbundle doctor(1)\fR \fIbundle\-doctor\.1\.html\fR Display warnings about common problems -. .TP \fBbundle remove(1)\fR \fIbundle\-remove\.1\.html\fR Removes gems from the Gemfile -. .TP \fBbundle plugin(1)\fR \fIbundle\-plugin\.1\.html\fR Manage Bundler plugins -. .TP \fBbundle version(1)\fR \fIbundle\-version\.1\.html\fR Prints Bundler version information -. .SH "PLUGINS" -When running a command that isn\'t listed in PRIMARY COMMANDS or UTILITIES, Bundler will try to find an executable on your path named \fBbundler\-<command>\fR and execute it, passing down any extra arguments to it\. -. +When running a command that isn't listed in PRIMARY COMMANDS or UTILITIES, Bundler will try to find an executable on your path named \fBbundler\-<command>\fR and execute it, passing down any extra arguments to it\. .SH "OBSOLETE" These commands are obsolete and should no longer be used: -. .IP "\(bu" 4 \fBbundle inject(1)\fR -. .IP "" 0 diff --git a/lib/bundler/man/gemfile.5 b/lib/bundler/man/gemfile.5 index 8e56506c88..fa9e31f615 100644 --- a/lib/bundler/man/gemfile.5 +++ b/lib/bundler/man/gemfile.5 @@ -1,215 +1,143 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "GEMFILE" "5" "February 2023" "" "" -. +.\" generated with nRonn/v0.11.1 +.\" https://github.com/n-ronn/nronn/tree/0.11.1 +.TH "GEMFILE" "5" "May 2024" "" .SH "NAME" \fBGemfile\fR \- A format for describing gem dependencies for Ruby programs -. .SH "SYNOPSIS" A \fBGemfile\fR describes the gem dependencies required to execute associated Ruby code\. -. .P Place the \fBGemfile\fR in the root of the directory containing the associated code\. For instance, in a Rails application, place the \fBGemfile\fR in the same directory as the \fBRakefile\fR\. -. .SH "SYNTAX" A \fBGemfile\fR is evaluated as Ruby code, in a context which makes available a number of methods used to describe the gem requirements\. -. .SH "GLOBAL SOURCE" At the top of the \fBGemfile\fR, add a single line for the \fBRubyGems\fR source that contains the gems listed in the \fBGemfile\fR\. -. .IP "" 4 -. .nf - source "https://rubygems\.org" -. .fi -. .IP "" 0 -. .P You can add only one global source\. In Bundler 1\.13, adding multiple global sources was deprecated\. The \fBsource\fR \fBMUST\fR be a valid RubyGems repository\. -. .P To use more than one source of RubyGems, you should use \fI\fBsource\fR block\fR\. -. .P A source is checked for gems following the heuristics described in \fISOURCE PRIORITY\fR\. -. .P \fBNote about a behavior of the feature deprecated in Bundler 1\.13\fR: If a gem is found in more than one global source, Bundler will print a warning after installing the gem indicating which source was used, and listing the other sources where the gem is available\. A specific source can be selected for gems that need to use a non\-standard repository, suppressing this warning, by using the \fI\fB:source\fR option\fR or \fBsource\fR block\. -. .SS "CREDENTIALS" Some gem sources require a username and password\. Use bundle config(1) \fIbundle\-config\.1\.html\fR to set the username and password for any of the sources that need it\. The command must be run once on each computer that will install the Gemfile, but this keeps the credentials from being stored in plain text in version control\. -. .IP "" 4 -. .nf - bundle config gems\.example\.com user:password -. .fi -. .IP "" 0 -. .P For some sources, like a company Gemfury account, it may be easier to include the credentials in the Gemfile as part of the source URL\. -. .IP "" 4 -. .nf - source "https://user:password@gems\.example\.com" -. .fi -. .IP "" 0 -. .P Credentials in the source URL will take precedence over credentials set using \fBconfig\fR\. -. .SH "RUBY" If your application requires a specific Ruby version or engine, specify your requirements using the \fBruby\fR method, with the following arguments\. All parameters are \fBOPTIONAL\fR unless otherwise specified\. -. .SS "VERSION (required)" The version of Ruby that your application requires\. If your application requires an alternate Ruby engine, such as JRuby, TruffleRuby, etc\., this should be the Ruby version that the engine is compatible with\. -. .IP "" 4 -. .nf - ruby "3\.1\.2" -. .fi -. .IP "" 0 -. +.P +If you wish to derive your Ruby version from a version file (ie \.ruby\-version), you can use the \fBfile\fR option instead\. +.IP "" 4 +.nf +ruby file: "\.ruby\-version" +.fi +.IP "" 0 +.P +The version file should conform to any of the following formats: +.IP "\(bu" 4 +\fB3\.1\.2\fR (\.ruby\-version) +.IP "\(bu" 4 +\fBruby 3\.1\.2\fR (\.tool\-versions, read: https://asdf\-vm\.com/manage/configuration\.html#tool\-versions) +.IP "" 0 .SS "ENGINE" Each application \fImay\fR specify a Ruby engine\. If an engine is specified, an engine version \fImust\fR also be specified\. -. .P -What exactly is an Engine? \- A Ruby engine is an implementation of the Ruby language\. -. +What exactly is an Engine? +.IP "\(bu" 4 +A Ruby engine is an implementation of the Ruby language\. .IP "\(bu" 4 -For background: the reference or original implementation of the Ruby programming language is called Matz\'s Ruby Interpreter \fIhttps://en\.wikipedia\.org/wiki/Ruby_MRI\fR, or MRI for short\. This is named after Ruby creator Yukihiro Matsumoto, also known as Matz\. MRI is also known as CRuby, because it is written in C\. MRI is the most widely used Ruby engine\. -. +For background: the reference or original implementation of the Ruby programming language is called Matz's Ruby Interpreter \fIhttps://en\.wikipedia\.org/wiki/Ruby_MRI\fR, or MRI for short\. This is named after Ruby creator Yukihiro Matsumoto, also known as Matz\. MRI is also known as CRuby, because it is written in C\. MRI is the most widely used Ruby engine\. .IP "\(bu" 4 -Other implementations \fIhttps://www\.ruby\-lang\.org/en/about/\fR of Ruby exist\. Some of the more well\-known implementations include JRuby \fIhttp://jruby\.org/\fR and TruffleRuby \fIhttps://www\.graalvm\.org/ruby/\fR\. Rubinius is an alternative implementation of Ruby written in Ruby\. JRuby is an implementation of Ruby on the JVM, short for Java Virtual Machine\. TruffleRuby is a Ruby implementation on the GraalVM, a language toolkit built on the JVM\. -. +Other implementations \fIhttps://www\.ruby\-lang\.org/en/about/\fR of Ruby exist\. Some of the more well\-known implementations include JRuby \fIhttps://www\.jruby\.org/\fR and TruffleRuby \fIhttps://www\.graalvm\.org/ruby/\fR\. Rubinius is an alternative implementation of Ruby written in Ruby\. JRuby is an implementation of Ruby on the JVM, short for Java Virtual Machine\. TruffleRuby is a Ruby implementation on the GraalVM, a language toolkit built on the JVM\. .IP "" 0 -. .SS "ENGINE VERSION" Each application \fImay\fR specify a Ruby engine version\. If an engine version is specified, an engine \fImust\fR also be specified\. If the engine is "ruby" the engine version specified \fImust\fR match the Ruby version\. -. .IP "" 4 -. .nf - ruby "2\.6\.8", engine: "jruby", engine_version: "9\.3\.8\.0" -. .fi -. .IP "" 0 -. .SS "PATCHLEVEL" Each application \fImay\fR specify a Ruby patchlevel\. Specifying the patchlevel has been meaningless since Ruby 2\.1\.0 was released as the patchlevel is now uniquely determined by a combination of major, minor, and teeny version numbers\. -. .P This option was implemented in Bundler 1\.4\.0 for Ruby 2\.0 or earlier\. -. .IP "" 4 -. .nf - ruby "3\.1\.2", patchlevel: "20" -. .fi -. .IP "" 0 -. .SH "GEMS" Specify gem requirements using the \fBgem\fR method, with the following arguments\. All parameters are \fBOPTIONAL\fR unless otherwise specified\. -. .SS "NAME (required)" For each gem requirement, list a single \fIgem\fR line\. -. .IP "" 4 -. .nf - gem "nokogiri" -. .fi -. .IP "" 0 -. .SS "VERSION" Each \fIgem\fR \fBMAY\fR have one or more version specifiers\. -. .IP "" 4 -. .nf - gem "nokogiri", ">= 1\.4\.2" gem "RedCloth", ">= 4\.1\.0", "< 4\.2\.0" -. .fi -. .IP "" 0 -. .SS "REQUIRE AS" Each \fIgem\fR \fBMAY\fR specify files that should be used when autorequiring via \fBBundler\.require\fR\. You may pass an array with multiple files or \fBtrue\fR if the file you want \fBrequired\fR has the same name as \fIgem\fR or \fBfalse\fR to prevent any file from being autorequired\. -. .IP "" 4 -. .nf - gem "redis", require: ["redis/connection/hiredis", "redis"] gem "webmock", require: false gem "byebug", require: true -. .fi -. .IP "" 0 -. .P The argument defaults to the name of the gem\. For example, these are identical: -. .IP "" 4 -. .nf - gem "nokogiri" gem "nokogiri", require: "nokogiri" gem "nokogiri", require: true -. .fi -. .IP "" 0 -. .SS "GROUPS" Each \fIgem\fR \fBMAY\fR specify membership in one or more groups\. Any \fIgem\fR that does not specify membership in any group is placed in the \fBdefault\fR group\. -. .IP "" 4 -. .nf - gem "rspec", group: :test gem "wirble", groups: [:development, :test] -. .fi -. .IP "" 0 -. .P The Bundler runtime allows its two main methods, \fBBundler\.setup\fR and \fBBundler\.require\fR, to limit their impact to particular groups\. -. .IP "" 4 -. .nf - -# setup adds gems to Ruby\'s load path +# setup adds gems to Ruby's load path Bundler\.setup # defaults to all groups require "bundler/setup" # same as Bundler\.setup Bundler\.setup(:default) # only set up the _default_ group @@ -221,437 +149,269 @@ Bundler\.require # defaults to the _default_ group Bundler\.require(:default) # identical Bundler\.require(:default, :test) # requires the _default_ and _test_ groups Bundler\.require(:test) # requires the _test_ group -. .fi -. .IP "" 0 -. .P The Bundler CLI allows you to specify a list of groups whose gems \fBbundle install\fR should not install with the \fBwithout\fR configuration\. -. .P To specify multiple groups to ignore, specify a list of groups separated by spaces\. -. .IP "" 4 -. .nf - bundle config set \-\-local without test bundle config set \-\-local without development test -. .fi -. .IP "" 0 -. .P Also, calling \fBBundler\.setup\fR with no parameters, or calling \fBrequire "bundler/setup"\fR will setup all groups except for the ones you excluded via \fB\-\-without\fR (since they are not available)\. -. .P Note that on \fBbundle install\fR, bundler downloads and evaluates all gems, in order to create a single canonical list of all of the required gems and their dependencies\. This means that you cannot list different versions of the same gems in different groups\. For more details, see Understanding Bundler \fIhttps://bundler\.io/rationale\.html\fR\. -. .SS "PLATFORMS" If a gem should only be used in a particular platform or set of platforms, you can specify them\. Platforms are essentially identical to groups, except that you do not need to use the \fB\-\-without\fR install\-time flag to exclude groups of gems for other platforms\. -. .P There are a number of \fBGemfile\fR platforms: -. .TP \fBruby\fR C Ruby (MRI), Rubinius, or TruffleRuby, but not Windows -. .TP \fBmri\fR C Ruby (MRI) only, but not Windows -. .TP \fBwindows\fR Windows C Ruby (MRI), including RubyInstaller 32\-bit and 64\-bit versions -. .TP \fBmswin\fR Windows C Ruby (MRI), including RubyInstaller 32\-bit versions -. .TP \fBmswin64\fR Windows C Ruby (MRI), including RubyInstaller 64\-bit versions -. .TP \fBrbx\fR Rubinius -. .TP \fBjruby\fR JRuby -. .TP \fBtruffleruby\fR TruffleRuby -. .P On platforms \fBruby\fR, \fBmri\fR, \fBmswin\fR, \fBmswin64\fR, and \fBwindows\fR, you may additionally specify a version by appending the major and minor version numbers without a delimiter\. For example, to specify that a gem should only be used on platform \fBruby\fR version 3\.1, use: -. .IP "" 4 -. .nf - ruby_31 -. .fi -. .IP "" 0 -. .P As with groups (above), you may specify one or more platforms: -. .IP "" 4 -. .nf - gem "weakling", platforms: :jruby gem "ruby\-debug", platforms: :mri_31 gem "nokogiri", platforms: [:windows_31, :jruby] -. .fi -. .IP "" 0 -. .P All operations involving groups (\fBbundle install\fR \fIbundle\-install\.1\.html\fR, \fBBundler\.setup\fR, \fBBundler\.require\fR) behave exactly the same as if any groups not matching the current platform were explicitly excluded\. -. .P The following platform values are deprecated and should be replaced with \fBwindows\fR: -. .IP "\(bu" 4 \fBmswin\fR, \fBmswin64\fR, \fBmingw32\fR, \fBx64_mingw\fR -. .IP "" 0 -. .SS "FORCE_RUBY_PLATFORM" If you always want the pure ruby variant of a gem to be chosen over platform specific variants, you can use the \fBforce_ruby_platform\fR option: -. .IP "" 4 -. .nf - gem "ffi", force_ruby_platform: true -. .fi -. .IP "" 0 -. .P This can be handy (assuming the pure ruby variant works fine) when: -. .IP "\(bu" 4 -You\'re having issues with the platform specific variant\. -. +You're having issues with the platform specific variant\. .IP "\(bu" 4 The platform specific variant does not yet support a newer ruby (and thus has a \fBrequired_ruby_version\fR upper bound), but you still want your Gemfile{\.lock} files to resolve under that ruby\. -. .IP "" 0 -. .SS "SOURCE" -You can select an alternate RubyGems repository for a gem using the \':source\' option\. -. +You can select an alternate RubyGems repository for a gem using the ':source' option\. .IP "" 4 -. .nf - gem "some_internal_gem", source: "https://gems\.example\.com" -. .fi -. .IP "" 0 -. .P This forces the gem to be loaded from this source and ignores the global source declared at the top level of the file\. If the gem does not exist in this source, it will not be installed\. -. .P Bundler will search for child dependencies of this gem by first looking in the source selected for the parent, but if they are not found there, it will fall back on the global source\. -. .P \fBNote about a behavior of the feature deprecated in Bundler 1\.13\fR: Selecting a specific source repository this way also suppresses the ambiguous gem warning described above in \fIGLOBAL SOURCE\fR\. -. .P Using the \fB:source\fR option for an individual gem will also make that source available as a possible global source for any other gems which do not specify explicit sources\. Thus, when adding gems with explicit sources, it is recommended that you also ensure all other gems in the Gemfile are using explicit sources\. -. .SS "GIT" If necessary, you can specify that a gem is located at a particular git repository using the \fB:git\fR parameter\. The repository can be accessed via several protocols: -. .TP \fBHTTP(S)\fR gem "rails", git: "https://github\.com/rails/rails\.git" -. .TP \fBSSH\fR gem "rails", git: "git@github\.com:rails/rails\.git" -. .TP \fBgit\fR gem "rails", git: "git://github\.com/rails/rails\.git" -. .P If using SSH, the user that you use to run \fBbundle install\fR \fBMUST\fR have the appropriate keys available in their \fB$HOME/\.ssh\fR\. -. .P \fBNOTE\fR: \fBhttp://\fR and \fBgit://\fR URLs should be avoided if at all possible\. These protocols are unauthenticated, so a man\-in\-the\-middle attacker can deliver malicious code and compromise your system\. HTTPS and SSH are strongly preferred\. -. .P The \fBgroup\fR, \fBplatforms\fR, and \fBrequire\fR options are available and behave exactly the same as they would for a normal gem\. -. .P A git repository \fBSHOULD\fR have at least one file, at the root of the directory containing the gem, with the extension \fB\.gemspec\fR\. This file \fBMUST\fR contain a valid gem specification, as expected by the \fBgem build\fR command\. -. .P If a git repository does not have a \fB\.gemspec\fR, bundler will attempt to create one, but it will not contain any dependencies, executables, or C extension compilation instructions\. As a result, it may fail to properly integrate into your application\. -. .P If a git repository does have a \fB\.gemspec\fR for the gem you attached it to, a version specifier, if provided, means that the git repository is only valid if the \fB\.gemspec\fR specifies a version matching the version specifier\. If not, bundler will print a warning\. -. .IP "" 4 -. .nf - gem "rails", "2\.3\.8", git: "https://github\.com/rails/rails\.git" # bundle install will fail, because the \.gemspec in the rails -# repository\'s master branch specifies version 3\.0\.0 -. +# repository's master branch specifies version 3\.0\.0 .fi -. .IP "" 0 -. .P If a git repository does \fBnot\fR have a \fB\.gemspec\fR for the gem you attached it to, a version specifier \fBMUST\fR be provided\. Bundler will use this version in the simple \fB\.gemspec\fR it creates\. -. .P Git repositories support a number of additional options\. -. .TP \fBbranch\fR, \fBtag\fR, and \fBref\fR You \fBMUST\fR only specify at most one of these options\. The default is \fBbranch: "master"\fR\. For example: -. .IP gem "rails", git: "https://github\.com/rails/rails\.git", branch: "5\-0\-stable" -. .IP gem "rails", git: "https://github\.com/rails/rails\.git", tag: "v5\.0\.0" -. .IP gem "rails", git: "https://github\.com/rails/rails\.git", ref: "4aded" -. .TP \fBsubmodules\fR For reference, a git submodule \fIhttps://git\-scm\.com/book/en/v2/Git\-Tools\-Submodules\fR lets you have another git repository within a subfolder of your repository\. Specify \fBsubmodules: true\fR to cause bundler to expand any submodules included in the git repository -. .P If a git repository contains multiple \fB\.gemspecs\fR, each \fB\.gemspec\fR represents a gem located at the same place in the file system as the \fB\.gemspec\fR\. -. .IP "" 4 -. .nf - |~rails [git root] | |\-rails\.gemspec [rails gem located here] |~actionpack | |\-actionpack\.gemspec [actionpack gem located here] |~activesupport | |\-activesupport\.gemspec [activesupport gem located here] -|\.\.\. -. +|\|\.\|\.\|\. .fi -. .IP "" 0 -. .P To install a gem located in a git repository, bundler changes to the directory containing the gemspec, runs \fBgem build name\.gemspec\fR and then installs the resulting gem\. The \fBgem build\fR command, which comes standard with Rubygems, evaluates the \fB\.gemspec\fR in the context of the directory in which it is located\. -. .SS "GIT SOURCE" -A custom git source can be defined via the \fBgit_source\fR method\. Provide the source\'s name as an argument, and a block which receives a single argument and interpolates it into a string to return the full repo address: -. +A custom git source can be defined via the \fBgit_source\fR method\. Provide the source's name as an argument, and a block which receives a single argument and interpolates it into a string to return the full repo address: .IP "" 4 -. .nf - git_source(:stash){ |repo_name| "https://stash\.corp\.acme\.pl/#{repo_name}\.git" } -gem \'rails\', stash: \'forks/rails\' -. +gem 'rails', stash: 'forks/rails' .fi -. .IP "" 0 -. .P In addition, if you wish to choose a specific branch: -. .IP "" 4 -. .nf - gem "rails", stash: "forks/rails", branch: "branch_name" -. .fi -. .IP "" 0 -. .SS "GITHUB" \fBNOTE\fR: This shorthand should be avoided until Bundler 2\.0, since it currently expands to an insecure \fBgit://\fR URL\. This allows a man\-in\-the\-middle attacker to compromise your system\. -. .P If the git repository you want to use is hosted on GitHub and is public, you can use the :github shorthand to specify the github username and repository name (without the trailing "\.git"), separated by a slash\. If both the username and repository name are the same, you can omit one\. -. .IP "" 4 -. .nf - gem "rails", github: "rails/rails" gem "rails", github: "rails" -. .fi -. .IP "" 0 -. .P Are both equivalent to -. .IP "" 4 -. .nf - gem "rails", git: "https://github\.com/rails/rails\.git" -. .fi -. .IP "" 0 -. .P Since the \fBgithub\fR method is a specialization of \fBgit_source\fR, it accepts a \fB:branch\fR named argument\. -. .P You can also directly pass a pull request URL: -. .IP "" 4 -. .nf - gem "rails", github: "https://github\.com/rails/rails/pull/43753" -. .fi -. .IP "" 0 -. .P Which is equivalent to: -. .IP "" 4 -. .nf - gem "rails", github: "rails/rails", branch: "refs/pull/43753/head" -. .fi -. .IP "" 0 -. .SS "GIST" If the git repository you want to use is hosted as a GitHub Gist and is public, you can use the :gist shorthand to specify the gist identifier (without the trailing "\.git")\. -. .IP "" 4 -. .nf - gem "the_hatch", gist: "4815162342" -. .fi -. .IP "" 0 -. .P Is equivalent to: -. .IP "" 4 -. .nf - gem "the_hatch", git: "https://gist\.github\.com/4815162342\.git" -. .fi -. .IP "" 0 -. .P Since the \fBgist\fR method is a specialization of \fBgit_source\fR, it accepts a \fB:branch\fR named argument\. -. .SS "BITBUCKET" If the git repository you want to use is hosted on Bitbucket and is public, you can use the :bitbucket shorthand to specify the bitbucket username and repository name (without the trailing "\.git"), separated by a slash\. If both the username and repository name are the same, you can omit one\. -. .IP "" 4 -. .nf - gem "rails", bitbucket: "rails/rails" gem "rails", bitbucket: "rails" -. .fi -. .IP "" 0 -. .P Are both equivalent to -. .IP "" 4 -. .nf - gem "rails", git: "https://rails@bitbucket\.org/rails/rails\.git" -. .fi -. .IP "" 0 -. .P Since the \fBbitbucket\fR method is a specialization of \fBgit_source\fR, it accepts a \fB:branch\fR named argument\. -. .SS "PATH" You can specify that a gem is located in a particular location on the file system\. Relative paths are resolved relative to the directory containing the \fBGemfile\fR\. -. .P Similar to the semantics of the \fB:git\fR option, the \fB:path\fR option requires that the directory in question either contains a \fB\.gemspec\fR for the gem, or that you specify an explicit version that bundler should use\. -. .P Unlike \fB:git\fR, bundler does not compile C extensions for gems specified as paths\. -. .IP "" 4 -. .nf - gem "rails", path: "vendor/rails" -. .fi -. .IP "" 0 -. .P -If you would like to use multiple local gems directly from the filesystem, you can set a global \fBpath\fR option to the path containing the gem\'s files\. This will automatically load gemspec files from subdirectories\. -. +If you would like to use multiple local gems directly from the filesystem, you can set a global \fBpath\fR option to the path containing the gem's files\. This will automatically load gemspec files from subdirectories\. .IP "" 4 -. .nf - -path \'components\' do - gem \'admin_ui\' - gem \'public_ui\' +path 'components' do + gem 'admin_ui' + gem 'public_ui' end -. .fi -. .IP "" 0 -. .SH "BLOCK FORM OF SOURCE, GIT, PATH, GROUP and PLATFORMS" The \fB:source\fR, \fB:git\fR, \fB:path\fR, \fB:group\fR, and \fB:platforms\fR options may be applied to a group of gems by using block form\. -. .IP "" 4 -. .nf - source "https://gems\.example\.com" do gem "some_internal_gem" gem "another_internal_gem" @@ -671,61 +431,40 @@ group :development, optional: true do gem "wirble" gem "faker" end -. .fi -. .IP "" 0 -. .P In the case of the group block form the :optional option can be given to prevent a group from being installed unless listed in the \fB\-\-with\fR option given to the \fBbundle install\fR command\. -. .P In the case of the \fBgit\fR block form, the \fB:ref\fR, \fB:branch\fR, \fB:tag\fR, and \fB:submodules\fR options may be passed to the \fBgit\fR method, and all gems in the block will inherit those options\. -. .P The presence of a \fBsource\fR block in a Gemfile also makes that source available as a possible global source for any other gems which do not specify explicit sources\. Thus, when defining source blocks, it is recommended that you also ensure all other gems in the Gemfile are using explicit sources, either via source blocks or \fB:source\fR directives on individual gems\. -. .SH "INSTALL_IF" The \fBinstall_if\fR method allows gems to be installed based on a proc or lambda\. This is especially useful for optional gems that can only be used if certain software is installed or some other conditions are met\. -. .IP "" 4 -. .nf - install_if \-> { RUBY_PLATFORM =~ /darwin/ } do gem "pasteboard" end -. .fi -. .IP "" 0 -. .SH "GEMSPEC" -The \fB\.gemspec\fR \fIhttp://guides\.rubygems\.org/specification\-reference/\fR file is where you provide metadata about your gem to Rubygems\. Some required Gemspec attributes include the name, description, and homepage of your gem\. This is also where you specify the dependencies your gem needs to run\. -. +The \fB\.gemspec\fR \fIhttps://guides\.rubygems\.org/specification\-reference/\fR file is where you provide metadata about your gem to Rubygems\. Some required Gemspec attributes include the name, description, and homepage of your gem\. This is also where you specify the dependencies your gem needs to run\. .P If you wish to use Bundler to help install dependencies for a gem while it is being developed, use the \fBgemspec\fR method to pull in the dependencies listed in the \fB\.gemspec\fR file\. -. .P -The \fBgemspec\fR method adds any runtime dependencies as gem requirements in the default group\. It also adds development dependencies as gem requirements in the \fBdevelopment\fR group\. Finally, it adds a gem requirement on your project (\fBpath: \'\.\'\fR)\. In conjunction with \fBBundler\.setup\fR, this allows you to require project files in your test code as you would if the project were installed as a gem; you need not manipulate the load path manually or require project files via relative paths\. -. +The \fBgemspec\fR method adds any runtime dependencies as gem requirements in the default group\. It also adds development dependencies as gem requirements in the \fBdevelopment\fR group\. Finally, it adds a gem requirement on your project (\fBpath: '\.'\fR)\. In conjunction with \fBBundler\.setup\fR, this allows you to require project files in your test code as you would if the project were installed as a gem; you need not manipulate the load path manually or require project files via relative paths\. .P -The \fBgemspec\fR method supports optional \fB:path\fR, \fB:glob\fR, \fB:name\fR, and \fB:development_group\fR options, which control where bundler looks for the \fB\.gemspec\fR, the glob it uses to look for the gemspec (defaults to: "{,\fI,\fR/*}\.gemspec"), what named \fB\.gemspec\fR it uses (if more than one is present), and which group development dependencies are included in\. -. +The \fBgemspec\fR method supports optional \fB:path\fR, \fB:glob\fR, \fB:name\fR, and \fB:development_group\fR options, which control where bundler looks for the \fB\.gemspec\fR, the glob it uses to look for the gemspec (defaults to: \fB{,*,*/*}\.gemspec\fR), what named \fB\.gemspec\fR it uses (if more than one is present), and which group development dependencies are included in\. .P When a \fBgemspec\fR dependency encounters version conflicts during resolution, the local version under development will always be selected \-\- even if there are remote versions that better match other requirements for the \fBgemspec\fR gem\. -. .SH "SOURCE PRIORITY" When attempting to locate a gem to satisfy a gem requirement, bundler uses the following priority order: -. .IP "1." 4 The source explicitly attached to the gem (using \fB:source\fR, \fB:path\fR, or \fB:git\fR) -. .IP "2." 4 For implicit gems (dependencies of explicit gems), any source, git, or path repository declared on the parent\. This results in bundler prioritizing the ActiveSupport gem from the Rails git repository over ones from \fBrubygems\.org\fR -. .IP "3." 4 If neither of the above conditions are met, the global source will be used\. If multiple global sources are specified, they will be prioritized from last to first, but this is deprecated since Bundler 1\.13, so Bundler prints a warning and will abort with an error in the future\. -. .IP "" 0 diff --git a/lib/bundler/man/gemfile.5.ronn b/lib/bundler/man/gemfile.5.ronn index a5d2288b96..7c1e00d13a 100644 --- a/lib/bundler/man/gemfile.5.ronn +++ b/lib/bundler/man/gemfile.5.ronn @@ -69,6 +69,16 @@ should be the Ruby version that the engine is compatible with. ruby "3.1.2" +If you wish to derive your Ruby version from a version file (ie .ruby-version), +you can use the `file` option instead. + + ruby file: ".ruby-version" + +The version file should conform to any of the following formats: + + - `3.1.2` (.ruby-version) + - `ruby 3.1.2` (.tool-versions, read: https://asdf-vm.com/manage/configuration.html#tool-versions) + ### ENGINE Each application _may_ specify a Ruby engine. If an engine is specified, an @@ -86,7 +96,7 @@ What exactly is an Engine? - [Other implementations](https://www.ruby-lang.org/en/about/) of Ruby exist. Some of the more well-known implementations include - [JRuby](http://jruby.org/) and [TruffleRuby](https://www.graalvm.org/ruby/). + [JRuby](https://www.jruby.org/) and [TruffleRuby](https://www.graalvm.org/ruby/). Rubinius is an alternative implementation of Ruby written in Ruby. JRuby is an implementation of Ruby on the JVM, short for Java Virtual Machine. TruffleRuby is a Ruby implementation on the GraalVM, a language toolkit built on the JVM. @@ -499,7 +509,7 @@ software is installed or some other conditions are met. ## GEMSPEC -The [`.gemspec`](http://guides.rubygems.org/specification-reference/) file is where +The [`.gemspec`](https://guides.rubygems.org/specification-reference/) file is where you provide metadata about your gem to Rubygems. Some required Gemspec attributes include the name, description, and homepage of your gem. This is also where you specify the dependencies your gem needs to run. @@ -518,7 +528,7 @@ paths. The `gemspec` method supports optional `:path`, `:glob`, `:name`, and `:development_group` options, which control where bundler looks for the `.gemspec`, the glob it uses to look -for the gemspec (defaults to: "{,*,*/*}.gemspec"), what named `.gemspec` it uses +for the gemspec (defaults to: `{,*,*/*}.gemspec`), what named `.gemspec` it uses (if more than one is present), and which group development dependencies are included in. When a `gemspec` dependency encounters version conflicts during resolution, the diff --git a/lib/bundler/match_metadata.rb b/lib/bundler/match_metadata.rb index 499036ca93..f6cc27df32 100644 --- a/lib/bundler/match_metadata.rb +++ b/lib/bundler/match_metadata.rb @@ -2,6 +2,10 @@ module Bundler module MatchMetadata + def matches_current_metadata? + matches_current_ruby? && matches_current_rubygems? + end + def matches_current_ruby? @required_ruby_version.satisfied_by?(Gem.ruby_version) end diff --git a/lib/bundler/match_platform.rb b/lib/bundler/match_platform.rb index 7f7e8227f9..ece9fb8679 100644 --- a/lib/bundler/match_platform.rb +++ b/lib/bundler/match_platform.rb @@ -12,7 +12,7 @@ module Bundler def self.platforms_match?(gemspec_platform, local_platform) return true if gemspec_platform.nil? - return true if Gem::Platform::RUBY == gemspec_platform + return true if gemspec_platform == Gem::Platform::RUBY return true if local_platform == gemspec_platform gemspec_platform = Gem::Platform.new(gemspec_platform) return true if gemspec_platform === local_platform diff --git a/lib/bundler/mirror.rb b/lib/bundler/mirror.rb index 9d437a0951..494a6d6aef 100644 --- a/lib/bundler/mirror.rb +++ b/lib/bundler/mirror.rb @@ -47,7 +47,7 @@ module Bundler def fetch_valid_mirror_for(uri) downcased = uri.to_s.downcase - mirror = @mirrors[downcased] || @mirrors[Bundler::URI(downcased).host] || Mirror.new(uri) + mirror = @mirrors[downcased] || @mirrors[Gem::URI(downcased).host] || Mirror.new(uri) mirror.validate!(@prober) mirror = Mirror.new(uri) unless mirror.valid? mirror @@ -74,7 +74,7 @@ module Bundler @uri = if uri.nil? nil else - Bundler::URI(uri.to_s) + Gem::URI(uri.to_s) end @valid = nil end @@ -126,7 +126,7 @@ module Bundler if uri == "all" @all = true else - @uri = Bundler::URI(uri).absolute? ? Settings.normalize_uri(uri) : uri + @uri = Gem::URI(uri).absolute? ? Settings.normalize_uri(uri) : uri end @value = value end diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index f3caff8963..588fa79be8 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -62,7 +62,8 @@ module Bundler if names.any? names.each do |name| if index.installed?(name) - Bundler.rm_rf(index.plugin_path(name)) + path = index.plugin_path(name).to_s + Bundler.rm_rf(path) if index.installed_in_plugin_root?(name) index.unregister_plugin(name) Bundler.ui.info "Uninstalled plugin #{name}" else @@ -100,7 +101,7 @@ module Bundler # @param [Pathname] gemfile path # @param [Proc] block that can be evaluated for (inline) Gemfile def gemfile_install(gemfile = nil, &inline) - Bundler.settings.temporary(:frozen => false, :deployment => false) do + Bundler.settings.temporary(frozen: false, deployment: false) do builder = DSL.new if block_given? builder.instance_eval(&inline) @@ -197,7 +198,7 @@ module Bundler # @param [Hash] The options that are present in the lock file # @return [API::Source] the instance of the class that handles the source # type passed in locked_opts - def source_from_lock(locked_opts) + def from_lock(locked_opts) src = source(locked_opts["type"]) src.new(locked_opts.merge("uri" => locked_opts["remote"])) @@ -227,7 +228,7 @@ module Bundler plugins = index.hook_plugins(event) return unless plugins.any? - (plugins - @loaded_plugin_names).each {|name| load_plugin(name) } + plugins.each {|name| load_plugin(name) } @hooks_by_event[event].each {|blk| blk.call(*args, &arg_blk) } end @@ -239,6 +240,11 @@ module Bundler Index.new.installed?(plugin) end + # @return [true, false] whether the plugin is loaded + def loaded?(plugin) + @loaded_plugin_names.include?(plugin) + end + # Post installation processing and registering with index # # @param [Array<String>] plugins list to be installed @@ -301,7 +307,7 @@ module Bundler @hooks_by_event = Hash.new {|h, k| h[k] = [] } load_paths = spec.load_paths - Bundler.rubygems.add_to_load_path(load_paths) + Gem.add_to_load_path(*load_paths) path = Pathname.new spec.full_gem_path begin @@ -329,13 +335,14 @@ module Bundler # @param [String] name of the plugin def load_plugin(name) return unless name && !name.empty? + return if loaded?(name) # Need to ensure before this that plugin root where the rest of gems # are installed to be on load path to support plugin deps. Currently not # done to avoid conflicts path = index.plugin_path(name) - Bundler.rubygems.add_to_load_path(index.load_paths(name)) + Gem.add_to_load_path(*index.load_paths(name)) load path.join(PLUGIN_FILE_NAME) diff --git a/lib/bundler/plugin/api/source.rb b/lib/bundler/plugin/api/source.rb index 67c45bd204..8563ee358a 100644 --- a/lib/bundler/plugin/api/source.rb +++ b/lib/bundler/plugin/api/source.rb @@ -39,7 +39,7 @@ module Bundler # is present to be compatible with `Definition` and is used by # rubygems source. module Source - attr_reader :uri, :options, :name + attr_reader :uri, :options, :name, :checksum_store attr_accessor :dependency_names def initialize(opts) @@ -48,6 +48,7 @@ module Bundler @uri = opts["uri"] @type = opts["type"] @name = opts["name"] || "#{@type} at #{@uri}" + @checksum_store = Checksum::Store.new end # This is used by the default `spec` method to constructs the @@ -95,7 +96,7 @@ module Bundler # # Note: Do not override if you don't know what you are doing. def post_install(spec, disable_exts = false) - opts = { :env_shebang => false, :disable_extensions => disable_exts } + opts = { env_shebang: false, disable_extensions: disable_exts } installer = Bundler::Source::Path::Installer.new(spec, opts) installer.post_install end @@ -106,7 +107,7 @@ module Bundler def install_path @install_path ||= begin - base_name = File.basename(Bundler::URI.parse(uri).normalize.path) + base_name = File.basename(Gem::URI.parse(uri).normalize.path) gem_install_dir.join("#{base_name}-#{uri_hash[0..11]}") end @@ -175,7 +176,7 @@ module Bundler # # This is used by `app_cache_path` def app_cache_dirname - base_name = File.basename(Bundler::URI.parse(uri).normalize.path) + base_name = File.basename(Gem::URI.parse(uri).normalize.path) "#{base_name}-#{uri_hash}" end diff --git a/lib/bundler/plugin/events.rb b/lib/bundler/plugin/events.rb index bc037d1af5..29c05098ae 100644 --- a/lib/bundler/plugin/events.rb +++ b/lib/bundler/plugin/events.rb @@ -56,6 +56,30 @@ module Bundler # Includes an Array of Bundler::Dependency objects # GEM_AFTER_INSTALL_ALL = "after-install-all" define :GEM_AFTER_INSTALL_ALL, "after-install-all" + + # @!parse + # A hook called before each individual gem is required + # Includes a Bundler::Dependency. + # GEM_BEFORE_REQUIRE = "before-require" + define :GEM_BEFORE_REQUIRE, "before-require" + + # @!parse + # A hook called after each individual gem is required + # Includes a Bundler::Dependency. + # GEM_AFTER_REQUIRE = "after-require" + define :GEM_AFTER_REQUIRE, "after-require" + + # @!parse + # A hook called before any gems require + # Includes an Array of Bundler::Dependency objects. + # GEM_BEFORE_REQUIRE_ALL = "before-require-all" + define :GEM_BEFORE_REQUIRE_ALL, "before-require-all" + + # @!parse + # A hook called after all gems required + # Includes an Array of Bundler::Dependency objects. + # GEM_AFTER_REQUIRE_ALL = "after-require-all" + define :GEM_AFTER_REQUIRE_ALL, "after-require-all" end end end diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index a2d5eaa38a..c2ab8f90da 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -136,6 +136,14 @@ module Bundler @hooks[event] || [] end + # This plugin is installed inside the .bundle/plugin directory, + # and thus is managed solely by Bundler + def installed_in_plugin_root?(name) + return false unless (path = installed?(name)) + + path.start_with?("#{Plugin.root}/") + end + private # Reads the index file from the directory and initializes the instance diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb index c9ff12ce4b..4f60862bb4 100644 --- a/lib/bundler/plugin/installer.rb +++ b/lib/bundler/plugin/installer.rb @@ -10,6 +10,7 @@ module Bundler class Installer autoload :Rubygems, File.expand_path("installer/rubygems", __dir__) autoload :Git, File.expand_path("installer/git", __dir__) + autoload :Path, File.expand_path("installer/path", __dir__) def install(names, options) check_sources_consistency!(options) @@ -18,8 +19,8 @@ module Bundler if options[:git] install_git(names, version, options) - elsif options[:local_git] - install_local_git(names, version, options) + elsif options[:path] + install_path(names, version, options[:path]) else sources = options[:source] || Gem.sources install_rubygems(names, version, sources) @@ -45,20 +46,40 @@ module Bundler if options.key?(:git) && options.key?(:local_git) raise InvalidOption, "Remote and local plugin git sources can't be both specified" end + + # back-compat; local_git is an alias for git + if options.key?(:local_git) + Bundler::SharedHelpers.major_deprecation(2, "--local_git is deprecated, use --git") + options[:git] = options.delete(:local_git) + end + + if (options.keys & [:source, :git, :path]).length > 1 + raise InvalidOption, "Only one of --source, --git, or --path may be specified" + end + + if (options.key?(:branch) || options.key?(:ref)) && !options.key?(:git) + raise InvalidOption, "--#{options.key?(:branch) ? "branch" : "ref"} can only be used with git sources" + end + + if options.key?(:branch) && options.key?(:ref) + raise InvalidOption, "--branch and --ref can't be both specified" + end end def install_git(names, version, options) - uri = options.delete(:git) - options["uri"] = uri + source_list = SourceList.new + source = source_list.add_git_source({ "uri" => options[:git], + "branch" => options[:branch], + "ref" => options[:ref] }) - install_all_sources(names, version, options, options[:source]) + install_all_sources(names, version, source_list, source) end - def install_local_git(names, version, options) - uri = options.delete(:local_git) - options["uri"] = uri + def install_path(names, version, path) + source_list = SourceList.new + source = source_list.add_path_source({ "path" => path, "root_path" => SharedHelpers.pwd }) - install_all_sources(names, version, options, options[:source]) + install_all_sources(names, version, source_list, source) end # Installs the plugin from rubygems source and returns the path where the @@ -70,20 +91,19 @@ module Bundler # # @return [Hash] map of names to the specs of plugins installed def install_rubygems(names, version, sources) - install_all_sources(names, version, nil, sources) - end - - def install_all_sources(names, version, git_source_options, rubygems_source) source_list = SourceList.new - source_list.add_git_source(git_source_options) if git_source_options - Array(rubygems_source).each {|remote| source_list.add_global_rubygems_remote(remote) } if rubygems_source + Array(sources).each {|remote| source_list.add_global_rubygems_remote(remote) } + + install_all_sources(names, version, source_list) + end - deps = names.map {|name| Dependency.new name, version } + def install_all_sources(names, version, source_list, source = nil) + deps = names.map {|name| Dependency.new(name, version, { "source" => source }) } Bundler.configure_gem_home_and_path(Plugin.root) - Bundler.settings.temporary(:deployment => false, :frozen => false) do + Bundler.settings.temporary(deployment: false, frozen: false) do definition = Definition.new(nil, deps, source_list, true) install_definition(definition) diff --git a/lib/bundler/plugin/installer/path.rb b/lib/bundler/plugin/installer/path.rb new file mode 100644 index 0000000000..58a8fa7426 --- /dev/null +++ b/lib/bundler/plugin/installer/path.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Bundler + module Plugin + class Installer + class Path < Bundler::Source::Path + def root + SharedHelpers.in_bundle? ? Bundler.root : Plugin.root + end + + def generate_bin(spec, disable_extensions = false) + # Need to find a way without code duplication + # For now, we can ignore this + end + end + end + end +end diff --git a/lib/bundler/plugin/source_list.rb b/lib/bundler/plugin/source_list.rb index 547661cf2f..746996de55 100644 --- a/lib/bundler/plugin/source_list.rb +++ b/lib/bundler/plugin/source_list.rb @@ -9,6 +9,10 @@ module Bundler add_source_to_list Plugin::Installer::Git.new(options), git_sources end + def add_path_source(options = {}) + add_source_to_list Plugin::Installer::Path.new(options), path_sources + end + def add_rubygems_source(options = {}) add_source_to_list Plugin::Installer::Rubygems.new(options), @rubygems_sources end @@ -17,10 +21,6 @@ module Bundler path_sources + git_sources + rubygems_sources + [metadata_source] end - def default_source - git_sources.first || global_rubygems_source - end - private def rubygems_aggregate_class diff --git a/lib/bundler/remote_specification.rb b/lib/bundler/remote_specification.rb index f626a3218e..9d237f3fa0 100644 --- a/lib/bundler/remote_specification.rb +++ b/lib/bundler/remote_specification.rb @@ -88,6 +88,10 @@ module Bundler end end + def runtime_dependencies + dependencies.select(&:runtime?) + end + def git_version return unless loaded_from && source.is_a?(Bundler::Source::Git) " #{source.revision[0..6]}" diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index c8cc88a3ee..1a6711ea6f 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -29,7 +29,7 @@ module Bundler Bundler.ui.info "Resolving dependencies...", true - solve_versions(:root => root, :logger => logger) + solve_versions(root: root, logger: logger) end def setup_solver @@ -37,31 +37,39 @@ module Bundler root_version = Resolver::Candidate.new(0) @all_specs = Hash.new do |specs, name| - specs[name] = source_for(name).specs.search(name).reject do |s| - s.dependencies.any? {|d| d.name == name && !d.requirement.satisfied_by?(s.version) } # ignore versions that depend on themselves incorrectly - end.sort_by {|s| [s.version, s.platform.to_s] } + source = source_for(name) + matches = source.specs.search(name) + + # Don't bother to check for circular deps when no dependency API are + # available, since it's too slow to be usable. That edge case won't work + # but resolution other than that should work fine and reasonably fast. + if source.respond_to?(:dependency_api_available?) && source.dependency_api_available? + matches = filter_invalid_self_dependencies(matches, name) + end + + specs[name] = matches.sort_by {|s| [s.version, s.platform.to_s] } + end + + @all_versions = Hash.new do |candidates, package| + candidates[package] = all_versions_for(package) end @sorted_versions = Hash.new do |candidates, package| - candidates[package] = if package.root? - [root_version] - else - all_versions_for(package).sort - end + candidates[package] = filtered_versions_for(package).sort end + @sorted_versions[root] = [root_version] + root_dependencies = prepare_dependencies(@requirements, @packages) @cached_dependencies = Hash.new do |dependencies, package| - dependencies[package] = if package.root? - { root_version => root_dependencies } - else - Hash.new do |versions, version| - versions[version] = to_dependency_hash(version.dependencies.reject {|d| d.name == package.name }, @packages) - end + dependencies[package] = Hash.new do |versions, version| + versions[version] = to_dependency_hash(version.dependencies.reject {|d| d.name == package.name }, @packages) end end + @cached_dependencies[root] = { root_version => root_dependencies } + logger = Bundler::UI::Shell.new logger.level = debug? ? "debug" : "warn" @@ -69,7 +77,7 @@ module Bundler end def solve_versions(root:, logger:) - solver = PubGrub::VersionSolver.new(:source => self, :root => root, :logger => logger) + solver = PubGrub::VersionSolver.new(source: self, root: root, logger: logger) result = solver.solve result.map {|package, version| version.to_specs(package) }.flatten.uniq rescue PubGrub::SolveFailure => e @@ -123,7 +131,7 @@ module Bundler if base_requirements[name] names_to_unlock << name - elsif package.ignores_prereleases? + elsif package.ignores_prereleases? && @all_specs[name].any? {|s| s.version.prerelease? } names_to_allow_prereleases_for << name end @@ -144,13 +152,19 @@ module Bundler requirement_to_range(dependency) end - PubGrub::VersionConstraint.new(package, :range => range) + PubGrub::VersionConstraint.new(package, range: range) end def versions_for(package, range=VersionRange.any) - versions = range.select_versions(@sorted_versions[package]) + versions = select_sorted_versions(package, range) - sort_versions(package, versions) + # Conditional avoids (among other things) calling + # sort_versions_by_preferred with the root package + if versions.size > 1 + sort_versions_by_preferred(package, versions) + else + versions + end end def no_versions_incompatibility_for(package, unsatisfied_term) @@ -160,7 +174,7 @@ module Bundler constraint_string = constraint.constraint_string requirements = constraint_string.split(" OR ").map {|req| Gem::Requirement.new(req.split(",")) } - if name == "bundler" + if name == "bundler" && bundler_pinned_to_current_version? custom_explanation = "the current Bundler version (#{Bundler::VERSION}) does not satisfy #{constraint}" extended_explanation = bundler_not_found_message(requirements) else @@ -173,7 +187,7 @@ module Bundler extended_explanation = other_specs_matching_message(specs_matching_other_platforms, label) if specs_matching_other_platforms.any? end - Incompatibility.new([unsatisfied_term], :cause => cause, :custom_explanation => custom_explanation, :extended_explanation => extended_explanation) + Incompatibility.new([unsatisfied_term], cause: cause, custom_explanation: custom_explanation, extended_explanation: extended_explanation) end def debug? @@ -212,9 +226,9 @@ module Bundler sorted_versions[high] end - range = PubGrub::VersionRange.new(:min => low, :max => high, :include_min => true) + range = PubGrub::VersionRange.new(min: low, max: high, include_min: true) - self_constraint = PubGrub::VersionConstraint.new(package, :range => range) + self_constraint = PubGrub::VersionConstraint.new(package, range: range) dep_term = PubGrub::Term.new(dep_constraint, false) self_term = PubGrub::Term.new(self_constraint, true) @@ -223,37 +237,63 @@ module Bundler "current #{dep_package} version is #{dep_constraint.constraint_string}" end - PubGrub::Incompatibility.new([self_term, dep_term], :cause => :dependency, :custom_explanation => custom_explanation) + PubGrub::Incompatibility.new([self_term, dep_term], cause: :dependency, custom_explanation: custom_explanation) end end def all_versions_for(package) name = package.name results = (@base[name] + filter_prereleases(@all_specs[name], package)).uniq {|spec| [spec.version.hash, spec.platform] } + + if name == "bundler" && !bundler_pinned_to_current_version? + bundler_spec = Gem.loaded_specs["bundler"] + results << bundler_spec if bundler_spec + end + locked_requirement = base_requirements[name] results = filter_matching_specs(results, locked_requirement) if locked_requirement - versions = results.group_by(&:version).reduce([]) do |groups, (version, specs)| - platform_specs = package.platforms.flat_map {|platform| select_best_platform_match(specs, platform) } - next groups if platform_specs.empty? + results.group_by(&:version).reduce([]) do |groups, (version, specs)| + platform_specs = package.platforms.map {|platform| select_best_platform_match(specs, platform) } + + # If package is a top-level dependency, + # candidate is only valid if there are matching versions for all resolution platforms. + # + # If package is not a top-level deependency, + # then it's not necessary that it has matching versions for all platforms, since it may have been introduced only as + # a dependency for a platform specific variant, so it will only need to have a valid version for that platform. + # + if package.top_level? + next groups if platform_specs.any?(&:empty?) + else + next groups if platform_specs.all?(&:empty?) + end + + platform_specs.flatten! ruby_specs = select_best_platform_match(specs, Gem::Platform::RUBY) - groups << Resolver::Candidate.new(version, :specs => ruby_specs) if ruby_specs.any? + groups << Resolver::Candidate.new(version, specs: ruby_specs) if ruby_specs.any? next groups if platform_specs == ruby_specs || package.force_ruby_platform? - groups << Resolver::Candidate.new(version, :specs => platform_specs) + groups << Resolver::Candidate.new(version, specs: platform_specs) groups end - - sort_versions(package, versions) end def source_for(name) @source_requirements[name] || @source_requirements[:default] end + def default_bundler_source + @source_requirements[:default_bundler] + end + + def bundler_pinned_to_current_version? + !default_bundler_source.nil? + end + def name_for_explicit_dependency_source Bundler.default_gemfile.basename.to_s rescue StandardError @@ -273,15 +313,21 @@ module Bundler end specs_matching_requirement = filter_matching_specs(specs, package.dependency.requirement) - if specs_matching_requirement.any? + not_found_message = if specs_matching_requirement.any? specs = specs_matching_requirement matching_part = requirement_label platforms = package.platforms - platform_label = platforms.size == 1 ? "platform '#{platforms.first}" : "platforms '#{platforms.join("', '")}" - requirement_label = "#{requirement_label}' with #{platform_label}" + + if platforms.size == 1 + "Could not find gem '#{requirement_label}' with platform '#{platforms.first}'" + else + "Could not find gems matching '#{requirement_label}' valid for all resolution platforms (#{platforms.join(", ")})" + end + else + "Could not find gem '#{requirement_label}'" end - message = String.new("Could not find gem '#{requirement_label}' in #{source}#{cache_message}.\n") + message = String.new("#{not_found_message} in #{source}#{cache_message}.\n") if specs.any? message << "\n#{other_specs_matching_message(specs, matching_part)}" @@ -292,6 +338,21 @@ module Bundler private + def filtered_versions_for(package) + @gem_version_promoter.filter_versions(package, @all_versions[package]) + end + + def raise_all_versions_filtered_out!(package) + level = @gem_version_promoter.level + name = package.name + locked_version = package.locked_version + requirement = package.dependency + + raise GemNotFound, + "#{name} is locked to #{locked_version}, while Gemfile is requesting #{requirement}. " \ + "--strict --#{level} was specified, but there are no #{level} level upgrades from #{locked_version} satisfying #{requirement}, so version solving has failed" + end + def filter_matching_specs(specs, requirements) Array(requirements).flat_map do |requirement| specs.select {| spec| requirement_satisfied_by?(requirement, spec) } @@ -304,16 +365,19 @@ module Bundler specs.reject {|s| s.version.prerelease? } end + # Ignore versions that depend on themselves incorrectly + def filter_invalid_self_dependencies(specs, name) + specs.reject do |s| + s.dependencies.any? {|d| d.name == name && !d.requirement.satisfied_by?(s.version) } + end + end + def requirement_satisfied_by?(requirement, spec) requirement.satisfied_by?(spec.version) || spec.source.is_a?(Source::Gemspec) end - def sort_versions(package, versions) - if versions.size > 1 - @gem_version_promoter.sort_versions(package, versions).reverse - else - versions - end + def sort_versions_by_preferred(package, versions) + @gem_version_promoter.sort_versions(package, versions) end def repository_for(package) @@ -330,12 +394,19 @@ module Bundler next [dep_package, dep_constraint] if name == "bundler" - versions = versions_for(dep_package, dep_constraint.range) + dep_range = dep_constraint.range + versions = select_sorted_versions(dep_package, dep_range) if versions.empty? && dep_package.ignores_prereleases? + @all_versions.delete(dep_package) @sorted_versions.delete(dep_package) dep_package.consider_prereleases! - versions = versions_for(dep_package, dep_constraint.range) + versions = select_sorted_versions(dep_package, dep_range) + end + + if versions.empty? && select_all_versions(dep_package, dep_range).any? + raise_all_versions_filtered_out!(dep_package) end + next [dep_package, dep_constraint] unless versions.empty? next unless dep_package.current_platform? @@ -344,6 +415,14 @@ module Bundler end.compact.to_h end + def select_sorted_versions(package, range) + range.select_versions(@sorted_versions[package]) + end + + def select_all_versions(package, range) + range.select_versions(@all_versions[package]) + end + def other_specs_matching_message(specs, requirement) message = String.new("The source contains the following gems matching '#{requirement}':\n") message << specs.map {|s| " * #{s.full_name}" }.join("\n") @@ -359,19 +438,19 @@ module Bundler when "~>" name = "~> #{ver}" bump = Resolver::Candidate.new(version.bump.to_s + ".A") - PubGrub::VersionRange.new(:name => name, :min => ver, :max => bump, :include_min => true) + PubGrub::VersionRange.new(name: name, min: ver, max: bump, include_min: true) when ">" - PubGrub::VersionRange.new(:min => platform_ver) + PubGrub::VersionRange.new(min: platform_ver) when ">=" - PubGrub::VersionRange.new(:min => ver, :include_min => true) + PubGrub::VersionRange.new(min: ver, include_min: true) when "<" - PubGrub::VersionRange.new(:max => ver) + PubGrub::VersionRange.new(max: ver) when "<=" - PubGrub::VersionRange.new(:max => platform_ver, :include_max => true) + PubGrub::VersionRange.new(max: platform_ver, include_max: true) when "=" - PubGrub::VersionRange.new(:min => ver, :max => platform_ver, :include_min => true, :include_max => true) + PubGrub::VersionRange.new(min: ver, max: platform_ver, include_min: true, include_max: true) when "!=" - PubGrub::VersionRange.new(:min => ver, :max => platform_ver, :include_min => true, :include_max => true).invert + PubGrub::VersionRange.new(min: ver, max: platform_ver, include_min: true, include_max: true).invert else raise "bad version specifier: #{op}" end @@ -398,7 +477,7 @@ module Bundler end def bundler_not_found_message(conflict_dependencies) - candidate_specs = filter_matching_specs(source_for(:default_bundler).specs.search("bundler"), conflict_dependencies) + candidate_specs = filter_matching_specs(default_bundler_source.specs.search("bundler"), conflict_dependencies) if candidate_specs.any? target_version = candidate_specs.last.version diff --git a/lib/bundler/resolver/base.rb b/lib/bundler/resolver/base.rb index e5c3763c3f..ad19eeb3f4 100644 --- a/lib/bundler/resolver/base.rb +++ b/lib/bundler/resolver/base.rb @@ -24,7 +24,7 @@ module Bundler name = dep.name - @packages[name] = Package.new(name, dep_platforms, **options.merge(:dependency => dep)) + @packages[name] = Package.new(name, dep_platforms, **options.merge(dependency: dep)) dep end.compact diff --git a/lib/bundler/resolver/candidate.rb b/lib/bundler/resolver/candidate.rb index e695ef08ee..9e8b913335 100644 --- a/lib/bundler/resolver/candidate.rb +++ b/lib/bundler/resolver/candidate.rb @@ -15,7 +15,7 @@ module Bundler # considered separately. # # Some candidates may also keep some information explicitly about the - # package the refer to. These candidates are referred to as "canonical" and + # package they refer to. These candidates are referred to as "canonical" and # are used when materializing resolution results back into RubyGems # specifications that can be installed, written to lock files, and so on. # diff --git a/lib/bundler/resolver/incompatibility.rb b/lib/bundler/resolver/incompatibility.rb index c61151fbeb..4ac1b2e1ea 100644 --- a/lib/bundler/resolver/incompatibility.rb +++ b/lib/bundler/resolver/incompatibility.rb @@ -8,7 +8,7 @@ module Bundler def initialize(terms, cause:, custom_explanation: nil, extended_explanation: nil) @extended_explanation = extended_explanation - super(terms, :cause => cause, :custom_explanation => custom_explanation) + super(terms, cause: cause, custom_explanation: custom_explanation) end end end diff --git a/lib/bundler/resolver/package.rb b/lib/bundler/resolver/package.rb index 7499a75006..0461328683 100644 --- a/lib/bundler/resolver/package.rb +++ b/lib/bundler/resolver/package.rb @@ -21,6 +21,7 @@ module Bundler @locked_version = locked_specs[name].first&.version @unlock = unlock @dependency = dependency || Dependency.new(name, @locked_version) + @top_level = !dependency.nil? @prerelease = @dependency.prerelease? || @locked_version&.prerelease? || prerelease ? :consider_first : :ignore end @@ -32,6 +33,10 @@ module Bundler false end + def top_level? + @top_level + end + def meta? @name.end_with?("\0") end diff --git a/lib/bundler/resolver/spec_group.rb b/lib/bundler/resolver/spec_group.rb index b44c19a73f..5cee444e5e 100644 --- a/lib/bundler/resolver/spec_group.rb +++ b/lib/bundler/resolver/spec_group.rb @@ -25,9 +25,8 @@ module Bundler def to_specs(force_ruby_platform) @specs.map do |s| - lazy_spec = LazySpecification.new(name, version, s.platform, source) + lazy_spec = LazySpecification.from_spec(s) lazy_spec.force_ruby_platform = force_ruby_platform - lazy_spec.dependencies.replace s.dependencies lazy_spec end end @@ -64,8 +63,6 @@ module Bundler end def metadata_dependencies(spec) - return [] if spec.is_a?(LazySpecification) - [ metadata_dependency("Ruby", spec.required_ruby_version), metadata_dependency("RubyGems", spec.required_rubygems_version), diff --git a/lib/bundler/retry.rb b/lib/bundler/retry.rb index 2415ade200..b95c42c361 100644 --- a/lib/bundler/retry.rb +++ b/lib/bundler/retry.rb @@ -56,7 +56,7 @@ module Bundler def keep_trying? return true if current_run.zero? return false if last_attempt? - return true if @failed + true if @failed end def last_attempt? diff --git a/lib/bundler/ruby_dsl.rb b/lib/bundler/ruby_dsl.rb index 3b3a0583a5..fb4b79c4df 100644 --- a/lib/bundler/ruby_dsl.rb +++ b/lib/bundler/ruby_dsl.rb @@ -3,16 +3,51 @@ module Bundler module RubyDsl def ruby(*ruby_version) - options = ruby_version.last.is_a?(Hash) ? ruby_version.pop : {} + options = ruby_version.pop if ruby_version.last.is_a?(Hash) ruby_version.flatten! - raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil? - raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil? - if options[:engine] == "ruby" && options[:engine_version] && - ruby_version != Array(options[:engine_version]) - raise GemfileEvalError, "ruby_version must match the :engine_version for MRI" + if options + patchlevel = options[:patchlevel] + engine = options[:engine] + engine_version = options[:engine_version] + + raise GemfileError, "Please define :engine_version" if engine && engine_version.nil? + raise GemfileError, "Please define :engine" if engine_version && engine.nil? + + if options[:file] + raise GemfileError, "Do not pass version argument when using :file option" unless ruby_version.empty? + ruby_version << normalize_ruby_file(options[:file]) + end + + if engine == "ruby" && engine_version && ruby_version != Array(engine_version) + raise GemfileEvalError, "ruby_version must match the :engine_version for MRI" + end + end + + @ruby_version = RubyVersion.new(ruby_version, patchlevel, engine, engine_version) + end + + # Support the various file formats found in .ruby-version files. + # + # 3.2.2 + # ruby-3.2.2 + # + # Also supports .tool-versions files for asdf. Lines not starting with "ruby" are ignored. + # + # ruby 2.5.1 # comment is ignored + # ruby 2.5.1# close comment and extra spaces doesn't confuse + # + # Intentionally does not support `3.2.1@gemset` since rvm recommends using .ruby-gemset instead + # + # Loads the file relative to the dirname of the Gemfile itself. + def normalize_ruby_file(filename) + file_content = Bundler.read_file(gemfile.dirname.join(filename)) + # match "ruby-3.2.2" or "ruby 3.2.2" capturing version string up to the first space or comment + if /^ruby(-|\s+)([^\s#]+)/.match(file_content) + $2 + else + file_content.strip end - @ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version]) end end end diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index b5396abb6e..7e9e072b83 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -23,7 +23,7 @@ module Bundler # specified must match the version. @versions = Array(versions).map do |v| - op, v = Gem::Requirement.parse(v) + op, v = Gem::Requirement.parse(normalize_version(v)) op == "=" ? v.to_s : "#{op} #{v}" end @@ -49,7 +49,7 @@ module Bundler (\d+\.\d+\.\d+(?:\.\S+)?) # ruby version (?:p(-?\d+))? # optional patchlevel (?:\s\((\S+)\s(.+)\))? # optional engine info - /xo.freeze + /xo # Returns a RubyVersion from the given string. # @param [String] the version string to match. @@ -112,6 +112,13 @@ module Bundler private + # Ruby's official preview version format uses a `-`: Example: 3.3.0-preview2 + # However, RubyGems recognizes preview version format with a `.`: Example: 3.3.0.preview2 + # Returns version string after replacing `-` with `.` + def normalize_version(version) + version.tr("-", ".") + end + def matches?(requirements, version) # Handles RUBY_PATCHLEVEL of -1 for instances like ruby-head return requirements == version if requirements.to_s == "-1" || version.to_s == "-1" diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index b96edd5e2d..18180a81a1 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true -require "pathname" - -require "rubygems/specification" +require "rubygems" unless defined?(Gem) # We can't let `Gem::Source` be autoloaded in the `Gem::Specification#source` # redefinition below, so we need to load it upfront. The reason is that if @@ -15,10 +13,6 @@ require "rubygems/specification" # `Gem::Source` from the redefined `Gem::Specification#source`. require "rubygems/source" -require_relative "match_metadata" -require_relative "force_platform" -require_relative "match_platform" - # Cherry-pick fixes to `Gem.ruby_version` to be useful for modern Bundler # versions and ignore patchlevels # (https://github.com/rubygems/rubygems/pull/5472, @@ -29,7 +23,19 @@ unless Gem.ruby_version.to_s == RUBY_VERSION || RUBY_PATCHLEVEL == -1 end module Gem + # Can be removed once RubyGems 3.5.11 support is dropped + unless Gem.respond_to?(:freebsd_platform?) + def self.freebsd_platform? + RbConfig::CONFIG["host_os"].to_s.include?("bsd") + end + end + + require "rubygems/specification" + class Specification + require_relative "match_metadata" + require_relative "match_platform" + include ::Bundler::MatchMetadata include ::Bundler::MatchPlatform @@ -46,7 +52,7 @@ module Gem def full_gem_path if source.respond_to?(:root) - Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap {|x| x.untaint if RUBY_VERSION < "2.7" } + File.expand_path(File.dirname(loaded_from), source.root) else rg_full_gem_path end @@ -76,25 +82,7 @@ module Gem end end - alias_method :rg_missing_extensions?, :missing_extensions? - def missing_extensions? - # When we use this methods with local gemspec, we don't handle - # build status of extension correctly. So We need to find extension - # files in require_paths. - # TODO: Gem::Specification couldn't access extension name from extconf.rb - # so we find them with heuristic way. We should improve it. - if source.respond_to?(:root) - return false if raw_require_paths.any? do |path| - ext_dir = File.join(full_gem_path, path) - File.exist?(File.join(ext_dir, "#{name}.#{RbConfig::CONFIG["DLEXT"]}")) || - !Dir.glob(File.join(ext_dir, name, "*.#{RbConfig::CONFIG["DLEXT"]}")).empty? - end - end - - rg_missing_extensions? - end - - remove_method :gem_dir if instance_methods(false).include?(:gem_dir) + remove_method :gem_dir def gem_dir full_gem_path end @@ -135,17 +123,6 @@ module Gem gemfile end - # Backfill missing YAML require when not defined. Fixed since 3.1.0.pre1. - module YamlBackfiller - def to_yaml(opts = {}) - Gem.load_yaml unless defined?(::YAML) - - super(opts) - end - end - - prepend YamlBackfiller - def nondevelopment_dependencies dependencies - development_dependencies end @@ -173,7 +150,23 @@ module Gem end end + module BetterPermissionError + def data + super + rescue Errno::EACCES + raise Bundler::PermissionError.new(loaded_from, :read) + end + end + + require "rubygems/stub_specification" + + class StubSpecification + prepend BetterPermissionError + end + class Dependency + require_relative "force_platform" + include ::Bundler::ForcePlatform attr_accessor :source, :groups @@ -206,37 +199,7 @@ 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) - return unless Gem::Requirement === other - - if _requirements_sorted? && other._requirements_sorted? - super - else - _with_sorted_requirements == other._with_sorted_requirements - end - end - - protected - - def _requirements_sorted? - return @_requirements_sorted if defined?(@_requirements_sorted) - strings = as_list - @_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 - + # Requirements using lambda operator differentiate trailing zeros since rubygems 3.2.6 if Gem::Requirement.new("~> 2.0").hash == Gem::Requirement.new("~> 2.0.0").hash class Requirement module CorrectHashForLambdaOperator @@ -338,7 +301,7 @@ module Gem end # On universal Rubies, resolve the "universal" arch to the real CPU arch, without changing the extension directory. - class Specification + class BasicSpecification if /^universal\.(?<arch>.*?)-/ =~ (CROSS_COMPILING || RUBY_PLATFORM) local_platform = Platform.local if local_platform.cpu == "universal" @@ -351,23 +314,35 @@ module Gem end def extensions_dir - Gem.default_ext_dir_for(base_dir) || - File.join(base_dir, "extensions", ORIGINAL_LOCAL_PLATFORM, - Gem.extension_api_version) + @extensions_dir ||= + Gem.default_ext_dir_for(base_dir) || File.join(base_dir, "extensions", ORIGINAL_LOCAL_PLATFORM, Gem.extension_api_version) end end end end - require "rubygems/util" + require "rubygems/name_tuple" - 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 + class NameTuple + # Versions of RubyGems before about 3.5.0 don't to_s the platform. + unless Gem::NameTuple.new("a", Gem::Version.new("1"), Gem::Platform.new("x86_64-linux")).platform.is_a?(String) + alias_method :initialize_with_platform, :initialize + + def initialize(name, version, platform=Gem::Platform::RUBY) + if Gem::Platform === platform + initialize_with_platform(name, version, platform.to_s) + else + initialize_with_platform(name, version, platform) + end + end end - def glob_files_in_dir(glob, base_path) - Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) } + def lock_name + if platform == Gem::Platform::RUBY + "#{name} (#{version})" + else + "#{name} (#{version}-#{platform})" + end end end end diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb index 38035a00ac..d563868cd2 100644 --- a/lib/bundler/rubygems_gem_installer.rb +++ b/lib/bundler/rubygems_gem_installer.rb @@ -20,7 +20,7 @@ module Bundler strict_rm_rf spec.extension_dir SharedHelpers.filesystem_access(gem_dir, :create) do - FileUtils.mkdir_p gem_dir, :mode => 0o755 + FileUtils.mkdir_p gem_dir, mode: 0o755 end extract_files @@ -45,6 +45,14 @@ module Bundler spec end + def pre_install_checks + super + rescue Gem::FilePermissionError + # Ignore permission checks in RubyGems. Instead, go on, and try to write + # for real. We properly handle permission errors when they happen. + nil + end + def generate_plugins return unless Gem::Installer.instance_methods(false).include?(:generate_plugins) @@ -60,10 +68,6 @@ module Bundler end end - def pre_install_checks - super && validate_bundler_checksum(options[:bundler_expected_checksum]) - end - def build_extensions extension_cache_path = options[:bundler_extension_cache_path] extension_dir = spec.extension_dir @@ -98,6 +102,10 @@ module Bundler end end + def gem_checksum + Checksum.from_gem_package(@package) + end + private def prepare_extension_build(extension_dir) @@ -108,64 +116,21 @@ module Bundler end def strict_rm_rf(dir) - Bundler.rm_rf dir - rescue StandardError => e - raise unless File.exist?(dir) + return unless File.exist?(dir) - raise DirectoryRemovalError.new(e, "Could not delete previous installation of `#{dir}`") - end - - def validate_bundler_checksum(checksum) - return true if Bundler.settings[:disable_checksum_validation] - return true unless checksum - return true unless source = @package.instance_variable_get(:@gem) - return true unless source.respond_to?(:with_read_io) - digest = source.with_read_io do |io| - digest = SharedHelpers.digest(:SHA256).new - digest << io.read(16_384) until io.eof? - io.rewind - send(checksum_type(checksum), digest) - end - unless digest == checksum - raise SecurityError, <<-MESSAGE - Bundler cannot continue installing #{spec.name} (#{spec.version}). - The checksum for the downloaded `#{spec.full_name}.gem` does not match \ - the checksum given by the server. This means the contents of the downloaded \ - gem is different from what was uploaded to the server, and could be a potential security issue. - - To resolve this issue: - 1. delete the downloaded gem located at: `#{spec.gem_dir}/#{spec.full_name}.gem` - 2. run `bundle install` - - 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 --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 \ - checksum for the downloaded gem was #{digest.inspect}.) - MESSAGE - end - true - end + parent = File.dirname(dir) + parent_st = File.stat(parent) - def checksum_type(checksum) - case checksum.length - when 64 then :hexdigest! - when 44 then :base64digest! - else raise InstallError, "The given checksum for #{spec.full_name} (#{checksum.inspect}) is not a valid SHA256 hexdigest nor base64digest" + if parent_st.world_writable? && !parent_st.sticky? + raise InsecureInstallPathError.new(parent) end - end - def hexdigest!(digest) - digest.hexdigest! - end + begin + FileUtils.remove_entry_secure(dir) + rescue StandardError => e + raise unless File.exist?(dir) - def base64digest!(digest) - if digest.respond_to?(:base64digest!) - digest.base64digest! - else - [digest.digest!].pack("m0") + raise DirectoryRemovalError.new(e, "Could not delete previous installation of `#{dir}`") end end end diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb index d8b7886af7..b841462263 100644 --- a/lib/bundler/rubygems_integration.rb +++ b/lib/bundler/rubygems_integration.rb @@ -4,17 +4,12 @@ require "rubygems" unless defined?(Gem) module Bundler class RubygemsIntegration - if defined?(Gem::Ext::Builder::CHDIR_MONITOR) - EXT_LOCK = Gem::Ext::Builder::CHDIR_MONITOR - else - require "monitor" + require "monitor" - EXT_LOCK = Monitor.new - end + EXT_LOCK = Monitor.new def initialize @replaced_methods = {} - backport_ext_builder_monitor end def version @@ -43,18 +38,6 @@ module Bundler Gem.loaded_specs[name] end - def add_to_load_path(paths) - return Gem.add_to_load_path(*paths) if Gem.respond_to?(:add_to_load_path) - - if insert_index = Gem.load_path_insert_index - # Gem directories must come after -I and ENV['RUBYLIB'] - $LOAD_PATH.insert(insert_index, *paths) - else - # We are probably testing in core, -I and RUBYLIB don't apply - $LOAD_PATH.unshift(*paths) - end - end - def mark_loaded(spec) if spec.respond_to?(:activated=) current = Gem.loaded_specs[spec.name] @@ -91,9 +74,9 @@ module Bundler def spec_matches_for_glob(spec, glob) return spec.matches_for_glob(glob) if spec.respond_to?(:matches_for_glob) - spec.load_paths.map do |lp| + spec.load_paths.flat_map do |lp| Dir["#{lp}/#{glob}#{suffix_pattern}"] - end.flatten(1) + end end def stub_set_spec(stub, spec) @@ -116,16 +99,6 @@ module Bundler Gem::Util.inflate(obj) end - def correct_for_windows_path(path) - if Gem::Util.respond_to?(:correct_for_windows_path) - Gem::Util.correct_for_windows_path(path) - elsif path[0].chr == "/" && path[1].chr =~ /[a-z]/i && path[2].chr == ":" - path[1..-1] - else - path - end - end - def gem_dir Gem.dir end @@ -161,7 +134,7 @@ module Bundler def spec_cache_dirs @spec_cache_dirs ||= begin dirs = gem_path.map {|dir| File.join(dir, "specifications") } - dirs << Gem.spec_cache_dir if Gem.respond_to?(:spec_cache_dir) # Not in RubyGems 2.0.3 or earlier + dirs << Gem.spec_cache_dir dirs.uniq.select {|dir| File.directory? dir } end end @@ -184,15 +157,15 @@ module Bundler end def load_plugins - Gem.load_plugins if Gem.respond_to?(:load_plugins) + Gem.load_plugins end - def load_plugin_files(files) - Gem.load_plugin_files(files) if Gem.respond_to?(:load_plugin_files) + def load_plugin_files(plugin_files) + Gem.load_plugin_files(plugin_files) end def load_env_plugins - Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins) + Gem.load_env_plugins end def ui=(obj) @@ -230,8 +203,7 @@ module Bundler if Gem.respond_to?(:discover_gems_on_require=) Gem.discover_gems_on_require = false else - kernel = (class << ::Kernel; self; end) - [kernel, ::Kernel].each do |k| + [::Kernel.singleton_class, ::Kernel].each do |k| if k.private_method_defined?(:gem_original_require) redefine_method(k, :require, k.instance_method(:gem_original_require)) end @@ -240,12 +212,9 @@ module Bundler end def replace_gem(specs, specs_by_name) - reverse_rubygems_kernel_mixin - executables = nil - kernel = (class << ::Kernel; self; end) - [kernel, ::Kernel].each do |kernel_class| + [::Kernel.singleton_class, ::Kernel].each do |kernel_class| redefine_method(kernel_class, :gem) do |dep, *reqs| if executables&.include?(File.basename(caller.first.split(":").first)) break @@ -358,6 +327,14 @@ module Bundler def replace_entrypoints(specs) specs_by_name = add_default_gems_to(specs) + reverse_rubygems_kernel_mixin + begin + # bundled_gems only provide with Ruby 3.3 or later + require "bundled_gems" + rescue LoadError + else + Gem::BUNDLED_GEMS.replace_require(specs) if Gem::BUNDLED_GEMS.respond_to?(:replace_require) + end replace_gem(specs, specs_by_name) stub_rubygems(specs) replace_bin_path(specs_by_name) @@ -447,30 +424,28 @@ module Bundler Gem::Specification.all = specs end - def fetch_specs(remote, name) + def fetch_specs(remote, name, fetcher) require "rubygems/remote_fetcher" path = remote.uri.to_s + "#{name}.#{Gem.marshal_version}.gz" - fetcher = gem_remote_fetcher - fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri string = fetcher.fetch_path(path) - Bundler.safe_load_marshal(string) + specs = Bundler.safe_load_marshal(string) + raise MarshalError, "Specs #{name} from #{remote} is expected to be an Array but was unexpected class #{specs.class}" unless specs.is_a?(Array) + specs rescue Gem::RemoteFetcher::FetchError # it's okay for prerelease to fail raise unless name == "prerelease_specs" end - def fetch_all_remote_specs(remote) - specs = fetch_specs(remote, "specs") - pres = fetch_specs(remote, "prerelease_specs") || [] + def fetch_all_remote_specs(remote, gem_remote_fetcher) + specs = fetch_specs(remote, "specs", gem_remote_fetcher) + pres = fetch_specs(remote, "prerelease_specs", gem_remote_fetcher) || [] specs.concat(pres) end - def download_gem(spec, uri, cache_dir) + def download_gem(spec, uri, cache_dir, fetcher) require "rubygems/remote_fetcher" uri = Bundler.settings.mirror_for(uri) - fetcher = gem_remote_fetcher - fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri Bundler::Retry.new("download gem from #{uri}").attempts do gem_file_name = spec.file_name local_gem_path = File.join cache_dir, gem_file_name @@ -478,7 +453,6 @@ module Bundler begin remote_gem_path = uri + "gems/#{gem_file_name}" - remote_gem_path = remote_gem_path.to_s if provides?("< 3.2.0.rc.1") SharedHelpers.filesystem_access(local_gem_path) do fetcher.cache_update_path remote_gem_path, local_gem_path @@ -497,12 +471,6 @@ module Bundler raise Bundler::HTTPError, "Could not download gem from #{uri} due to underlying error <#{e.message}>" end - def gem_remote_fetcher - require "rubygems/remote_fetcher" - proxy = Gem.configuration[:http_proxy] - Gem::RemoteFetcher.new(proxy) - end - def build(spec, skip_validation = false) require "rubygems/package" Gem::Package.build(spec, skip_validation) @@ -513,27 +481,22 @@ module Bundler end def all_specs + SharedHelpers.major_deprecation 2, "Bundler.rubygems.all_specs has been removed in favor of Bundler.rubygems.installed_specs" + Gem::Specification.stubs.map do |stub| StubSpecification.from_stub(stub) end end - def backport_ext_builder_monitor - # So we can avoid requiring "rubygems/ext" in its entirety - Gem.module_eval <<-RUBY, __FILE__, __LINE__ + 1 - module Ext - end - RUBY - - require "rubygems/ext/builder" - - Gem::Ext::Builder.class_eval do - unless const_defined?(:CHDIR_MONITOR) - const_set(:CHDIR_MONITOR, EXT_LOCK) - end + def installed_specs + Gem::Specification.stubs.reject(&:default_gem?).map do |stub| + StubSpecification.from_stub(stub) + end + end - remove_const(:CHDIR_MUTEX) if const_defined?(:CHDIR_MUTEX) - const_set(:CHDIR_MUTEX, const_get(:CHDIR_MONITOR)) + def default_specs + Gem::Specification.default_stubs.map do |stub| + StubSpecification.from_stub(stub) end end @@ -545,14 +508,8 @@ module Bundler Gem::Specification.stubs_for(name).map(&:to_spec) end - if Gem::Specification.respond_to?(:default_stubs) - def default_stubs - Gem::Specification.default_stubs("*.gemspec") - end - else - def default_stubs - Gem::Specification.send(:default_stubs, "*.gemspec") - end + def default_stubs + Gem::Specification.default_stubs("*.gemspec") end end diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index bd38353d3c..54aa30ce0b 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -28,11 +28,11 @@ module Bundler spec.load_paths.reject {|path| $LOAD_PATH.include?(path) } end.reverse.flatten - Bundler.rubygems.add_to_load_path(load_paths) + Gem.add_to_load_path(*load_paths) setup_manpath - lock(:preserve_unknown_sections => true) + lock(preserve_unknown_sections: true) self end @@ -41,12 +41,17 @@ module Bundler groups.map!(&:to_sym) groups = [:default] if groups.empty? - @definition.dependencies.each do |dep| - # Skip the dependency if it is not in any of the requested groups, or - # not for the current platform, or doesn't match the gem constraints. - next unless (dep.groups & groups).any? && dep.should_include? + dependencies = @definition.dependencies.select do |dep| + # Select the dependency if it is in any of the requested groups, and + # for the current platform, and matches the gem constraints. + (dep.groups & groups).any? && dep.should_include? + end + + Plugin.hook(Plugin::Events::GEM_BEFORE_REQUIRE_ALL, dependencies) + dependencies.each do |dep| required_file = nil + Plugin.hook(Plugin::Events::GEM_BEFORE_REQUIRE, dep) begin # Loop through all the specified autorequires for the @@ -76,7 +81,13 @@ module Bundler end end end + + Plugin.hook(Plugin::Events::GEM_AFTER_REQUIRE, dep) end + + Plugin.hook(Plugin::Events::GEM_AFTER_REQUIRE_ALL, dependencies) + + dependencies end def self.definition_method(meth) @@ -94,8 +105,8 @@ module Bundler definition_method :requires def lock(opts = {}) - return if @definition.nothing_changed? && !@definition.unlocking? - @definition.lock(Bundler.default_lockfile, opts[:preserve_unknown_sections]) + return if @definition.no_resolve_needed? + @definition.lock(opts[:preserve_unknown_sections]) end alias_method :gems, :specs diff --git a/lib/bundler/self_manager.rb b/lib/bundler/self_manager.rb index 827f3f9222..5accda4bcb 100644 --- a/lib/bundler/self_manager.rb +++ b/lib/bundler/self_manager.rb @@ -9,17 +9,23 @@ module Bundler def restart_with_locked_bundler_if_needed return unless needs_switching? && installed? - restart_with(lockfile_version) + restart_with(restart_version) end def install_locked_bundler_and_restart_with_it_if_needed return unless needs_switching? - Bundler.ui.info \ - "Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \ - "Installing Bundler #{lockfile_version} and restarting using that version." + if restart_version == lockfile_version + Bundler.ui.info \ + "Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \ + "Installing Bundler #{lockfile_version} and restarting using that version." + else + Bundler.ui.info \ + "Bundler #{current_version} is running, but your configuration was #{restart_version}. " \ + "Installing Bundler #{restart_version} and restarting using that version." + end - install_and_restart_with(lockfile_version) + install_and_restart_with(restart_version) end def update_bundler_and_restart_with_it_if_needed(target) @@ -79,7 +85,8 @@ module Bundler autoswitching_applies? && released?(lockfile_version) && !running?(lockfile_version) && - !updating? + !updating? && + Bundler.settings[:version] != "system" end def autoswitching_applies? @@ -114,7 +121,7 @@ module Bundler source = Bundler::Source::Rubygems.new("remotes" => "https://rubygems.org") source.remote! source.add_dependency_names("bundler") - source.specs + source.specs.select(&:matches_current_metadata?) end end @@ -151,7 +158,7 @@ module Bundler def installed? Bundler.configure - Bundler.rubygems.find_bundler(lockfile_version.to_s) + Bundler.rubygems.find_bundler(restart_version.to_s) end def current_version @@ -163,6 +170,17 @@ module Bundler parsed_version = Bundler::LockfileParser.bundled_with @lockfile_version = parsed_version ? Gem::Version.new(parsed_version) : nil + rescue ArgumentError + @lockfile_version = nil + end + + def restart_version + return @restart_version if defined?(@restart_version) + # BUNDLE_VERSION=x.y.z + @restart_version = Gem::Version.new(Bundler.settings[:version]) + rescue ArgumentError + # BUNDLE_VERSION=lockfile + @restart_version = lockfile_version end end end diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 88dd829d66..878747a53b 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -7,7 +7,6 @@ module Bundler autoload :Validator, File.expand_path("settings/validator", __dir__) BOOL_KEYS = %w[ - allow_deployment_source_credential_changes allow_offline_install auto_clean_without_path auto_install @@ -43,10 +42,23 @@ module Bundler setup_makes_kernel_gem_public silence_deprecations silence_root_warning - suppress_install_using_messages update_requires_all_flag ].freeze + REMEMBERED_KEYS = %w[ + bin + cache_all + clean + deployment + frozen + no_prune + path + shebang + path.system + without + with + ].freeze + NUMBER_KEYS = %w[ jobs redirect @@ -75,6 +87,7 @@ module Bundler shebang system_bindir trust-policy + version ].freeze DEFAULT_CONFIG = { @@ -84,25 +97,39 @@ module Bundler "BUNDLE_REDIRECT" => 5, "BUNDLE_RETRY" => 3, "BUNDLE_TIMEOUT" => 10, + "BUNDLE_VERSION" => "lockfile", }.freeze def initialize(root = nil) @root = root @local_config = load_config(local_config_file) - @env_config = ENV.to_h.select {|key, _value| key =~ /\ABUNDLE_.+/ } + @local_root = root || Pathname.new(".bundle").expand_path + + @env_config = ENV.to_h + @env_config.select! {|key, _value| key.start_with?("BUNDLE_") } + @env_config.delete("BUNDLE_") + @global_config = load_config(global_config_file) @temporary = {} + + @key_cache = {} end def [](name) key = key_for(name) - value = configs.values.map {|config| config[key] }.compact.first + + value = nil + configs.each do |_, config| + value = config[key] + next if value.nil? + break + end converted_value(value, name) end def set_command_option(key, value) - if Bundler.feature_flag.forget_cli_options? + if !is_remembered(key) || Bundler.feature_flag.forget_cli_options? temporary(key => value) value else @@ -116,7 +143,7 @@ module Bundler end def set_local(key, value) - local_config_file || raise(GemfileNotFound, "Could not locate Gemfile") + local_config_file = @local_root.join("config") set_key(key, value, @local_config, local_config_file) end @@ -139,17 +166,22 @@ module Bundler end def all - keys = @temporary.keys | @global_config.keys | @local_config.keys | @env_config.keys + keys = @temporary.keys.union(@global_config.keys, @local_config.keys, @env_config.keys) - keys.map do |key| - key.sub(/^BUNDLE_/, "").gsub(/___/, "-").gsub(/__/, ".").downcase - end.sort + keys.map! do |key| + key = key.delete_prefix("BUNDLE_") + key.gsub!("___", "-") + key.gsub!("__", ".") + key.downcase! + key + end.sort! + keys end def local_overrides repos = {} all.each do |k| - repos[$'] = self[k] if k =~ /^local\./ + repos[k.delete_prefix("local.")] = self[k] if k.start_with?("local.") end repos end @@ -157,7 +189,7 @@ module Bundler def mirror_for(uri) if uri.is_a?(String) require_relative "vendored_uri" - uri = Bundler::URI(uri) + uri = Gem::URI(uri) end gem_mirrors.for(uri.to_s).uri @@ -219,7 +251,6 @@ module Bundler def path configs.each do |_level, settings| path = value_for("path", settings) - path = "vendor/bundle" if value_for("deployment", settings) && path.nil? 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? @@ -227,7 +258,9 @@ module Bundler return Path.new(path, system_path) end - Path.new(nil, false) + path = "vendor/bundle" if self[:deployment] + + Path.new(path, false) end Path = Struct.new(:explicit_path, :system_path) do @@ -295,18 +328,18 @@ module Bundler end def key_for(key) - self.class.key_for(key) + @key_cache[key] ||= self.class.key_for(key) end private def configs - { - :temporary => @temporary, - :local => @local_config, - :env => @env_config, - :global => @global_config, - :default => DEFAULT_CONFIG, + @configs ||= { + temporary: @temporary, + local: @local_config, + env: @env_config, + global: @global_config, + default: DEFAULT_CONFIG, } end @@ -327,16 +360,20 @@ module Bundler end def is_bool(name) - BOOL_KEYS.include?(name.to_s) || BOOL_KEYS.include?(parent_setting_for(name.to_s)) + name = self.class.key_to_s(name) + BOOL_KEYS.include?(name) || BOOL_KEYS.include?(parent_setting_for(name)) end def is_string(name) - STRING_KEYS.include?(name.to_s) || name.to_s.start_with?("local.") || name.to_s.start_with?("mirror.") || name.to_s.start_with?("build.") + name = self.class.key_to_s(name) + STRING_KEYS.include?(name) || name.start_with?("local.") || name.start_with?("mirror.") || name.start_with?("build.") end def to_bool(value) case value - when nil, /\A(false|f|no|n|0|)\z/i, false + when String + value.match?(/\A(false|f|no|n|0|)\z/i) ? false : true + when nil, false false else true @@ -344,11 +381,15 @@ module Bundler end def is_num(key) - NUMBER_KEYS.include?(key.to_s) + NUMBER_KEYS.include?(self.class.key_to_s(key)) end def is_array(key) - ARRAY_KEYS.include?(key.to_s) + ARRAY_KEYS.include?(self.class.key_to_s(key)) + end + + def is_remembered(key) + REMEMBERED_KEYS.include?(self.class.key_to_s(key)) end def is_credential(key) @@ -371,7 +412,7 @@ module Bundler end def set_key(raw_key, value, hash, file) - raw_key = raw_key.to_s + raw_key = self.class.key_to_s(raw_key) value = array_to_s(value) if is_array(raw_key) key = key_for(raw_key) @@ -391,6 +432,8 @@ module Bundler end def converted_value(value, key) + key = self.class.key_to_s(key) + if is_array(key) to_array(value) elsif value.nil? @@ -449,17 +492,23 @@ module Bundler valid_file = file.exist? && !file.size.zero? return {} unless valid_file serializer_class.load(file.read).inject({}) do |config, (k, v)| - new_k = k + k = k.dup + k << "/" if /https?:/i.match?(k) && !k.end_with?("/", "__#{FALLBACK_TIMEOUT_URI_OPTION.upcase}") + k.gsub!(".", "__") + + unless k.start_with?("#") + if k.include?("-") + Bundler.ui.warn "Your #{file} config includes `#{k}`, which contains the dash character (`-`).\n" \ + "This is deprecated, because configuration through `ENV` should be possible, but `ENV` keys cannot include dashes.\n" \ + "Please edit #{file} and replace any dashes in configuration keys with a triple underscore (`___`)." - if k.include?("-") - Bundler.ui.warn "Your #{file} config includes `#{k}`, which contains the dash character (`-`).\n" \ - "This is deprecated, because configuration through `ENV` should be possible, but `ENV` keys cannot include dashes.\n" \ - "Please edit #{file} and replace any dashes in configuration keys with a triple underscore (`___`)." + # string hash keys are frozen + k = k.gsub("-", "___") + end - new_k = k.gsub("-", "___") + config[k] = v end - config[new_k] = v config end end @@ -474,23 +523,25 @@ module Bundler YAMLSerializer end - PER_URI_OPTIONS = %w[ - fallback_timeout - ].freeze + FALLBACK_TIMEOUT_URI_OPTION = "fallback_timeout" NORMALIZE_URI_OPTIONS_PATTERN = / \A (\w+\.)? # optional prefix key (https?.*?) # URI - (\.#{Regexp.union(PER_URI_OPTIONS)})? # optional suffix key + (\.#{FALLBACK_TIMEOUT_URI_OPTION})? # optional suffix key \z - /ix.freeze + /ix def self.key_for(key) - key = normalize_uri(key).to_s if key.is_a?(String) && key.start_with?("http", "mirror.http") - key = key.to_s.gsub(".", "__").gsub("-", "___").upcase - "BUNDLE_#{key}" + key = key_to_s(key) + key = normalize_uri(key) if key.start_with?("http", "mirror.http") + key = key.gsub(".", "__") + key.gsub!("-", "___") + key.upcase! + + key.gsub(/\A([ #]*)/, '\1BUNDLE_') end # TODO: duplicates Rubygems#normalize_uri @@ -504,11 +555,40 @@ module Bundler end uri = URINormalizer.normalize_suffix(uri) require_relative "vendored_uri" - uri = Bundler::URI(uri) + uri = Gem::URI(uri) unless uri.absolute? raise ArgumentError, format("Gem sources must be absolute. You provided '%s'.", uri) end "#{prefix}#{uri}#{suffix}" end + + # This is a hot method, so avoid respond_to? checks on every invocation + if :read.respond_to?(:name) + def self.key_to_s(key) + case key + when String + key + when Symbol + key.name + when Gem::URI::HTTP + key.to_s + else + raise ArgumentError, "Invalid key: #{key.inspect}" + end + end + else + def self.key_to_s(key) + case key + when String + key + when Symbol + key.to_s + when Gem::URI::HTTP + key.to_s + else + raise ArgumentError, "Invalid key: #{key.inspect}" + end + end + end end end diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb index 801fd5312a..6010d66742 100644 --- a/lib/bundler/setup.rb +++ b/lib/bundler/setup.rb @@ -5,6 +5,9 @@ require_relative "shared_helpers" if Bundler::SharedHelpers.in_bundle? require_relative "../bundler" + # try to auto_install first before we get to the `Bundler.ui.silence`, so user knows what is happening + Bundler.auto_install + if STDOUT.tty? || ENV["BUNDLER_FORCE_TTY"] begin Bundler.ui.silence { Bundler.setup } @@ -12,7 +15,10 @@ if Bundler::SharedHelpers.in_bundle? Bundler.ui.error e.message Bundler.ui.warn e.backtrace.join("\n") if ENV["DEBUG"] if e.is_a?(Bundler::GemNotFound) - suggested_cmd = "bundle install" + default_bundle = Gem.bin_path("bundler", "bundle") + current_bundle = Bundler::SharedHelpers.bundle_bin_path + suggested_bundle = default_bundle == current_bundle ? "bundle" : current_bundle + suggested_cmd = "#{suggested_bundle} install" original_gemfile = Bundler.original_env["BUNDLE_GEMFILE"] suggested_cmd += " --gemfile #{original_gemfile}" if original_gemfile Bundler.ui.warn "Run `#{suggested_cmd}` to install missing gems." diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index d1d4e1d07a..e55632b89f 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -1,25 +1,27 @@ # frozen_string_literal: true -require "pathname" -require "rbconfig" - require_relative "version" -require_relative "constants" require_relative "rubygems_integration" require_relative "current_ruby" +autoload :Pathname, "pathname" + module Bundler + autoload :WINDOWS, File.expand_path("constants", __dir__) + autoload :FREEBSD, File.expand_path("constants", __dir__) + autoload :NULL, File.expand_path("constants", __dir__) + module SharedHelpers def root gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile - Pathname.new(gemfile).tap {|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path.parent + Pathname.new(gemfile).expand_path.parent end def default_gemfile gemfile = find_gemfile raise GemfileNotFound, "Could not locate Gemfile" unless gemfile - Pathname.new(gemfile).tap {|x| x.untaint if RUBY_VERSION < "2.7" }.expand_path + Pathname.new(gemfile).expand_path end def default_lockfile @@ -28,7 +30,7 @@ module Bundler case gemfile.basename.to_s when "gems.rb" then Pathname.new(gemfile.sub(/.rb$/, ".locked")) else Pathname.new("#{gemfile}.lock") - end.tap {|x| x.untaint if RUBY_VERSION < "2.7" } + end end def default_bundle_dir @@ -100,7 +102,7 @@ module Bundler # # @see {Bundler::PermissionError} def filesystem_access(path, action = :write, &block) - yield(path.dup.tap {|x| x.untaint if RUBY_VERSION < "2.7" }) + yield(path.dup) rescue Errno::EACCES raise PermissionError.new(path, action) rescue Errno::EAGAIN @@ -117,16 +119,18 @@ module Bundler raise GenericSystemCallError.new(e, "There was an error accessing `#{path}`.") end - def major_deprecation(major_version, message, print_caller_location: false) + def major_deprecation(major_version, message, removed_message: nil, 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})" + suffix = " (called at #{caller_location.path}:#{caller_location.lineno})" + message += suffix + removed_message += suffix if removed_message end bundler_major_version = Bundler.bundler_major_version if bundler_major_version > major_version require_relative "errors" - raise DeprecatedError, "[REMOVED] #{message}" + raise DeprecatedError, "[REMOVED] #{removed_message || message}" end return unless bundler_major_version >= major_version && prints_major_deprecations? @@ -193,10 +197,40 @@ module Bundler Digest(name) end + def checksum_for_file(path, digest) + return unless path.file? + # This must use File.read instead of Digest.file().hexdigest + # because we need to preserve \n line endings on windows when calculating + # the checksum + SharedHelpers.filesystem_access(path, :read) do + File.open(path, "rb") do |f| + digest = SharedHelpers.digest(digest).new + buf = String.new(capacity: 16_384, encoding: Encoding::BINARY) + digest << buf while f.read(16_384, buf) + digest.hexdigest + end + end + end + def write_to_gemfile(gemfile_path, contents) filesystem_access(gemfile_path) {|g| File.open(g, "w") {|file| file.puts contents } } end + def relative_gemfile_path + relative_path_to(Bundler.default_gemfile) + end + + def relative_lockfile_path + relative_path_to(Bundler.default_lockfile) + end + + def relative_path_to(destination, from: pwd) + Pathname.new(destination).relative_path_from(from).to_s + rescue ArgumentError + # on Windows, if source and destination are on different drivers, there's no relative path from one to the other + destination + end + private def validate_bundle_path @@ -235,7 +269,7 @@ module Bundler def search_up(*names) previous = nil - current = File.expand_path(SharedHelpers.pwd).tap {|x| x.untaint if RUBY_VERSION < "2.7" } + current = File.expand_path(SharedHelpers.pwd) until !File.directory?(current) || current == previous if ENV["BUNDLER_SPEC_RUN"] @@ -272,6 +306,13 @@ module Bundler public :set_env def set_bundle_variables + Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", bundle_bin_path + Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile.to_s + Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION + Bundler::SharedHelpers.set_env "BUNDLER_SETUP", File.expand_path("setup", __dir__) + end + + def bundle_bin_path # bundler exe & lib folders have same root folder, typical gem installation exe_file = File.expand_path("../../exe/bundle", __dir__) @@ -281,11 +322,9 @@ module Bundler # bundler is a default gem, exe path is separate exe_file = Bundler.rubygems.bin_path("bundler", "bundle", VERSION) unless File.exist?(exe_file) - Bundler::SharedHelpers.set_env "BUNDLE_BIN_PATH", exe_file - Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", find_gemfile.to_s - Bundler::SharedHelpers.set_env "BUNDLER_VERSION", Bundler::VERSION - Bundler::SharedHelpers.set_env "BUNDLER_SETUP", File.expand_path("setup", __dir__) unless RUBY_VERSION < "2.7" + exe_file end + public :bundle_bin_path def set_path validate_bundle_path @@ -297,7 +336,7 @@ module Bundler def set_rubyopt rubyopt = [ENV["RUBYOPT"]].compact setup_require = "-r#{File.expand_path("setup", __dir__)}" - return if !rubyopt.empty? && rubyopt.first =~ /#{setup_require}/ + return if !rubyopt.empty? && rubyopt.first.include?(setup_require) rubyopt.unshift setup_require Bundler::SharedHelpers.set_env "RUBYOPT", rubyopt.join(" ") end diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 69804a2e63..115dbd1378 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -11,6 +11,8 @@ module Bundler attr_accessor :dependency_names + attr_reader :checksum_store + def unmet_deps specs.unmet_dependency_names end @@ -100,7 +102,7 @@ module Bundler end def print_using_message(message) - if !message.include?("(was ") && Bundler.feature_flag.suppress_install_using_messages? + if !message.include?("(was ") Bundler.ui.debug message else Bundler.ui.info message diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 42897813b4..198e335bb6 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -11,6 +11,7 @@ module Bundler def initialize(options) @options = options + @checksum_store = Checksum::Store.new @glob = options["glob"] || DEFAULT_GLOB @allow_cached = false @@ -19,7 +20,7 @@ module Bundler # Stringify options that could be set as symbols %w[ref branch tag revision].each {|k| options[k] = options[k].to_s if options[k] } - @uri = URINormalizer.normalize_suffix(options["uri"] || "", :trailing_slash => false) + @uri = URINormalizer.normalize_suffix(options["uri"] || "", trailing_slash: false) @safe_uri = URICredentialsFilter.credential_filtered_uri(@uri) @branch = options["branch"] @ref = options["ref"] || options["branch"] || options["tag"] @@ -46,6 +47,14 @@ module Bundler out << " specs:\n" end + def to_gemfile + specifiers = %w[ref branch tag submodules glob].map do |opt| + "#{opt}: #{options[opt]}" if options[opt] + end + + uri_with_specifiers(specifiers) + end + def hash [self.class, uri, ref, branch, name, version, glob, submodules].hash end @@ -59,28 +68,32 @@ module Bundler alias_method :==, :eql? + def include?(other) + other.is_a?(Git) && uri == other.uri && + name == other.name && + glob == other.glob && + submodules == other.submodules + end + def to_s begin - at = if local? - path - elsif user_ref = options["ref"] - if /\A[a-z0-9]{4,}\z/i.match?(ref) - shortref_for_display(user_ref) - else - user_ref - end - elsif ref - ref - else - current_branch - end + at = humanized_ref || current_branch rev = "at #{at}@#{shortref_for_display(revision)}" rescue GitError "" end - specifiers = [rev, glob_for_display].compact + uri_with_specifiers([rev, glob_for_display]) + end + + def identifier + uri_with_specifiers([humanized_ref, cached_revision, glob_for_display]) + end + + def uri_with_specifiers(specifiers) + specifiers.compact! + suffix = if specifiers.any? " (#{specifiers.join(", ")})" @@ -185,7 +198,7 @@ module Bundler @copied = true end - generate_bin_options = { :disable_extensions => !Bundler.rubygems.spec_missing_extensions?(spec), :build_args => options[:build_args] } + generate_bin_options = { disable_extensions: !Bundler.rubygems.spec_missing_extensions?(spec), build_args: options[:build_args] } generate_bin(spec, generate_bin_options) requires_checkout? ? spec.post_install_message : nil @@ -243,6 +256,20 @@ module Bundler private + def humanized_ref + if local? + path + elsif user_ref = options["ref"] + if /\A[a-z0-9]{4,}\z/i.match?(ref) + shortref_for_display(user_ref) + else + user_ref + end + elsif ref + ref + end + end + def serialize_gemspecs_in(destination) destination = destination.expand_path(Bundler.root) if destination.relative? Dir["#{destination}/#{@glob}"].each do |spec_path| @@ -299,7 +326,7 @@ module Bundler if %r{^\w+://(\w+@)?}.match?(uri) # Downcase the domain component of the URI # and strip off a trailing slash, if one is present - input = Bundler::URI.parse(uri).normalize.to_s.sub(%r{/$}, "") + input = Gem::URI.parse(uri).normalize.to_s.sub(%r{/$}, "") else # If there is no URI scheme, assume it is an ssh/git URI input = uri @@ -333,7 +360,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.tap {|x| x.untaint if RUBY_VERSION < "2.7" } + stub.full_gem_path = Pathname.new(file).dirname.expand_path(root).to_s StubSpecification.from_stub(stub) end diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index 926c9b8ead..2fc9c6535f 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -43,6 +43,13 @@ module Bundler end end + class AmbiguousGitReference < GitError + def initialize(options) + msg = "Specification of branch or ref with tag is ambiguous. You specified #{options.inspect}" + super msg + end + end + # The GitProxy is responsible to interact with git repositories. # All actions required by the Git source is encapsulated in this # object. @@ -53,10 +60,15 @@ module Bundler def initialize(path, uri, options = {}, revision = nil, git = nil) @path = path @uri = uri - @branch = options["branch"] @tag = options["tag"] + @branch = options["branch"] @ref = options["ref"] - @explicit_ref = branch || tag || ref + if @tag + raise AmbiguousGitReference.new(options) if @branch || @ref + @explicit_ref = @tag + else + @explicit_ref = @ref || @branch + end @revision = revision @git = git @commit_ref = nil @@ -67,15 +79,15 @@ module Bundler end def current_branch - @current_branch ||= allowed_with_path do - git("rev-parse", "--abbrev-ref", "HEAD", :dir => path).strip + @current_branch ||= with_path do + git_local("rev-parse", "--abbrev-ref", "HEAD", dir: path).strip end end def contains?(commit) allowed_with_path do - result, status = git_null("branch", "--contains", commit, :dir => path) - status.success? && result =~ /^\* (.*)$/ + result, status = git_null("branch", "--contains", commit, dir: path) + status.success? && result.match?(/^\* (.*)$/) end end @@ -84,7 +96,7 @@ module Bundler end def full_version - @full_version ||= git("--version").sub(/git version\s*/, "").strip + @full_version ||= git_local("--version").sub(/git version\s*/, "").strip end def checkout @@ -118,15 +130,20 @@ module Bundler end end - git "fetch", "--force", "--quiet", *extra_fetch_args, :dir => destination if @commit_ref + ref = @commit_ref || (locked_to_full_sha? && @revision) + if ref + git "config", "uploadpack.allowAnySHA1InWant", "true", dir: path.to_s if @commit_ref.nil? && needs_allow_any_sha1_in_want? - git "reset", "--hard", @revision, :dir => destination + git "fetch", "--force", "--quiet", *extra_fetch_args(ref), dir: destination + end + + git "reset", "--hard", @revision, dir: destination if submodules - git_retry "submodule", "update", "--init", "--recursive", :dir => destination + git_retry "submodule", "update", "--init", "--recursive", dir: destination elsif Gem::Version.create(version) >= Gem::Version.create("2.9.0") inner_command = "git -C $toplevel submodule deinit --force $sm_path" - git_retry "submodule", "foreach", "--quiet", inner_command, :dir => destination + git_retry "submodule", "foreach", "--quiet", inner_command, dir: destination end end @@ -165,6 +182,14 @@ module Bundler if err.include?("Could not find remote branch") raise MissingGitRevisionError.new(command_with_no_credentials, nil, explicit_ref, credential_filtered_uri) else + idx = command.index("--depth") + if idx + command.delete_at(idx) + command.delete_at(idx) + command_with_no_credentials = check_allowed(command) + + err += "Retrying without --depth argument." + end raise GitCommandError.new(command_with_no_credentials, path, err) end end @@ -235,38 +260,46 @@ module Bundler end def pinned_to_full_sha? - ref =~ /\A\h{40}\z/ + full_sha_revision?(ref) + end + + def locked_to_full_sha? + full_sha_revision?(@revision) + end + + def full_sha_revision?(ref) + ref&.match?(/\A\h{40}\z/) end def git_null(*command, dir: nil) check_allowed(command) - capture(command, dir, :ignore_err => true) + capture(command, dir, ignore_err: true) end def git_retry(*command, dir: nil) command_with_no_credentials = check_allowed(command) Bundler::Retry.new("`#{command_with_no_credentials}` at #{dir || SharedHelpers.pwd}").attempts do - git(*command, :dir => dir) + git(*command, dir: dir) end end def git(*command, dir: nil) - command_with_no_credentials = check_allowed(command) - - out, err, status = capture(command, dir) - - raise GitCommandError.new(command_with_no_credentials, dir || SharedHelpers.pwd, err) unless status.success? - - Bundler.ui.warn err unless err.empty? + run_command(*command, dir: dir) do |unredacted_command| + check_allowed(unredacted_command) + end + end - out + def git_local(*command, dir: nil) + run_command(*command, dir: dir) do |unredacted_command| + redact_and_check_presence(unredacted_command) + end end def has_revision_cached? return unless @revision && path.exist? - git("cat-file", "-e", @revision, :dir => path) + git("cat-file", "-e", @revision, dir: path) true rescue GitError false @@ -289,13 +322,13 @@ module Bundler end def verify(reference) - git("rev-parse", "--verify", reference, :dir => path).strip + git("rev-parse", "--verify", reference, dir: path).strip end # Adds credentials to the URI def configured_uri if /https?:/.match?(uri) - remote = Bundler::URI(uri) + remote = Gem::URI(uri) config_auth = Bundler.settings[remote.to_s] || Bundler.settings[remote.host] remote.userinfo ||= config_auth remote.to_s @@ -330,12 +363,30 @@ module Bundler end def check_allowed(command) - require "shellwords" - command_with_no_credentials = URICredentialsFilter.credential_filtered_string("git #{command.shelljoin}", uri) + command_with_no_credentials = redact_and_check_presence(command) raise GitNotAllowedError.new(command_with_no_credentials) unless allow? command_with_no_credentials end + def redact_and_check_presence(command) + raise GitNotInstalledError.new unless Bundler.git_present? + + require "shellwords" + URICredentialsFilter.credential_filtered_string("git #{command.shelljoin}", uri) + end + + def run_command(*command, dir: nil) + command_with_no_credentials = yield(command) + + out, err, status = capture(command, dir) + + raise GitCommandError.new(command_with_no_credentials, dir || SharedHelpers.pwd, err) unless status.success? + + Bundler.ui.warn err unless err.empty? + + out + end + def capture(cmd, dir, ignore_err: false) SharedHelpers.with_clean_git_env do require "open3" @@ -355,7 +406,7 @@ module Bundler if Bundler.feature_flag.bundler_3_mode? || supports_minus_c? ["git", "-C", dir.to_s, *cmd] else - ["git", *cmd, { :chdir => dir.to_s }] + ["git", *cmd, { chdir: dir.to_s }] end end @@ -381,9 +432,9 @@ module Bundler ["--depth", depth.to_s] end - def extra_fetch_args + def extra_fetch_args(ref) extra_args = [path.to_s, *depth_args] - extra_args.push(@commit_ref) + extra_args.push(ref) extra_args end @@ -395,6 +446,10 @@ module Bundler @supports_minus_c ||= Gem::Version.new(version) >= Gem::Version.new("1.8.5") end + def needs_allow_any_sha1_in_want? + @needs_allow_any_sha1_in_want ||= Gem::Version.new(version) <= Gem::Version.new("2.13.7") + end + def supports_fetching_unreachable_refs? @supports_fetching_unreachable_refs ||= Gem::Version.new(version) >= Gem::Version.new("2.5.0") end diff --git a/lib/bundler/source/metadata.rb b/lib/bundler/source/metadata.rb index 593da6d1a7..6b05e17727 100644 --- a/lib/bundler/source/metadata.rb +++ b/lib/bundler/source/metadata.rb @@ -5,27 +5,29 @@ module Bundler class Metadata < Source def specs @specs ||= Index.build do |idx| - idx << Gem::Specification.new("Ruby\0", Gem.ruby_version) + idx << Gem::Specification.new("Ruby\0", Bundler::RubyVersion.system.gem_version) idx << Gem::Specification.new("RubyGems\0", Gem::VERSION) do |s| s.required_rubygems_version = Gem::Requirement.default end - idx << Gem::Specification.new do |s| - s.name = "bundler" - s.version = VERSION - s.license = "MIT" - s.platform = Gem::Platform::RUBY - s.authors = ["bundler team"] - s.bindir = "exe" - s.homepage = "https://bundler.io" - s.summary = "The best way to manage your application's dependencies" - s.executables = %w[bundle] - # can't point to the actual gemspec or else the require paths will be wrong - s.loaded_from = __dir__ - end + if local_spec = Gem.loaded_specs["bundler"] + raise CorruptBundlerInstallError.new(local_spec) if local_spec.version.to_s != Bundler::VERSION - if local_spec = Bundler.rubygems.find_bundler(VERSION) idx << local_spec + else + idx << Gem::Specification.new do |s| + s.name = "bundler" + s.version = VERSION + s.license = "MIT" + s.platform = Gem::Platform::RUBY + s.authors = ["bundler team"] + s.bindir = "exe" + s.homepage = "https://bundler.io" + s.summary = "The best way to manage your application's dependencies" + s.executables = %w[bundle] + # can't point to the actual gemspec or else the require paths will be wrong + s.loaded_from = __dir__ + end end idx.each {|s| s.source = self } diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb index bdfcf8274a..978b0b2c9f 100644 --- a/lib/bundler/source/path.rb +++ b/lib/bundler/source/path.rb @@ -14,6 +14,7 @@ module Bundler DEFAULT_GLOB = "{,*,*/*}.gemspec" def initialize(options) + @checksum_store = Checksum::Store.new @options = options.dup @glob = options["glob"] || DEFAULT_GLOB @@ -85,7 +86,7 @@ module Bundler using_message = "Using #{version_message(spec, options[:previous_spec])} from #{self}" using_message += " and installing its executables" unless spec.executables.empty? print_using_message using_message - generate_bin(spec, :disable_extensions => true) + generate_bin(spec, disable_extensions: true) nil # no post-install message end @@ -225,7 +226,7 @@ module Bundler # Some gem authors put absolute paths in their gemspec # and we have to save them from themselves spec.files = spec.files.map do |path| - next path unless /\A#{Pathname::SEPARATOR_PAT}/.match?(path) + next path unless /\A#{Pathname::SEPARATOR_PAT}/o.match?(path) next if File.directory?(path) begin Pathname.new(path).relative_path_from(gem_dir).to_s @@ -236,10 +237,10 @@ module Bundler installer = Path::Installer.new( spec, - :env_shebang => false, - :disable_extensions => options[:disable_extensions], - :build_args => options[:build_args], - :bundler_extension_cache_path => extension_cache_path(spec) + env_shebang: false, + disable_extensions: options[:disable_extensions], + build_args: options[:build_args], + bundler_extension_cache_path: extension_cache_path(spec) ) installer.post_install rescue Gem::InvalidSpecificationException => e diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index a8d2e26324..dafc674f9d 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -10,7 +10,7 @@ module Bundler # Ask for X gems per API request API_REQUEST_SIZE = 50 - attr_reader :remotes, :caches + attr_accessor :remotes def initialize(options = {}) @options = options @@ -19,11 +19,15 @@ module Bundler @allow_remote = false @allow_cached = false @allow_local = options["allow_local"] || false - @caches = [cache_path, *Bundler.rubygems.gem_cache] + @checksum_store = Checksum::Store.new Array(options["remotes"]).reverse_each {|r| add_remote(r) } end + def caches + @caches ||= [cache_path, *Bundler.rubygems.gem_cache] + end + def local_only! @specs = nil @allow_local = true @@ -46,10 +50,11 @@ module Bundler end def cached! + return unless File.exist?(cache_path) + return if @allow_cached @specs = nil - @allow_local = true @allow_cached = true end @@ -85,13 +90,14 @@ module Bundler end def self.from_lock(options) + options["remotes"] = Array(options.delete("remote")).reverse new(options) end def to_lock out = String.new("GEM\n") remotes.reverse_each do |remote| - out << " remote: #{suppress_configured_credentials remote}\n" + out << " remote: #{remove_auth remote}\n" end out << " specs:\n" end @@ -120,29 +126,27 @@ module Bundler end end alias_method :name, :identifier + alias_method :to_gemfile, :identifier def specs @specs ||= begin # remote_specs usually generates a way larger Index than the other - # sources, and large_idx.use small_idx is way faster than - # small_idx.use large_idx. - idx = @allow_remote ? remote_specs.dup : Index.new - idx.use(cached_specs, :override_dupes) if @allow_cached || @allow_remote - idx.use(installed_specs, :override_dupes) if @allow_local - idx - end - end + # sources, and large_idx.merge! small_idx is way faster than + # small_idx.merge! large_idx. + index = @allow_remote ? remote_specs.dup : Index.new + index.merge!(cached_specs) if @allow_cached + index.merge!(installed_specs) if @allow_local - def install(spec, options = {}) - force = options[:force] - ensure_builtin_gems_cached = options[:ensure_builtin_gems_cached] + # complete with default specs, only if not already available in the + # index through remote, cached, or installed specs + index.use(default_specs) if @allow_local - if ensure_builtin_gems_cached && spec.default_gem? && !cached_path(spec) - cached_built_in_gem(spec) unless spec.remote - force = true + index end + end - if installed?(spec) && !force + def install(spec, options = {}) + if (spec.default_gem? && !cached_built_in_gem(spec)) || (installed?(spec) && !options[:force]) print_using_message "Using #{version_message(spec, options[:previous_spec])}" return nil # no post-install message end @@ -165,15 +169,14 @@ module Bundler installer = Bundler::RubyGemsGemInstaller.at( path, - :security_policy => Bundler.rubygems.security_policies[Bundler.settings["trust-policy"]], - :install_dir => install_path.to_s, - :bin_dir => bin_path.to_s, - :ignore_dependencies => true, - :wrappers => true, - :env_shebang => true, - :build_args => options[:build_args], - :bundler_expected_checksum => spec.respond_to?(:checksum) && spec.checksum, - :bundler_extension_cache_path => extension_cache_path(spec) + security_policy: Bundler.rubygems.security_policies[Bundler.settings["trust-policy"]], + install_dir: install_path.to_s, + bin_dir: bin_path.to_s, + ignore_dependencies: true, + wrappers: true, + env_shebang: true, + build_args: options[:build_args], + bundler_extension_cache_path: extension_cache_path(spec) ) if spec.remote @@ -191,6 +194,8 @@ module Bundler spec.__swap__(s) end + spec.source.checksum_store.register(spec, installer.gem_checksum) + message = "Installing #{version_message(spec, options[:previous_spec])}" message += " with native extensions" if spec.extensions.any? Bundler.ui.confirm message @@ -233,7 +238,7 @@ module Bundler end def spec_names - if @allow_remote && dependency_api_available? + if dependency_api_available? remote_specs.spec_names else [] @@ -241,22 +246,25 @@ module Bundler end def unmet_deps - if @allow_remote && dependency_api_available? + if dependency_api_available? remote_specs.unmet_dependency_names else [] end end - def fetchers - @fetchers ||= remotes.map do |uri| + def remote_fetchers + @remote_fetchers ||= remotes.to_h do |uri| remote = Source::Rubygems::Remote.new(uri) - Bundler::Fetcher.new(remote) - end + [remote, Bundler::Fetcher.new(remote)] + end.freeze + end + + def fetchers + @fetchers ||= remote_fetchers.values.freeze end def double_check_for(unmet_dependency_names) - return unless @allow_remote return unless dependency_api_available? unmet_dependency_names = unmet_dependency_names.call @@ -271,7 +279,9 @@ module Bundler Bundler.ui.debug "Double checking for #{unmet_dependency_names || "all specs (due to the size of the request)"} in #{self}" - fetch_names(api_fetchers, unmet_dependency_names, specs, false) + fetch_names(api_fetchers, unmet_dependency_names, remote_specs) + + specs.use remote_specs end def dependency_names_to_double_check @@ -300,11 +310,7 @@ module Bundler end def credless_remotes - if Bundler.settings[:allow_deployment_source_credential_changes] - remotes.map(&method(:remove_auth)) - else - remotes.map(&method(:suppress_configured_credentials)) - end + remotes.map(&method(:remove_auth)) end def remotes_for_spec(spec) @@ -324,9 +330,9 @@ module Bundler def cached_path(spec) global_cache_path = download_cache_path(spec) - @caches << global_cache_path if global_cache_path + caches << global_cache_path if global_cache_path - possibilities = @caches.map {|p| package_path(p, spec) } + possibilities = caches.map {|p| package_path(p, spec) } possibilities.find {|p| File.exist?(p) } end @@ -337,21 +343,12 @@ module Bundler def normalize_uri(uri) uri = URINormalizer.normalize_suffix(uri.to_s) require_relative "../vendored_uri" - uri = Bundler::URI(uri) + uri = Gem::URI(uri) raise ArgumentError, "The source must be an absolute URI. For example:\n" \ - "source 'https://rubygems.org'" if !uri.absolute? || (uri.is_a?(Bundler::URI::HTTP) && uri.host.nil?) + "source 'https://rubygems.org'" if !uri.absolute? || (uri.is_a?(Gem::URI::HTTP) && uri.host.nil?) uri end - def suppress_configured_credentials(remote) - remote_nouser = remove_auth(remote) - if remote.userinfo && remote.userinfo == Bundler.settings[remote_nouser] - remote_nouser - else - remote - end - end - def remove_auth(remote) if remote.user || remote.password remote.dup.tap {|uri| uri.user = uri.password = nil }.to_s @@ -362,7 +359,7 @@ module Bundler def installed_specs @installed_specs ||= Index.build do |idx| - Bundler.rubygems.all_specs.reverse_each do |spec| + Bundler.rubygems.installed_specs.reverse_each do |spec| spec.source = self if Bundler.rubygems.spec_missing_extensions?(spec, false) Bundler.ui.debug "Source #{self} is ignoring #{spec} because it is missing extensions" @@ -373,12 +370,20 @@ module Bundler end end + def default_specs + @default_specs ||= Index.build do |idx| + Bundler.rubygems.default_specs.each do |spec| + spec.source = self + idx << spec + end + end + end + def cached_specs @cached_specs ||= begin - idx = @allow_local ? installed_specs.dup : Index.new + idx = Index.new Dir["#{cache_path}/*.gem"].each do |gemfile| - next if /^bundler\-[\d\.]+?\.gem/.match?(gemfile) s ||= Bundler.rubygems.spec_from_gem(gemfile) s.source = self idx << s @@ -389,35 +394,30 @@ module Bundler end def api_fetchers - fetchers.select {|f| f.use_api && f.fetchers.first.api_fetcher? } + fetchers.select(&:api_fetcher?) end def remote_specs @remote_specs ||= Index.build do |idx| index_fetchers = fetchers - api_fetchers - # gather lists from non-api sites - fetch_names(index_fetchers, nil, idx, false) - - # legacy multi-remote sources need special logic to figure out - # dependency names and that logic can be very costly if one remote - # uses the dependency API but others don't. So use full indexes - # consistently in that particular case. - allow_api = !multiple_remotes? - - fetch_names(api_fetchers, allow_api && dependency_names, idx, false) + if index_fetchers.empty? + fetch_names(api_fetchers, dependency_names, idx) + else + fetch_names(fetchers, nil, idx) + end end end - def fetch_names(fetchers, dependency_names, index, override_dupes) + def fetch_names(fetchers, dependency_names, index) fetchers.each do |f| if dependency_names Bundler.ui.info "Fetching gem metadata from #{URICredentialsFilter.credential_filtered_uri(f.uri)}", Bundler.ui.debug? - index.use f.specs_with_retry(dependency_names, self), override_dupes + index.use f.specs_with_retry(dependency_names, self) Bundler.ui.info "" unless Bundler.ui.debug? # new line now that the dots are over else Bundler.ui.info "Fetching source index from #{URICredentialsFilter.credential_filtered_uri(f.uri)}" - index.use f.specs_with_retry(nil, self), override_dupes + index.use f.specs_with_retry(nil, self) end end end @@ -478,7 +478,8 @@ module Bundler def download_gem(spec, download_cache_path, previous_spec = nil) uri = spec.remote.uri Bundler.ui.confirm("Fetching #{version_message(spec, previous_spec)}") - Bundler.rubygems.download_gem(spec, uri, download_cache_path) + gem_remote_fetcher = remote_fetchers.fetch(spec.remote).gem_remote_fetcher + Bundler.rubygems.download_gem(spec, uri, download_cache_path, gem_remote_fetcher) end # Returns the global cache path of the calling Rubygems::Source object. diff --git a/lib/bundler/source/rubygems/remote.rb b/lib/bundler/source/rubygems/remote.rb index 82c850ffbb..9c5c06de24 100644 --- a/lib/bundler/source/rubygems/remote.rb +++ b/lib/bundler/source/rubygems/remote.rb @@ -48,7 +48,7 @@ module Bundler end uri - rescue Bundler::URI::InvalidComponentError + rescue Gem::URI::InvalidComponentError error_message = "Please CGI escape your usernames and passwords before " \ "setting them for authentication." raise HTTPError.new(error_message) diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index 63798db941..5f9dd68f17 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -22,6 +22,7 @@ module Bundler @metadata_source = Source::Metadata.new @merged_gem_lockfile_sections = false + @local_mode = true end def merged_gem_lockfile_sections? @@ -73,6 +74,10 @@ module Bundler global_rubygems_source end + def local_mode? + @local_mode + end + def default_source global_path_source || global_rubygems_source end @@ -101,10 +106,6 @@ module Bundler source_list_for(source).find {|s| equivalent_source?(source, s) } end - def get_with_fallback(source) - get(source) || default_source - end - def lock_sources lock_other_sources + lock_rubygems_sources end @@ -144,11 +145,17 @@ module Bundler all_sources.each(&:local_only!) end + def local! + all_sources.each(&:local!) + end + def cached! all_sources.each(&:cached!) end def remote! + @local_mode = false + all_sources.each(&:remote!) end @@ -161,7 +168,11 @@ module Bundler end def map_sources(replacement_sources) - rubygems, git, plugin = [@rubygems_sources, @git_sources, @plugin_sources].map do |sources| + rubygems = @rubygems_sources.map do |source| + replace_rubygems_source(replacement_sources, source) || source + end + + git, plugin = [@git_sources, @plugin_sources].map do |sources| sources.map do |source| replacement_sources.find {|s| s == source } || source end @@ -175,13 +186,22 @@ module Bundler end def global_replacement_source(replacement_sources) - replacement_source = replacement_sources.find {|s| s == global_rubygems_source } + replacement_source = replace_rubygems_source(replacement_sources, global_rubygems_source) return global_rubygems_source unless replacement_source replacement_source.local! replacement_source end + def replace_rubygems_source(replacement_sources, gemfile_source) + replacement_source = replacement_sources.find {|s| s == gemfile_source } + return unless replacement_source + + # locked sources never include credentials so always prefer remotes from the gemfile + replacement_source.remotes = gemfile_source.remotes + replacement_source + end + def different_sources?(lock_sources, replacement_sources) !equivalent_sources?(lock_sources, replacement_sources) end diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb index 21630e3a3e..2933d28450 100644 --- a/lib/bundler/spec_set.rb +++ b/lib/bundler/spec_set.rb @@ -37,7 +37,7 @@ module Bundler specs_for_dep.first.dependencies.each do |d| next if d.type == :development - incomplete = true if d.name != "bundler" && lookup[d.name].empty? + incomplete = true if d.name != "bundler" && lookup[d.name].nil? deps << [d, dep[1]] end else @@ -45,28 +45,64 @@ module Bundler end if incomplete && check - @incomplete_specs += lookup[name].any? ? lookup[name] : [LazySpecification.new(name, nil, nil)] + @incomplete_specs += lookup[name] || [LazySpecification.new(name, nil, nil)] end end specs.uniq end + def add_extra_platforms!(platforms) + return platforms.concat([Gem::Platform::RUBY]).uniq if @specs.empty? + + new_platforms = all_platforms.select do |platform| + next if platforms.include?(platform) + next unless GemHelpers.generic(platform) == Gem::Platform::RUBY + + complete_platform(platform) + end + return platforms if new_platforms.empty? + + platforms.concat(new_platforms) + + less_specific_platform = new_platforms.find {|platform| platform != Gem::Platform::RUBY && Bundler.local_platform === platform && platform === Bundler.local_platform } + platforms.delete(Bundler.local_platform) if less_specific_platform + + platforms + end + + def complete_platforms!(platforms) + platforms.each do |platform| + complete_platform(platform) + end + end + + def validate_deps(s) + s.runtime_dependencies.each do |dep| + next if dep.name == "bundler" + + return :missing unless names.include?(dep.name) + return :invalid if none? {|spec| dep.matches_spec?(spec) } + end + + :valid + end + def [](key) key = key.name if key.respond_to?(:name) - lookup[key].reverse + lookup[key]&.reverse || [] end def []=(key, value) @specs << value - @lookup = nil - @sorted = nil + + reset! end def delete(specs) specs.each {|spec| @specs.delete(spec) } - @lookup = nil - @sorted = nil + + reset! end def sort! @@ -100,12 +136,12 @@ module Bundler end end - def incomplete_ruby_specs?(deps) + def incomplete_for_platform?(deps, platform) return false if @specs.empty? @incomplete_specs = [] - self.for(deps, true, [Gem::Platform::RUBY]) + self.for(deps, true, [platform]) @incomplete_specs.any? end @@ -114,16 +150,6 @@ module Bundler @specs.select {|s| s.is_a?(LazySpecification) } end - def merge(set) - arr = sorted.dup - set.each do |set_spec| - full_name = set_spec.full_name - next if arr.any? {|spec| spec.full_name == full_name } - arr << set_spec - end - SpecSet.new(arr) - end - def -(other) SpecSet.new(to_a - other.to_a) end @@ -134,12 +160,12 @@ module Bundler def delete_by_name(name) @specs.reject! {|spec| spec.name == name } - @lookup = nil - @sorted = nil + + reset! end def what_required(spec) - unless req = find {|s| s.dependencies.any? {|d| d.type == :runtime && d.name == spec.name } } + unless req = find {|s| s.runtime_dependencies.any? {|d| d.name == spec.name } } return [spec] end what_required(req) << spec @@ -165,8 +191,52 @@ module Bundler sorted.each(&b) end + def names + lookup.keys + end + private + def reset! + @sorted = nil + @lookup = nil + end + + def complete_platform(platform) + new_specs = [] + + valid_platform = lookup.all? do |_, specs| + spec = specs.first + matching_specs = spec.source.specs.search([spec.name, spec.version]) + platform_spec = GemHelpers.select_best_platform_match(matching_specs, platform).find do |s| + s.matches_current_metadata? && valid_dependencies?(s) + end + + if platform_spec + new_specs << LazySpecification.from_spec(platform_spec) unless specs.include?(platform_spec) + true + else + false + end + end + + if valid_platform && new_specs.any? + @specs.concat(new_specs) + + reset! + end + + valid_platform + end + + def all_platforms + @specs.flat_map {|spec| spec.source.specs.search([spec.name, spec.version]).map(&:platform) }.uniq + end + + def valid_dependencies?(s) + validate_deps(s) == :valid + end + def sorted rake = @specs.find {|s| s.name == "rake" } begin @@ -185,8 +255,9 @@ module Bundler def lookup @lookup ||= begin - lookup = Hash.new {|h, k| h[k] = [] } + lookup = {} @specs.each do |s| + lookup[s.name] ||= [] lookup[s.name] << s end lookup @@ -200,8 +271,13 @@ module Bundler def specs_for_dependency(dep, platform) specs_for_name = lookup[dep.name] - target_platform = dep.force_ruby_platform ? Gem::Platform::RUBY : (platform || Bundler.local_platform) - matching_specs = GemHelpers.select_best_platform_match(specs_for_name, target_platform) + return [] unless specs_for_name + + matching_specs = if dep.force_ruby_platform + GemHelpers.force_ruby_platform(specs_for_name) + else + GemHelpers.select_best_platform_match(specs_for_name, platform || Bundler.local_platform) + end matching_specs.map!(&:materialize_for_installation).compact! if platform.nil? matching_specs end @@ -209,7 +285,11 @@ module Bundler def tsort_each_child(s) s.dependencies.sort_by(&:name).each do |d| next if d.type == :development - lookup[d.name].each {|s2| yield s2 } + + specs_for_name = lookup[d.name] + next unless specs_for_name + + specs_for_name.each {|s2| yield s2 } end end end diff --git a/lib/bundler/stub_specification.rb b/lib/bundler/stub_specification.rb index 88a4257fa4..da830cf8d4 100644 --- a/lib/bundler/stub_specification.rb +++ b/lib/bundler/stub_specification.rb @@ -9,6 +9,7 @@ module Bundler spec end + attr_reader :checksum attr_accessor :stub, :ignored def source=(source) @@ -16,7 +17,8 @@ module Bundler # Stub has no concept of source, which means that extension_dir may be wrong # This is the case for git-based gems. So, instead manually assign the extension dir return unless source.respond_to?(:extension_dir_name) - path = File.join(stub.extensions_dir, source.extension_dir_name) + unique_extension_dir = [source.extension_dir_name, File.basename(full_gem_path)].uniq.join("-") + path = File.join(stub.extensions_dir, unique_extension_dir) stub.extension_dir = File.expand_path(path) end @@ -56,7 +58,7 @@ module Bundler end def gem_build_complete_path - File.join(extension_dir, "gem.build_complete") + stub.gem_build_complete_path end def default_gem? @@ -108,6 +110,7 @@ module Bundler end rs.source = source + rs.base_dir = stub.base_dir rs end diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler index e290fe91eb..caa2021701 100644 --- a/lib/bundler/templates/Executable.bundler +++ b/lib/bundler/templates/Executable.bundler @@ -27,7 +27,7 @@ m = Module.new do bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| - if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) bundler_version = a end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ diff --git a/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt b/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt index 175b821a62..67fe8cee79 100644 --- a/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +++ b/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt @@ -2,83 +2,131 @@ ## Our Pledge -We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. -We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to a positive environment for our community include: +Examples of behavior that contributes to a positive environment for our +community include: * Demonstrating empathy and kindness toward other people * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the overall community +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community Examples of unacceptable behavior include: -* The use of sexualized language or imagery, and sexual attention or - advances of any kind +* The use of sexualized language or imagery, and sexual attention or advances of + any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or email - address, without their explicit permission +* Publishing others' private information, such as a physical or email address, + without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities -Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. -Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. ## Scope -This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official email address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at <%= config[:email] %>. All complaints will be reviewed and investigated promptly and fairly. +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. -All community leaders are obligated to respect the privacy and security of the reporter of any incident. +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. ## Enforcement Guidelines -Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction -**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. -**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. ### 2. Warning -**Community Impact**: A violation through a single incident or series of actions. +**Community Impact**: A violation through a single incident or series of +actions. -**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. ### 3. Temporary Ban -**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. -**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. ### 4. Permanent Ban -**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. -**Consequence**: A permanent ban from any sort of public interaction within the community. +**Consequence**: A permanent ban from any sort of public interaction within the +community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, -available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. -Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). - -[homepage]: https://www.contributor-covenant.org +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations diff --git a/lib/bundler/templates/newgem/Rakefile.tt b/lib/bundler/templates/newgem/Rakefile.tt index b5a5c4e392..172183d4b4 100644 --- a/lib/bundler/templates/newgem/Rakefile.tt +++ b/lib/bundler/templates/newgem/Rakefile.tt @@ -4,13 +4,9 @@ require "bundler/gem_tasks" <% default_task_names = [config[:test_task]].compact -%> <% case config[:test] -%> <% when "minitest" -%> -require "rake/testtask" +require "minitest/test_task" -Rake::TestTask.new(:test) do |t| - t.libs << "test" - t.libs << "lib" - t.test_files = FileList["test/**/test_*.rb"] -end +Minitest::TestTask.create <% when "test-unit" -%> require "rake/testtask" @@ -46,7 +42,9 @@ require "rb_sys/extensiontask" task build: :compile -RbSys::ExtensionTask.new(<%= config[:name].inspect %>) do |ext| +GEMSPEC = Gem::Specification.load("<%= config[:underscored_name] %>.gemspec") + +RbSys::ExtensionTask.new(<%= config[:name].inspect %>, GEMSPEC) do |ext| ext.lib_dir = "lib/<%= config[:namespaced_path] %>" end <% else -%> @@ -54,7 +52,9 @@ require "rake/extensiontask" task build: :compile -Rake::ExtensionTask.new("<%= config[:underscored_name] %>") do |ext| +GEMSPEC = Gem::Specification.load("<%= config[:underscored_name] %>.gemspec") + +Rake::ExtensionTask.new("<%= config[:underscored_name] %>", GEMSPEC) do |ext| ext.lib_dir = "lib/<%= config[:namespaced_path] %>" end <% end -%> diff --git a/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt b/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt index 4b6e9587f7..0ebce0e4a0 100644 --- a/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +++ b/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt @@ -12,4 +12,4 @@ publish = false crate-type = ["cdylib"] [dependencies] -magnus = { version = "0.4" } +magnus = { version = "0.6.2" } diff --git a/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt b/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt index b311283997..ba234529a3 100644 --- a/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +++ b/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt @@ -1,12 +1,12 @@ -use magnus::{define_module, function, prelude::*, Error}; +use magnus::{function, prelude::*, Error, Ruby}; fn hello(subject: String) -> String { - format!("Hello from Rust, {}!", subject) + format!("Hello from Rust, {subject}!") } #[magnus::init] -fn init() -> Result<(), Error> { - let module = <%= config[:constant_array].map {|c| "define_module(#{c.dump})?"}.join(".") %>; +fn init(ruby: &Ruby) -> Result<(), Error> { + let module = ruby.<%= config[:constant_array].map {|c| "define_module(#{c.dump})?"}.join(".") %>; module.define_singleton_method("hello", function!(hello, 1))?; Ok(()) } diff --git a/lib/bundler/templates/newgem/github/workflows/main.yml.tt b/lib/bundler/templates/newgem/github/workflows/main.yml.tt index be58dd8156..32b39558d8 100644 --- a/lib/bundler/templates/newgem/github/workflows/main.yml.tt +++ b/lib/bundler/templates/newgem/github/workflows/main.yml.tt @@ -17,7 +17,7 @@ jobs: - '<%= RUBY_VERSION %>' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 <%- if config[:ext] == 'rust' -%> - name: Set up Ruby & Rust uses: oxidize-rb/actions/setup-ruby-and-rust@v1 diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index da81f046d4..6e88f4dab1 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -27,9 +27,11 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. - spec.files = Dir.chdir(__dir__) do - `git ls-files -z`.split("\x0").reject do |f| - (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor]) + gemspec = File.basename(__FILE__) + spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| + ls.readlines("\x0", chomp: true).reject do |f| + (f == gemspec) || + f.start_with?(*%w[bin/ test/ spec/ features/ .git <%= config[:ci_config_path] %>appveyor Gemfile]) end end spec.bindir = "exe" diff --git a/lib/bundler/templates/newgem/rubocop.yml.tt b/lib/bundler/templates/newgem/rubocop.yml.tt index 9ecec78807..3d1c4ee7b2 100644 --- a/lib/bundler/templates/newgem/rubocop.yml.tt +++ b/lib/bundler/templates/newgem/rubocop.yml.tt @@ -2,12 +2,7 @@ AllCops: TargetRubyVersion: <%= ::Gem::Version.new(config[:required_ruby_version]).segments[0..1].join(".") %> Style/StringLiterals: - Enabled: true EnforcedStyle: double_quotes Style/StringLiteralsInInterpolation: - Enabled: true EnforcedStyle: double_quotes - -Layout/LineLength: - Max: 120 diff --git a/lib/bundler/templates/newgem/standard.yml.tt b/lib/bundler/templates/newgem/standard.yml.tt index 934b0b2c37..a0696cd2e9 100644 --- a/lib/bundler/templates/newgem/standard.yml.tt +++ b/lib/bundler/templates/newgem/standard.yml.tt @@ -1,3 +1,3 @@ # For available configuration options, see: -# https://github.com/testdouble/standard +# https://github.com/standardrb/standard ruby_version: <%= ::Gem::Version.new(config[:required_ruby_version]).segments[0..1].join(".") %> diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb index 4139585c47..4555612dbb 100644 --- a/lib/bundler/ui/shell.rb +++ b/lib/bundler/ui/shell.rb @@ -130,7 +130,7 @@ module Bundler def tell_err(message, color = nil, newline = nil) return if @shell.send(:stderr).closed? - newline ||= message.to_s !~ /( |\t)\Z/ + newline ||= !message.to_s.match?(/( |\t)\Z/) message = word_wrap(message) if newline.is_a?(Hash) && newline[:wrap] color = nil if color && !$stderr.tty? @@ -147,7 +147,7 @@ module Bundler spaces ? text.gsub(/#{spaces}/, "") : text end - def word_wrap(text, line_width = @shell.terminal_width) + def word_wrap(text, line_width = Thor::Terminal.terminal_width) strip_leading_spaces(text).split("\n").collect do |line| line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line end * "\n" diff --git a/lib/bundler/uri_credentials_filter.rb b/lib/bundler/uri_credentials_filter.rb index ccfaf0bc5d..a83f5304e2 100644 --- a/lib/bundler/uri_credentials_filter.rb +++ b/lib/bundler/uri_credentials_filter.rb @@ -11,7 +11,7 @@ module Bundler return uri if File.exist?(uri) require_relative "vendored_uri" - uri = Bundler::URI(uri) + uri = Gem::URI(uri) end if uri.userinfo @@ -25,7 +25,7 @@ module Bundler end return uri.to_s if uri_to_anonymize.is_a?(String) uri - rescue Bundler::URI::InvalidURIError # uri is not canonical uri scheme + rescue Gem::URI::InvalidURIError # uri is not canonical uri scheme uri end diff --git a/lib/bundler/vendor/connection_pool/.document b/lib/bundler/vendor/connection_pool/.document new file mode 100644 index 0000000000..0c43bbd6b3 --- /dev/null +++ b/lib/bundler/vendor/connection_pool/.document @@ -0,0 +1 @@ +# Vendored files do not need to be documented diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool.rb index 455319efe3..317088a866 100644 --- a/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +++ b/lib/bundler/vendor/connection_pool/lib/connection_pool.rb @@ -1,4 +1,4 @@ -require "timeout" +require_relative "../../../vendored_timeout" require_relative "connection_pool/version" class Bundler::ConnectionPool @@ -6,7 +6,7 @@ class Bundler::ConnectionPool class PoolShuttingDownError < ::Bundler::ConnectionPool::Error; end - class TimeoutError < ::Timeout::Error; end + class TimeoutError < ::Gem::Timeout::Error; end end # Generic connection pool class for sharing a limited number of objects or network connections @@ -36,14 +36,57 @@ end # Accepts the following options: # - :size - number of connections to pool, defaults to 5 # - :timeout - amount of time to wait for a connection if none currently available, defaults to 5 seconds +# - :auto_reload_after_fork - automatically drop all connections after fork, defaults to true # class Bundler::ConnectionPool - DEFAULTS = {size: 5, timeout: 5} + DEFAULTS = {size: 5, timeout: 5, auto_reload_after_fork: true} def self.wrap(options, &block) Wrapper.new(options, &block) end + if Process.respond_to?(:fork) + INSTANCES = ObjectSpace::WeakMap.new + private_constant :INSTANCES + + def self.after_fork + INSTANCES.values.each do |pool| + next unless pool.auto_reload_after_fork + + # We're on after fork, so we know all other threads are dead. + # All we need to do is to ensure the main thread doesn't have a + # checked out connection + pool.checkin(force: true) + pool.reload do |connection| + # Unfortunately we don't know what method to call to close the connection, + # so we try the most common one. + connection.close if connection.respond_to?(:close) + end + end + nil + end + + if ::Process.respond_to?(:_fork) # MRI 3.1+ + module ForkTracker + def _fork + pid = super + if pid == 0 + Bundler::ConnectionPool.after_fork + end + pid + end + end + Process.singleton_class.prepend(ForkTracker) + end + else + INSTANCES = nil + private_constant :INSTANCES + + def self.after_fork + # noop + end + end + def initialize(options = {}, &block) raise ArgumentError, "Connection pool requires a block" unless block @@ -51,10 +94,12 @@ class Bundler::ConnectionPool @size = Integer(options.fetch(:size)) @timeout = options.fetch(:timeout) + @auto_reload_after_fork = options.fetch(:auto_reload_after_fork) @available = TimedStack.new(@size, &block) @key = :"pool-#{@available.object_id}" @key_count = :"pool-#{@available.object_id}-count" + INSTANCES[self] = self if INSTANCES end def with(options = {}) @@ -81,16 +126,16 @@ class Bundler::ConnectionPool end end - def checkin + def checkin(force: false) if ::Thread.current[@key] - if ::Thread.current[@key_count] == 1 + if ::Thread.current[@key_count] == 1 || force @available.push(::Thread.current[@key]) ::Thread.current[@key] = nil ::Thread.current[@key_count] = nil else ::Thread.current[@key_count] -= 1 end - else + elsif !force raise Bundler::ConnectionPool::Error, "no connections are checked out" end @@ -117,6 +162,8 @@ class Bundler::ConnectionPool # Size of this connection pool attr_reader :size + # Automatically drop all connections after fork + attr_reader :auto_reload_after_fork # Number of pool entries available for checkout at this instant. def available diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb index 56ebf69902..384d6fc977 100644 --- a/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +++ b/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb @@ -1,3 +1,3 @@ class Bundler::ConnectionPool - VERSION = "2.3.0" + VERSION = "2.4.1" end diff --git a/lib/bundler/vendor/fileutils/.document b/lib/bundler/vendor/fileutils/.document new file mode 100644 index 0000000000..0c43bbd6b3 --- /dev/null +++ b/lib/bundler/vendor/fileutils/.document @@ -0,0 +1 @@ +# Vendored files do not need to be documented diff --git a/lib/bundler/vendor/fileutils/lib/fileutils.rb b/lib/bundler/vendor/fileutils/lib/fileutils.rb index 211311c069..6db19caf6f 100644 --- a/lib/bundler/vendor/fileutils/lib/fileutils.rb +++ b/lib/bundler/vendor/fileutils/lib/fileutils.rb @@ -180,7 +180,7 @@ end # - {CVE-2004-0452}[https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0452]. # module Bundler::FileUtils - VERSION = "1.7.0" + VERSION = "1.7.2" def self.private_module_function(name) #:nodoc: module_function name @@ -192,8 +192,6 @@ module Bundler::FileUtils # # Bundler::FileUtils.pwd # => "/rdoc/fileutils" # - # Bundler::FileUtils.getwd is an alias for Bundler::FileUtils.pwd. - # # Related: Bundler::FileUtils.cd. # def pwd @@ -235,8 +233,6 @@ module Bundler::FileUtils # cd .. # cd fileutils # - # Bundler::FileUtils.chdir is an alias for Bundler::FileUtils.cd. - # # Related: Bundler::FileUtils.pwd. # def cd(dir, verbose: nil, &block) # :yield: dir @@ -515,8 +511,6 @@ module Bundler::FileUtils # Raises an exception if +dest+ is the path to an existing file # and keyword argument +force+ is not +true+. # - # Bundler::FileUtils#link is an alias for Bundler::FileUtils#ln. - # # Related: Bundler::FileUtils.link_entry (has different options). # def ln(src, dest, force: nil, noop: nil, verbose: nil) @@ -707,8 +701,6 @@ module Bundler::FileUtils # ln -sf src2.txt dest2.txt # ln -s srcdir3/src0.txt srcdir3/src1.txt destdir3 # - # Bundler::FileUtils.symlink is an alias for Bundler::FileUtils.ln_s. - # # Related: Bundler::FileUtils.ln_sf. # def ln_s(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil) @@ -876,8 +868,6 @@ module Bundler::FileUtils # # Raises an exception if +src+ is a directory. # - # Bundler::FileUtils.copy is an alias for Bundler::FileUtils.cp. - # # Related: {methods for copying}[rdoc-ref:FileUtils@Copying]. # def cp(src, dest, preserve: nil, noop: nil, verbose: nil) @@ -1164,8 +1154,6 @@ module Bundler::FileUtils # mv src0 dest0 # mv src1.txt src1 dest1 # - # Bundler::FileUtils.move is an alias for Bundler::FileUtils.mv. - # def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil) fu_output_message "mv#{force ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if verbose return if noop @@ -1223,8 +1211,6 @@ module Bundler::FileUtils # # rm src0.dat src0.txt # - # Bundler::FileUtils.remove is an alias for Bundler::FileUtils.rm. - # # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting]. # def rm(list, force: nil, noop: nil, verbose: nil) @@ -1250,8 +1236,6 @@ module Bundler::FileUtils # # See Bundler::FileUtils.rm for keyword arguments. # - # Bundler::FileUtils.safe_unlink is an alias for Bundler::FileUtils.rm_f. - # # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting]. # def rm_f(list, noop: nil, verbose: nil) @@ -1339,8 +1323,6 @@ module Bundler::FileUtils # # See Bundler::FileUtils.rm_r for keyword arguments. # - # Bundler::FileUtils.rmtree is an alias for Bundler::FileUtils.rm_rf. - # # Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting]. # def rm_rf(list, noop: nil, verbose: nil, secure: nil) @@ -1642,7 +1624,13 @@ module Bundler::FileUtils st = File.stat(s) unless File.exist?(d) and compare_file(s, d) remove_file d, true - copy_file s, d + if d.end_with?('/') + mkdir_p d + copy_file s, d + File.basename(s) + else + mkdir_p File.expand_path('..', d) + copy_file s, d + end File.utime st.atime, st.mtime, d if preserve File.chmod fu_mode(mode, st), d if mode File.chown uid, gid, d if uid or gid diff --git a/lib/bundler/vendor/net-http-persistent/.document b/lib/bundler/vendor/net-http-persistent/.document new file mode 100644 index 0000000000..0c43bbd6b3 --- /dev/null +++ b/lib/bundler/vendor/net-http-persistent/.document @@ -0,0 +1 @@ +# Vendored files do not need to be documented 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 a4e1c5a750..c15b346330 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 @@ -1,14 +1,14 @@ -require 'net/http' -require_relative '../../../../uri/lib/uri' +require_relative '../../../../../vendored_net_http' +require_relative '../../../../../vendored_uri' require 'cgi' # for escaping require_relative '../../../../connection_pool/lib/connection_pool' autoload :OpenSSL, 'openssl' ## -# Persistent connections for Net::HTTP +# Persistent connections for Gem::Net::HTTP # -# Bundler::Persistent::Net::HTTP::Persistent maintains persistent connections across all the +# Gem::Net::HTTP::Persistent maintains persistent connections across all the # servers you wish to talk to. For each host:port you communicate with a # single persistent connection is created. # @@ -22,34 +22,34 @@ autoload :OpenSSL, 'openssl' # # require 'bundler/vendor/net-http-persistent/lib/net/http/persistent' # -# uri = Bundler::URI 'http://example.com/awesome/web/service' +# uri = Gem::URI 'http://example.com/awesome/web/service' # -# http = Bundler::Persistent::Net::HTTP::Persistent.new +# http = Gem::Net::HTTP::Persistent.new # # # perform a GET # response = http.request uri # # # or # -# get = Net::HTTP::Get.new uri.request_uri +# get = Gem::Net::HTTP::Get.new uri.request_uri # response = http.request get # # # create a POST # post_uri = uri + 'create' -# post = Net::HTTP::Post.new post_uri.path +# post = Gem::Net::HTTP::Post.new post_uri.path # post.set_form_data 'some' => 'cool data' # -# # perform the POST, the Bundler::URI is always required +# # perform the POST, the Gem::URI is always required # response http.request post_uri, post # # Note that for GET, HEAD and other requests that do not have a body you want -# to use Bundler::URI#request_uri not Bundler::URI#path. The request_uri contains the query +# to use Gem::URI#request_uri not Gem::URI#path. The request_uri contains the query # params which are sent in the body for other requests. # # == TLS/SSL # # TLS connections are automatically created depending upon the scheme of the -# Bundler::URI. TLS connections are automatically verified against the default +# Gem::URI. TLS connections are automatically verified against the default # certificate store for your computer. You can override this by changing # verify_mode or by specifying an alternate cert_store. # @@ -72,7 +72,7 @@ autoload :OpenSSL, 'openssl' # == Proxies # # A proxy can be set through #proxy= or at initialization time by providing a -# second argument to ::new. The proxy may be the Bundler::URI of the proxy server or +# second argument to ::new. The proxy may be the Gem::URI of the proxy server or # <code>:ENV</code> which will consult environment variables. # # See #proxy= and #proxy_from_env for details. @@ -92,7 +92,7 @@ autoload :OpenSSL, 'openssl' # # === Segregation # -# Each Bundler::Persistent::Net::HTTP::Persistent instance has its own pool of connections. There +# Each Gem::Net::HTTP::Persistent instance has its own pool of connections. There # is no sharing with other instances (as was true in earlier versions). # # === Idle Timeout @@ -131,7 +131,7 @@ autoload :OpenSSL, 'openssl' # # === Connection Termination # -# If you are done using the Bundler::Persistent::Net::HTTP::Persistent instance you may shut down +# If you are done using the Gem::Net::HTTP::Persistent instance you may shut down # all the connections in the current thread with #shutdown. This is not # recommended for normal use, it should only be used when it will be several # minutes before you make another HTTP request. @@ -141,7 +141,7 @@ autoload :OpenSSL, 'openssl' # Ruby will automatically garbage collect and shutdown your HTTP connections # when the thread terminates. -class Bundler::Persistent::Net::HTTP::Persistent +class Gem::Net::HTTP::Persistent ## # The beginning of Time @@ -172,12 +172,12 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # The version of Bundler::Persistent::Net::HTTP::Persistent you are using + # The version of Gem::Net::HTTP::Persistent you are using - VERSION = '4.0.1' + VERSION = '4.0.2' ## - # Error class for errors raised by Bundler::Persistent::Net::HTTP::Persistent. Various + # Error class for errors raised by Gem::Net::HTTP::Persistent. Various # SystemCallErrors are re-raised with a human-readable message under this # class. @@ -197,10 +197,10 @@ class Bundler::Persistent::Net::HTTP::Persistent # NOTE: This may not work on ruby > 1.9. def self.detect_idle_timeout uri, max = 10 - uri = Bundler::URI uri unless Bundler::URI::Generic === uri + uri = Gem::URI uri unless Gem::URI::Generic === uri uri += '/' - req = Net::HTTP::Head.new uri.request_uri + req = Gem::Net::HTTP::Head.new uri.request_uri http = new 'net-http-persistent detect_idle_timeout' @@ -214,7 +214,7 @@ class Bundler::Persistent::Net::HTTP::Persistent $stderr.puts "HEAD #{uri} => #{response.code}" if $DEBUG - unless Net::HTTPOK === response then + unless Gem::Net::HTTPOK === response then raise Error, "bad response code #{response.code} detecting idle timeout" end @@ -238,7 +238,7 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_reader :certificate ## - # For Net::HTTP parity + # For Gem::Net::HTTP parity alias cert certificate @@ -266,7 +266,7 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_reader :ciphers ## - # Sends debug_output to this IO via Net::HTTP#set_debug_output. + # Sends debug_output to this IO via Gem::Net::HTTP#set_debug_output. # # Never use this method in production code, it causes a serious security # hole. @@ -279,7 +279,7 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_reader :generation # :nodoc: ## - # Headers that are added to every request using Net::HTTP#add_field + # Headers that are added to every request using Gem::Net::HTTP#add_field attr_reader :headers @@ -304,7 +304,7 @@ class Bundler::Persistent::Net::HTTP::Persistent ## # Number of retries to perform if a request fails. # - # See also #max_retries=, Net::HTTP#max_retries=. + # See also #max_retries=, Gem::Net::HTTP#max_retries=. attr_reader :max_retries @@ -325,12 +325,12 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_reader :name ## - # Seconds to wait until a connection is opened. See Net::HTTP#open_timeout + # Seconds to wait until a connection is opened. See Gem::Net::HTTP#open_timeout attr_accessor :open_timeout ## - # Headers that are added to every request using Net::HTTP#[]= + # Headers that are added to every request using Gem::Net::HTTP#[]= attr_reader :override_headers @@ -340,7 +340,7 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_reader :private_key ## - # For Net::HTTP parity + # For Gem::Net::HTTP parity alias key private_key @@ -360,12 +360,12 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_reader :pool # :nodoc: ## - # Seconds to wait until reading one block. See Net::HTTP#read_timeout + # Seconds to wait until reading one block. See Gem::Net::HTTP#read_timeout attr_accessor :read_timeout ## - # Seconds to wait until writing one block. See Net::HTTP#write_timeout + # Seconds to wait until writing one block. See Gem::Net::HTTP#write_timeout attr_accessor :write_timeout @@ -450,18 +450,18 @@ class Bundler::Persistent::Net::HTTP::Persistent attr_reader :verify_mode ## - # Creates a new Bundler::Persistent::Net::HTTP::Persistent. + # Creates a new Gem::Net::HTTP::Persistent. # # Set a +name+ for fun. Your library name should be good enough, but this # otherwise has no purpose. # - # +proxy+ may be set to a Bundler::URI::HTTP or :ENV to pick up proxy options from + # +proxy+ may be set to a Gem::URI::HTTP or :ENV to pick up proxy options from # the environment. See proxy_from_env for details. # - # In order to use a Bundler::URI for the proxy you may need to do some extra work - # beyond Bundler::URI parsing if the proxy requires a password: + # In order to use a Gem::URI for the proxy you may need to do some extra work + # beyond Gem::URI parsing if the proxy requires a password: # - # proxy = Bundler::URI 'http://proxy.example' + # proxy = Gem::URI 'http://proxy.example' # proxy.user = 'AzureDiamond' # proxy.password = 'hunter2' # @@ -492,8 +492,8 @@ class Bundler::Persistent::Net::HTTP::Persistent @socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if Socket.const_defined? :TCP_NODELAY - @pool = Bundler::Persistent::Net::HTTP::Persistent::Pool.new size: pool_size do |http_args| - Bundler::Persistent::Net::HTTP::Persistent::Connection.new Net::HTTP, http_args, @ssl_generation + @pool = Gem::Net::HTTP::Persistent::Pool.new size: pool_size do |http_args| + Gem::Net::HTTP::Persistent::Connection.new Gem::Net::HTTP, http_args, @ssl_generation end @certificate = nil @@ -510,7 +510,7 @@ class Bundler::Persistent::Net::HTTP::Persistent @verify_mode = nil @cert_store = nil - @generation = 0 # incremented when proxy Bundler::URI changes + @generation = 0 # incremented when proxy Gem::URI changes if HAVE_OPENSSL then @verify_mode = OpenSSL::SSL::VERIFY_PEER @@ -529,7 +529,7 @@ class Bundler::Persistent::Net::HTTP::Persistent reconnect_ssl end - # For Net::HTTP parity + # For Gem::Net::HTTP parity alias cert= certificate= ## @@ -648,7 +648,7 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # Starts the Net::HTTP +connection+ + # Starts the Gem::Net::HTTP +connection+ def start http http.set_debug_output @debug_output if @debug_output @@ -666,7 +666,7 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # Finishes the Net::HTTP +connection+ + # Finishes the Gem::Net::HTTP +connection+ def finish connection connection.finish @@ -716,16 +716,16 @@ class Bundler::Persistent::Net::HTTP::Persistent reconnect_ssl end - # For Net::HTTP parity + # For Gem::Net::HTTP parity alias key= private_key= ## - # Sets the proxy server. The +proxy+ may be the Bundler::URI of the proxy server, + # Sets the proxy server. The +proxy+ may be the Gem::URI of the proxy server, # the symbol +:ENV+ which will read the proxy from the environment or nil to # disable use of a proxy. See #proxy_from_env for details on setting the # proxy from the environment. # - # If the proxy Bundler::URI is set after requests have been made, the next request + # If the proxy Gem::URI is set after requests have been made, the next request # will shut-down and re-open all connections. # # The +no_proxy+ query parameter can be used to specify hosts which shouldn't @@ -736,9 +736,9 @@ class Bundler::Persistent::Net::HTTP::Persistent def proxy= proxy @proxy_uri = case proxy when :ENV then proxy_from_env - when Bundler::URI::HTTP then proxy + when Gem::URI::HTTP then proxy when nil then # ignore - else raise ArgumentError, 'proxy must be :ENV or a Bundler::URI::HTTP' + else raise ArgumentError, 'proxy must be :ENV or a Gem::URI::HTTP' end @no_proxy.clear @@ -763,13 +763,13 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # Creates a Bundler::URI for an HTTP proxy server from ENV variables. + # Creates a Gem::URI for an HTTP proxy server from ENV variables. # # If +HTTP_PROXY+ is set a proxy will be returned. # - # If +HTTP_PROXY_USER+ or +HTTP_PROXY_PASS+ are set the Bundler::URI is given the + # If +HTTP_PROXY_USER+ or +HTTP_PROXY_PASS+ are set the Gem::URI is given the # indicated user and password unless HTTP_PROXY contains either of these in - # the Bundler::URI. + # the Gem::URI. # # The +NO_PROXY+ ENV variable can be used to specify hosts which shouldn't # be reached via proxy; if set it should be a comma separated list of @@ -785,7 +785,7 @@ class Bundler::Persistent::Net::HTTP::Persistent return nil if env_proxy.nil? or env_proxy.empty? - uri = Bundler::URI normalize_uri env_proxy + uri = Gem::URI normalize_uri env_proxy env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY'] @@ -835,7 +835,7 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # Finishes then restarts the Net::HTTP +connection+ + # Finishes then restarts the Gem::Net::HTTP +connection+ def reset connection http = connection.http @@ -854,16 +854,16 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # Makes a request on +uri+. If +req+ is nil a Net::HTTP::Get is performed + # Makes a request on +uri+. If +req+ is nil a Gem::Net::HTTP::Get is performed # against +uri+. # - # If a block is passed #request behaves like Net::HTTP#request (the body of + # If a block is passed #request behaves like Gem::Net::HTTP#request (the body of # the response will not have been read). # - # +req+ must be a Net::HTTPGenericRequest subclass (see Net::HTTP for a list). + # +req+ must be a Gem::Net::HTTPGenericRequest subclass (see Gem::Net::HTTP for a list). def request uri, req = nil, &block - uri = Bundler::URI uri + uri = Gem::URI uri req = request_setup req || uri response = nil @@ -896,14 +896,14 @@ class Bundler::Persistent::Net::HTTP::Persistent end ## - # Creates a GET request if +req_or_uri+ is a Bundler::URI and adds headers to the + # Creates a GET request if +req_or_uri+ is a Gem::URI and adds headers to the # request. # # Returns the request. def request_setup req_or_uri # :nodoc: req = if req_or_uri.respond_to? 'request_uri' then - Net::HTTP::Get.new req_or_uri.request_uri + Gem::Net::HTTP::Get.new req_or_uri.request_uri else req_or_uri end diff --git a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb index a57a5d1352..8b9ab5cc78 100644 --- a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb +++ b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb @@ -1,8 +1,8 @@ ## -# A Net::HTTP connection wrapper that holds extra information for managing the +# A Gem::Net::HTTP connection wrapper that holds extra information for managing the # connection's lifetime. -class Bundler::Persistent::Net::HTTP::Persistent::Connection # :nodoc: +class Gem::Net::HTTP::Persistent::Connection # :nodoc: attr_accessor :http @@ -25,9 +25,10 @@ class Bundler::Persistent::Net::HTTP::Persistent::Connection # :nodoc: ensure reset end + alias_method :close, :finish def reset - @last_use = Bundler::Persistent::Net::HTTP::Persistent::EPOCH + @last_use = Gem::Net::HTTP::Persistent::EPOCH @requests = 0 end diff --git a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb index 9dfa6ffdb1..04a1e754bf 100644 --- a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb +++ b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb @@ -1,4 +1,4 @@ -class Bundler::Persistent::Net::HTTP::Persistent::Pool < Bundler::ConnectionPool # :nodoc: +class Gem::Net::HTTP::Persistent::Pool < Bundler::ConnectionPool # :nodoc: attr_reader :available # :nodoc: attr_reader :key # :nodoc: @@ -6,25 +6,37 @@ class Bundler::Persistent::Net::HTTP::Persistent::Pool < Bundler::ConnectionPool def initialize(options = {}, &block) super - @available = Bundler::Persistent::Net::HTTP::Persistent::TimedStackMulti.new(@size, &block) + @available = Gem::Net::HTTP::Persistent::TimedStackMulti.new(@size, &block) @key = "current-#{@available.object_id}" end def checkin net_http_args - stack = Thread.current[@key][net_http_args] ||= [] + if net_http_args.is_a?(Hash) && net_http_args.size == 1 && net_http_args[:force] + # Bundler::ConnectionPool 2.4+ calls `checkin(force: true)` after fork. + # When this happens, we should remove all connections from Thread.current + if stacks = Thread.current[@key] + stacks.each do |http_args, connections| + connections.each do |conn| + @available.push conn, connection_args: http_args + end + connections.clear + end + end + else + stack = Thread.current[@key][net_http_args] ||= [] - raise Bundler::ConnectionPool::Error, 'no connections are checked out' if - stack.empty? + raise Bundler::ConnectionPool::Error, 'no connections are checked out' if + stack.empty? - conn = stack.pop + conn = stack.pop - if stack.empty? - @available.push conn, connection_args: net_http_args + if stack.empty? + @available.push conn, connection_args: net_http_args - Thread.current[@key].delete(net_http_args) - Thread.current[@key] = nil if Thread.current[@key].empty? + Thread.current[@key].delete(net_http_args) + Thread.current[@key] = nil if Thread.current[@key].empty? + end end - nil end diff --git a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb index 2da881c554..214804fcd9 100644 --- a/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb +++ b/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb @@ -1,4 +1,4 @@ -class Bundler::Persistent::Net::HTTP::Persistent::TimedStackMulti < Bundler::ConnectionPool::TimedStack # :nodoc: +class Gem::Net::HTTP::Persistent::TimedStackMulti < Bundler::ConnectionPool::TimedStack # :nodoc: ## # Returns a new hash that has arrays for keys diff --git a/lib/bundler/vendor/pub_grub/.document b/lib/bundler/vendor/pub_grub/.document new file mode 100644 index 0000000000..0c43bbd6b3 --- /dev/null +++ b/lib/bundler/vendor/pub_grub/.document @@ -0,0 +1 @@ +# Vendored files do not need to be documented diff --git a/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb b/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb index 4bf61461b2..36ab06254d 100644 --- a/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +++ b/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb @@ -1,4 +1,5 @@ require_relative 'package' +require_relative 'rubygems' require_relative 'version_constraint' require_relative 'incompatibility' require_relative 'basic_package_source' diff --git a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb index 2cb8412cf3..4caf6b355b 100644 --- a/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +++ b/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb @@ -162,7 +162,7 @@ module Bundler::PubGrub def resolve_conflict(incompatibility) logger.info { "conflict: #{incompatibility}" } - new_incompatibility = false + new_incompatibility = nil while !incompatibility.failure? most_recent_term = nil @@ -204,7 +204,7 @@ module Bundler::PubGrub solution.backtrack(previous_level) if new_incompatibility - add_incompatibility(incompatibility) + add_incompatibility(new_incompatibility) end return incompatibility @@ -219,9 +219,14 @@ module Bundler::PubGrub new_terms << difference.invert end - incompatibility = Incompatibility.new(new_terms, cause: Incompatibility::ConflictCause.new(incompatibility, most_recent_satisfier.cause)) + new_incompatibility = Incompatibility.new(new_terms, cause: Incompatibility::ConflictCause.new(incompatibility, most_recent_satisfier.cause)) - new_incompatibility = true + if incompatibility.to_s == new_incompatibility.to_s + logger.info { "!! failed to resolve conflicts, this shouldn't have happened" } + break + end + + incompatibility = new_incompatibility partially = difference ? " partially" : "" logger.info { "! #{most_recent_term} is#{partially} satisfied by #{most_recent_satisfier.term}" } diff --git a/lib/bundler/vendor/thor/.document b/lib/bundler/vendor/thor/.document new file mode 100644 index 0000000000..0c43bbd6b3 --- /dev/null +++ b/lib/bundler/vendor/thor/.document @@ -0,0 +1 @@ +# Vendored files do not need to be documented diff --git a/lib/bundler/vendor/thor/lib/thor.rb b/lib/bundler/vendor/thor/lib/thor.rb index 83ebe25593..627722164f 100644 --- a/lib/bundler/vendor/thor/lib/thor.rb +++ b/lib/bundler/vendor/thor/lib/thor.rb @@ -65,8 +65,15 @@ class Bundler::Thor # Defines the long description of the next command. # + # Long description is by default indented, line-wrapped and repeated whitespace merged. + # In order to print long description verbatim, with indentation and spacing exactly + # as found in the code, use the +wrap+ option + # + # long_desc 'your very long description', wrap: false + # # ==== Parameters # long description<String> + # options<Hash> # def long_desc(long_description, options = {}) if options[:for] @@ -74,6 +81,7 @@ class Bundler::Thor command.long_description = long_description if long_description else @long_desc = long_description + @long_desc_wrap = options[:wrap] != false end end @@ -133,7 +141,7 @@ class Bundler::Thor # # magic # end # - # method_option :foo => :bar, :for => :previous_command + # method_option :foo, :for => :previous_command # # def next_command # # magic @@ -153,6 +161,9 @@ class Bundler::Thor # :hide - If you want to hide this option from the help. # def method_option(name, options = {}) + unless [ Symbol, String ].any? { |klass| name.is_a?(klass) } + raise ArgumentError, "Expected a Symbol or String, got #{name.inspect}" + end scope = if options[:for] find_and_refresh_command(options[:for]).options else @@ -163,6 +174,81 @@ class Bundler::Thor end alias_method :option, :method_option + # Adds and declares option group for exclusive options in the + # block and arguments. You can declare options as the outside of the block. + # + # If :for is given as option, it allows you to change the options from + # a previous defined command. + # + # ==== Parameters + # Array[Bundler::Thor::Option.name] + # options<Hash>:: :for is applied for previous defined command. + # + # ==== Examples + # + # exclusive do + # option :one + # option :two + # end + # + # Or + # + # option :one + # option :two + # exclusive :one, :two + # + # If you give "--one" and "--two" at the same time ExclusiveArgumentsError + # will be raised. + # + def method_exclusive(*args, &block) + register_options_relation_for(:method_options, + :method_exclusive_option_names, *args, &block) + end + alias_method :exclusive, :method_exclusive + + # Adds and declares option group for required at least one of options in the + # block of arguments. You can declare options as the outside of the block. + # + # If :for is given as option, it allows you to change the options from + # a previous defined command. + # + # ==== Parameters + # Array[Bundler::Thor::Option.name] + # options<Hash>:: :for is applied for previous defined command. + # + # ==== Examples + # + # at_least_one do + # option :one + # option :two + # end + # + # Or + # + # option :one + # option :two + # at_least_one :one, :two + # + # If you do not give "--one" and "--two" AtLeastOneRequiredArgumentError + # will be raised. + # + # You can use at_least_one and exclusive at the same time. + # + # exclusive do + # at_least_one do + # option :one + # option :two + # end + # end + # + # Then it is required either only one of "--one" or "--two". + # + def method_at_least_one(*args, &block) + register_options_relation_for(:method_options, + :method_at_least_one_option_names, *args, &block) + end + alias_method :at_least_one, :method_at_least_one + # Prints help information for the given command. # # ==== Parameters @@ -178,9 +264,16 @@ class Bundler::Thor shell.say " #{banner(command).split("\n").join("\n ")}" shell.say class_options_help(shell, nil => command.options.values) + print_exclusive_options(shell, command) + print_at_least_one_required_options(shell, command) + if command.long_description shell.say "Description:" - shell.print_wrapped(command.long_description, :indent => 2) + if command.wrap_long_description + shell.print_wrapped(command.long_description, indent: 2) + else + shell.say command.long_description + end else shell.say command.description end @@ -197,7 +290,7 @@ class Bundler::Thor Bundler::Thor::Util.thor_classes_in(self).each do |klass| list += klass.printable_commands(false) end - list.sort! { |a, b| a[0] <=> b[0] } + sort_commands!(list) if defined?(@package_name) && @package_name shell.say "#{@package_name} commands:" @@ -205,9 +298,11 @@ class Bundler::Thor shell.say "Commands:" end - shell.print_table(list, :indent => 2, :truncate => true) + shell.print_table(list, indent: 2, truncate: true) shell.say class_options_help(shell) + print_exclusive_options(shell) + print_at_least_one_required_options(shell) end # Returns commands ready to be printed. @@ -238,7 +333,7 @@ class Bundler::Thor define_method(subcommand) do |*args| args, opts = Bundler::Thor::Arguments.split(args) - invoke_args = [args, opts, {:invoked_via_subcommand => true, :class_options => options}] + invoke_args = [args, opts, {invoked_via_subcommand: true, class_options: options}] invoke_args.unshift "help" if opts.delete("--help") || opts.delete("-h") invoke subcommand_class, *invoke_args end @@ -346,6 +441,24 @@ class Bundler::Thor protected + # Returns this class exclusive options array set. + # + # ==== Returns + # Array[Array[Bundler::Thor::Option.name]] + # + def method_exclusive_option_names #:nodoc: + @method_exclusive_option_names ||= [] + end + + # Returns this class at least one of required options array set. + # + # ==== Returns + # Array[Array[Bundler::Thor::Option.name]] + # + def method_at_least_one_option_names #:nodoc: + @method_at_least_one_option_names ||= [] + end + def stop_on_unknown_option #:nodoc: @stop_on_unknown_option ||= [] end @@ -355,6 +468,28 @@ class Bundler::Thor @disable_required_check ||= [:help] end + def print_exclusive_options(shell, command = nil) # :nodoc: + opts = [] + opts = command.method_exclusive_option_names unless command.nil? + opts += class_exclusive_option_names + unless opts.empty? + shell.say "Exclusive Options:" + shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, indent: 2 ) + shell.say + end + end + + def print_at_least_one_required_options(shell, command = nil) # :nodoc: + opts = [] + opts = command.method_at_least_one_option_names unless command.nil? + opts += class_at_least_one_option_names + unless opts.empty? + shell.say "Required At Least One:" + shell.print_table(opts.map{ |ex| ex.map{ |e| "--#{e}"}}, indent: 2 ) + shell.say + end + end + # The method responsible for dispatching given the args. def dispatch(meth, given_args, given_opts, config) #:nodoc: meth ||= retrieve_command_name(given_args) @@ -415,12 +550,16 @@ class Bundler::Thor @usage ||= nil @desc ||= nil @long_desc ||= nil + @long_desc_wrap ||= nil @hide ||= nil if @usage && @desc base_class = @hide ? Bundler::Thor::HiddenCommand : Bundler::Thor::Command - commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options) - @usage, @desc, @long_desc, @method_options, @hide = nil + relations = {exclusive_option_names: method_exclusive_option_names, + at_least_one_option_names: method_at_least_one_option_names} + commands[meth] = base_class.new(meth, @desc, @long_desc, @long_desc_wrap, @usage, method_options, relations) + @usage, @desc, @long_desc, @long_desc_wrap, @method_options, @hide = nil + @method_exclusive_option_names, @method_at_least_one_option_names = nil true elsif all_commands[meth] || meth == "method_missing" true @@ -495,6 +634,14 @@ class Bundler::Thor " end alias_method :subtask_help, :subcommand_help + + # Sort the commands, lexicographically by default. + # + # Can be overridden in the subclass to change the display order of the + # commands. + def sort_commands!(list) + list.sort! { |a, b| a[0] <=> b[0] } + end end include Bundler::Thor::Base diff --git a/lib/bundler/vendor/thor/lib/thor/actions.rb b/lib/bundler/vendor/thor/lib/thor/actions.rb index a7afaf1d07..ca58182691 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions.rb @@ -46,17 +46,17 @@ class Bundler::Thor # Add runtime options that help actions execution. # def add_runtime_options! - class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime, - :desc => "Overwrite files that already exist" + class_option :force, type: :boolean, aliases: "-f", group: :runtime, + desc: "Overwrite files that already exist" - class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime, - :desc => "Run but do not make any changes" + class_option :pretend, type: :boolean, aliases: "-p", group: :runtime, + desc: "Run but do not make any changes" - class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime, - :desc => "Suppress status output" + class_option :quiet, type: :boolean, aliases: "-q", group: :runtime, + desc: "Suppress status output" - class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime, - :desc => "Skip files that already exist" + class_option :skip, type: :boolean, aliases: "-s", group: :runtime, + desc: "Skip files that already exist" end end @@ -113,9 +113,9 @@ class Bundler::Thor # def relative_to_original_destination_root(path, remove_dot = true) root = @destination_stack[0] - if path.start_with?(root) && [File::SEPARATOR, File::ALT_SEPARATOR, nil, ''].include?(path[root.size..root.size]) + if path.start_with?(root) && [File::SEPARATOR, File::ALT_SEPARATOR, nil, ""].include?(path[root.size..root.size]) path = path.dup - path[0...root.size] = '.' + path[0...root.size] = "." remove_dot ? (path[2..-1] || "") : path else path @@ -223,8 +223,7 @@ class Bundler::Thor contents = if is_uri require "open-uri" - # for ruby 2.1-2.4 - URI.send(:open, path, "Accept" => "application/x-thor-template", &:read) + URI.open(path, "Accept" => "application/x-thor-template", &:read) else File.open(path, &:read) end @@ -285,7 +284,7 @@ class Bundler::Thor # def run_ruby_script(command, config = {}) return unless behavior == :invoke - run command, config.merge(:with => Bundler::Thor::Util.ruby_command) + run command, config.merge(with: Bundler::Thor::Util.ruby_command) end # Run a thor command. A hash of options can be given and it's converted to @@ -316,7 +315,7 @@ class Bundler::Thor args.push Bundler::Thor::Options.to_switches(config) command = args.join(" ").strip - run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture + run command, with: :thor, verbose: verbose, pretend: pretend, capture: capture end protected @@ -324,7 +323,7 @@ class Bundler::Thor # Allow current root to be shared between invocations. # def _shared_configuration #:nodoc: - super.merge!(:destination_root => destination_root) + super.merge!(destination_root: destination_root) end def _cleanup_options_and_set(options, key) #:nodoc: diff --git a/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb b/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb index 1b90e567ba..6724835b01 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb @@ -43,7 +43,8 @@ class Bundler::Thor # Boolean:: true if it is identical, false otherwise. # def identical? - exists? && File.binread(destination) == render + # binread uses ASCII-8BIT, so to avoid false negatives, the string must use the same + exists? && File.binread(destination) == String.new(render).force_encoding("ASCII-8BIT") end # Holds the content to be added to the file. diff --git a/lib/bundler/vendor/thor/lib/thor/actions/directory.rb b/lib/bundler/vendor/thor/lib/thor/actions/directory.rb index d37327a139..2f9687c0a5 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/directory.rb @@ -58,7 +58,7 @@ class Bundler::Thor def initialize(base, source, destination = nil, config = {}, &block) @source = File.expand_path(Dir[Util.escape_globs(base.find_in_source_paths(source.to_s))].first) @block = block - super(base, destination, {:recursive => true}.merge(config)) + super(base, destination, {recursive: true}.merge(config)) end def invoke! diff --git a/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb b/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb index 284d92c19a..c0bca78525 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb @@ -33,7 +33,7 @@ class Bundler::Thor # def initialize(base, destination, config = {}) @base = base - @config = {:verbose => true}.merge(config) + @config = {verbose: true}.merge(config) self.destination = destination end diff --git a/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb b/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb index ffc29aa8e2..80a0255996 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb @@ -66,12 +66,15 @@ class Bundler::Thor # ==== Parameters # source<String>:: the address of the given content. # destination<String>:: the relative path to the destination root. - # config<Hash>:: give :verbose => false to not log the status. + # config<Hash>:: give :verbose => false to not log the status, and + # :http_headers => <Hash> to add headers to an http request. # # ==== Examples # # get "http://gist.github.com/103208", "doc/README" # + # get "http://gist.github.com/103208", "doc/README", :http_headers => {"Content-Type" => "application/json"} + # # get "http://gist.github.com/103208" do |content| # content.split("\n").first # end @@ -82,7 +85,7 @@ class Bundler::Thor render = if source =~ %r{^https?\://} require "open-uri" - URI.send(:open, source) { |input| input.binmode.read } + URI.send(:open, source, config.fetch(:http_headers, {})) { |input| input.binmode.read } else source = File.expand_path(find_in_source_paths(source.to_s)) File.open(source) { |input| input.binmode.read } @@ -120,12 +123,7 @@ class Bundler::Thor context = config.delete(:context) || instance_eval("binding") create_file destination, nil, config do - match = ERB.version.match(/(\d+\.\d+\.\d+)/) - capturable_erb = if match && match[1] >= "2.2.0" # Ruby 2.6+ - CapturableERB.new(::File.binread(source), :trim_mode => "-", :eoutvar => "@output_buffer") - else - CapturableERB.new(::File.binread(source), nil, "-", "@output_buffer") - end + capturable_erb = CapturableERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer") content = capturable_erb.tap do |erb| erb.filename = source end.result(context) diff --git a/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb b/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb index 6572f7a4f1..70526e615f 100644 --- a/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +++ b/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb @@ -21,7 +21,7 @@ class Bundler::Thor # gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n") # end # - WARNINGS = { unchanged_no_flag: 'File unchanged! Either the supplied flag value not found or the content has already been inserted!' } + WARNINGS = {unchanged_no_flag: "File unchanged! Either the supplied flag value not found or the content has already been inserted!"} def insert_into_file(destination, *args, &block) data = block_given? ? block : args.shift @@ -37,7 +37,7 @@ class Bundler::Thor attr_reader :replacement, :flag, :behavior def initialize(base, destination, data, config) - super(base, destination, {:verbose => true}.merge(config)) + super(base, destination, {verbose: true}.merge(config)) @behavior, @flag = if @config.key?(:after) [:after, @config.delete(:after)] @@ -59,6 +59,8 @@ class Bundler::Thor if exists? if replace!(/#{flag}/, content, config[:force]) say_status(:invoke) + elsif replacement_present? + say_status(:unchanged, color: :blue) else say_status(:unchanged, warning: WARNINGS[:unchanged_no_flag], color: :red) end @@ -96,6 +98,8 @@ class Bundler::Thor end elsif warning warning + elsif behavior == :unchanged + :unchanged else :subtract end @@ -103,11 +107,18 @@ class Bundler::Thor super(status, (color || config[:verbose])) end + def content + @content ||= File.read(destination) + end + + def replacement_present? + content.include?(replacement) + end + # Adds the content to the file. # def replace!(regexp, string, force) - content = File.read(destination) - if force || !content.include?(replacement) + if force || !replacement_present? success = content.gsub!(regexp, string) File.open(destination, "wb") { |file| file.write(content) } unless pretend? diff --git a/lib/bundler/vendor/thor/lib/thor/base.rb b/lib/bundler/vendor/thor/lib/thor/base.rb index 211855680c..b156899c1e 100644 --- a/lib/bundler/vendor/thor/lib/thor/base.rb +++ b/lib/bundler/vendor/thor/lib/thor/base.rb @@ -24,9 +24,9 @@ class Bundler::Thor class << self def deprecation_warning(message) #:nodoc: - unless ENV['THOR_SILENCE_DEPRECATION'] + unless ENV["THOR_SILENCE_DEPRECATION"] warn "Deprecation warning: #{message}\n" + - 'You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.' + "You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION." end end end @@ -60,6 +60,7 @@ class Bundler::Thor command_options = config.delete(:command_options) # hook for start parse_options = parse_options.merge(command_options) if command_options + if local_options.is_a?(Array) array_options = local_options hash_options = {} @@ -73,9 +74,24 @@ class Bundler::Thor # Let Bundler::Thor::Options parse the options first, so it can remove # declared options from the array. This will leave us with # a list of arguments that weren't declared. - stop_on_unknown = self.class.stop_on_unknown_option? config[:current_command] - disable_required_check = self.class.disable_required_check? config[:current_command] - opts = Bundler::Thor::Options.new(parse_options, hash_options, stop_on_unknown, disable_required_check) + current_command = config[:current_command] + stop_on_unknown = self.class.stop_on_unknown_option? current_command + + # Give a relation of options. + # After parsing, Bundler::Thor::Options check whether right relations are kept + relations = if current_command.nil? + {exclusive_option_names: [], at_least_one_option_names: []} + else + current_command.options_relation + end + + self.class.class_exclusive_option_names.map { |n| relations[:exclusive_option_names] << n } + self.class.class_at_least_one_option_names.map { |n| relations[:at_least_one_option_names] << n } + + disable_required_check = self.class.disable_required_check? current_command + + opts = Bundler::Thor::Options.new(parse_options, hash_options, stop_on_unknown, disable_required_check, relations) + self.options = opts.parse(array_options) self.options = config[:class_options].merge(options) if config[:class_options] @@ -310,9 +326,92 @@ class Bundler::Thor # :hide:: -- If you want to hide this option from the help. # def class_option(name, options = {}) + unless [ Symbol, String ].any? { |klass| name.is_a?(klass) } + raise ArgumentError, "Expected a Symbol or String, got #{name.inspect}" + end build_option(name, options, class_options) end + # Adds and declares option group for exclusive options in the + # block and arguments. You can declare options as the outside of the block. + # + # ==== Parameters + # Array[Bundler::Thor::Option.name] + # + # ==== Examples + # + # class_exclusive do + # class_option :one + # class_option :two + # end + # + # Or + # + # class_option :one + # class_option :two + # class_exclusive :one, :two + # + # If you give "--one" and "--two" at the same time ExclusiveArgumentsError + # will be raised. + # + def class_exclusive(*args, &block) + register_options_relation_for(:class_options, + :class_exclusive_option_names, *args, &block) + end + + # Adds and declares option group for required at least one of options in the + # block and arguments. You can declare options as the outside of the block. + # + # ==== Examples + # + # class_at_least_one do + # class_option :one + # class_option :two + # end + # + # Or + # + # class_option :one + # class_option :two + # class_at_least_one :one, :two + # + # If you do not give "--one" and "--two" AtLeastOneRequiredArgumentError + # will be raised. + # + # You can use class_at_least_one and class_exclusive at the same time. + # + # class_exclusive do + # class_at_least_one do + # class_option :one + # class_option :two + # end + # end + # + # Then it is required either only one of "--one" or "--two". + # + def class_at_least_one(*args, &block) + register_options_relation_for(:class_options, + :class_at_least_one_option_names, *args, &block) + end + + # Returns this class exclusive options array set, looking up in the ancestors chain. + # + # ==== Returns + # Array[Array[Bundler::Thor::Option.name]] + # + def class_exclusive_option_names + @class_exclusive_option_names ||= from_superclass(:class_exclusive_option_names, []) + end + + # Returns this class at least one of required options array set, looking up in the ancestors chain. + # + # ==== Returns + # Array[Array[Bundler::Thor::Option.name]] + # + def class_at_least_one_option_names + @class_at_least_one_option_names ||= from_superclass(:class_at_least_one_option_names, []) + end + # Removes a previous defined argument. If :undefine is given, undefine # accessors as well. # @@ -565,12 +664,12 @@ class Bundler::Thor item.push(option.description ? "# #{option.description}" : "") list << item - list << ["", "# Default: #{option.default}"] if option.show_default? - list << ["", "# Possible values: #{option.enum.join(', ')}"] if option.enum + list << ["", "# Default: #{option.print_default}"] if option.show_default? + list << ["", "# Possible values: #{option.enum_to_s}"] if option.enum end shell.say(group_name ? "#{group_name} options:" : "Options:") - shell.print_table(list, :indent => 2) + shell.print_table(list, indent: 2) shell.say "" end @@ -587,7 +686,7 @@ class Bundler::Thor # options<Hash>:: Described in both class_option and method_option. # scope<Hash>:: Options hash that is being built up def build_option(name, options, scope) #:nodoc: - scope[name] = Bundler::Thor::Option.new(name, {:check_default_type => check_default_type}.merge!(options)) + scope[name] = Bundler::Thor::Option.new(name, {check_default_type: check_default_type}.merge!(options)) end # Receives a hash of options, parse them and add to the scope. This is a @@ -693,6 +792,34 @@ class Bundler::Thor def dispatch(command, given_args, given_opts, config) #:nodoc: raise NotImplementedError end + + # Register a relation of options for target(method_option/class_option) + # by args and block. + def register_options_relation_for(target, relation, *args, &block) # :nodoc: + opt = args.pop if args.last.is_a? Hash + opt ||= {} + names = args.map{ |arg| arg.to_s } + names += built_option_names(target, opt, &block) if block_given? + command_scope_member(relation, opt) << names + end + + # Get target(method_options or class_options) options + # of before and after by block evaluation. + def built_option_names(target, opt = {}, &block) # :nodoc: + before = command_scope_member(target, opt).map{ |k,v| v.name } + instance_eval(&block) + after = command_scope_member(target, opt).map{ |k,v| v.name } + after - before + end + + # Get command scope member by name. + def command_scope_member(name, options = {}) # :nodoc: + if options[:for] + find_and_refresh_command(options[:for]).send(name) + else + send(name) + end + end end end end diff --git a/lib/bundler/vendor/thor/lib/thor/command.rb b/lib/bundler/vendor/thor/lib/thor/command.rb index 040c971c0c..68c8fffedb 100644 --- a/lib/bundler/vendor/thor/lib/thor/command.rb +++ b/lib/bundler/vendor/thor/lib/thor/command.rb @@ -1,14 +1,15 @@ class Bundler::Thor - class Command < Struct.new(:name, :description, :long_description, :usage, :options, :ancestor_name) + class Command < Struct.new(:name, :description, :long_description, :wrap_long_description, :usage, :options, :options_relation, :ancestor_name) FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/ - def initialize(name, description, long_description, usage, options = nil) - super(name.to_s, description, long_description, usage, options || {}) + def initialize(name, description, long_description, wrap_long_description, usage, options = nil, options_relation = nil) + super(name.to_s, description, long_description, wrap_long_description, usage, options || {}, options_relation || {}) end def initialize_copy(other) #:nodoc: super(other) self.options = other.options.dup if other.options + self.options_relation = other.options_relation.dup if other.options_relation end def hidden? @@ -62,6 +63,14 @@ class Bundler::Thor end.join("\n") end + def method_exclusive_option_names #:nodoc: + self.options_relation[:exclusive_option_names] || [] + end + + def method_at_least_one_option_names #:nodoc: + self.options_relation[:at_least_one_option_names] || [] + end + protected # Add usage with required arguments @@ -127,7 +136,7 @@ class Bundler::Thor # A dynamic command that handles method missing scenarios. class DynamicCommand < Command def initialize(name, options = nil) - super(name.to_s, "A dynamically-generated command", name.to_s, name.to_s, options) + super(name.to_s, "A dynamically-generated command", name.to_s, nil, name.to_s, options) end def run(instance, args = []) diff --git a/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb b/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb index 3c4483e5dd..b16a98f782 100644 --- a/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +++ b/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb @@ -38,6 +38,10 @@ class Bundler::Thor super(convert_key(key), *args) end + def slice(*keys) + super(*keys.map{ |key| convert_key(key) }) + end + def key?(key) super(convert_key(key)) end diff --git a/lib/bundler/vendor/thor/lib/thor/error.rb b/lib/bundler/vendor/thor/lib/thor/error.rb index dd64f750c9..928646e501 100644 --- a/lib/bundler/vendor/thor/lib/thor/error.rb +++ b/lib/bundler/vendor/thor/lib/thor/error.rb @@ -1,26 +1,15 @@ class Bundler::Thor Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable) # rubocop:disable Naming/ConstantName - # In order to support versions of Ruby that don't have keyword - # arguments, we need our own spell checker class that doesn't take key - # words. Even though this code wouldn't be hit because of the check - # above, it's still necessary because the interpreter would otherwise be - # unable to parse the file. - class NoKwargSpellChecker < DidYouMean::SpellChecker # :nodoc: - def initialize(dictionary) - @dictionary = dictionary - end - end - - Module.new do - def to_s - super + DidYouMean.formatter.message_for(corrections) - end - - def corrections - @corrections ||= self.class.const_get(:SpellChecker).new(self).corrections - end - end - end + Module.new do + def to_s + super + DidYouMean.formatter.message_for(corrections) + end + + def corrections + @corrections ||= self.class.const_get(:SpellChecker).new(self).corrections + end + end + end # Bundler::Thor::Error is raised when it's caused by wrong usage of thor classes. Those # errors have their backtrace suppressed and are nicely shown to the user. @@ -45,7 +34,7 @@ class Bundler::Thor end def spell_checker - NoKwargSpellChecker.new(error.all_commands) + DidYouMean::SpellChecker.new(dictionary: error.all_commands) end end @@ -87,7 +76,7 @@ class Bundler::Thor end def spell_checker - @spell_checker ||= NoKwargSpellChecker.new(error.switches) + @spell_checker ||= DidYouMean::SpellChecker.new(dictionary: error.switches) end end @@ -108,4 +97,10 @@ class Bundler::Thor class MalformattedArgumentError < InvocationError end + + class ExclusiveArgumentError < InvocationError + end + + class AtLeastOneRequiredArgumentError < InvocationError + end end diff --git a/lib/bundler/vendor/thor/lib/thor/invocation.rb b/lib/bundler/vendor/thor/lib/thor/invocation.rb index 248a466f8e..5ce74710ba 100644 --- a/lib/bundler/vendor/thor/lib/thor/invocation.rb +++ b/lib/bundler/vendor/thor/lib/thor/invocation.rb @@ -143,7 +143,7 @@ class Bundler::Thor # Configuration values that are shared between invocations. def _shared_configuration #:nodoc: - {:invocations => @_invocations} + {invocations: @_invocations} end # This method simply retrieves the class and command to be invoked. diff --git a/lib/bundler/vendor/thor/lib/thor/nested_context.rb b/lib/bundler/vendor/thor/lib/thor/nested_context.rb index fd36b9d43f..7d60cb1c12 100644 --- a/lib/bundler/vendor/thor/lib/thor/nested_context.rb +++ b/lib/bundler/vendor/thor/lib/thor/nested_context.rb @@ -13,10 +13,10 @@ class Bundler::Thor end def entered? - @depth > 0 + @depth.positive? end - private + private def push @depth += 1 diff --git a/lib/bundler/vendor/thor/lib/thor/parser/argument.rb b/lib/bundler/vendor/thor/lib/thor/parser/argument.rb index dfe7398583..b9e94e4669 100644 --- a/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +++ b/lib/bundler/vendor/thor/lib/thor/parser/argument.rb @@ -24,6 +24,17 @@ class Bundler::Thor validate! # Trigger specific validations end + def print_default + if @type == :array and @default.is_a?(Array) + @default.map { |x| + p = x.gsub('"','\\"') + "\"#{p}\"" + }.join(" ") + else + @default + end + end + def usage required? ? banner : "[#{banner}]" end @@ -41,11 +52,19 @@ class Bundler::Thor end end + def enum_to_s + if enum.respond_to? :join + enum.join(", ") + else + "#{enum.first}..#{enum.last}" + end + end + protected def validate! raise ArgumentError, "An argument cannot be required and have default value." if required? && !default.nil? - raise ArgumentError, "An argument cannot have an enum other than an array." if @enum && !@enum.is_a?(Array) + raise ArgumentError, "An argument cannot have an enum other than an enumerable." if @enum && !@enum.is_a?(Enumerable) end def valid_type?(type) diff --git a/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb b/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb index af395a0346..b6f9c9a37a 100644 --- a/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +++ b/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb @@ -30,11 +30,7 @@ class Bundler::Thor arguments.each do |argument| if !argument.default.nil? - begin - @assigns[argument.human_name] = argument.default.dup - rescue TypeError # Compatibility shim for un-dup-able Fixnum in Ruby < 2.4 - @assigns[argument.human_name] = argument.default - end + @assigns[argument.human_name] = argument.default.dup elsif argument.required? @non_assigned_required << argument end @@ -121,8 +117,18 @@ class Bundler::Thor # def parse_array(name) return shift if peek.is_a?(Array) + array = [] - array << shift while current_is_value? + + while current_is_value? + value = shift + + if !value.empty? + validate_enum_value!(name, value, "Expected all values of '%s' to be one of %s; got %s") + end + + array << value + end array end @@ -138,11 +144,9 @@ class Bundler::Thor end value = $&.index(".") ? shift.to_f : shift.to_i - if @switches.is_a?(Hash) && switch = @switches[name] - if switch.enum && !switch.enum.include?(value) - raise MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}" - end - end + + validate_enum_value!(name, value, "Expected '%s' to be one of %s; got %s") + value end @@ -156,15 +160,27 @@ class Bundler::Thor nil else value = shift - if @switches.is_a?(Hash) && switch = @switches[name] - if switch.enum && !switch.enum.include?(value) - raise MalformattedArgumentError, "Expected '#{name}' to be one of #{switch.enum.join(', ')}; got #{value}" - end - end + + validate_enum_value!(name, value, "Expected '%s' to be one of %s; got %s") + value end end + # Raises an error if the switch is an enum and the values aren't included on it. + # + def validate_enum_value!(name, value, message) + return unless @switches.is_a?(Hash) + + switch = @switches[name] + + return unless switch + + if switch.enum && !switch.enum.include?(value) + raise MalformattedArgumentError, message % [name, switch.enum_to_s, value] + end + end + # Raises an error if @non_assigned_required array is not empty. # def check_requirement! diff --git a/lib/bundler/vendor/thor/lib/thor/parser/option.rb b/lib/bundler/vendor/thor/lib/thor/parser/option.rb index 393955f107..c6af4e1e87 100644 --- a/lib/bundler/vendor/thor/lib/thor/parser/option.rb +++ b/lib/bundler/vendor/thor/lib/thor/parser/option.rb @@ -11,7 +11,7 @@ class Bundler::Thor super @lazy_default = options[:lazy_default] @group = options[:group].to_s.capitalize if options[:group] - @aliases = Array(options[:aliases]) + @aliases = normalize_aliases(options[:aliases]) @hide = options[:hide] end @@ -69,7 +69,7 @@ class Bundler::Thor value.class.name.downcase.to_sym end - new(name.to_s, :required => required, :type => type, :default => default, :aliases => aliases) + new(name.to_s, required: required, type: type, default: default, aliases: aliases) end def switch_name @@ -90,7 +90,7 @@ class Bundler::Thor sample = "[#{sample}]".dup unless required? if boolean? - sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-") + sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.match(/\Ano[\-_]/) end aliases_for_usage.ljust(padding) + sample @@ -104,6 +104,15 @@ class Bundler::Thor end end + def show_default? + case default + when TrueClass, FalseClass + true + else + super + end + end + VALID_TYPES.each do |type| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{type}? @@ -142,8 +151,8 @@ class Bundler::Thor raise ArgumentError, err elsif @check_default_type == nil Bundler::Thor.deprecation_warning "#{err}.\n" + - 'This will be rejected in the future unless you explicitly pass the options `check_default_type: false`' + - ' or call `allow_incompatible_default_type!` in your code' + "This will be rejected in the future unless you explicitly pass the options `check_default_type: false`" + + " or call `allow_incompatible_default_type!` in your code" end end end @@ -159,5 +168,11 @@ class Bundler::Thor def dasherize(str) (str.length > 1 ? "--" : "-") + str.tr("_", "-") end + + private + + def normalize_aliases(aliases) + Array(aliases).map { |short| short.to_s.sub(/^(?!\-)/, "-") } + end end end diff --git a/lib/bundler/vendor/thor/lib/thor/parser/options.rb b/lib/bundler/vendor/thor/lib/thor/parser/options.rb index 499ce15339..978e76b132 100644 --- a/lib/bundler/vendor/thor/lib/thor/parser/options.rb +++ b/lib/bundler/vendor/thor/lib/thor/parser/options.rb @@ -29,8 +29,10 @@ class Bundler::Thor # # If +stop_on_unknown+ is true, #parse will stop as soon as it encounters # an unknown option or a regular argument. - def initialize(hash_options = {}, defaults = {}, stop_on_unknown = false, disable_required_check = false) + def initialize(hash_options = {}, defaults = {}, stop_on_unknown = false, disable_required_check = false, relations = {}) @stop_on_unknown = stop_on_unknown + @exclusives = (relations[:exclusive_option_names] || []).select{|array| !array.empty?} + @at_least_ones = (relations[:at_least_one_option_names] || []).select{|array| !array.empty?} @disable_required_check = disable_required_check options = hash_options.values super(options) @@ -50,8 +52,7 @@ class Bundler::Thor options.each do |option| @switches[option.switch_name] = option - option.aliases.each do |short| - name = short.to_s.sub(/^(?!\-)/, "-") + option.aliases.each do |name| @shorts[name] ||= option.switch_name end end @@ -101,7 +102,7 @@ class Bundler::Thor unshift($1.split("").map { |f| "-#{f}" }) next when EQ_RE - unshift($2, :is_value => true) + unshift($2, is_value: true) switch = $1 when SHORT_NUM unshift($2) @@ -132,12 +133,38 @@ class Bundler::Thor end check_requirement! unless @disable_required_check + check_exclusive! + check_at_least_one! assigns = Bundler::Thor::CoreExt::HashWithIndifferentAccess.new(@assigns) assigns.freeze assigns end + def check_exclusive! + opts = @assigns.keys + # When option A and B are exclusive, if A and B are given at the same time, + # the diffrence of argument array size will decrease. + found = @exclusives.find{ |ex| (ex - opts).size < ex.size - 1 } + if found + names = names_to_switch_names(found & opts).map{|n| "'#{n}'"} + class_name = self.class.name.split("::").last.downcase + fail ExclusiveArgumentError, "Found exclusive #{class_name} #{names.join(", ")}" + end + end + + def check_at_least_one! + opts = @assigns.keys + # When at least one is required of the options A and B, + # if the both options were not given, none? would be true. + found = @at_least_ones.find{ |one_reqs| one_reqs.none?{ |o| opts.include? o} } + if found + names = names_to_switch_names(found).map{|n| "'#{n}'"} + class_name = self.class.name.split("::").last.downcase + fail AtLeastOneRequiredArgumentError, "Not found at least one of required #{class_name} #{names.join(", ")}" + end + end + def check_unknown! to_check = @stopped_parsing_after_extra_index ? @extra[0...@stopped_parsing_after_extra_index] : @extra @@ -148,6 +175,17 @@ class Bundler::Thor protected + # Option names changes to swith name or human name + def names_to_switch_names(names = []) + @switches.map do |_, o| + if names.include? o.name + o.respond_to?(:switch_name) ? o.switch_name : o.human_name + else + nil + end + end.compact + end + def assign_result!(option, result) if option.repeatable && option.type == :hash (@assigns[option.human_name] ||= {}).merge!(result) diff --git a/lib/bundler/vendor/thor/lib/thor/runner.rb b/lib/bundler/vendor/thor/lib/thor/runner.rb index 8157c6c5b2..c7cc873131 100644 --- a/lib/bundler/vendor/thor/lib/thor/runner.rb +++ b/lib/bundler/vendor/thor/lib/thor/runner.rb @@ -23,7 +23,7 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: initialize_thorfiles(meth) klass, command = Bundler::Thor::Util.find_class_and_command_by_namespace(meth) self.class.handle_no_command_error(command, false) if klass.nil? - klass.start(["-h", command].compact, :shell => shell) + klass.start(["-h", command].compact, shell: shell) else super end @@ -38,11 +38,11 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: klass, command = Bundler::Thor::Util.find_class_and_command_by_namespace(meth) self.class.handle_no_command_error(command, false) if klass.nil? args.unshift(command) if command - klass.start(args, :shell => shell) + klass.start(args, shell: shell) end desc "install NAME", "Install an optionally named Bundler::Thor file into your system commands" - method_options :as => :string, :relative => :boolean, :force => :boolean + method_options as: :string, relative: :boolean, force: :boolean def install(name) # rubocop:disable Metrics/MethodLength initialize_thorfiles @@ -53,7 +53,7 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: package = :file require "open-uri" begin - contents = URI.send(:open, name, &:read) # Using `send` for Ruby 2.4- support + contents = URI.open(name, &:read) rescue OpenURI::HTTPError raise Error, "Error opening URI '#{name}'" end @@ -69,7 +69,7 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: base = name package = :file require "open-uri" - contents = URI.send(:open, name, &:read) # for ruby 2.1-2.4 + contents = URI.open(name, &:read) end rescue Errno::ENOENT raise Error, "Error opening file '#{name}'" @@ -101,9 +101,9 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: end thor_yaml[as] = { - :filename => Digest::SHA256.hexdigest(name + as), - :location => location, - :namespaces => Bundler::Thor::Util.namespaces_in_content(contents, base) + filename: Digest::SHA256.hexdigest(name + as), + location: location, + namespaces: Bundler::Thor::Util.namespaces_in_content(contents, base) } save_yaml(thor_yaml) @@ -164,14 +164,14 @@ class Bundler::Thor::Runner < Bundler::Thor #:nodoc: end desc "installed", "List the installed Bundler::Thor modules and commands" - method_options :internal => :boolean + method_options internal: :boolean def installed initialize_thorfiles(nil, true) display_klasses(true, options["internal"]) end desc "list [SEARCH]", "List the available thor commands (--substring means .*SEARCH)" - method_options :substring => :boolean, :group => :string, :all => :boolean, :debug => :boolean + method_options substring: :boolean, group: :string, all: :boolean, debug: :boolean def list(search = "") initialize_thorfiles @@ -313,7 +313,7 @@ private say shell.set_color(namespace, :blue, true) say "-" * namespace.size - print_table(list, :truncate => true) + print_table(list, truncate: true) say end alias_method :display_tasks, :display_commands diff --git a/lib/bundler/vendor/thor/lib/thor/shell.rb b/lib/bundler/vendor/thor/lib/thor/shell.rb index a4137d1bde..265f3ba046 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell.rb @@ -75,7 +75,7 @@ class Bundler::Thor # Allow shell to be shared between invocations. # def _shared_configuration #:nodoc: - super.merge!(:shell => shell) + super.merge!(shell: shell) end end end diff --git a/lib/bundler/vendor/thor/lib/thor/shell/basic.rb b/lib/bundler/vendor/thor/lib/thor/shell/basic.rb index 7f414e9a08..dc3179e5f3 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/basic.rb @@ -1,8 +1,10 @@ +require_relative "column_printer" +require_relative "table_printer" +require_relative "wrapped_printer" + class Bundler::Thor module Shell class Basic - DEFAULT_TERMINAL_WIDTH = 80 - attr_accessor :base attr_reader :padding @@ -145,14 +147,14 @@ class Bundler::Thor # "yes". # def yes?(statement, color = nil) - !!(ask(statement, color, :add_to_history => false) =~ is?(:yes)) + !!(ask(statement, color, add_to_history: false) =~ is?(:yes)) end # Make a question the to user and returns true if the user replies "n" or # "no". # def no?(statement, color = nil) - !!(ask(statement, color, :add_to_history => false) =~ is?(:no)) + !!(ask(statement, color, add_to_history: false) =~ is?(:no)) end # Prints values in columns @@ -161,16 +163,8 @@ class Bundler::Thor # Array[String, String, ...] # def print_in_columns(array) - return if array.empty? - colwidth = (array.map { |el| el.to_s.size }.max || 0) + 2 - array.each_with_index do |value, index| - # Don't output trailing spaces when printing the last column - if ((((index + 1) % (terminal_width / colwidth))).zero? && !index.zero?) || index + 1 == array.length - stdout.puts value - else - stdout.printf("%-#{colwidth}s", value) - end - end + printer = ColumnPrinter.new(stdout) + printer.print(array) end # Prints a table. @@ -181,58 +175,11 @@ class Bundler::Thor # ==== Options # indent<Integer>:: Indent the first column by indent value. # colwidth<Integer>:: Force the first column to colwidth spaces wide. + # borders<Boolean>:: Adds ascii borders. # def print_table(array, options = {}) # rubocop:disable Metrics/MethodLength - return if array.empty? - - formats = [] - indent = options[:indent].to_i - colwidth = options[:colwidth] - options[:truncate] = terminal_width if options[:truncate] == true - - formats << "%-#{colwidth + 2}s".dup if colwidth - start = colwidth ? 1 : 0 - - colcount = array.max { |a, b| a.size <=> b.size }.size - - maximas = [] - - start.upto(colcount - 1) do |index| - maxima = array.map { |row| row[index] ? row[index].to_s.size : 0 }.max - maximas << maxima - formats << if index == colcount - 1 - # Don't output 2 trailing spaces when printing the last column - "%-s".dup - else - "%-#{maxima + 2}s".dup - end - end - - formats[0] = formats[0].insert(0, " " * indent) - formats << "%s" - - array.each do |row| - sentence = "".dup - - row.each_with_index do |column, index| - maxima = maximas[index] - - f = if column.is_a?(Numeric) - if index == row.size - 1 - # Don't output 2 trailing spaces when printing the last column - "%#{maxima}s" - else - "%#{maxima}s " - end - else - formats[index] - end - sentence << f % column.to_s - end - - sentence = truncate(sentence, options[:truncate]) if options[:truncate] - stdout.puts sentence - end + printer = TablePrinter.new(stdout, options) + printer.print(array) end # Prints a long string, word-wrapping the text to the current width of the @@ -245,33 +192,8 @@ class Bundler::Thor # indent<Integer>:: Indent each line of the printed paragraph by indent value. # def print_wrapped(message, options = {}) - indent = options[:indent] || 0 - width = terminal_width - indent - paras = message.split("\n\n") - - paras.map! do |unwrapped| - words = unwrapped.split(" ") - counter = words.first.length - words.inject do |memo, word| - word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n") - counter = 0 if word.include? "\n" - if (counter + word.length + 1) < width - memo = "#{memo} #{word}" - counter += (word.length + 1) - else - memo = "#{memo}\n#{word}" - counter = word.length - end - memo - end - end.compact! - - paras.each do |para| - para.split("\n").each do |line| - stdout.puts line.insert(0, " " * indent) - end - stdout.puts unless para == paras.last - end + printer = WrappedPrinter.new(stdout, options) + printer.print(message) end # Deals with file collision and returns true if the file should be @@ -289,7 +211,7 @@ class Bundler::Thor loop do answer = ask( %[Overwrite #{destination}? (enter "h" for help) #{options}], - :add_to_history => false + add_to_history: false ) case answer @@ -316,24 +238,11 @@ class Bundler::Thor say "Please specify merge tool to `THOR_MERGE` env." else - say file_collision_help + say file_collision_help(block_given?) end end end - # This code was copied from Rake, available under MIT-LICENSE - # Copyright (c) 2003, 2004 Jim Weirich - def terminal_width - result = if ENV["THOR_COLUMNS"] - ENV["THOR_COLUMNS"].to_i - else - unix? ? dynamic_width : DEFAULT_TERMINAL_WIDTH - end - result < 10 ? DEFAULT_TERMINAL_WIDTH : result - rescue - DEFAULT_TERMINAL_WIDTH - end - # Called if something goes wrong during the execution. This is used by Bundler::Thor # internally and should not be used inside your scripts. If something went # wrong, you can always raise an exception. If you raise a Bundler::Thor::Error, it @@ -384,16 +293,21 @@ class Bundler::Thor end end - def file_collision_help #:nodoc: - <<-HELP + def file_collision_help(block_given) #:nodoc: + help = <<-HELP Y - yes, overwrite n - no, do not overwrite a - all, overwrite this and all others q - quit, abort - d - diff, show the differences between the old and the new h - help, show this help - m - merge, run merge tool HELP + if block_given + help << <<-HELP + d - diff, show the differences between the old and the new + m - merge, run merge tool + HELP + end + help end def show_diff(destination, content) #:nodoc: @@ -411,46 +325,8 @@ class Bundler::Thor mute? || (base && base.options[:quiet]) end - # Calculate the dynamic width of the terminal - def dynamic_width - @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput) - end - - def dynamic_width_stty - `stty size 2>/dev/null`.split[1].to_i - end - - def dynamic_width_tput - `tput cols 2>/dev/null`.to_i - end - def unix? - RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris)/i - end - - def truncate(string, width) - as_unicode do - chars = string.chars.to_a - if chars.length <= width - chars.join - else - chars[0, width - 3].join + "..." - end - end - end - - if "".respond_to?(:encode) - def as_unicode - yield - end - else - def as_unicode - old = $KCODE - $KCODE = "U" - yield - ensure - $KCODE = old - end + Terminal.unix? end def ask_simply(statement, color, options) diff --git a/lib/bundler/vendor/thor/lib/thor/shell/color.rb b/lib/bundler/vendor/thor/lib/thor/shell/color.rb index ccb7c3c079..5d708fadca 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/color.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/color.rb @@ -105,52 +105,7 @@ class Bundler::Thor end def are_colors_disabled? - !ENV['NO_COLOR'].nil? && !ENV['NO_COLOR'].empty? - end - - # Overwrite show_diff to show diff with colors if Diff::LCS is - # available. - # - def show_diff(destination, content) #:nodoc: - if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil? - actual = File.binread(destination).to_s.split("\n") - content = content.to_s.split("\n") - - Diff::LCS.sdiff(actual, content).each do |diff| - output_diff_line(diff) - end - else - super - end - end - - def output_diff_line(diff) #:nodoc: - case diff.action - when "-" - say "- #{diff.old_element.chomp}", :red, true - when "+" - say "+ #{diff.new_element.chomp}", :green, true - when "!" - say "- #{diff.old_element.chomp}", :red, true - say "+ #{diff.new_element.chomp}", :green, true - else - say " #{diff.old_element.chomp}", nil, true - end - end - - # Check if Diff::LCS is loaded. If it is, use it to create pretty output - # for diff. - # - def diff_lcs_loaded? #:nodoc: - return true if defined?(Diff::LCS) - return @diff_lcs_loaded unless @diff_lcs_loaded.nil? - - @diff_lcs_loaded = begin - require "diff/lcs" - true - rescue LoadError - false - end + !ENV["NO_COLOR"].nil? && !ENV["NO_COLOR"].empty? end end end diff --git a/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb b/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb new file mode 100644 index 0000000000..56a9e6181b --- /dev/null +++ b/lib/bundler/vendor/thor/lib/thor/shell/column_printer.rb @@ -0,0 +1,29 @@ +require_relative "terminal" + +class Bundler::Thor + module Shell + class ColumnPrinter + attr_reader :stdout, :options + + def initialize(stdout, options = {}) + @stdout = stdout + @options = options + @indent = options[:indent].to_i + end + + def print(array) + return if array.empty? + colwidth = (array.map { |el| el.to_s.size }.max || 0) + 2 + array.each_with_index do |value, index| + # Don't output trailing spaces when printing the last column + if ((((index + 1) % (Terminal.terminal_width / colwidth))).zero? && !index.zero?) || index + 1 == array.length + stdout.puts value + else + stdout.printf("%-#{colwidth}s", value) + end + end + end + end + end +end + diff --git a/lib/bundler/vendor/thor/lib/thor/shell/html.rb b/lib/bundler/vendor/thor/lib/thor/shell/html.rb index 77a6d13a23..0277b882b7 100644 --- a/lib/bundler/vendor/thor/lib/thor/shell/html.rb +++ b/lib/bundler/vendor/thor/lib/thor/shell/html.rb @@ -76,51 +76,6 @@ class Bundler::Thor def can_display_colors? true end - - # Overwrite show_diff to show diff with colors if Diff::LCS is - # available. - # - def show_diff(destination, content) #:nodoc: - if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil? - actual = File.binread(destination).to_s.split("\n") - content = content.to_s.split("\n") - - Diff::LCS.sdiff(actual, content).each do |diff| - output_diff_line(diff) - end - else - super - end - end - - def output_diff_line(diff) #:nodoc: - case diff.action - when "-" - say "- #{diff.old_element.chomp}", :red, true - when "+" - say "+ #{diff.new_element.chomp}", :green, true - when "!" - say "- #{diff.old_element.chomp}", :red, true - say "+ #{diff.new_element.chomp}", :green, true - else - say " #{diff.old_element.chomp}", nil, true - end - end - - # Check if Diff::LCS is loaded. If it is, use it to create pretty output - # for diff. - # - def diff_lcs_loaded? #:nodoc: - return true if defined?(Diff::LCS) - return @diff_lcs_loaded unless @diff_lcs_loaded.nil? - - @diff_lcs_loaded = begin - require "diff/lcs" - true - rescue LoadError - false - end - end end end end diff --git a/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb b/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb new file mode 100644 index 0000000000..525f9ce5bb --- /dev/null +++ b/lib/bundler/vendor/thor/lib/thor/shell/table_printer.rb @@ -0,0 +1,134 @@ +require_relative "column_printer" +require_relative "terminal" + +class Bundler::Thor + module Shell + class TablePrinter < ColumnPrinter + BORDER_SEPARATOR = :separator + + def initialize(stdout, options = {}) + super + @formats = [] + @maximas = [] + @colwidth = options[:colwidth] + @truncate = options[:truncate] == true ? Terminal.terminal_width : options[:truncate] + @padding = 1 + end + + def print(array) + return if array.empty? + + prepare(array) + + print_border_separator if options[:borders] + + array.each do |row| + if options[:borders] && row == BORDER_SEPARATOR + print_border_separator + next + end + + sentence = "".dup + + row.each_with_index do |column, index| + sentence << format_cell(column, row.size, index) + end + + sentence = truncate(sentence) + sentence << "|" if options[:borders] + stdout.puts indentation + sentence + + end + print_border_separator if options[:borders] + end + + private + + def prepare(array) + array = array.reject{|row| row == BORDER_SEPARATOR } + + @formats << "%-#{@colwidth + 2}s".dup if @colwidth + start = @colwidth ? 1 : 0 + + colcount = array.max { |a, b| a.size <=> b.size }.size + + start.upto(colcount - 1) do |index| + maxima = array.map { |row| row[index] ? row[index].to_s.size : 0 }.max + + @maximas << maxima + @formats << if options[:borders] + "%-#{maxima}s".dup + elsif index == colcount - 1 + # Don't output 2 trailing spaces when printing the last column + "%-s".dup + else + "%-#{maxima + 2}s".dup + end + end + + @formats << "%s" + end + + def format_cell(column, row_size, index) + maxima = @maximas[index] + + f = if column.is_a?(Numeric) + if options[:borders] + # With borders we handle padding separately + "%#{maxima}s" + elsif index == row_size - 1 + # Don't output 2 trailing spaces when printing the last column + "%#{maxima}s" + else + "%#{maxima}s " + end + else + @formats[index] + end + + cell = "".dup + cell << "|" + " " * @padding if options[:borders] + cell << f % column.to_s + cell << " " * @padding if options[:borders] + cell + end + + def print_border_separator + separator = @maximas.map do |maxima| + "+" + "-" * (maxima + 2 * @padding) + end + stdout.puts indentation + separator.join + "+" + end + + def truncate(string) + return string unless @truncate + as_unicode do + chars = string.chars.to_a + if chars.length <= @truncate + chars.join + else + chars[0, @truncate - 3 - @indent].join + "..." + end + end + end + + def indentation + " " * @indent + end + + if "".respond_to?(:encode) + def as_unicode + yield + end + else + def as_unicode + old = $KCODE # rubocop:disable Style/GlobalVars + $KCODE = "U" # rubocop:disable Style/GlobalVars + yield + ensure + $KCODE = old # rubocop:disable Style/GlobalVars + end + end + end + end +end diff --git a/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb b/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb new file mode 100644 index 0000000000..2c60684308 --- /dev/null +++ b/lib/bundler/vendor/thor/lib/thor/shell/terminal.rb @@ -0,0 +1,42 @@ +class Bundler::Thor + module Shell + module Terminal + DEFAULT_TERMINAL_WIDTH = 80 + + class << self + # This code was copied from Rake, available under MIT-LICENSE + # Copyright (c) 2003, 2004 Jim Weirich + def terminal_width + result = if ENV["THOR_COLUMNS"] + ENV["THOR_COLUMNS"].to_i + else + unix? ? dynamic_width : DEFAULT_TERMINAL_WIDTH + end + result < 10 ? DEFAULT_TERMINAL_WIDTH : result + rescue + DEFAULT_TERMINAL_WIDTH + end + + def unix? + RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris)/i + end + + private + + # Calculate the dynamic width of the terminal + def dynamic_width + @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput) + end + + def dynamic_width_stty + `stty size 2>/dev/null`.split[1].to_i + end + + def dynamic_width_tput + `tput cols 2>/dev/null`.to_i + end + + end + end + end +end diff --git a/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb b/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb new file mode 100644 index 0000000000..ba88e952db --- /dev/null +++ b/lib/bundler/vendor/thor/lib/thor/shell/wrapped_printer.rb @@ -0,0 +1,38 @@ +require_relative "column_printer" +require_relative "terminal" + +class Bundler::Thor + module Shell + class WrappedPrinter < ColumnPrinter + def print(message) + width = Terminal.terminal_width - @indent + paras = message.split("\n\n") + + paras.map! do |unwrapped| + words = unwrapped.split(" ") + counter = words.first.length + words.inject do |memo, word| + word = word.gsub(/\n\005/, "\n").gsub(/\005/, "\n") + counter = 0 if word.include? "\n" + if (counter + word.length + 1) < width + memo = "#{memo} #{word}" + counter += (word.length + 1) + else + memo = "#{memo}\n#{word}" + counter = word.length + end + memo + end + end.compact! + + paras.each do |para| + para.split("\n").each do |line| + stdout.puts line.insert(0, " " * @indent) + end + stdout.puts unless para == paras.last + end + end + end + end +end + diff --git a/lib/bundler/vendor/thor/lib/thor/util.rb b/lib/bundler/vendor/thor/lib/thor/util.rb index a17eabc22c..68916daf2e 100644 --- a/lib/bundler/vendor/thor/lib/thor/util.rb +++ b/lib/bundler/vendor/thor/lib/thor/util.rb @@ -130,9 +130,10 @@ class Bundler::Thor # def find_class_and_command_by_namespace(namespace, fallback = true) if namespace.include?(":") # look for a namespaced command - pieces = namespace.split(":") - command = pieces.pop - klass = Bundler::Thor::Util.find_by_namespace(pieces.join(":")) + *pieces, command = namespace.split(":") + namespace = pieces.join(":") + namespace = "default" if namespace.empty? + klass = Bundler::Thor::Base.subclasses.detect { |thor| thor.namespace == namespace && thor.commands.keys.include?(command) } end unless klass # look for a Bundler::Thor::Group with the right name klass = Bundler::Thor::Util.find_by_namespace(namespace) diff --git a/lib/bundler/vendor/thor/lib/thor/version.rb b/lib/bundler/vendor/thor/lib/thor/version.rb index 43e462c531..1fb00017ed 100644 --- a/lib/bundler/vendor/thor/lib/thor/version.rb +++ b/lib/bundler/vendor/thor/lib/thor/version.rb @@ -1,3 +1,3 @@ class Bundler::Thor - VERSION = "1.2.2" + VERSION = "1.3.0" end diff --git a/lib/bundler/vendor/tsort/.document b/lib/bundler/vendor/tsort/.document new file mode 100644 index 0000000000..0c43bbd6b3 --- /dev/null +++ b/lib/bundler/vendor/tsort/.document @@ -0,0 +1 @@ +# Vendored files do not need to be documented diff --git a/lib/bundler/vendor/tsort/lib/tsort.rb b/lib/bundler/vendor/tsort/lib/tsort.rb index 4a0e1a4e25..cf8731f760 100644 --- a/lib/bundler/vendor/tsort/lib/tsort.rb +++ b/lib/bundler/vendor/tsort/lib/tsort.rb @@ -122,6 +122,9 @@ # module Bundler::TSort + + VERSION = "0.2.0" + class Cyclic < StandardError end diff --git a/lib/bundler/vendor/uri/.document b/lib/bundler/vendor/uri/.document new file mode 100644 index 0000000000..0c43bbd6b3 --- /dev/null +++ b/lib/bundler/vendor/uri/.document @@ -0,0 +1 @@ +# Vendored files do not need to be documented diff --git a/lib/bundler/vendor/uri/lib/uri/common.rb b/lib/bundler/vendor/uri/lib/uri/common.rb index 914a4c7581..93f4f226ad 100644 --- a/lib/bundler/vendor/uri/lib/uri/common.rb +++ b/lib/bundler/vendor/uri/lib/uri/common.rb @@ -68,16 +68,32 @@ module Bundler::URI end private_constant :Schemes + # Registers the given +klass+ as the class to be instantiated + # when parsing a \Bundler::URI with the given +scheme+: # - # Register the given +klass+ to be instantiated when parsing URLs with the given +scheme+. - # Note that currently only schemes which after .upcase are valid constant names - # can be registered (no -/+/. allowed). + # Bundler::URI.register_scheme('MS_SEARCH', Bundler::URI::Generic) # => Bundler::URI::Generic + # Bundler::URI.scheme_list['MS_SEARCH'] # => Bundler::URI::Generic # + # Note that after calling String#upcase on +scheme+, it must be a valid + # constant name. def self.register_scheme(scheme, klass) Schemes.const_set(scheme.to_s.upcase, klass) end - # Returns a Hash of the defined schemes. + # Returns a hash of the defined schemes: + # + # Bundler::URI.scheme_list + # # => + # {"MAILTO"=>Bundler::URI::MailTo, + # "LDAPS"=>Bundler::URI::LDAPS, + # "WS"=>Bundler::URI::WS, + # "HTTP"=>Bundler::URI::HTTP, + # "HTTPS"=>Bundler::URI::HTTPS, + # "LDAP"=>Bundler::URI::LDAP, + # "FILE"=>Bundler::URI::File, + # "FTP"=>Bundler::URI::FTP} + # + # Related: Bundler::URI.register_scheme. def self.scheme_list Schemes.constants.map { |name| [name.to_s.upcase, Schemes.const_get(name)] @@ -88,9 +104,21 @@ module Bundler::URI private_constant :INITIAL_SCHEMES Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor) + # Returns a new object constructed from the given +scheme+, +arguments+, + # and +default+: + # + # - The new object is an instance of <tt>Bundler::URI.scheme_list[scheme.upcase]</tt>. + # - The object is initialized by calling the class initializer + # using +scheme+ and +arguments+. + # See Bundler::URI::Generic.new. + # + # Examples: # - # Construct a Bundler::URI instance, using the scheme to detect the appropriate class - # from +Bundler::URI.scheme_list+. + # values = ['john.doe', 'www.example.com', '123', nil, '/forum/questions/', nil, 'tag=networking&order=newest', 'top'] + # Bundler::URI.for('https', *values) + # # => #<Bundler::URI::HTTPS https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top> + # Bundler::URI.for('foo', *values, default: Bundler::URI::HTTP) + # # => #<Bundler::URI::HTTP foo://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top> # def self.for(scheme, *arguments, default: Generic) const_name = scheme.to_s.upcase @@ -121,95 +149,49 @@ module Bundler::URI # class BadURIError < Error; end - # - # == Synopsis - # - # Bundler::URI::split(uri) - # - # == Args - # - # +uri+:: - # String with Bundler::URI. - # - # == Description - # - # Splits the string on following parts and returns array with result: - # - # * Scheme - # * Userinfo - # * Host - # * Port - # * Registry - # * Path - # * Opaque - # * Query - # * Fragment - # - # == Usage - # - # require 'bundler/vendor/uri/lib/uri' - # - # Bundler::URI.split("http://www.ruby-lang.org/") - # # => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil] + # Returns a 9-element array representing the parts of the \Bundler::URI + # formed from the string +uri+; + # each array element is a string or +nil+: + # + # names = %w[scheme userinfo host port registry path opaque query fragment] + # values = Bundler::URI.split('https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top') + # names.zip(values) + # # => + # [["scheme", "https"], + # ["userinfo", "john.doe"], + # ["host", "www.example.com"], + # ["port", "123"], + # ["registry", nil], + # ["path", "/forum/questions/"], + # ["opaque", nil], + # ["query", "tag=networking&order=newest"], + # ["fragment", "top"]] # def self.split(uri) RFC3986_PARSER.split(uri) end + # Returns a new \Bundler::URI object constructed from the given string +uri+: # - # == Synopsis - # - # Bundler::URI::parse(uri_str) - # - # == Args - # - # +uri_str+:: - # String with Bundler::URI. - # - # == Description - # - # Creates one of the Bundler::URI's subclasses instance from the string. - # - # == Raises - # - # Bundler::URI::InvalidURIError:: - # Raised if Bundler::URI given is not a correct one. + # Bundler::URI.parse('https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top') + # # => #<Bundler::URI::HTTPS https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top> + # Bundler::URI.parse('http://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top') + # # => #<Bundler::URI::HTTP http://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top> # - # == Usage - # - # require 'bundler/vendor/uri/lib/uri' - # - # uri = Bundler::URI.parse("http://www.ruby-lang.org/") - # # => #<Bundler::URI::HTTP http://www.ruby-lang.org/> - # uri.scheme - # # => "http" - # uri.host - # # => "www.ruby-lang.org" - # - # It's recommended to first ::escape the provided +uri_str+ if there are any - # invalid Bundler::URI characters. + # It's recommended to first ::escape string +uri+ + # if it may contain invalid Bundler::URI characters. # def self.parse(uri) RFC3986_PARSER.parse(uri) end + # Merges the given Bundler::URI strings +str+ + # per {RFC 2396}[https://www.rfc-editor.org/rfc/rfc2396.html]. # - # == Synopsis - # - # Bundler::URI::join(str[, str, ...]) + # Each string in +str+ is converted to an + # {RFC3986 Bundler::URI}[https://www.rfc-editor.org/rfc/rfc3986.html] before being merged. # - # == Args - # - # +str+:: - # String(s) to work with, will be converted to RFC3986 URIs before merging. - # - # == Description - # - # Joins URIs. - # - # == Usage - # - # require 'bundler/vendor/uri/lib/uri' + # Examples: # # Bundler::URI.join("http://example.com/","main.rbx") # # => #<Bundler::URI::HTTP http://example.com/main.rbx> @@ -254,7 +236,7 @@ module Bundler::URI # Bundler::URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.") # # => ["http://foo.example.com/bla", "mailto:test@example.com"] # - def self.extract(str, schemes = nil, &block) + def self.extract(str, schemes = nil, &block) # :nodoc: warn "Bundler::URI.extract is obsolete", uplevel: 1 if $VERBOSE DEFAULT_PARSER.extract(str, schemes, &block) end @@ -291,7 +273,7 @@ module Bundler::URI # p $& # end # - def self.regexp(schemes = nil) + def self.regexp(schemes = nil)# :nodoc: warn "Bundler::URI.regexp is obsolete", uplevel: 1 if $VERBOSE DEFAULT_PARSER.make_regexp(schemes) end @@ -314,40 +296,86 @@ module Bundler::URI TBLDECWWWCOMP_['+'] = ' ' TBLDECWWWCOMP_.freeze - # Encodes given +str+ to URL-encoded form data. + # Returns a URL-encoded string derived from the given string +str+. + # + # The returned string: + # + # - Preserves: + # + # - Characters <tt>'*'</tt>, <tt>'.'</tt>, <tt>'-'</tt>, and <tt>'_'</tt>. + # - Character in ranges <tt>'a'..'z'</tt>, <tt>'A'..'Z'</tt>, + # and <tt>'0'..'9'</tt>. + # + # Example: # - # This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP - # (ASCII space) to + and converts others to %XX. + # Bundler::URI.encode_www_form_component('*.-_azAZ09') + # # => "*.-_azAZ09" # - # If +enc+ is given, convert +str+ to the encoding before percent encoding. + # - Converts: # - # This is an implementation of - # https://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data. + # - Character <tt>' '</tt> to character <tt>'+'</tt>. + # - Any other character to "percent notation"; + # the percent notation for character <i>c</i> is <tt>'%%%X' % c.ord</tt>. # - # See Bundler::URI.decode_www_form_component, Bundler::URI.encode_www_form. + # Example: + # + # Bundler::URI.encode_www_form_component('Here are some punctuation characters: ,;?:') + # # => "Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A" + # + # Encoding: + # + # - If +str+ has encoding Encoding::ASCII_8BIT, argument +enc+ is ignored. + # - Otherwise +str+ is converted first to Encoding::UTF_8 + # (with suitable character replacements), + # and then to encoding +enc+. + # + # In either case, the returned string has forced encoding Encoding::US_ASCII. + # + # Related: Bundler::URI.encode_uri_component (encodes <tt>' '</tt> as <tt>'%20'</tt>). def self.encode_www_form_component(str, enc=nil) _encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_, str, enc) end - # Decodes given +str+ of URL-encoded form data. + # Returns a string decoded from the given \URL-encoded string +str+. + # + # The given string is first encoded as Encoding::ASCII-8BIT (using String#b), + # then decoded (as below), and finally force-encoded to the given encoding +enc+. + # + # The returned string: + # + # - Preserves: + # + # - Characters <tt>'*'</tt>, <tt>'.'</tt>, <tt>'-'</tt>, and <tt>'_'</tt>. + # - Character in ranges <tt>'a'..'z'</tt>, <tt>'A'..'Z'</tt>, + # and <tt>'0'..'9'</tt>. + # + # Example: + # + # Bundler::URI.decode_www_form_component('*.-_azAZ09') + # # => "*.-_azAZ09" + # + # - Converts: + # + # - Character <tt>'+'</tt> to character <tt>' '</tt>. + # - Each "percent notation" to an ASCII character. # - # This decodes + to SP. + # Example: # - # See Bundler::URI.encode_www_form_component, Bundler::URI.decode_www_form. + # Bundler::URI.decode_www_form_component('Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A') + # # => "Here are some punctuation characters: ,;?:" + # + # Related: Bundler::URI.decode_uri_component (preserves <tt>'+'</tt>). def self.decode_www_form_component(str, enc=Encoding::UTF_8) _decode_uri_component(/\+|%\h\h/, str, enc) end - # Encodes +str+ using URL encoding - # - # This encodes SP to %20 instead of +. + # Like Bundler::URI.encode_www_form_component, except that <tt>' '</tt> (space) + # is encoded as <tt>'%20'</tt> (instead of <tt>'+'</tt>). def self.encode_uri_component(str, enc=nil) _encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCURICOMP_, str, enc) end - # Decodes given +str+ of URL-encoded data. - # - # This does not decode + to SP. + # Like Bundler::URI.decode_www_form_component, except that <tt>'+'</tt> is preserved. def self.decode_uri_component(str, enc=Encoding::UTF_8) _decode_uri_component(/%\h\h/, str, enc) end @@ -372,33 +400,104 @@ module Bundler::URI end private_class_method :_decode_uri_component - # Generates URL-encoded form data from given +enum+. + # Returns a URL-encoded string derived from the given + # {Enumerable}[rdoc-ref:Enumerable@Enumerable+in+Ruby+Classes] + # +enum+. + # + # The result is suitable for use as form data + # for an \HTTP request whose <tt>Content-Type</tt> is + # <tt>'application/x-www-form-urlencoded'</tt>. + # + # The returned string consists of the elements of +enum+, + # each converted to one or more URL-encoded strings, + # and all joined with character <tt>'&'</tt>. + # + # Simple examples: + # + # Bundler::URI.encode_www_form([['foo', 0], ['bar', 1], ['baz', 2]]) + # # => "foo=0&bar=1&baz=2" + # Bundler::URI.encode_www_form({foo: 0, bar: 1, baz: 2}) + # # => "foo=0&bar=1&baz=2" + # + # The returned string is formed using method Bundler::URI.encode_www_form_component, + # which converts certain characters: + # + # Bundler::URI.encode_www_form('f#o': '/', 'b-r': '$', 'b z': '@') + # # => "f%23o=%2F&b-r=%24&b+z=%40" + # + # When +enum+ is Array-like, each element +ele+ is converted to a field: + # + # - If +ele+ is an array of two or more elements, + # the field is formed from its first two elements + # (and any additional elements are ignored): + # + # name = Bundler::URI.encode_www_form_component(ele[0], enc) + # value = Bundler::URI.encode_www_form_component(ele[1], enc) + # "#{name}=#{value}" # - # This generates application/x-www-form-urlencoded data defined in HTML5 - # from given an Enumerable object. + # Examples: # - # This internally uses Bundler::URI.encode_www_form_component(str). + # Bundler::URI.encode_www_form([%w[foo bar], %w[baz bat bah]]) + # # => "foo=bar&baz=bat" + # Bundler::URI.encode_www_form([['foo', 0], ['bar', :baz, 'bat']]) + # # => "foo=0&bar=baz" # - # This method doesn't convert the encoding of given items, so convert them - # before calling this method if you want to send data as other than original - # encoding or mixed encoding data. (Strings which are encoded in an HTML5 - # ASCII incompatible encoding are converted to UTF-8.) + # - If +ele+ is an array of one element, + # the field is formed from <tt>ele[0]</tt>: # - # This method doesn't handle files. When you send a file, use - # multipart/form-data. + # Bundler::URI.encode_www_form_component(ele[0]) # - # This refers https://url.spec.whatwg.org/#concept-urlencoded-serializer + # Example: # - # Bundler::URI.encode_www_form([["q", "ruby"], ["lang", "en"]]) - # #=> "q=ruby&lang=en" - # Bundler::URI.encode_www_form("q" => "ruby", "lang" => "en") - # #=> "q=ruby&lang=en" - # Bundler::URI.encode_www_form("q" => ["ruby", "perl"], "lang" => "en") - # #=> "q=ruby&q=perl&lang=en" - # Bundler::URI.encode_www_form([["q", "ruby"], ["q", "perl"], ["lang", "en"]]) - # #=> "q=ruby&q=perl&lang=en" + # Bundler::URI.encode_www_form([['foo'], [:bar], [0]]) + # # => "foo&bar&0" + # + # - Otherwise the field is formed from +ele+: + # + # Bundler::URI.encode_www_form_component(ele) + # + # Example: + # + # Bundler::URI.encode_www_form(['foo', :bar, 0]) + # # => "foo&bar&0" + # + # The elements of an Array-like +enum+ may be mixture: + # + # Bundler::URI.encode_www_form([['foo', 0], ['bar', 1, 2], ['baz'], :bat]) + # # => "foo=0&bar=1&baz&bat" + # + # When +enum+ is Hash-like, + # each +key+/+value+ pair is converted to one or more fields: + # + # - If +value+ is + # {Array-convertible}[rdoc-ref:implicit_conversion.rdoc@Array-Convertible+Objects], + # each element +ele+ in +value+ is paired with +key+ to form a field: + # + # name = Bundler::URI.encode_www_form_component(key, enc) + # value = Bundler::URI.encode_www_form_component(ele, enc) + # "#{name}=#{value}" + # + # Example: + # + # Bundler::URI.encode_www_form({foo: [:bar, 1], baz: [:bat, :bam, 2]}) + # # => "foo=bar&foo=1&baz=bat&baz=bam&baz=2" + # + # - Otherwise, +key+ and +value+ are paired to form a field: + # + # name = Bundler::URI.encode_www_form_component(key, enc) + # value = Bundler::URI.encode_www_form_component(value, enc) + # "#{name}=#{value}" + # + # Example: + # + # Bundler::URI.encode_www_form({foo: 0, bar: 1, baz: 2}) + # # => "foo=0&bar=1&baz=2" + # + # The elements of a Hash-like +enum+ may be mixture: + # + # Bundler::URI.encode_www_form({foo: [0, 1], bar: 2}) + # # => "foo=0&foo=1&bar=2" # - # See Bundler::URI.encode_www_form_component, Bundler::URI.decode_www_form. def self.encode_www_form(enum, enc=nil) enum.map do |k,v| if v.nil? @@ -419,22 +518,39 @@ module Bundler::URI end.join('&') end - # Decodes URL-encoded form data from given +str+. + # Returns name/value pairs derived from the given string +str+, + # which must be an ASCII string. + # + # The method may be used to decode the body of Net::HTTPResponse object +res+ + # for which <tt>res['Content-Type']</tt> is <tt>'application/x-www-form-urlencoded'</tt>. + # + # The returned data is an array of 2-element subarrays; + # each subarray is a name/value pair (both are strings). + # Each returned string has encoding +enc+, + # and has had invalid characters removed via + # {String#scrub}[rdoc-ref:String#scrub]. # - # This decodes application/x-www-form-urlencoded data - # and returns an array of key-value arrays. + # A simple example: # - # This refers http://url.spec.whatwg.org/#concept-urlencoded-parser, - # so this supports only &-separator, and doesn't support ;-separator. + # Bundler::URI.decode_www_form('foo=0&bar=1&baz') + # # => [["foo", "0"], ["bar", "1"], ["baz", ""]] # - # ary = Bundler::URI.decode_www_form("a=1&a=2&b=3") - # ary #=> [['a', '1'], ['a', '2'], ['b', '3']] - # ary.assoc('a').last #=> '1' - # ary.assoc('b').last #=> '3' - # ary.rassoc('a').last #=> '2' - # Hash[ary] #=> {"a"=>"2", "b"=>"3"} + # The returned strings have certain conversions, + # similar to those performed in Bundler::URI.decode_www_form_component: + # + # Bundler::URI.decode_www_form('f%23o=%2F&b-r=%24&b+z=%40') + # # => [["f#o", "/"], ["b-r", "$"], ["b z", "@"]] + # + # The given string may contain consecutive separators: + # + # Bundler::URI.decode_www_form('foo=0&&bar=1&&baz=2') + # # => [["foo", "0"], ["", ""], ["bar", "1"], ["", ""], ["baz", "2"]] + # + # A different separator may be specified: + # + # Bundler::URI.decode_www_form('foo=0--bar=1--baz', separator: '--') + # # => [["foo", "0"], ["bar", "1"], ["baz", ""]] # - # See Bundler::URI.decode_www_form_component, Bundler::URI.encode_www_form. def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_: false, isindex: false) raise ArgumentError, "the input of #{self.name}.#{__method__} must be ASCII only string" unless str.ascii_only? ary = [] @@ -713,7 +829,15 @@ end # module Bundler::URI module Bundler # - # Returns +uri+ converted to an Bundler::URI object. + # Returns a \Bundler::URI object derived from the given +uri+, + # which may be a \Bundler::URI string or an existing \Bundler::URI object: + # + # # Returns a new Bundler::URI. + # uri = Bundler::URI('http://github.com/ruby/ruby') + # # => #<Bundler::URI::HTTP http://github.com/ruby/ruby> + # # Returns the given Bundler::URI. + # Bundler::URI(uri) + # # => #<Bundler::URI::HTTP http://github.com/ruby/ruby> # def URI(uri) if uri.is_a?(Bundler::URI::Generic) diff --git a/lib/bundler/vendor/uri/lib/uri/generic.rb b/lib/bundler/vendor/uri/lib/uri/generic.rb index 9ae6915826..762c425ac1 100644 --- a/lib/bundler/vendor/uri/lib/uri/generic.rb +++ b/lib/bundler/vendor/uri/lib/uri/generic.rb @@ -1376,6 +1376,7 @@ module Bundler::URI end str end + alias to_str to_s # # Compares two URIs. diff --git a/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb b/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb index 2f8d55353b..09c22c9906 100644 --- a/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +++ b/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb @@ -497,8 +497,8 @@ module Bundler::URI ret = {} # for Bundler::URI::split - ret[:ABS_URI] = Regexp.new('\A\s*' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED) - ret[:REL_URI] = Regexp.new('\A\s*' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED) + ret[:ABS_URI] = Regexp.new('\A\s*+' + pattern[:X_ABS_URI] + '\s*\z', Regexp::EXTENDED) + ret[:REL_URI] = Regexp.new('\A\s*+' + pattern[:X_REL_URI] + '\s*\z', Regexp::EXTENDED) # for Bundler::URI::extract ret[:URI_REF] = Regexp.new(pattern[:URI_REF]) diff --git a/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb b/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb index d527072db4..4c9882f595 100644 --- a/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +++ b/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb @@ -1,9 +1,73 @@ -# frozen_string_literal: false +# frozen_string_literal: true module Bundler::URI class RFC3986_Parser # :nodoc: # Bundler::URI defined in RFC3986 - RFC3986_URI = /\A(?<Bundler::URI>(?<scheme>[A-Za-z][+\-.0-9A-Za-z]*+):(?<hier-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*+)@)?(?<host>(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h++\.[!$&-.0-;=A-Z_a-z~]++))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])*+))(?::(?<port>\d*+))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*+))*+)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])++)(?:\/\g<segment>)*+)?)|(?<path-rootless>\g<segment-nz>(?:\/\g<segment>)*+)|(?<path-empty>))(?:\?(?<query>[^#]*+))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*+))?)\z/ - RFC3986_relative_ref = /\A(?<relative-ref>(?<relative-part>\/\/(?<authority>(?:(?<userinfo>(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*+)@)?(?<host>(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{1,4}?::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:){,1}\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h++\.[!$&-.0-;=A-Z_a-z~]++))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])++))?(?::(?<port>\d*+))?)(?<path-abempty>(?:\/(?<segment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*+))*+)|(?<path-absolute>\/(?:(?<segment-nz>(?:%\h\h|[!$&-.0-;=@-Z_a-z~])++)(?:\/\g<segment>)*+)?)|(?<path-noscheme>(?<segment-nz-nc>(?:%\h\h|[!$&-.0-9;=@-Z_a-z~])++)(?:\/\g<segment>)*+)|(?<path-empty>))(?:\?(?<query>[^#]*+))?(?:\#(?<fragment>(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*+))?)\z/ + HOST = %r[ + (?<IP-literal>\[(?: + (?<IPv6address> + (?:\h{1,4}:){6} + (?<ls32>\h{1,4}:\h{1,4} + | (?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d) + \.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>) + ) + | ::(?:\h{1,4}:){5}\g<ls32> + | \h{1,4}?::(?:\h{1,4}:){4}\g<ls32> + | (?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32> + | (?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32> + | (?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32> + | (?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32> + | (?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4} + | (?:(?:\h{1,4}:){,6}\h{1,4})?:: + ) + | (?<IPvFuture>v\h++\.[!$&-.0-9:;=A-Z_a-z~]++) + )\]) + | \g<IPv4address> + | (?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])*+) + ]x + + USERINFO = /(?:%\h\h|[!$&-.0-9:;=A-Z_a-z~])*+/ + + SCHEME = %r[[A-Za-z][+\-.0-9A-Za-z]*+].source + SEG = %r[(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/])].source + SEG_NC = %r[(?:%\h\h|[!$&-.0-9;=@A-Z_a-z~])].source + FRAGMENT = %r[(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/?])*+].source + + RFC3986_URI = %r[\A + (?<seg>#{SEG}){0} + (?<Bundler::URI> + (?<scheme>#{SCHEME}): + (?<hier-part>// + (?<authority> + (?:(?<userinfo>#{USERINFO.source})@)? + (?<host>#{HOST.source.delete(" \n")}) + (?::(?<port>\d*+))? + ) + (?<path-abempty>(?:/\g<seg>*+)?) + | (?<path-absolute>/((?!/)\g<seg>++)?) + | (?<path-rootless>(?!/)\g<seg>++) + | (?<path-empty>) + ) + (?:\?(?<query>[^\#]*+))? + (?:\#(?<fragment>#{FRAGMENT}))? + )\z]x + + RFC3986_relative_ref = %r[\A + (?<seg>#{SEG}){0} + (?<relative-ref> + (?<relative-part>// + (?<authority> + (?:(?<userinfo>#{USERINFO.source})@)? + (?<host>#{HOST.source.delete(" \n")}(?<!/))? + (?::(?<port>\d*+))? + ) + (?<path-abempty>(?:/\g<seg>*+)?) + | (?<path-absolute>/\g<seg>*+) + | (?<path-noscheme>#{SEG_NC}++(?:/\g<seg>*+)?) + | (?<path-empty>) + ) + (?:\?(?<query>[^#]*+))? + (?:\#(?<fragment>#{FRAGMENT}))? + )\z]x attr_reader :regexp def initialize @@ -19,9 +83,9 @@ module Bundler::URI uri.ascii_only? or raise InvalidURIError, "Bundler::URI must be ascii only #{uri.dump}" if m = RFC3986_URI.match(uri) - query = m["query".freeze] - scheme = m["scheme".freeze] - opaque = m["path-rootless".freeze] + query = m["query"] + scheme = m["scheme"] + opaque = m["path-rootless"] if opaque opaque << "?#{query}" if query [ scheme, @@ -32,35 +96,35 @@ module Bundler::URI nil, # path opaque, nil, # query - m["fragment".freeze] + m["fragment"] ] else # normal [ scheme, - m["userinfo".freeze], - m["host".freeze], - m["port".freeze], + m["userinfo"], + m["host"], + m["port"], nil, # registry - (m["path-abempty".freeze] || - m["path-absolute".freeze] || - m["path-empty".freeze]), + (m["path-abempty"] || + m["path-absolute"] || + m["path-empty"]), nil, # opaque query, - m["fragment".freeze] + m["fragment"] ] end elsif m = RFC3986_relative_ref.match(uri) [ nil, # scheme - m["userinfo".freeze], - m["host".freeze], - m["port".freeze], + m["userinfo"], + m["host"], + m["port"], nil, # registry, - (m["path-abempty".freeze] || - m["path-absolute".freeze] || - m["path-noscheme".freeze] || - m["path-empty".freeze]), + (m["path-abempty"] || + m["path-absolute"] || + m["path-noscheme"] || + m["path-empty"]), nil, # opaque - m["query".freeze], - m["fragment".freeze] + m["query"], + m["fragment"] ] else raise InvalidURIError, "bad Bundler::URI(is not Bundler::URI?): #{uri.inspect}" @@ -92,15 +156,15 @@ module Bundler::URI def default_regexp # :nodoc: { - SCHEME: /\A[A-Za-z][A-Za-z0-9+\-.]*\z/, - USERINFO: /\A(?:%\h\h|[!$&-.0-;=A-Z_a-z~])*\z/, - HOST: /\A(?:(?<IP-literal>\[(?:(?<IPv6address>(?:\h{1,4}:){6}(?<ls32>\h{1,4}:\h{1,4}|(?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)\.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>))|::(?:\h{1,4}:){5}\g<ls32>|\h{,4}::(?:\h{1,4}:){4}\g<ls32>|(?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>|(?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>|(?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>|(?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>|(?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}|(?:(?:\h{1,4}:){,6}\h{1,4})?::)|(?<IPvFuture>v\h+\.[!$&-.0-;=A-Z_a-z~]+))\])|\g<IPv4address>|(?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])*))\z/, - ABS_PATH: /\A\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*(?:\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*)*\z/, - REL_PATH: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~])+(?:\/(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*)*\z/, - QUERY: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/, - FRAGMENT: /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~\/?])*\z/, - OPAQUE: /\A(?:[^\/].*)?\z/, - PORT: /\A[\x09\x0a\x0c\x0d ]*\d*[\x09\x0a\x0c\x0d ]*\z/, + SCHEME: %r[\A#{SCHEME}\z]o, + USERINFO: %r[\A#{USERINFO}\z]o, + HOST: %r[\A#{HOST}\z]o, + ABS_PATH: %r[\A/#{SEG}*+\z]o, + REL_PATH: %r[\A(?!/)#{SEG}++\z]o, + QUERY: %r[\A(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/?])*+\z], + FRAGMENT: %r[\A#{FRAGMENT}\z]o, + OPAQUE: %r[\A(?:[^/].*)?\z], + PORT: /\A[\x09\x0a\x0c\x0d ]*+\d*[\x09\x0a\x0c\x0d ]*\z/, } end diff --git a/lib/bundler/vendor/uri/lib/uri/version.rb b/lib/bundler/vendor/uri/lib/uri/version.rb index 500fdb3f99..1fa1c7c09a 100644 --- a/lib/bundler/vendor/uri/lib/uri/version.rb +++ b/lib/bundler/vendor/uri/lib/uri/version.rb @@ -1,6 +1,6 @@ module Bundler::URI # :stopdoc: - VERSION_CODE = '001201'.freeze + VERSION_CODE = '001300'.freeze VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze # :startdoc: end diff --git a/lib/bundler/vendored_net_http.rb b/lib/bundler/vendored_net_http.rb new file mode 100644 index 0000000000..0dcabaa7d7 --- /dev/null +++ b/lib/bundler/vendored_net_http.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +begin + require "rubygems/vendored_net_http" +rescue LoadError + begin + require "rubygems/net/http" + rescue LoadError + require "net/http" + Gem::Net = Net + end +end diff --git a/lib/bundler/vendored_persistent.rb b/lib/bundler/vendored_persistent.rb index e29f27cdfd..ab985c267f 100644 --- a/lib/bundler/vendored_persistent.rb +++ b/lib/bundler/vendored_persistent.rb @@ -9,7 +9,3 @@ module Bundler end end require_relative "vendor/net-http-persistent/lib/net/http/persistent" - -module Bundler - PersistentHTTP = Persistent::Net::HTTP::Persistent -end diff --git a/lib/bundler/vendored_timeout.rb b/lib/bundler/vendored_timeout.rb new file mode 100644 index 0000000000..9b2507c0cc --- /dev/null +++ b/lib/bundler/vendored_timeout.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +begin + require "rubygems/vendored_timeout" +rescue LoadError + begin + require "rubygems/timeout" + rescue LoadError + require "timeout" + Gem::Timeout = Timeout + end +end diff --git a/lib/bundler/vendored_uri.rb b/lib/bundler/vendored_uri.rb index 905e8158e8..2efddc65f9 100644 --- a/lib/bundler/vendored_uri.rb +++ b/lib/bundler/vendored_uri.rb @@ -1,4 +1,21 @@ # frozen_string_literal: true module Bundler; end -require_relative "vendor/uri/lib/uri" + +# Use RubyGems vendored copy when available. Otherwise fallback to Bundler +# vendored copy. The vendored copy in Bundler can be removed once support for +# RubyGems 3.5 is dropped. + +begin + require "rubygems/vendor/uri/lib/uri" +rescue LoadError + require_relative "vendor/uri/lib/uri" + Gem::URI = Bundler::URI + + module Gem + def URI(uri) # rubocop:disable Naming/MethodName + Bundler::URI(uri) + end + module_function :URI + end +end diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb index 7c03d8687f..f2f6236cda 100644 --- a/lib/bundler/version.rb +++ b/lib/bundler/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Bundler - VERSION = "2.5.0.dev".freeze + VERSION = "2.6.0.dev".freeze def self.bundler_major_version @bundler_major_version ||= VERSION.split(".").first.to_i diff --git a/lib/bundler/vlad.rb b/lib/bundler/vlad.rb index 538e8c3e74..6179d0e4eb 100644 --- a/lib/bundler/vlad.rb +++ b/lib/bundler/vlad.rb @@ -13,5 +13,5 @@ require_relative "deployment" include Rake::DSL if defined? Rake::DSL namespace :vlad do - Bundler::Deployment.define_task(Rake::RemoteTask, :remote_task, :roles => :app) + Bundler::Deployment.define_task(Rake::RemoteTask, :remote_task, roles: :app) end diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index d5ecbd4aef..93d08a05aa 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -17,7 +17,11 @@ module Bundler if v.is_a?(Hash) yaml << dump_hash(v).gsub(/^(?!$)/, " ") # indent all non-empty lines elsif v.is_a?(Array) # Expected to be array of strings - yaml << "\n- " << v.map {|s| s.to_s.gsub(/\s+/, " ").inspect }.join("\n- ") << "\n" + if v.empty? + yaml << " []\n" + else + yaml << "\n- " << v.map {|s| s.to_s.gsub(/\s+/, " ").inspect }.join("\n- ") << "\n" + end else yaml << " " << v.to_s.gsub(/\s+/, " ").inspect << "\n" end @@ -32,7 +36,7 @@ module Bundler (.*) # value \1 # matching closing quote $ - /xo.freeze + /xo HASH_REGEX = / ^ @@ -44,18 +48,19 @@ module Bundler (.*) # value \3 # matching closing quote $ - /xo.freeze + /xo def load(str) res = {} stack = [res] last_hash = nil last_empty_key = nil - str.split(/\r?\n/).each do |line| + str.split(/\r?\n/) do |line| if match = HASH_REGEX.match(line) indent, key, quote, val = match.captures - key = convert_to_backward_compatible_key(key) - depth = indent.scan(/ /).length + val = strip_comment(val) + + depth = indent.size / 2 if quote.empty? && val.empty? new_hash = {} stack[depth][key] = new_hash @@ -63,10 +68,13 @@ module Bundler last_empty_key = key last_hash = stack[depth] else + val = [] if val == "[]" # empty array stack[depth][key] = val end elsif match = ARRAY_REGEX.match(line) _, val = match.captures + val = strip_comment(val) + last_hash[last_empty_key] = [] unless last_hash[last_empty_key].is_a?(Array) last_hash[last_empty_key].push(val) @@ -75,15 +83,16 @@ module Bundler res end - # for settings' keys - def convert_to_backward_compatible_key(key) - key = "#{key}/" if key =~ /https?:/i && key !~ %r{/\Z} - key = key.gsub(".", "__") if key.include?(".") - key + def strip_comment(val) + if val.include?("#") && !val.start_with?("#") + val.split("#", 2).first.strip + else + val + end end class << self - private :dump_hash, :convert_to_backward_compatible_key + private :dump_hash end end end |