aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bundler/cli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bundler/cli')
-rw-r--r--lib/bundler/cli/binstubs.rb2
-rw-r--r--lib/bundler/cli/common.rb10
-rw-r--r--lib/bundler/cli/fund.rb2
-rw-r--r--lib/bundler/cli/gem.rb23
-rw-r--r--lib/bundler/cli/info.rb15
-rw-r--r--lib/bundler/cli/install.rb6
-rw-r--r--lib/bundler/cli/lock.rb9
-rw-r--r--lib/bundler/cli/outdated.rb75
-rw-r--r--lib/bundler/cli/plugin.rb5
-rw-r--r--lib/bundler/cli/pristine.rb68
10 files changed, 90 insertions, 125 deletions
diff --git a/lib/bundler/cli/binstubs.rb b/lib/bundler/cli/binstubs.rb
index ad41ebf4b4..8ce138df96 100644
--- a/lib/bundler/cli/binstubs.rb
+++ b/lib/bundler/cli/binstubs.rb
@@ -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/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/fund.rb b/lib/bundler/cli/fund.rb
index 52db5aef68..ad7f31f3d6 100644
--- a/lib/bundler/cli/fund.rb
+++ b/lib/bundler/cli/fund.rb
@@ -16,7 +16,7 @@ module Bundler
deps = if groups.any?
Bundler.definition.dependencies_for(groups)
else
- Bundler.definition.current_dependencies
+ Bundler.definition.requested_dependencies
end
fund_info = deps.each_with_object([]) do |dep, arr|
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index 98192d952e..50288a02e7 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -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
@@ -276,6 +275,7 @@ module Bundler
end
def ask_and_set_test_framework
+ return if skip?(:test)
test_framework = options[:test] || Bundler.settings["gem.test"]
if test_framework.to_s.empty?
@@ -301,6 +301,10 @@ module Bundler
test_framework
end
+ def skip?(option)
+ options.key?(option) && options[option].nil?
+ end
+
def hint_text(setting)
if Bundler.settings["gem.#{setting}"] == false
"Your choice will only be applied to this gem."
@@ -311,6 +315,7 @@ module Bundler
end
def ask_and_set_ci
+ return if skip?(:ci)
ci_template = options[:ci] || Bundler.settings["gem.ci"]
if ci_template.to_s.empty?
@@ -342,6 +347,7 @@ module Bundler
end
def ask_and_set_linter
+ return if skip?(:linter)
linter_template = options[:linter] || Bundler.settings["gem.linter"]
linter_template = deprecated_rubocop_option if linter_template.nil?
@@ -437,7 +443,7 @@ module Bundler
end
def required_ruby_version
- "2.6.0"
+ "3.0.0"
end
def rubocop_version
@@ -448,19 +454,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 3facde1947..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
- 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 6c102d537d..fbe6b587d4 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -14,11 +14,15 @@ 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]
+ if target_rbconfig_path = options[:"target-rbconfig"]
+ Bundler.rubygems.set_target_rbconfig(target_rbconfig_path)
+ end
+
check_for_options_conflicts
check_trust_policy
diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb
index 7247121df5..dac3d2a09a 100644
--- a/lib/bundler/cli/lock.rb
+++ b/lib/bundler/cli/lock.rb
@@ -33,8 +33,11 @@ module Bundler
update = { bundler: bundler }
end
+ file = options[:lockfile]
+ file = file ? Pathname.new(file).expand_path : Bundler.default_lockfile
+
Bundler.settings.temporary(frozen: false) do
- definition = Bundler.definition(update)
+ definition = Bundler.definition(update, file)
Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update]
@@ -60,10 +63,8 @@ module Bundler
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)
+ definition.lock
end
end
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb
index 68c1bfd405..ec42e631bb 100644
--- a/lib/bundler/cli/outdated.rb
+++ b/lib/bundler/cli/outdated.rb
@@ -53,13 +53,13 @@ module Bundler
options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
end
- if options[:parseable] || options[:json]
+ if options[:parseable]
Bundler.ui.silence(&definition_resolution)
else
definition_resolution.call
end
- Bundler.ui.info "" unless options[:json]
+ Bundler.ui.info ""
# Loop through the current specs
gemfile_specs, dependency_specs = current_specs.partition do |spec|
@@ -98,24 +98,27 @@ module Bundler
end
if outdated_gems.empty?
- if options[:json]
- print_gems_json([])
- elsif !options[:parseable]
+ unless options[:parseable]
Bundler.ui.info(nothing_outdated_message)
end
else
- relevant_outdated_gems = if options_include_groups
- by_group(outdated_gems, filter: options[:group])
- else
- outdated_gems
- end
-
- if options[:json]
- print_gems_json(relevant_outdated_gems)
+ if options_include_groups
+ relevant_outdated_gems = outdated_gems.group_by {|g| g[:groups] }.sort.flat_map do |groups, gems|
+ contains_group = groups.split(", ").include?(options[:group])
+ next unless options[:groups] || contains_group
+
+ gems
+ end.compact
+
+ if options[:parseable]
+ print_gems(relevant_outdated_gems)
+ else
+ print_gems_table(relevant_outdated_gems)
+ end
elsif options[:parseable]
- print_gems(relevant_outdated_gems)
+ print_gems(outdated_gems)
else
- print_gems_table(relevant_outdated_gems)
+ print_gems_table(outdated_gems)
end
exit 1
@@ -159,13 +162,6 @@ module Bundler
active_specs.last
end
- def by_group(gems, filter: nil)
- gems.group_by {|g| g[:groups] }.sort.flat_map do |groups_string, grouped_gems|
- next if filter && !groups_string.split(", ").include?(filter)
- grouped_gems
- end.compact
- end
-
def print_gems(gems_list)
gems_list.each do |gem|
print_gem(
@@ -177,21 +173,6 @@ module Bundler
end
end
- def print_gems_json(gems_list)
- require "json"
- data = gems_list.map do |gem|
- gem_data_for(
- gem[:current_spec],
- gem[:active_spec],
- gem[:dependency],
- gem[:groups]
- )
- end
-
- data = { outdated_count: gems_list.count, outdated_gems: data }
- Bundler.ui.info data.to_json
- end
-
def print_gems_table(gems_list)
data = gems_list.map do |gem|
gem_column_for(
@@ -231,26 +212,6 @@ module Bundler
Bundler.ui.info output_message.rstrip
end
- def gem_data_for(current_spec, active_spec, dependency, groups)
- {
- current_spec: spec_data_for(current_spec),
- active_spec: spec_data_for(active_spec),
- dependency: dependency&.to_s,
- groups: (groups || "").split(", "),
- }
- end
-
- def spec_data_for(spec)
- {
- name: spec.name,
- version: spec.version.to_s,
- platform: spec.platform,
- source: spec.source.to_s,
- required_ruby_version: spec.required_ruby_version.to_s,
- required_rubygems_version: spec.required_rubygems_version.to_s,
- }
- end
-
def gem_column_for(current_spec, active_spec, dependency, groups)
current_version = "#{current_spec.version}#{current_spec.git_version}"
spec_version = "#{active_spec.version}#{active_spec.git_version}"
diff --git a/lib/bundler/cli/plugin.rb b/lib/bundler/cli/plugin.rb
index 1a33b5fc27..fd61ef0d95 100644
--- a/lib/bundler/cli/plugin.rb
+++ b/lib/bundler/cli/plugin.rb
@@ -5,14 +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 "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
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