This commit is contained in:
@@ -0,0 +1 @@
|
||||
# not in RDoc
|
||||
@@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
# Represents metadata from when the Bundler gem was built.
|
||||
module BuildMetadata
|
||||
# begin ivars
|
||||
@built_at = "2024-04-12".freeze
|
||||
@git_commit_sha = "4304697e0c".freeze
|
||||
@release = true
|
||||
# end ivars
|
||||
|
||||
# A hash representation of the build metadata.
|
||||
def self.to_h
|
||||
{
|
||||
"Built At" => built_at,
|
||||
"Git SHA" => git_commit_sha,
|
||||
"Released Version" => release?,
|
||||
}
|
||||
end
|
||||
|
||||
# A string representing the date the bundler gem was built.
|
||||
def self.built_at
|
||||
@built_at ||= Time.now.utc.strftime("%Y-%m-%d").freeze
|
||||
end
|
||||
|
||||
# The SHA for the git commit the bundler gem was built from.
|
||||
def self.git_commit_sha
|
||||
return @git_commit_sha if instance_variable_defined? :@git_commit_sha
|
||||
|
||||
# If Bundler has been installed without its .git directory and without a
|
||||
# commit instance variable then we can't determine its commits SHA.
|
||||
git_dir = File.expand_path("../../../.git", __dir__)
|
||||
if File.directory?(git_dir)
|
||||
return @git_commit_sha = IO.popen(%w[git rev-parse --short HEAD], { chdir: git_dir }, &:read).strip.freeze
|
||||
end
|
||||
|
||||
@git_commit_sha ||= "unknown"
|
||||
end
|
||||
|
||||
# Whether this is an official release build of Bundler.
|
||||
def self.release?
|
||||
@release
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "shared_helpers"
|
||||
Bundler::SharedHelpers.major_deprecation 2,
|
||||
"The Bundler task for Capistrano. Please use https://github.com/capistrano/bundler"
|
||||
|
||||
# Capistrano task for Bundler.
|
||||
#
|
||||
# Add "require 'bundler/capistrano'" in your Capistrano deploy.rb, and
|
||||
# Bundler will be activated after each new deployment.
|
||||
require_relative "deployment"
|
||||
require "capistrano/version"
|
||||
|
||||
if defined?(Capistrano::Version) && Gem::Version.new(Capistrano::Version).release >= Gem::Version.new("3.0")
|
||||
raise "For Capistrano 3.x integration, please use https://github.com/capistrano/bundler"
|
||||
end
|
||||
|
||||
Capistrano::Configuration.instance(:must_exist).load do
|
||||
before "deploy:finalize_update", "bundle:install"
|
||||
Bundler::Deployment.define_task(self, :task, except: { no_release: true })
|
||||
set :rake, lambda { "#{fetch(:bundle_cmd, "bundle")} exec rake" }
|
||||
end
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,846 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "vendored_thor"
|
||||
|
||||
module Bundler
|
||||
class CLI < Thor
|
||||
require_relative "cli/common"
|
||||
|
||||
package_name "Bundler"
|
||||
|
||||
AUTO_INSTALL_CMDS = %w[show binstubs outdated exec open console licenses clean].freeze
|
||||
PARSEABLE_COMMANDS = %w[check config help exec platform show version].freeze
|
||||
EXTENSIONS = ["c", "rust"].freeze
|
||||
|
||||
COMMAND_ALIASES = {
|
||||
"check" => "c",
|
||||
"install" => "i",
|
||||
"plugin" => "",
|
||||
"list" => "ls",
|
||||
"exec" => ["e", "ex", "exe"],
|
||||
"cache" => ["package", "pack"],
|
||||
"version" => ["-v", "--version"],
|
||||
}.freeze
|
||||
|
||||
def self.start(*)
|
||||
check_deprecated_ext_option(ARGV) if ARGV.include?("--ext")
|
||||
|
||||
super
|
||||
ensure
|
||||
Bundler::SharedHelpers.print_major_deprecations!
|
||||
end
|
||||
|
||||
def self.dispatch(*)
|
||||
super do |i|
|
||||
i.send(:print_command)
|
||||
i.send(:warn_on_outdated_bundler)
|
||||
end
|
||||
end
|
||||
|
||||
def self.all_aliases
|
||||
@all_aliases ||= begin
|
||||
command_aliases = {}
|
||||
|
||||
COMMAND_ALIASES.each do |name, aliases|
|
||||
Array(aliases).each do |one_alias|
|
||||
command_aliases[one_alias] = name
|
||||
end
|
||||
end
|
||||
|
||||
command_aliases
|
||||
end
|
||||
end
|
||||
|
||||
def self.aliases_for(command_name)
|
||||
COMMAND_ALIASES.select {|k, _| k == command_name }.invert
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
|
||||
custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile]
|
||||
if custom_gemfile && !custom_gemfile.empty?
|
||||
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", File.expand_path(custom_gemfile)
|
||||
Bundler.reset_settings_and_root!
|
||||
end
|
||||
|
||||
Bundler.self_manager.restart_with_locked_bundler_if_needed
|
||||
|
||||
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)
|
||||
rescue UnknownArgumentError => e
|
||||
raise InvalidOption, e.message
|
||||
ensure
|
||||
self.options ||= {}
|
||||
unprinted_warnings = Bundler.ui.unprinted_warnings
|
||||
Bundler.ui = UI::Shell.new(options)
|
||||
Bundler.ui.level = "debug" if options["verbose"]
|
||||
unprinted_warnings.each {|w| Bundler.ui.warn(w) }
|
||||
end
|
||||
|
||||
check_unknown_options!(except: [:config, :exec])
|
||||
stop_on_unknown_option! :exec
|
||||
|
||||
desc "cli_help", "Prints a summary of bundler commands", hide: true
|
||||
def cli_help
|
||||
version
|
||||
Bundler.ui.info "\n"
|
||||
|
||||
primary_commands = ["install", "update", "cache", "exec", "config", "help"]
|
||||
|
||||
list = self.class.printable_commands(true)
|
||||
by_name = list.group_by {|name, _message| name.match(/^bundle (\w+)/)[1] }
|
||||
utilities = by_name.keys.sort - primary_commands
|
||||
primary_commands.map! {|name| (by_name[name] || raise("no primary command #{name}")).first }
|
||||
utilities.map! {|name| by_name[name].first }
|
||||
|
||||
shell.say "Bundler commands:\n\n"
|
||||
|
||||
shell.say " Primary commands:\n"
|
||||
shell.print_table(primary_commands, indent: 4, truncate: true)
|
||||
shell.say
|
||||
shell.say " Utilities:\n"
|
||||
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"
|
||||
|
||||
def help(cli = nil)
|
||||
case cli
|
||||
when "gemfile" then command = "gemfile"
|
||||
when nil then command = "bundle"
|
||||
else command = "bundle-#{cli}"
|
||||
end
|
||||
|
||||
man_path = File.expand_path("man", __dir__)
|
||||
man_pages = Hash[Dir.glob(File.join(man_path, "**", "*")).grep(/.*\.\d*\Z/).collect do |f|
|
||||
[File.basename(f, ".*"), f]
|
||||
end]
|
||||
|
||||
if man_pages.include?(command)
|
||||
man_page = man_pages[command]
|
||||
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
|
||||
elsif command_path = Bundler.which("bundler-#{cli}")
|
||||
Kernel.exec(command_path, "--help")
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def self.handle_no_command_error(command, has_namespace = $thor_runner)
|
||||
if Bundler.feature_flag.plugins? && Bundler::Plugin.command?(command)
|
||||
return Bundler::Plugin.exec_command(command, ARGV[1..-1])
|
||||
end
|
||||
|
||||
return super unless command_path = Bundler.which("bundler-#{command}")
|
||||
|
||||
Kernel.exec(command_path, *ARGV[1..-1])
|
||||
end
|
||||
|
||||
desc "init [OPTIONS]", "Generates a Gemfile into the current working directory"
|
||||
long_desc <<-D
|
||||
Init generates a default Gemfile in the current working directory. When adding a
|
||||
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'"
|
||||
def init
|
||||
require_relative "cli/init"
|
||||
Init.new(options.dup).run
|
||||
end
|
||||
|
||||
desc "check [OPTIONS]", "Checks if the dependencies listed in Gemfile are satisfied by currently installed gems"
|
||||
long_desc <<-D
|
||||
Check 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.
|
||||
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?}"
|
||||
def check
|
||||
remembered_flag_deprecation("path")
|
||||
|
||||
require_relative "cli/check"
|
||||
Check.new(options).run
|
||||
end
|
||||
|
||||
map aliases_for("check")
|
||||
|
||||
desc "remove [GEM [GEM ...]]", "Removes gems from the Gemfile"
|
||||
long_desc <<-D
|
||||
Removes the given gems from the Gemfile while ensuring that the resulting Gemfile is still valid. If the gem is not found, Bundler prints a error message and if gem could not be removed due to any reason Bundler will display a warning.
|
||||
D
|
||||
method_option "install", type: :boolean, banner: "Runs 'bundle install' after removing the gems from the Gemfile"
|
||||
def remove(*gems)
|
||||
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
|
||||
|
||||
desc "install [OPTIONS]", "Install the current environment to the system"
|
||||
long_desc <<-D
|
||||
Install will install all of the gems in the current bundle, making them available
|
||||
for use. In a freshly checked out repository, this command will give you the same
|
||||
gem versions as the last person who updated the Gemfile and ran `bundle update`.
|
||||
|
||||
Passing [DIR] to install (e.g. vendor) will cause the unpacked gems to be installed
|
||||
into the [DIR] directory rather than into system gems.
|
||||
|
||||
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."
|
||||
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 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
|
||||
Install.new(options.dup).run
|
||||
end
|
||||
end
|
||||
|
||||
map aliases_for("install")
|
||||
|
||||
desc "update [OPTIONS]", "Update the current environment"
|
||||
long_desc <<-D
|
||||
Update will install the newest versions of the gems listed in the Gemfile. Use
|
||||
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."
|
||||
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
|
||||
Update.new(options, gems).run
|
||||
end
|
||||
end
|
||||
|
||||
desc "show GEM [OPTIONS]", "Shows all gems that are part of the bundle, or the path to a given gem"
|
||||
long_desc <<-D
|
||||
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."
|
||||
def show(gem_name = nil)
|
||||
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"
|
||||
def list
|
||||
require_relative "cli/list"
|
||||
List.new(options).run
|
||||
end
|
||||
|
||||
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"
|
||||
def info(gem_name)
|
||||
require_relative "cli/info"
|
||||
Info.new(options, gem_name).run
|
||||
end
|
||||
|
||||
desc "binstubs GEM [OPTIONS]", "Install the binstubs of the listed gem"
|
||||
long_desc <<-D
|
||||
Generate binstubs for executables in [GEM]. Binstubs are put into bin,
|
||||
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"
|
||||
def binstubs(*gems)
|
||||
require_relative "cli/binstubs"
|
||||
Binstubs.new(options, gems).run
|
||||
end
|
||||
|
||||
desc "add GEM VERSION", "Add gem to Gemfile and run bundle install"
|
||||
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"
|
||||
def add(*gems)
|
||||
require_relative "cli/add"
|
||||
Add.new(options.dup, gems).run
|
||||
end
|
||||
|
||||
desc "outdated GEM [OPTIONS]", "List installed gems with newer versions available"
|
||||
long_desc <<-D
|
||||
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.
|
||||
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
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
|
||||
control repository, others who check out your source will be able to install the
|
||||
bundle without having to download any additional gems.
|
||||
D
|
||||
def cache
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
into the system wide RubyGems repository.
|
||||
D
|
||||
def exec(*args)
|
||||
if ARGV.include?("--no-keep-file-descriptors")
|
||||
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"
|
||||
Exec.new(options, args).run
|
||||
end
|
||||
|
||||
map aliases_for("exec")
|
||||
|
||||
desc "config NAME [VALUE]", "Retrieve or set a configuration value"
|
||||
long_desc <<-D
|
||||
Retrieves or sets a configuration value. If only one parameter is provided, retrieve the value. If two parameters are provided, replace the
|
||||
existing value with the newly provided one.
|
||||
|
||||
By default, setting a configuration value sets it for all projects
|
||||
on the machine.
|
||||
|
||||
If a global setting is superseded by local configuration, this command
|
||||
will show the current value, as well as any superseded values and
|
||||
where they were specified.
|
||||
D
|
||||
require_relative "cli/config"
|
||||
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."
|
||||
def open(name)
|
||||
require_relative "cli/open"
|
||||
Open.new(options, name).run
|
||||
end
|
||||
|
||||
unless Bundler.feature_flag.bundler_3_mode?
|
||||
desc "console [GROUP]", "Opens an IRB session with the bundle pre-loaded"
|
||||
def console(group = nil)
|
||||
require_relative "cli/console"
|
||||
Console.new(options, group).run
|
||||
end
|
||||
end
|
||||
|
||||
desc "version", "Prints Bundler version information"
|
||||
def version
|
||||
cli_help = current_command.name == "cli_help"
|
||||
if cli_help || ARGV.include?("version")
|
||||
build_info = " (#{BuildMetadata.built_at} commit #{BuildMetadata.git_commit_sha})"
|
||||
end
|
||||
|
||||
if !cli_help && Bundler.feature_flag.print_only_version_number?
|
||||
Bundler.ui.info "#{Bundler::VERSION}#{build_info}"
|
||||
else
|
||||
Bundler.ui.info "Bundler version #{Bundler::VERSION}#{build_info}"
|
||||
end
|
||||
end
|
||||
|
||||
map aliases_for("version")
|
||||
|
||||
desc "licenses", "Prints the license of all gems in the bundle"
|
||||
def licenses
|
||||
Bundler.load.specs.sort_by {|s| s.license.to_s }.reverse_each do |s|
|
||||
gem_name = s.name
|
||||
license = s.license || s.licenses
|
||||
|
||||
if license.empty?
|
||||
Bundler.ui.warn "#{gem_name}: Unknown"
|
||||
else
|
||||
Bundler.ui.info "#{gem_name}: #{license}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Bundler.feature_flag.bundler_3_mode?
|
||||
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."
|
||||
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"
|
||||
Viz.new(options.dup).run
|
||||
end
|
||||
end
|
||||
|
||||
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>`."
|
||||
|
||||
def gem(name)
|
||||
end
|
||||
|
||||
commands["gem"].tap do |gem_command|
|
||||
def gem_command.run(instance, args = [])
|
||||
arity = 1 # name
|
||||
|
||||
require_relative "cli/gem"
|
||||
cmd_args = args + [instance]
|
||||
cmd_args.unshift(instance.options)
|
||||
|
||||
cmd = begin
|
||||
Gem.new(*cmd_args)
|
||||
rescue ArgumentError => e
|
||||
instance.class.handle_argument_error(self, e, args, arity)
|
||||
end
|
||||
|
||||
cmd.run
|
||||
end
|
||||
end
|
||||
|
||||
undef_method(:gem)
|
||||
define_method(:gem, old_gem)
|
||||
private :gem
|
||||
|
||||
def self.source_root
|
||||
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."
|
||||
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"
|
||||
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"
|
||||
def inject(name, version)
|
||||
SharedHelpers.major_deprecation 2, "The `inject` command has been replaced by the `add` command"
|
||||
require_relative "cli/inject"
|
||||
Inject.new(options.dup, name, version).run
|
||||
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"
|
||||
def lock
|
||||
require_relative "cli/lock"
|
||||
Lock.new(options).run
|
||||
end
|
||||
|
||||
desc "env", "Print information about the environment Bundler is running under"
|
||||
def env
|
||||
Env.write($stdout)
|
||||
end
|
||||
|
||||
desc "doctor [OPTIONS]", "Checks the bundle for common problems"
|
||||
long_desc <<-D
|
||||
Doctor scans the OS dependencies of each of the gems requested in the Gemfile. If
|
||||
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."
|
||||
def doctor
|
||||
require_relative "cli/doctor"
|
||||
Doctor.new(options).run
|
||||
end
|
||||
|
||||
desc "issue", "Learn how to report an issue in Bundler"
|
||||
def issue
|
||||
require_relative "cli/issue"
|
||||
Issue.new.run
|
||||
end
|
||||
|
||||
desc "pristine [GEMS...]", "Restores installed gems to pristine condition"
|
||||
long_desc <<-D
|
||||
Restores installed gems to pristine condition from files located in the
|
||||
gem cache. Gems installed from a git repository will be issued `git
|
||||
checkout --force`.
|
||||
D
|
||||
def pristine(*gems)
|
||||
require_relative "cli/pristine"
|
||||
Bundler.settings.temporary(no_install: false) do
|
||||
Pristine.new(gems).run
|
||||
end
|
||||
end
|
||||
|
||||
if Bundler.feature_flag.plugins?
|
||||
require_relative "cli/plugin"
|
||||
desc "plugin", "Manage the bundler plugins"
|
||||
subcommand "plugin", Plugin
|
||||
end
|
||||
|
||||
# Reformat the arguments passed to bundle that include a --help flag
|
||||
# into the corresponding `bundle help #{command}` call
|
||||
def self.reformatted_help_args(args)
|
||||
bundler_commands = (COMMAND_ALIASES.keys + COMMAND_ALIASES.values).flatten
|
||||
|
||||
help_flags = %w[--help -h]
|
||||
exec_commands = ["exec"] + COMMAND_ALIASES["exec"]
|
||||
|
||||
help_used = args.index {|a| help_flags.include? a }
|
||||
exec_used = args.index {|a| exec_commands.include? a }
|
||||
|
||||
command = args.find {|a| bundler_commands.include? a }
|
||||
command = all_aliases[command] if all_aliases[command]
|
||||
|
||||
if exec_used && help_used
|
||||
if exec_used + help_used == 1
|
||||
%w[help exec]
|
||||
else
|
||||
args
|
||||
end
|
||||
elsif help_used
|
||||
args = args.dup
|
||||
args.delete_at(help_used)
|
||||
["help", command || args].flatten.compact
|
||||
else
|
||||
args
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_deprecated_ext_option(arguments)
|
||||
# when deprecated version of `--ext` is called
|
||||
# print out deprecation warning and pretend `--ext=c` was provided
|
||||
if deprecated_ext_value?(arguments)
|
||||
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
|
||||
|
||||
def self.deprecated_ext_value?(arguments)
|
||||
index = arguments.index("--ext")
|
||||
next_argument = arguments[index + 1]
|
||||
|
||||
# it is ok when --ext is followed with valid extension value
|
||||
# for example `bundle gem hello --ext c`
|
||||
return false if EXTENSIONS.include?(next_argument)
|
||||
|
||||
# deprecated call when --ext is called with no value in last position
|
||||
# for example `bundle gem hello_gem --ext`
|
||||
return true if next_argument.nil?
|
||||
|
||||
# deprecated call when --ext is followed by other parameter
|
||||
# for example `bundle gem --ext --no-ci hello_gem`
|
||||
return true if next_argument.start_with?("-")
|
||||
|
||||
# deprecated call when --ext is followed by gem name
|
||||
# for example `bundle gem --ext hello_gem`
|
||||
return true if next_argument
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
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, GitError
|
||||
Bundler.ui.info "Automatically installing missing gems."
|
||||
Bundler.reset!
|
||||
invoke :install, []
|
||||
Bundler.reset!
|
||||
end
|
||||
end
|
||||
|
||||
def current_command
|
||||
_, _, config = @_initializer
|
||||
config[:current_command]
|
||||
end
|
||||
|
||||
def print_command
|
||||
return unless Bundler.ui.debug?
|
||||
cmd = current_command
|
||||
command_name = cmd.name
|
||||
return if PARSEABLE_COMMANDS.include?(command_name)
|
||||
command = ["bundle", command_name] + args
|
||||
options_to_print = options.dup
|
||||
options_to_print.delete_if do |k, v|
|
||||
next unless o = cmd.options[k]
|
||||
o.default == v
|
||||
end
|
||||
command << Thor::Options.to_switches(options_to_print.sort_by(&:first)).strip
|
||||
command.reject!(&:empty?)
|
||||
Bundler.ui.info "Running `#{command * " "}` with bundler #{Bundler::VERSION}"
|
||||
end
|
||||
|
||||
def warn_on_outdated_bundler
|
||||
return if Bundler.settings[:disable_version_check]
|
||||
|
||||
command_name = current_command.name
|
||||
return if PARSEABLE_COMMANDS.include?(command_name)
|
||||
|
||||
return unless SharedHelpers.md5_available?
|
||||
|
||||
latest = Fetcher::CompactIndex.
|
||||
new(nil, Source::Rubygems::Remote.new(Gem::URI("https://rubygems.org")), nil, nil).
|
||||
send(:compact_index_client).
|
||||
instance_variable_get(:@cache).
|
||||
dependencies("bundler").
|
||||
map {|d| Gem::Version.new(d.first) }.
|
||||
max
|
||||
return unless latest
|
||||
|
||||
current = Gem::Version.new(VERSION)
|
||||
return if current >= latest
|
||||
|
||||
Bundler.ui.warn \
|
||||
"The latest bundler is #{latest}, but you are currently running #{current}.\n" \
|
||||
"To update to the most recent version, run `bundle update --bundler`"
|
||||
rescue RuntimeError
|
||||
nil
|
||||
end
|
||||
|
||||
def remembered_negative_flag_deprecation(name)
|
||||
positive_name = name.gsub(/\Ano-/, "")
|
||||
option = current_command.options[positive_name]
|
||||
flag_name = "--no-" + option.switch_name.gsub(/\A--/, "")
|
||||
|
||||
flag_deprecation(positive_name, flag_name, option)
|
||||
end
|
||||
|
||||
def remembered_flag_deprecation(name)
|
||||
option = current_command.options[name]
|
||||
flag_name = option.switch_name
|
||||
|
||||
flag_deprecation(name, flag_name, option)
|
||||
end
|
||||
|
||||
def flag_deprecation(name, flag_name, option)
|
||||
name_index = ARGV.find {|arg| flag_name == arg.split("=")[0] }
|
||||
return unless name_index
|
||||
|
||||
value = options[name]
|
||||
value = value.join(" ").to_s if option.type == :array
|
||||
value = "'#{value}'" unless option.type == :boolean
|
||||
|
||||
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 #{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
|
||||
@@ -0,0 +1,47 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Add
|
||||
attr_reader :gems, :options, :version
|
||||
|
||||
def initialize(options, gems)
|
||||
@gems = gems
|
||||
@options = options
|
||||
@options[:group] = options[:group].split(",").map(&:strip) unless options[:group].nil?
|
||||
@version = options[:version].split(",").map(&:strip) unless options[:version].nil?
|
||||
end
|
||||
|
||||
def run
|
||||
validate_options!
|
||||
inject_dependencies
|
||||
perform_bundle_install unless options["skip-install"]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def perform_bundle_install
|
||||
Installer.install(Bundler.root, Bundler.definition)
|
||||
Bundler.load.cache if Bundler.app_cache.exist?
|
||||
end
|
||||
|
||||
def inject_dependencies
|
||||
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])
|
||||
end
|
||||
|
||||
def validate_options!
|
||||
raise InvalidOption, "You can not specify `--strict` and `--optimistic` at the same time." if options[:strict] && options[:optimistic]
|
||||
|
||||
# raise error when no gems are specified
|
||||
raise InvalidOption, "Please specify gems to add." if gems.empty?
|
||||
|
||||
version.to_a.each do |v|
|
||||
raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN.match?(v.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,57 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Binstubs
|
||||
attr_reader :options, :gems
|
||||
def initialize(options, gems)
|
||||
@options = options
|
||||
@gems = gems
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.definition.validate_runtime!
|
||||
path_option = options["path"]
|
||||
path_option = nil if path_option&.empty?
|
||||
Bundler.settings.set_command_option :bin, path_option if options["path"]
|
||||
Bundler.settings.set_command_option_if_given :shebang, options["shebang"]
|
||||
installer = Installer.new(Bundler.root, Bundler.definition)
|
||||
|
||||
installer_opts = {
|
||||
force: options[:force],
|
||||
binstubs_cmd: true,
|
||||
all_platforms: options["all-platforms"],
|
||||
}
|
||||
|
||||
if options[:all]
|
||||
raise InvalidOption, "Cannot specify --all with specific gems" unless gems.empty?
|
||||
@gems = Bundler.definition.specs.map(&:name)
|
||||
installer_opts.delete(:binstubs_cmd)
|
||||
elsif gems.empty?
|
||||
Bundler.ui.error "`bundle binstubs` needs at least one gem to run."
|
||||
exit 1
|
||||
end
|
||||
|
||||
gems.each do |gem_name|
|
||||
spec = Bundler.definition.specs.find {|s| s.name == gem_name }
|
||||
unless spec
|
||||
raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(
|
||||
gem_name, Bundler.definition.specs
|
||||
)
|
||||
end
|
||||
|
||||
if options[:standalone]
|
||||
if gem_name == "bundler"
|
||||
Bundler.ui.warn("Sorry, Bundler can only be run via RubyGems.") unless options[:all]
|
||||
next
|
||||
end
|
||||
|
||||
Bundler.settings.temporary(path: Bundler.settings[:path] || Bundler.root) do
|
||||
installer.generate_standalone_bundler_executable_stubs(spec, installer_opts)
|
||||
end
|
||||
else
|
||||
installer.generate_bundler_executable_stubs(spec, installer_opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Cache
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.ui.level = "warn" if options[:quiet]
|
||||
Bundler.settings.set_command_option_if_given :path, options[:path]
|
||||
Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"]
|
||||
|
||||
setup_cache_all
|
||||
install
|
||||
|
||||
# TODO: move cache contents here now that all bundles are locked
|
||||
custom_path = Bundler.settings[:path] if options[:path]
|
||||
|
||||
Bundler.settings.temporary(cache_all_platforms: options["all-platforms"]) do
|
||||
Bundler.load.cache(custom_path)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def install
|
||||
require_relative "install"
|
||||
options = self.options.dup
|
||||
options["local"] = false if Bundler.settings[:cache_all_platforms]
|
||||
options["no-cache"] = true
|
||||
Bundler::CLI::Install.new(options).run
|
||||
end
|
||||
|
||||
def setup_cache_all
|
||||
all = options.fetch(:all, Bundler.feature_flag.cache_all? || nil)
|
||||
|
||||
Bundler.settings.set_command_option_if_given :cache_all, all
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,40 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Check
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.settings.set_command_option_if_given :path, options[:path]
|
||||
|
||||
definition = Bundler.definition
|
||||
definition.validate_runtime!
|
||||
|
||||
begin
|
||||
definition.resolve_only_locally!
|
||||
not_installed = definition.missing_specs
|
||||
rescue GemNotFound, SolveFailure
|
||||
Bundler.ui.error "Bundler can't satisfy your Gemfile's dependencies."
|
||||
Bundler.ui.warn "Install missing gems with `bundle install`."
|
||||
exit 1
|
||||
end
|
||||
|
||||
if not_installed.any?
|
||||
Bundler.ui.error "The following gems are missing"
|
||||
not_installed.each {|s| Bundler.ui.error " * #{s.name} (#{s.version})" }
|
||||
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 #{SharedHelpers.relative_lockfile_path} present"
|
||||
exit 1
|
||||
else
|
||||
Bundler.load.lock(preserve_unknown_sections: true) unless options[:"dry-run"]
|
||||
Bundler.ui.info "The Gemfile's dependencies are satisfied"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Clean
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
require_path_or_force unless options[:"dry-run"]
|
||||
Bundler.load.clean(options[:"dry-run"])
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def require_path_or_force
|
||||
return unless Bundler.use_system_gems? && !options[:force]
|
||||
raise InvalidOption, "Cleaning all the gems on your system is dangerous! " \
|
||||
"If you're sure you want to remove every system gem not in this " \
|
||||
"bundle, run `bundle clean --force`."
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,138 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
module CLI::Common
|
||||
def self.output_post_install_messages(messages)
|
||||
return if Bundler.settings["ignore_messages"]
|
||||
messages.to_a.each do |name, msg|
|
||||
print_post_install_message(name, msg) unless Bundler.settings["ignore_messages.#{name}"]
|
||||
end
|
||||
end
|
||||
|
||||
def self.print_post_install_message(name, msg)
|
||||
Bundler.ui.confirm "Post-install message from #{name}:"
|
||||
Bundler.ui.info msg
|
||||
end
|
||||
|
||||
def self.output_fund_metadata_summary
|
||||
return if Bundler.settings["ignore_funding_requests"]
|
||||
definition = Bundler.definition
|
||||
current_dependencies = definition.requested_dependencies
|
||||
current_specs = definition.specs
|
||||
|
||||
count = current_dependencies.count {|dep| current_specs[dep.name].first.metadata.key?("funding_uri") }
|
||||
|
||||
return if count.zero?
|
||||
|
||||
intro = count > 1 ? "#{count} installed gems you directly depend on are" : "#{count} installed gem you directly depend on is"
|
||||
message = "#{intro} looking for funding.\n Run `bundle fund` for details"
|
||||
Bundler.ui.info message
|
||||
end
|
||||
|
||||
def self.output_without_groups_message(command)
|
||||
return if Bundler.settings[:without].empty?
|
||||
Bundler.ui.confirm without_groups_message(command)
|
||||
end
|
||||
|
||||
def self.without_groups_message(command)
|
||||
command_in_past_tense = command == :install ? "installed" : "updated"
|
||||
groups = Bundler.settings[:without]
|
||||
"Gems in the #{verbalize_groups(groups)} were not #{command_in_past_tense}."
|
||||
end
|
||||
|
||||
def self.verbalize_groups(groups)
|
||||
groups.map! {|g| "'#{g}'" }
|
||||
group_list = [groups[0...-1].join(", "), groups[-1..-1]].
|
||||
reject {|s| s.to_s.empty? }.join(" and ")
|
||||
group_str = groups.size == 1 ? "group" : "groups"
|
||||
"#{group_str} #{group_list}"
|
||||
end
|
||||
|
||||
def self.select_spec(name, regex_match = nil)
|
||||
specs = []
|
||||
regexp = Regexp.new(name) if regex_match
|
||||
|
||||
Bundler.definition.specs.each do |spec|
|
||||
return spec if spec.name == name
|
||||
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 }
|
||||
|
||||
if dep_in_other_group
|
||||
raise GemNotFound, "Could not find gem '#{name}', because it's in the #{verbalize_groups(dep_in_other_group.groups)}, configured to be ignored."
|
||||
else
|
||||
raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
|
||||
end
|
||||
when 1
|
||||
specs.first
|
||||
else
|
||||
ask_for_spec_from(specs)
|
||||
end
|
||||
rescue RegexpError
|
||||
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
|
||||
end
|
||||
Bundler.ui.info "0 : - exit -", true
|
||||
|
||||
num = Bundler.ui.ask("> ").to_i
|
||||
num > 0 ? specs[num - 1] : nil
|
||||
end
|
||||
|
||||
def self.gem_not_found_message(missing_gem_name, alternatives)
|
||||
require_relative "../similarity_detector"
|
||||
message = "Could not find gem '#{missing_gem_name}'."
|
||||
alternate_names = alternatives.map {|a| a.respond_to?(:name) ? a.name : a }
|
||||
suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name)
|
||||
message += "\nDid you mean #{suggestions}?" if suggestions
|
||||
message
|
||||
end
|
||||
|
||||
def self.ensure_all_gems_in_lockfile!(names, locked_gems = Bundler.locked_gems)
|
||||
return unless locked_gems
|
||||
|
||||
locked_names = locked_gems.specs.map(&:name).uniq
|
||||
names.-(locked_names).each do |g|
|
||||
raise GemNotFound, gem_not_found_message(g, locked_names)
|
||||
end
|
||||
end
|
||||
|
||||
def self.configure_gem_version_promoter(definition, options)
|
||||
patch_level = patch_level_options(options)
|
||||
patch_level << :patch if patch_level.empty? && Bundler.settings[:prefer_patch]
|
||||
raise InvalidOption, "Provide only one of the following options: #{patch_level.join(", ")}" unless patch_level.length <= 1
|
||||
|
||||
definition.gem_version_promoter.tap do |gvp|
|
||||
gvp.level = patch_level.first || :major
|
||||
gvp.strict = options[:strict] || options["filter-strict"]
|
||||
gvp.pre = options[:pre]
|
||||
end
|
||||
end
|
||||
|
||||
def self.patch_level_options(options)
|
||||
[:major, :minor, :patch].select {|v| options.keys.include?(v.to_s) }
|
||||
end
|
||||
|
||||
def self.clean_after_install?
|
||||
clean = Bundler.settings[:clean]
|
||||
return clean unless clean.nil?
|
||||
clean ||= Bundler.feature_flag.auto_clean_without_path? && Bundler.settings[:path].nil?
|
||||
clean &&= !Bundler.use_system_gems?
|
||||
clean
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,204 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Config < Thor
|
||||
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"
|
||||
end
|
||||
private_class_method :scope_options
|
||||
|
||||
desc "base NAME [VALUE]", "The Bundler 1 config interface", hide: true
|
||||
scope_options
|
||||
method_option :delete, type: :boolean, banner: "delete"
|
||||
def base(name = nil, *value)
|
||||
new_args =
|
||||
if ARGV.size == 1
|
||||
["config", "list"]
|
||||
elsif ARGV.include?("--delete")
|
||||
ARGV.map {|arg| arg == "--delete" ? "unset" : arg }
|
||||
elsif ARGV.include?("--global") || ARGV.include?("--local") || ARGV.size == 3
|
||||
["config", "set", *ARGV[1..-1]]
|
||||
else
|
||||
["config", "get", ARGV[1]]
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
desc "list", "List out all configured settings"
|
||||
def list
|
||||
Base.new(options, nil, nil, self).run
|
||||
end
|
||||
|
||||
desc "get NAME", "Returns the value for the given key"
|
||||
def get(name)
|
||||
Base.new(options, name, nil, self).run
|
||||
end
|
||||
|
||||
desc "set NAME VALUE", "Sets the given value for the given key"
|
||||
scope_options
|
||||
def set(name, value, *value_)
|
||||
Base.new(options, name, value_.unshift(value), self).run
|
||||
end
|
||||
|
||||
desc "unset NAME", "Unsets the value for the given key"
|
||||
scope_options
|
||||
def unset(name)
|
||||
options[:delete] = true
|
||||
Base.new(options, name, nil, self).run
|
||||
end
|
||||
|
||||
default_task :base
|
||||
|
||||
class Base
|
||||
attr_reader :name, :value, :options, :scope, :thor
|
||||
|
||||
def initialize(options, name, value, thor)
|
||||
@options = options
|
||||
@name = name
|
||||
value = Array(value)
|
||||
@value = value.empty? ? nil : value.join(" ")
|
||||
@thor = thor
|
||||
validate_scope!
|
||||
end
|
||||
|
||||
def run
|
||||
unless name
|
||||
warn_unused_scope "Ignoring --#{scope}"
|
||||
confirm_all
|
||||
return
|
||||
end
|
||||
|
||||
if options[:delete]
|
||||
if !explicit_scope? || scope != "global"
|
||||
Bundler.settings.set_local(name, nil)
|
||||
end
|
||||
if !explicit_scope? || scope != "local"
|
||||
Bundler.settings.set_global(name, nil)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if value.nil?
|
||||
warn_unused_scope "Ignoring --#{scope} since no value to set was given"
|
||||
|
||||
if options[:parseable]
|
||||
if value = Bundler.settings[name]
|
||||
Bundler.ui.info("#{name}=#{value}")
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
confirm(name)
|
||||
return
|
||||
end
|
||||
|
||||
Bundler.ui.info(message) if message
|
||||
Bundler.settings.send("set_#{scope}", name, new_value)
|
||||
end
|
||||
|
||||
def confirm_all
|
||||
if @options[:parseable]
|
||||
thor.with_padding do
|
||||
Bundler.settings.all.each do |setting|
|
||||
val = Bundler.settings[setting]
|
||||
Bundler.ui.info "#{setting}=#{val}"
|
||||
end
|
||||
end
|
||||
else
|
||||
Bundler.ui.confirm "Settings are listed in order of priority. The top value will be used.\n"
|
||||
Bundler.settings.all.each do |setting|
|
||||
Bundler.ui.confirm setting
|
||||
show_pretty_values_for(setting)
|
||||
Bundler.ui.confirm ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def confirm(name)
|
||||
Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used"
|
||||
show_pretty_values_for(name)
|
||||
end
|
||||
|
||||
def new_value
|
||||
pathname = Pathname.new(value)
|
||||
if name.start_with?("local.") && pathname.directory?
|
||||
pathname.expand_path.to_s
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
def message
|
||||
locations = Bundler.settings.locations(name)
|
||||
if @options[:parseable]
|
||||
"#{name}=#{new_value}" if new_value
|
||||
elsif scope == "global"
|
||||
if !locations[:local].nil?
|
||||
"Your application has set #{name} to #{locations[:local].inspect}. " \
|
||||
"This will override the global value you are currently setting"
|
||||
elsif locations[:env]
|
||||
"You have a bundler environment variable for #{name} set to " \
|
||||
"#{locations[:env].inspect}. This will take precedence over the global value you are setting"
|
||||
elsif !locations[:global].nil? && locations[:global] != value
|
||||
"You are replacing the current global value of #{name}, which is currently " \
|
||||
"#{locations[:global].inspect}"
|
||||
end
|
||||
elsif scope == "local" && !locations[:local].nil? && locations[:local] != value
|
||||
"You are replacing the current local value of #{name}, which is currently " \
|
||||
"#{locations[:local].inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
def show_pretty_values_for(setting)
|
||||
thor.with_padding do
|
||||
Bundler.settings.pretty_values_for(setting).each do |line|
|
||||
Bundler.ui.info line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def explicit_scope?
|
||||
@explicit_scope
|
||||
end
|
||||
|
||||
def warn_unused_scope(msg)
|
||||
return unless explicit_scope?
|
||||
return if options[:parseable]
|
||||
|
||||
Bundler.ui.warn(msg)
|
||||
end
|
||||
|
||||
def validate_scope!
|
||||
@explicit_scope = true
|
||||
scopes = %w[global local].select {|s| options[s] }
|
||||
case scopes.size
|
||||
when 0
|
||||
@scope = inside_app? ? "local" : "global"
|
||||
@explicit_scope = false
|
||||
when 1
|
||||
@scope = scopes.first
|
||||
else
|
||||
raise InvalidOption,
|
||||
"The options #{scopes.join " and "} were specified. Please only use one of the switches at a time."
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def inside_app?
|
||||
Bundler.root
|
||||
true
|
||||
rescue GemfileNotFound
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Console
|
||||
attr_reader :options, :group
|
||||
def initialize(options, group)
|
||||
@options = options
|
||||
@group = group
|
||||
end
|
||||
|
||||
def run
|
||||
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
|
||||
|
||||
console = get_console(Bundler.settings[:console] || "irb")
|
||||
console.start
|
||||
end
|
||||
|
||||
def get_console(name)
|
||||
require name
|
||||
get_constant(name)
|
||||
rescue LoadError
|
||||
Bundler.ui.error "Couldn't load console #{name}, falling back to irb"
|
||||
require "irb"
|
||||
get_constant("irb")
|
||||
end
|
||||
|
||||
def get_constant(name)
|
||||
const_name = {
|
||||
"pry" => :Pry,
|
||||
"ripl" => :Ripl,
|
||||
"irb" => :IRB,
|
||||
}[name]
|
||||
Object.const_get(const_name)
|
||||
rescue NameError
|
||||
Bundler.ui.error "Could not find constant #{const_name}"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,157 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rbconfig"
|
||||
require "shellwords"
|
||||
require "fiddle"
|
||||
|
||||
module Bundler
|
||||
class CLI::Doctor
|
||||
DARWIN_REGEX = /\s+(.+) \(compatibility /
|
||||
LDD_REGEX = /\t\S+ => (\S+) \(\S+\)/
|
||||
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def otool_available?
|
||||
Bundler.which("otool")
|
||||
end
|
||||
|
||||
def ldd_available?
|
||||
Bundler.which("ldd")
|
||||
end
|
||||
|
||||
def dylibs_darwin(path)
|
||||
output = `/usr/bin/otool -L #{path.shellescape}`.chomp
|
||||
dylibs = output.split("\n")[1..-1].map {|l| l.match(DARWIN_REGEX).captures[0] }.uniq
|
||||
# ignore @rpath and friends
|
||||
dylibs.reject {|dylib| dylib.start_with? "@" }
|
||||
end
|
||||
|
||||
def dylibs_ldd(path)
|
||||
output = `/usr/bin/ldd #{path.shellescape}`.chomp
|
||||
output.split("\n").map do |l|
|
||||
match = l.match(LDD_REGEX)
|
||||
next if match.nil?
|
||||
match.captures[0]
|
||||
end.compact
|
||||
end
|
||||
|
||||
def dylibs(path)
|
||||
case RbConfig::CONFIG["host_os"]
|
||||
when /darwin/
|
||||
return [] unless otool_available?
|
||||
dylibs_darwin(path)
|
||||
when /(linux|solaris|bsd)/
|
||||
return [] unless ldd_available?
|
||||
dylibs_ldd(path)
|
||||
else # Windows, etc.
|
||||
Bundler.ui.warn("Dynamic library check not supported on this platform.")
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def bundles_for_gem(spec)
|
||||
Dir.glob("#{spec.full_gem_path}/**/*.bundle")
|
||||
end
|
||||
|
||||
def check!
|
||||
require_relative "check"
|
||||
Bundler::CLI::Check.new({}).run
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.ui.level = "warn" if options[:quiet]
|
||||
Bundler.settings.validate!
|
||||
check!
|
||||
|
||||
definition = Bundler.definition
|
||||
broken_links = {}
|
||||
|
||||
definition.specs.each do |spec|
|
||||
bundles_for_gem(spec).each do |bundle|
|
||||
bad_paths = dylibs(bundle).select do |f|
|
||||
Fiddle.dlopen(f)
|
||||
false
|
||||
rescue Fiddle::DLError
|
||||
true
|
||||
end
|
||||
if bad_paths.any?
|
||||
broken_links[spec] ||= []
|
||||
broken_links[spec].concat(bad_paths)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
permissions_valid = check_home_permissions
|
||||
|
||||
if broken_links.any?
|
||||
message = "The following gems are missing OS dependencies:"
|
||||
broken_links.map do |spec, paths|
|
||||
paths.uniq.map do |path|
|
||||
"\n * #{spec.name}: #{path}"
|
||||
end
|
||||
end.flatten.sort.each {|m| message += m }
|
||||
raise ProductionError, message
|
||||
elsif !permissions_valid
|
||||
Bundler.ui.info "No issues found with the installed bundle"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_home_permissions
|
||||
require "find"
|
||||
files_not_readable_or_writable = []
|
||||
files_not_rw_and_owned_by_different_user = []
|
||||
files_not_owned_by_current_user_but_still_rw = []
|
||||
broken_symlinks = []
|
||||
Find.find(Bundler.bundle_path.to_s).each do |f|
|
||||
if !File.exist?(f)
|
||||
broken_symlinks << f
|
||||
elsif !File.writable?(f) || !File.readable?(f)
|
||||
if File.stat(f).uid != Process.uid
|
||||
files_not_rw_and_owned_by_different_user << f
|
||||
else
|
||||
files_not_readable_or_writable << f
|
||||
end
|
||||
elsif File.stat(f).uid != Process.uid
|
||||
files_not_owned_by_current_user_but_still_rw << f
|
||||
end
|
||||
end
|
||||
|
||||
ok = true
|
||||
|
||||
if broken_symlinks.any?
|
||||
Bundler.ui.warn "Broken links exist in the Bundler home. Please report them to the offending gem's upstream repo. These files are:\n - #{broken_symlinks.join("\n - ")}"
|
||||
|
||||
ok = false
|
||||
end
|
||||
|
||||
if files_not_owned_by_current_user_but_still_rw.any?
|
||||
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
|
||||
"user, but are still readable/writable. These files are:\n - #{files_not_owned_by_current_user_but_still_rw.join("\n - ")}"
|
||||
|
||||
ok = false
|
||||
end
|
||||
|
||||
if files_not_rw_and_owned_by_different_user.any?
|
||||
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
|
||||
"user, and are not readable/writable. These files are:\n - #{files_not_rw_and_owned_by_different_user.join("\n - ")}"
|
||||
|
||||
ok = false
|
||||
end
|
||||
|
||||
if files_not_readable_or_writable.any?
|
||||
Bundler.ui.warn "Files exist in the Bundler home that are not " \
|
||||
"readable/writable by the current user. These files are:\n - #{files_not_readable_or_writable.join("\n - ")}"
|
||||
|
||||
ok = false
|
||||
end
|
||||
|
||||
ok
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,88 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../current_ruby"
|
||||
|
||||
module Bundler
|
||||
class CLI::Exec
|
||||
attr_reader :options, :args, :cmd
|
||||
|
||||
TRAPPED_SIGNALS = %w[INT].freeze
|
||||
|
||||
def initialize(options, args)
|
||||
@options = options
|
||||
@cmd = args.shift
|
||||
@args = args
|
||||
@args << { close_others: !options.keep_file_descriptors? } unless Bundler.current_ruby.jruby?
|
||||
end
|
||||
|
||||
def run
|
||||
validate_cmd!
|
||||
SharedHelpers.set_bundle_environment
|
||||
if bin_path = Bundler.which(cmd)
|
||||
if !Bundler.settings[:disable_exec_load] && ruby_shebang?(bin_path)
|
||||
return kernel_load(bin_path, *args)
|
||||
end
|
||||
kernel_exec(bin_path, *args)
|
||||
else
|
||||
# exec using the given command
|
||||
kernel_exec(cmd, *args)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_cmd!
|
||||
return unless cmd.nil?
|
||||
Bundler.ui.error "bundler: exec needs a command to run"
|
||||
exit 128
|
||||
end
|
||||
|
||||
def kernel_exec(*args)
|
||||
Kernel.exec(*args)
|
||||
rescue Errno::EACCES, Errno::ENOEXEC
|
||||
Bundler.ui.error "bundler: not executable: #{cmd}"
|
||||
exit 126
|
||||
rescue Errno::ENOENT
|
||||
Bundler.ui.error "bundler: command not found: #{cmd}"
|
||||
Bundler.ui.warn "Install missing gem executables with `bundle install`"
|
||||
exit 127
|
||||
end
|
||||
|
||||
def kernel_load(file, *args)
|
||||
args.pop if args.last.is_a?(Hash)
|
||||
ARGV.replace(args)
|
||||
$0 = file
|
||||
Process.setproctitle(process_title(file, args)) if Process.respond_to?(:setproctitle)
|
||||
require_relative "../setup"
|
||||
TRAPPED_SIGNALS.each {|s| trap(s, "DEFAULT") }
|
||||
Kernel.load(file)
|
||||
rescue SystemExit, SignalException
|
||||
raise
|
||||
rescue Exception # rubocop:disable Lint/RescueException
|
||||
Bundler.ui.error "bundler: failed to load command: #{cmd} (#{file})"
|
||||
Bundler::FriendlyErrors.disable!
|
||||
raise
|
||||
end
|
||||
|
||||
def process_title(file, args)
|
||||
"#{file} #{args.join(" ")}".strip
|
||||
end
|
||||
|
||||
def ruby_shebang?(file)
|
||||
possibilities = [
|
||||
"#!/usr/bin/env ruby\n",
|
||||
"#!/usr/bin/env jruby\n",
|
||||
"#!/usr/bin/env truffleruby\n",
|
||||
"#!#{Gem.ruby}\n",
|
||||
]
|
||||
|
||||
if File.zero?(file)
|
||||
Bundler.ui.warn "#{file} is empty"
|
||||
return false
|
||||
end
|
||||
|
||||
first_line = File.open(file, "rb") {|f| f.read(possibilities.map(&:size).max) }
|
||||
possibilities.any? {|shebang| first_line.start_with?(shebang) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Fund
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.definition.validate_runtime!
|
||||
|
||||
groups = Array(options[:group]).map(&:to_sym)
|
||||
|
||||
deps = if groups.any?
|
||||
Bundler.definition.dependencies_for(groups)
|
||||
else
|
||||
Bundler.definition.current_dependencies
|
||||
end
|
||||
|
||||
fund_info = deps.each_with_object([]) do |dep, arr|
|
||||
spec = Bundler.definition.specs[dep.name].first
|
||||
if spec.metadata.key?("funding_uri")
|
||||
arr << "* #{spec.name} (#{spec.version})\n Funding: #{spec.metadata["funding_uri"]}"
|
||||
end
|
||||
end
|
||||
|
||||
if fund_info.empty?
|
||||
Bundler.ui.info "None of the installed gems you directly depend on are looking for funding."
|
||||
else
|
||||
Bundler.ui.info fund_info.join("\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,471 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "pathname"
|
||||
|
||||
module Bundler
|
||||
class CLI
|
||||
Bundler.require_thor_actions
|
||||
include Thor::Actions
|
||||
end
|
||||
|
||||
class CLI::Gem
|
||||
TEST_FRAMEWORK_VERSIONS = {
|
||||
"rspec" => "3.0",
|
||||
"minitest" => "5.16",
|
||||
"test-unit" => "3.0",
|
||||
}.freeze
|
||||
|
||||
attr_reader :options, :gem_name, :thor, :name, :target, :extension
|
||||
|
||||
def initialize(options, gem_name, thor)
|
||||
@options = options
|
||||
@gem_name = resolve_name(gem_name)
|
||||
|
||||
@thor = thor
|
||||
thor.behavior = :invoke
|
||||
thor.destination_root = nil
|
||||
|
||||
@name = @gem_name
|
||||
@target = SharedHelpers.pwd.join(gem_name)
|
||||
|
||||
@extension = options[:ext]
|
||||
|
||||
validate_ext_name if @extension
|
||||
validate_rust_builder_rubygems_version if @extension == "rust"
|
||||
travis_removal_info
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.ui.confirm "Creating gem '#{name}'..."
|
||||
|
||||
underscored_name = name.tr("-", "_")
|
||||
namespaced_path = name.tr("-", "/")
|
||||
constant_name = name.gsub(/-[_-]*(?![_-]|$)/) { "::" }.gsub(/([_-]+|(::)|^)(.|$)/) { $2.to_s + $3.upcase }
|
||||
constant_array = constant_name.split("::")
|
||||
minitest_constant_name = constant_array.clone.tap {|a| a[-1] = "Test#{a[-1]}" }.join("::") # Foo::Bar => Foo::TestBar
|
||||
|
||||
use_git = Bundler.git_present? && options[:git]
|
||||
|
||||
git_author_name = use_git ? `git config user.name`.chomp : ""
|
||||
git_username = use_git ? `git config github.user`.chomp : ""
|
||||
git_user_email = use_git ? `git config user.email`.chomp : ""
|
||||
|
||||
github_username = if options[:github_username].nil?
|
||||
git_username
|
||||
elsif options[:github_username] == false
|
||||
""
|
||||
else
|
||||
options[:github_username]
|
||||
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,
|
||||
}
|
||||
ensure_safe_gem_name(name, constant_array)
|
||||
|
||||
templates = {
|
||||
"#{Bundler.preferred_gemfile_name}.tt" => Bundler.preferred_gemfile_name,
|
||||
"lib/newgem.rb.tt" => "lib/#{namespaced_path}.rb",
|
||||
"lib/newgem/version.rb.tt" => "lib/#{namespaced_path}/version.rb",
|
||||
"sig/newgem.rbs.tt" => "sig/#{namespaced_path}.rbs",
|
||||
"newgem.gemspec.tt" => "#{name}.gemspec",
|
||||
"Rakefile.tt" => "Rakefile",
|
||||
"README.md.tt" => "README.md",
|
||||
"bin/console.tt" => "bin/console",
|
||||
"bin/setup.tt" => "bin/setup",
|
||||
}
|
||||
|
||||
executables = %w[
|
||||
bin/console
|
||||
bin/setup
|
||||
]
|
||||
|
||||
templates.merge!("gitignore.tt" => ".gitignore") if use_git
|
||||
|
||||
if test_framework = ask_and_set_test_framework
|
||||
config[:test] = test_framework
|
||||
config[:test_framework_version] = TEST_FRAMEWORK_VERSIONS[test_framework]
|
||||
|
||||
case test_framework
|
||||
when "rspec"
|
||||
templates.merge!(
|
||||
"rspec.tt" => ".rspec",
|
||||
"spec/spec_helper.rb.tt" => "spec/spec_helper.rb",
|
||||
"spec/newgem_spec.rb.tt" => "spec/#{namespaced_path}_spec.rb"
|
||||
)
|
||||
config[:test_task] = :spec
|
||||
when "minitest"
|
||||
# Generate path for minitest target file (FileList["test/**/test_*.rb"])
|
||||
# foo => test/test_foo.rb
|
||||
# foo-bar => test/foo/test_bar.rb
|
||||
# foo_bar => test/test_foo_bar.rb
|
||||
paths = namespaced_path.rpartition("/")
|
||||
paths[2] = "test_#{paths[2]}"
|
||||
minitest_namespaced_path = paths.join("")
|
||||
|
||||
templates.merge!(
|
||||
"test/minitest/test_helper.rb.tt" => "test/test_helper.rb",
|
||||
"test/minitest/test_newgem.rb.tt" => "test/#{minitest_namespaced_path}.rb"
|
||||
)
|
||||
config[:test_task] = :test
|
||||
when "test-unit"
|
||||
templates.merge!(
|
||||
"test/test-unit/test_helper.rb.tt" => "test/test_helper.rb",
|
||||
"test/test-unit/newgem_test.rb.tt" => "test/#{namespaced_path}_test.rb"
|
||||
)
|
||||
config[:test_task] = :test
|
||||
end
|
||||
end
|
||||
|
||||
config[:ci] = ask_and_set_ci
|
||||
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?",
|
||||
"This means that any other developer or company will be legally allowed to use your code " \
|
||||
"for free as long as they admit you created it. You can read more about the MIT license " \
|
||||
"at https://choosealicense.com/licenses/mit.")
|
||||
config[:mit] = true
|
||||
Bundler.ui.info "MIT License enabled in config"
|
||||
templates.merge!("LICENSE.txt.tt" => "LICENSE.txt")
|
||||
end
|
||||
|
||||
if ask_and_set(:coc, "Do you want to include a code of conduct in gems you generate?",
|
||||
"Codes of conduct can increase contributions to your project by contributors who " \
|
||||
"prefer collaborative, safe spaces. You can read more about the code of conduct at " \
|
||||
"contributor-covenant.org. Having a code of conduct means agreeing to the responsibility " \
|
||||
"of enforcing it, so be sure that you are prepared to do that. Be sure that your email " \
|
||||
"address is specified as a contact in the generated code of conduct so that people know " \
|
||||
"who to contact in case of a violation. For suggestions about " \
|
||||
"how to enforce codes of conduct, see https://bit.ly/coc-enforcement.")
|
||||
config[:coc] = true
|
||||
Bundler.ui.info "Code of conduct enabled in config"
|
||||
templates.merge!("CODE_OF_CONDUCT.md.tt" => "CODE_OF_CONDUCT.md")
|
||||
end
|
||||
|
||||
if ask_and_set(:changelog, "Do you want to include a changelog?",
|
||||
"A changelog is a file which contains a curated, chronologically ordered list of notable " \
|
||||
"changes for each version of a project. To make it easier for users and contributors to" \
|
||||
" see precisely what notable changes have been made between each release (or version) of" \
|
||||
" the project. Whether consumers or developers, the end users of software are" \
|
||||
" human beings who care about what's in the software. When the software changes, people " \
|
||||
"want to know why and how. see https://keepachangelog.com")
|
||||
config[:changelog] = true
|
||||
Bundler.ui.info "Changelog enabled in config"
|
||||
templates.merge!("CHANGELOG.md.tt" => "CHANGELOG.md")
|
||||
end
|
||||
|
||||
config[:linter] = ask_and_set_linter
|
||||
case config[:linter]
|
||||
when "rubocop"
|
||||
config[:linter_version] = rubocop_version
|
||||
Bundler.ui.info "RuboCop enabled in config"
|
||||
templates.merge!("rubocop.yml.tt" => ".rubocop.yml")
|
||||
when "standard"
|
||||
config[:linter_version] = standard_version
|
||||
Bundler.ui.info "Standard enabled in config"
|
||||
templates.merge!("standard.yml.tt" => ".standard.yml")
|
||||
end
|
||||
|
||||
templates.merge!("exe/newgem.tt" => "exe/#{name}") if config[:exe]
|
||||
|
||||
if extension == "c"
|
||||
templates.merge!(
|
||||
"ext/newgem/extconf-c.rb.tt" => "ext/#{name}/extconf.rb",
|
||||
"ext/newgem/newgem.h.tt" => "ext/#{name}/#{underscored_name}.h",
|
||||
"ext/newgem/newgem.c.tt" => "ext/#{name}/#{underscored_name}.c"
|
||||
)
|
||||
end
|
||||
|
||||
if extension == "rust"
|
||||
templates.merge!(
|
||||
"Cargo.toml.tt" => "Cargo.toml",
|
||||
"ext/newgem/Cargo.toml.tt" => "ext/#{name}/Cargo.toml",
|
||||
"ext/newgem/extconf-rust.rb.tt" => "ext/#{name}/extconf.rb",
|
||||
"ext/newgem/src/lib.rs.tt" => "ext/#{name}/src/lib.rs",
|
||||
)
|
||||
end
|
||||
|
||||
if target.exist? && !target.directory?
|
||||
Bundler.ui.error "Couldn't create a new gem named `#{gem_name}` because there's an existing file named `#{gem_name}`."
|
||||
exit Bundler::BundlerError.all_errors[Bundler::GenericSystemCallError]
|
||||
end
|
||||
|
||||
if use_git
|
||||
Bundler.ui.info "Initializing git repo in #{target}"
|
||||
require "shellwords"
|
||||
`git init #{target.to_s.shellescape}`
|
||||
|
||||
config[:git_default_branch] = File.read("#{target}/.git/HEAD").split("/").last.chomp
|
||||
end
|
||||
|
||||
templates.each do |src, dst|
|
||||
destination = target.join(dst)
|
||||
thor.template("newgem/#{src}", destination, config)
|
||||
end
|
||||
|
||||
executables.each do |file|
|
||||
path = target.join(file)
|
||||
executable = (path.stat.mode | 0o111)
|
||||
path.chmod(executable)
|
||||
end
|
||||
|
||||
if use_git
|
||||
IO.popen(%w[git add .], { chdir: target }, &:read)
|
||||
end
|
||||
|
||||
# Open gemspec in editor
|
||||
open_editor(options["edit"], target.join("#{name}.gemspec")) if options[:edit]
|
||||
|
||||
Bundler.ui.info "Gem '#{name}' was successfully created. " \
|
||||
"For more information on making a RubyGem visit https://bundler.io/guides/creating_gem.html"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def resolve_name(name)
|
||||
SharedHelpers.pwd.join(name).basename.to_s
|
||||
end
|
||||
|
||||
def ask_and_set(key, header, message)
|
||||
choice = options[key]
|
||||
choice = Bundler.settings["gem.#{key}"] if choice.nil?
|
||||
|
||||
if choice.nil?
|
||||
Bundler.ui.confirm header
|
||||
choice = Bundler.ui.yes? "#{message} y/(n):"
|
||||
Bundler.settings.set_global("gem.#{key}", choice)
|
||||
end
|
||||
|
||||
choice
|
||||
end
|
||||
|
||||
def validate_ext_name
|
||||
return unless gem_name.index("-")
|
||||
|
||||
Bundler.ui.error "You have specified a gem name which does not conform to the \n" \
|
||||
"naming guidelines for C extensions. For more information, \n" \
|
||||
"see the 'Extension Naming' section at the following URL:\n" \
|
||||
"https://guides.rubygems.org/gems-with-extensions/\n"
|
||||
exit 1
|
||||
end
|
||||
|
||||
def ask_and_set_test_framework
|
||||
test_framework = options[:test] || Bundler.settings["gem.test"]
|
||||
|
||||
if test_framework.to_s.empty?
|
||||
Bundler.ui.confirm "Do you want to generate tests with your gem?"
|
||||
Bundler.ui.info hint_text("test")
|
||||
|
||||
result = Bundler.ui.ask "Enter a test framework. rspec/minitest/test-unit/(none):"
|
||||
if /rspec|minitest|test-unit/.match?(result)
|
||||
test_framework = result
|
||||
else
|
||||
test_framework = false
|
||||
end
|
||||
end
|
||||
|
||||
if Bundler.settings["gem.test"].nil?
|
||||
Bundler.settings.set_global("gem.test", test_framework)
|
||||
end
|
||||
|
||||
if options[:test] == Bundler.settings["gem.test"]
|
||||
Bundler.ui.info "#{options[:test]} is already configured, ignoring --test flag."
|
||||
end
|
||||
|
||||
test_framework
|
||||
end
|
||||
|
||||
def hint_text(setting)
|
||||
if Bundler.settings["gem.#{setting}"] == false
|
||||
"Your choice will only be applied to this gem."
|
||||
else
|
||||
"Future `bundle gem` calls will use your choice. " \
|
||||
"This setting can be changed anytime with `bundle config gem.#{setting}`."
|
||||
end
|
||||
end
|
||||
|
||||
def ask_and_set_ci
|
||||
ci_template = options[:ci] || Bundler.settings["gem.ci"]
|
||||
|
||||
if ci_template.to_s.empty?
|
||||
Bundler.ui.confirm "Do you want to set up continuous integration for your gem? " \
|
||||
"Supported services:\n" \
|
||||
"* CircleCI: https://circleci.com/\n" \
|
||||
"* GitHub Actions: https://github.com/features/actions\n" \
|
||||
"* GitLab CI: https://docs.gitlab.com/ee/ci/\n" \
|
||||
"\n"
|
||||
Bundler.ui.info hint_text("ci")
|
||||
|
||||
result = Bundler.ui.ask "Enter a CI service. github/gitlab/circle/(none):"
|
||||
if /github|gitlab|circle/.match?(result)
|
||||
ci_template = result
|
||||
else
|
||||
ci_template = false
|
||||
end
|
||||
end
|
||||
|
||||
if Bundler.settings["gem.ci"].nil?
|
||||
Bundler.settings.set_global("gem.ci", ci_template)
|
||||
end
|
||||
|
||||
if options[:ci] == Bundler.settings["gem.ci"]
|
||||
Bundler.ui.info "#{options[:ci]} is already configured, ignoring --ci flag."
|
||||
end
|
||||
|
||||
ci_template
|
||||
end
|
||||
|
||||
def ask_and_set_linter
|
||||
linter_template = options[:linter] || Bundler.settings["gem.linter"]
|
||||
linter_template = deprecated_rubocop_option if linter_template.nil?
|
||||
|
||||
if linter_template.to_s.empty?
|
||||
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/standardrb/standard\n" \
|
||||
"\n"
|
||||
Bundler.ui.info hint_text("linter")
|
||||
|
||||
result = Bundler.ui.ask "Enter a linter. rubocop/standard/(none):"
|
||||
if /rubocop|standard/.match?(result)
|
||||
linter_template = result
|
||||
else
|
||||
linter_template = false
|
||||
end
|
||||
end
|
||||
|
||||
if Bundler.settings["gem.linter"].nil?
|
||||
Bundler.settings.set_global("gem.linter", linter_template)
|
||||
end
|
||||
|
||||
# Once gem.linter safely set, unset the deprecated gem.rubocop
|
||||
unless Bundler.settings["gem.rubocop"].nil?
|
||||
Bundler.settings.set_global("gem.rubocop", nil)
|
||||
end
|
||||
|
||||
if options[:linter] == Bundler.settings["gem.linter"]
|
||||
Bundler.ui.info "#{options[:linter]} is already configured, ignoring --linter flag."
|
||||
end
|
||||
|
||||
linter_template
|
||||
end
|
||||
|
||||
def deprecated_rubocop_option
|
||||
if !options[:rubocop].nil?
|
||||
if options[: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",
|
||||
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",
|
||||
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
|
||||
|
||||
def bundler_dependency_version
|
||||
v = Gem::Version.new(Bundler::VERSION)
|
||||
req = v.segments[0..1]
|
||||
req << "a" if v.prerelease?
|
||||
req.join(".")
|
||||
end
|
||||
|
||||
def ensure_safe_gem_name(name, constant_array)
|
||||
if /^\d/.match?(name)
|
||||
Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
|
||||
exit 1
|
||||
end
|
||||
|
||||
constant_name = constant_array.join("::")
|
||||
|
||||
existing_constant = constant_array.inject(Object) do |c, s|
|
||||
defined = begin
|
||||
c.const_defined?(s)
|
||||
rescue NameError
|
||||
Bundler.ui.error "Invalid gem name #{name} -- `#{constant_name}` is an invalid constant name"
|
||||
exit 1
|
||||
end
|
||||
(defined && c.const_get(s)) || break
|
||||
end
|
||||
|
||||
return unless existing_constant
|
||||
Bundler.ui.error "Invalid gem name #{name} constant #{constant_name} is already in use. Please choose another gem name."
|
||||
exit 1
|
||||
end
|
||||
|
||||
def open_editor(editor, file)
|
||||
thor.run(%(#{editor} "#{file}"))
|
||||
end
|
||||
|
||||
def rust_builder_required_rubygems_version
|
||||
"3.3.11"
|
||||
end
|
||||
|
||||
def required_ruby_version
|
||||
"3.0.0"
|
||||
end
|
||||
|
||||
def rubocop_version
|
||||
"1.21"
|
||||
end
|
||||
|
||||
def standard_version
|
||||
"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."
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,83 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Info
|
||||
attr_reader :gem_name, :options
|
||||
def initialize(options, gem_name)
|
||||
@options = options
|
||||
@gem_name = gem_name
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.ui.silence do
|
||||
Bundler.definition.validate_runtime!
|
||||
Bundler.load.lock
|
||||
end
|
||||
|
||||
spec = spec_for_gem(gem_name)
|
||||
|
||||
if spec
|
||||
return print_gem_path(spec) if @options[:path]
|
||||
return print_gem_version(spec) if @options[:version]
|
||||
print_gem_info(spec)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def spec_for_gem(name)
|
||||
Bundler::CLI::Common.select_spec(name, :regex_match)
|
||||
end
|
||||
|
||||
def print_gem_version(spec)
|
||||
Bundler.ui.info spec.version.to_s
|
||||
end
|
||||
|
||||
def print_gem_path(spec)
|
||||
name = spec.name
|
||||
if name == "bundler"
|
||||
path = File.expand_path("../../..", __dir__)
|
||||
else
|
||||
path = spec.full_gem_path
|
||||
if spec.deleted_gem?
|
||||
return Bundler.ui.warn "The gem #{name} has been deleted. It was installed at: #{path}"
|
||||
end
|
||||
end
|
||||
|
||||
Bundler.ui.info path
|
||||
end
|
||||
|
||||
def print_gem_info(spec)
|
||||
metadata = spec.metadata
|
||||
name = spec.name
|
||||
gem_info = String.new
|
||||
gem_info << " * #{name} (#{spec.version}#{spec.git_version})\n"
|
||||
gem_info << "\tSummary: #{spec.summary}\n" if spec.summary
|
||||
gem_info << "\tHomepage: #{spec.homepage}\n" if spec.homepage
|
||||
gem_info << "\tDocumentation: #{metadata["documentation_uri"]}\n" if metadata.key?("documentation_uri")
|
||||
gem_info << "\tSource Code: #{metadata["source_code_uri"]}\n" if metadata.key?("source_code_uri")
|
||||
gem_info << "\tFunding: #{metadata["funding_uri"]}\n" if metadata.key?("funding_uri")
|
||||
gem_info << "\tWiki: #{metadata["wiki_uri"]}\n" if metadata.key?("wiki_uri")
|
||||
gem_info << "\tChangelog: #{metadata["changelog_uri"]}\n" if metadata.key?("changelog_uri")
|
||||
gem_info << "\tBug Tracker: #{metadata["bug_tracker_uri"]}\n" if metadata.key?("bug_tracker_uri")
|
||||
gem_info << "\tMailing List: #{metadata["mailing_list_uri"]}\n" if metadata.key?("mailing_list_uri")
|
||||
gem_info << "\tPath: #{spec.full_gem_path}\n"
|
||||
gem_info << "\tDefault Gem: yes\n" if spec.respond_to?(:default_gem?) && spec.default_gem?
|
||||
gem_info << "\tReverse Dependencies: \n\t\t#{gem_dependencies.join("\n\t\t")}" if gem_dependencies.any?
|
||||
|
||||
if name != "bundler" && spec.deleted_gem?
|
||||
return Bundler.ui.warn "The gem #{name} has been deleted. Gemspec information is still available though:\n#{gem_info}"
|
||||
end
|
||||
|
||||
Bundler.ui.info gem_info
|
||||
end
|
||||
|
||||
def gem_dependencies
|
||||
@gem_dependencies ||= Bundler.definition.specs.map do |spec|
|
||||
dependency = spec.dependencies.find {|dep| dep.name == gem_name }
|
||||
next unless dependency
|
||||
"#{spec.name} (#{spec.version}) depends on #{gem_name} (#{dependency.requirements_list.join(", ")})"
|
||||
end.compact.sort
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,51 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Init
|
||||
attr_reader :options
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
if File.exist?(gemfile)
|
||||
Bundler.ui.error "#{gemfile} already exists at #{File.expand_path(gemfile)}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
unless File.writable?(Dir.pwd)
|
||||
Bundler.ui.error "Can not create #{gemfile} as the current directory is not writable."
|
||||
exit 1
|
||||
end
|
||||
|
||||
if options[:gemspec]
|
||||
gemspec = File.expand_path(options[:gemspec])
|
||||
unless File.exist?(gemspec)
|
||||
Bundler.ui.error "Gem specification #{gemspec} doesn't exist"
|
||||
exit 1
|
||||
end
|
||||
|
||||
spec = Bundler.load_gemspec_uncached(gemspec)
|
||||
|
||||
File.open(gemfile, "wb") do |file|
|
||||
file << "# Generated from #{gemspec}\n"
|
||||
file << spec.to_gemfile
|
||||
end
|
||||
else
|
||||
File.open(File.expand_path("../templates/Gemfile", __dir__), "r") do |template|
|
||||
File.open(gemfile, "wb") do |destination|
|
||||
IO.copy_stream(template, destination)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def gemfile
|
||||
@gemfile ||= options[:gemfile] || Bundler.preferred_gemfile_name
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Inject
|
||||
attr_reader :options, :name, :version, :group, :source, :gems
|
||||
def initialize(options, name, version)
|
||||
@options = options
|
||||
@name = name
|
||||
@version = version || last_version_number
|
||||
@group = options[:group].split(",") unless options[:group].nil?
|
||||
@source = options[:source]
|
||||
@gems = []
|
||||
end
|
||||
|
||||
def run
|
||||
# The required arguments allow Thor to give useful feedback when the arguments
|
||||
# are incorrect. This adds those first two arguments onto the list as a whole.
|
||||
gems.unshift(source).unshift(group).unshift(version).unshift(name)
|
||||
|
||||
# Build an array of Dependency objects out of the arguments
|
||||
deps = []
|
||||
# when `inject` support addition of more than one gem, then this loop will
|
||||
# help. Currently this loop is running once.
|
||||
gems.each_slice(4) do |gem_name, gem_version, gem_group, gem_source|
|
||||
ops = Gem::Requirement::OPS.map {|key, _val| key }
|
||||
has_op = ops.any? {|op| gem_version.start_with? op }
|
||||
gem_version = "~> #{gem_version}" unless has_op
|
||||
deps << Bundler::Dependency.new(gem_name, gem_version, "group" => gem_group, "source" => gem_source)
|
||||
end
|
||||
|
||||
added = Injector.inject(deps, options)
|
||||
|
||||
if added.any?
|
||||
Bundler.ui.confirm "Added to Gemfile:"
|
||||
Bundler.ui.confirm(added.map do |d|
|
||||
name = "'#{d.name}'"
|
||||
requirement = ", '#{d.requirement}'"
|
||||
group = ", :group => #{d.groups.inspect}" if d.groups != Array(:default)
|
||||
source = ", :source => '#{d.source}'" unless d.source.nil?
|
||||
%(gem #{name}#{requirement}#{group}#{source})
|
||||
end.join("\n"))
|
||||
else
|
||||
Bundler.ui.confirm "All gems were already present in the Gemfile"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def last_version_number
|
||||
definition = Bundler.definition(true)
|
||||
definition.resolve_remotely!
|
||||
specs = definition.index[name].sort_by(&:version)
|
||||
unless options[:pre]
|
||||
specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? }
|
||||
end
|
||||
spec = specs.last
|
||||
spec.version.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,190 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Install
|
||||
attr_reader :options
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.ui.level = "warn" if options[:quiet]
|
||||
|
||||
warn_if_root
|
||||
|
||||
Bundler.self_manager.install_locked_bundler_and_restart_with_it_if_needed
|
||||
|
||||
Bundler::SharedHelpers.set_env "RB_USER_INSTALL", "1" if Bundler::FREEBSD
|
||||
|
||||
# Disable color in deployment mode
|
||||
Bundler.ui.shell = Thor::Shell::Basic.new if options[:deployment]
|
||||
|
||||
check_for_options_conflicts
|
||||
|
||||
check_trust_policy
|
||||
|
||||
if options[:deployment] || options[:frozen] || Bundler.frozen_bundle?
|
||||
unless Bundler.default_lockfile.exist?
|
||||
flag = "--deployment flag" if options[:deployment]
|
||||
flag ||= "--frozen flag" if options[:frozen]
|
||||
flag ||= "deployment setting"
|
||||
raise ProductionError, "The #{flag} requires a lockfile. Please make " \
|
||||
"sure you have checked your #{SharedHelpers.relative_lockfile_path} into version control " \
|
||||
"before deploying."
|
||||
end
|
||||
|
||||
options[:local] = true if Bundler.app_cache.exist?
|
||||
|
||||
Bundler.settings.set_command_option :deployment, true if options[:deployment]
|
||||
Bundler.settings.set_command_option :frozen, true if options[:frozen]
|
||||
end
|
||||
|
||||
# When install is called with --no-deployment, disable deployment mode
|
||||
if options[:deployment] == false
|
||||
Bundler.settings.set_command_option :frozen, nil
|
||||
options[:system] = true
|
||||
end
|
||||
|
||||
normalize_settings
|
||||
|
||||
Bundler::Fetcher.disable_endpoint = options["full-index"]
|
||||
|
||||
if options["binstubs"]
|
||||
Bundler::SharedHelpers.major_deprecation 2,
|
||||
"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?
|
||||
|
||||
definition = Bundler.definition
|
||||
definition.validate_runtime!
|
||||
|
||||
installer = Installer.install(Bundler.root, definition, options)
|
||||
|
||||
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
|
||||
|
||||
Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}."
|
||||
Bundler::CLI::Common.output_without_groups_message(:install)
|
||||
|
||||
if Bundler.use_system_gems?
|
||||
Bundler.ui.confirm "Use `bundle info [gemname]` to see where a bundled gem is installed."
|
||||
else
|
||||
relative_path = Bundler.configured_bundle_path.base_path_relative_to_pwd
|
||||
Bundler.ui.confirm "Bundled gems are installed into `#{relative_path}`"
|
||||
end
|
||||
|
||||
Bundler::CLI::Common.output_post_install_messages installer.post_install_messages
|
||||
|
||||
warn_ambiguous_gems
|
||||
|
||||
if CLI::Common.clean_after_install?
|
||||
require_relative "clean"
|
||||
Bundler::CLI::Clean.new(options).run
|
||||
end
|
||||
|
||||
Bundler::CLI::Common.output_fund_metadata_summary
|
||||
rescue Gem::InvalidSpecificationException
|
||||
Bundler.ui.warn "You have one or more invalid gemspecs that need to be fixed."
|
||||
raise
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def dependencies_count_for(definition)
|
||||
count = definition.dependencies.count
|
||||
"#{count} Gemfile #{count == 1 ? "dependency" : "dependencies"}"
|
||||
end
|
||||
|
||||
def gems_installed_for(definition)
|
||||
count = definition.specs.count
|
||||
"#{count} #{count == 1 ? "gem" : "gems"} now installed"
|
||||
end
|
||||
|
||||
def check_for_group_conflicts_in_cli_options
|
||||
conflicting_groups = Array(options[:without]) & Array(options[:with])
|
||||
return if conflicting_groups.empty?
|
||||
raise InvalidOption, "You can't list a group in both with and without." \
|
||||
" The offending groups are: #{conflicting_groups.join(", ")}."
|
||||
end
|
||||
|
||||
def check_for_options_conflicts
|
||||
if (options[:path] || options[:deployment]) && options[:system]
|
||||
error_message = String.new
|
||||
error_message << "You have specified both --path as well as --system. Please choose only one option.\n" if options[:path]
|
||||
error_message << "You have specified both --deployment as well as --system. Please choose only one option.\n" if options[:deployment]
|
||||
raise InvalidOption.new(error_message)
|
||||
end
|
||||
end
|
||||
|
||||
def check_trust_policy
|
||||
trust_policy = options["trust-policy"]
|
||||
unless Bundler.rubygems.security_policies.keys.unshift(nil).include?(trust_policy)
|
||||
raise InvalidOption, "RubyGems doesn't know about trust policy '#{trust_policy}'. " \
|
||||
"The known policies are: #{Bundler.rubygems.security_policies.keys.join(", ")}."
|
||||
end
|
||||
Bundler.settings.set_command_option_if_given :"trust-policy", trust_policy
|
||||
end
|
||||
|
||||
def normalize_groups
|
||||
check_for_group_conflicts_in_cli_options
|
||||
|
||||
# need to nil them out first to get around validation for backwards compatibility
|
||||
Bundler.settings.set_command_option :without, nil
|
||||
Bundler.settings.set_command_option :with, nil
|
||||
Bundler.settings.set_command_option :without, options[:without]
|
||||
Bundler.settings.set_command_option :with, options[:with]
|
||||
end
|
||||
|
||||
def normalize_settings
|
||||
Bundler.settings.set_command_option :path, nil if options[:system]
|
||||
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.set_command_option :path, "bundle"
|
||||
end
|
||||
end
|
||||
|
||||
bin_option = options["binstubs"]
|
||||
bin_option = nil if bin_option&.empty?
|
||||
Bundler.settings.set_command_option :bin, bin_option if options["binstubs"]
|
||||
|
||||
Bundler.settings.set_command_option_if_given :shebang, options["shebang"]
|
||||
|
||||
Bundler.settings.set_command_option_if_given :jobs, options["jobs"]
|
||||
|
||||
Bundler.settings.set_command_option_if_given :no_prune, options["no-prune"]
|
||||
|
||||
Bundler.settings.set_command_option_if_given :no_install, options["no-install"]
|
||||
|
||||
Bundler.settings.set_command_option_if_given :clean, options["clean"]
|
||||
|
||||
normalize_groups if options[:without] || options[:with]
|
||||
|
||||
options[:force] = options[:redownload]
|
||||
end
|
||||
|
||||
def warn_ambiguous_gems
|
||||
# TODO: remove this when we drop Bundler 1.x support
|
||||
Installer.ambiguous_gems.to_a.each do |name, installed_from_uri, *also_found_in_uris|
|
||||
Bundler.ui.warn "Warning: the gem '#{name}' was found in multiple sources."
|
||||
Bundler.ui.warn "Installed from: #{installed_from_uri}"
|
||||
Bundler.ui.warn "Also found in:"
|
||||
also_found_in_uris.each {|uri| Bundler.ui.warn " * #{uri}" }
|
||||
Bundler.ui.warn "You should add a source requirement to restrict this gem to your preferred source."
|
||||
Bundler.ui.warn "For example:"
|
||||
Bundler.ui.warn " gem '#{name}', :source => '#{installed_from_uri}'"
|
||||
Bundler.ui.warn "Then uninstall the gem '#{name}' (or delete all bundled gems) and then install again."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rbconfig"
|
||||
|
||||
module Bundler
|
||||
class CLI::Issue
|
||||
def run
|
||||
Bundler.ui.info <<~EOS
|
||||
Did you find an issue with Bundler? Before filing a new issue,
|
||||
be sure to check out these resources:
|
||||
|
||||
1. Check out our troubleshooting guide for quick fixes to common issues:
|
||||
https://github.com/rubygems/rubygems/blob/master/bundler/doc/TROUBLESHOOTING.md
|
||||
|
||||
2. Instructions for common Bundler uses can be found on the documentation
|
||||
site: https://bundler.io/
|
||||
|
||||
3. Information about each Bundler command can be found in the Bundler
|
||||
man pages: https://bundler.io/man/bundle.1.html
|
||||
|
||||
Hopefully the troubleshooting steps above resolved your problem! If things
|
||||
still aren't working the way you expect them to, please let us know so
|
||||
that we can diagnose and help fix the problem you're having, by filling
|
||||
in the new issue form located at
|
||||
https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md,
|
||||
and copy and pasting the information below.
|
||||
|
||||
EOS
|
||||
|
||||
Bundler.ui.info Bundler::Env.report
|
||||
|
||||
Bundler.ui.info "\n## Bundle Doctor"
|
||||
doctor
|
||||
end
|
||||
|
||||
def doctor
|
||||
require_relative "doctor"
|
||||
Bundler::CLI::Doctor.new({}).run
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,66 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::List
|
||||
def initialize(options)
|
||||
@options = options
|
||||
@without_group = options["without-group"].map(&:to_sym)
|
||||
@only_group = options["only-group"].map(&:to_sym)
|
||||
end
|
||||
|
||||
def run
|
||||
raise InvalidOption, "The `--only-group` and `--without-group` options cannot be used together" if @only_group.any? && @without_group.any?
|
||||
|
||||
raise InvalidOption, "The `--name-only` and `--paths` options cannot be used together" if @options["name-only"] && @options[:paths]
|
||||
|
||||
specs = if @only_group.any? || @without_group.any?
|
||||
filtered_specs_by_groups
|
||||
else
|
||||
begin
|
||||
Bundler.load.specs
|
||||
rescue GemNotFound => e
|
||||
Bundler.ui.error e.message
|
||||
Bundler.ui.warn "Install missing gems with `bundle install`."
|
||||
exit 1
|
||||
end
|
||||
end.reject {|s| s.name == "bundler" }.sort_by(&:name)
|
||||
|
||||
return Bundler.ui.info "No gems in the Gemfile" if specs.empty?
|
||||
|
||||
return specs.each {|s| Bundler.ui.info s.name } if @options["name-only"]
|
||||
return specs.each {|s| Bundler.ui.info s.full_gem_path } if @options["paths"]
|
||||
|
||||
Bundler.ui.info "Gems included by the bundle:"
|
||||
|
||||
specs.each {|s| Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})" }
|
||||
|
||||
Bundler.ui.info "Use `bundle info` to print more detailed information about a gem"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def verify_group_exists(groups)
|
||||
(@without_group + @only_group).each do |group|
|
||||
raise InvalidOption, "`#{group}` group could not be found." unless groups.include?(group)
|
||||
end
|
||||
end
|
||||
|
||||
def filtered_specs_by_groups
|
||||
definition = Bundler.definition
|
||||
groups = definition.groups
|
||||
|
||||
verify_group_exists(groups)
|
||||
|
||||
show_groups =
|
||||
if @without_group.any?
|
||||
groups.reject {|g| @without_group.include?(g) }
|
||||
elsif @only_group.any?
|
||||
groups.select {|g| @only_group.include?(g) }
|
||||
else
|
||||
groups
|
||||
end.map(&:to_sym)
|
||||
|
||||
definition.specs_for(show_groups)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,74 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Lock
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
unless Bundler.default_gemfile
|
||||
Bundler.ui.error "Unable to find a Gemfile to lock"
|
||||
exit 1
|
||||
end
|
||||
|
||||
print = options[:print]
|
||||
previous_ui_level = Bundler.ui.level
|
||||
Bundler.ui.level = "silent" if print
|
||||
|
||||
Bundler::Fetcher.disable_endpoint = options["full-index"]
|
||||
|
||||
update = options[:update]
|
||||
conservative = options[:conservative]
|
||||
bundler = options[:bundler]
|
||||
|
||||
if update.is_a?(Array) # unlocking specific gems
|
||||
Bundler::CLI::Common.ensure_all_gems_in_lockfile!(update)
|
||||
update = { gems: update, conservative: conservative }
|
||||
elsif update && conservative
|
||||
update = { conservative: conservative }
|
||||
elsif update && 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, file)
|
||||
|
||||
Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update]
|
||||
|
||||
options["remove-platform"].each do |platform|
|
||||
definition.remove_platform(platform)
|
||||
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]
|
||||
|
||||
if print
|
||||
puts definition.to_lock
|
||||
else
|
||||
puts "Writing lockfile to #{file}"
|
||||
definition.lock
|
||||
end
|
||||
end
|
||||
|
||||
Bundler.ui.level = previous_ui_level
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Open
|
||||
attr_reader :options, :name, :path
|
||||
def initialize(options, name)
|
||||
@options = options
|
||||
@name = name
|
||||
@path = options[:path] unless options[:path].nil?
|
||||
end
|
||||
|
||||
def run
|
||||
raise InvalidOption, "Cannot specify `--path` option without a value" if !@path.nil? && @path.empty?
|
||||
editor = [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? }
|
||||
return Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR") unless editor
|
||||
return unless spec = Bundler::CLI::Common.select_spec(name, :regex_match)
|
||||
if spec.default_gem?
|
||||
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
|
||||
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
|
||||
end
|
||||
@@ -0,0 +1,297 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Outdated
|
||||
attr_reader :options, :gems, :options_include_groups, :filter_options_patch, :sources, :strict
|
||||
attr_accessor :outdated_gems
|
||||
|
||||
def initialize(options, gems)
|
||||
@options = options
|
||||
@gems = gems
|
||||
@sources = Array(options[:source])
|
||||
|
||||
@filter_options_patch = options.keys & %w[filter-major filter-minor filter-patch]
|
||||
|
||||
@outdated_gems = []
|
||||
|
||||
@options_include_groups = [:group, :groups].any? do |v|
|
||||
options.keys.include?(v.to_s)
|
||||
end
|
||||
|
||||
# the patch level options imply strict is also true. It wouldn't make
|
||||
# sense otherwise.
|
||||
@strict = options["filter-strict"] || Bundler::CLI::Common.patch_level_options(options).any?
|
||||
end
|
||||
|
||||
def run
|
||||
check_for_deployment_mode!
|
||||
|
||||
gems.each do |gem_name|
|
||||
Bundler::CLI::Common.select_spec(gem_name)
|
||||
end
|
||||
|
||||
Bundler.definition.validate_runtime!
|
||||
current_specs = Bundler.ui.silence { Bundler.definition.resolve }
|
||||
|
||||
current_dependencies = Bundler.ui.silence do
|
||||
Bundler.load.dependencies.map {|dep| [dep.name, dep] }.to_h
|
||||
end
|
||||
|
||||
definition = if gems.empty? && sources.empty?
|
||||
# We're doing a full update
|
||||
Bundler.definition(true)
|
||||
else
|
||||
Bundler.definition(gems: gems, sources: sources)
|
||||
end
|
||||
|
||||
Bundler::CLI::Common.configure_gem_version_promoter(
|
||||
Bundler.definition,
|
||||
options.merge(strict: @strict)
|
||||
)
|
||||
|
||||
definition_resolution = proc do
|
||||
options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
|
||||
end
|
||||
|
||||
if options[:parseable]
|
||||
Bundler.ui.silence(&definition_resolution)
|
||||
else
|
||||
definition_resolution.call
|
||||
end
|
||||
|
||||
Bundler.ui.info ""
|
||||
|
||||
# Loop through the current specs
|
||||
gemfile_specs, dependency_specs = current_specs.partition do |spec|
|
||||
current_dependencies.key? spec.name
|
||||
end
|
||||
|
||||
specs = if options["only-explicit"]
|
||||
gemfile_specs
|
||||
else
|
||||
gemfile_specs + dependency_specs
|
||||
end
|
||||
|
||||
specs.sort_by(&:name).uniq(&:name).each do |current_spec|
|
||||
next unless gems.empty? || gems.include?(current_spec.name)
|
||||
|
||||
active_spec = retrieve_active_spec(definition, current_spec)
|
||||
next unless active_spec
|
||||
|
||||
next unless filter_options_patch.empty? || update_present_via_semver_portions(current_spec, active_spec, options)
|
||||
|
||||
gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
|
||||
next unless gem_outdated || (current_spec.git_version != active_spec.git_version)
|
||||
|
||||
dependency = current_dependencies[current_spec.name]
|
||||
groups = ""
|
||||
if dependency && !options[:parseable]
|
||||
groups = dependency.groups.join(", ")
|
||||
end
|
||||
|
||||
outdated_gems << {
|
||||
active_spec: active_spec,
|
||||
current_spec: current_spec,
|
||||
dependency: dependency,
|
||||
groups: groups,
|
||||
}
|
||||
end
|
||||
|
||||
if outdated_gems.empty?
|
||||
unless options[:parseable]
|
||||
Bundler.ui.info(nothing_outdated_message)
|
||||
end
|
||||
else
|
||||
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(outdated_gems)
|
||||
else
|
||||
print_gems_table(outdated_gems)
|
||||
end
|
||||
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def loaded_from_for(spec)
|
||||
return unless spec.respond_to?(:loaded_from)
|
||||
|
||||
spec.loaded_from
|
||||
end
|
||||
|
||||
def groups_text(group_text, groups)
|
||||
"#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\""
|
||||
end
|
||||
|
||||
def nothing_outdated_message
|
||||
if filter_options_patch.any?
|
||||
display = filter_options_patch.map do |o|
|
||||
o.sub("filter-", "")
|
||||
end.join(" or ")
|
||||
|
||||
"No #{display} updates to display.\n"
|
||||
else
|
||||
"Bundle up to date!\n"
|
||||
end
|
||||
end
|
||||
|
||||
def retrieve_active_spec(definition, current_spec)
|
||||
active_spec = definition.resolve.find_by_name_and_platform(current_spec.name, current_spec.platform)
|
||||
return unless active_spec
|
||||
|
||||
return active_spec if strict
|
||||
|
||||
active_specs = active_spec.source.specs.search(current_spec.name).select {|spec| spec.match_platform(current_spec.platform) }.sort_by(&:version)
|
||||
if !current_spec.version.prerelease? && !options[:pre] && active_specs.size > 1
|
||||
active_specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? }
|
||||
end
|
||||
active_specs.last
|
||||
end
|
||||
|
||||
def print_gems(gems_list)
|
||||
gems_list.each do |gem|
|
||||
print_gem(
|
||||
gem[:current_spec],
|
||||
gem[:active_spec],
|
||||
gem[:dependency],
|
||||
gem[:groups],
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def print_gems_table(gems_list)
|
||||
data = gems_list.map do |gem|
|
||||
gem_column_for(
|
||||
gem[:current_spec],
|
||||
gem[:active_spec],
|
||||
gem[:dependency],
|
||||
gem[:groups],
|
||||
)
|
||||
end
|
||||
|
||||
print_indented([table_header] + data)
|
||||
end
|
||||
|
||||
def print_gem(current_spec, active_spec, dependency, groups)
|
||||
spec_version = "#{active_spec.version}#{active_spec.git_version}"
|
||||
if Bundler.ui.debug?
|
||||
loaded_from = loaded_from_for(active_spec)
|
||||
spec_version += " (from #{loaded_from})" if loaded_from
|
||||
end
|
||||
current_version = "#{current_spec.version}#{current_spec.git_version}"
|
||||
|
||||
if dependency&.specific?
|
||||
dependency_version = %(, requested #{dependency.requirement})
|
||||
end
|
||||
|
||||
spec_outdated_info = "#{active_spec.name} (newest #{spec_version}, " \
|
||||
"installed #{current_version}#{dependency_version})"
|
||||
|
||||
output_message = if options[:parseable]
|
||||
spec_outdated_info.to_s
|
||||
elsif options_include_groups || groups.empty?
|
||||
" * #{spec_outdated_info}"
|
||||
else
|
||||
" * #{spec_outdated_info} in #{groups_text("group", groups)}"
|
||||
end
|
||||
|
||||
Bundler.ui.info output_message.rstrip
|
||||
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}"
|
||||
dependency = dependency.requirement if dependency
|
||||
|
||||
ret_val = [active_spec.name, current_version, spec_version, dependency.to_s, groups.to_s]
|
||||
ret_val << loaded_from_for(active_spec).to_s if Bundler.ui.debug?
|
||||
ret_val
|
||||
end
|
||||
|
||||
def check_for_deployment_mode!
|
||||
return unless Bundler.frozen_bundle?
|
||||
suggested_command = if Bundler.settings.locations("frozen").keys.&([:global, :local]).any?
|
||||
"bundle config unset frozen"
|
||||
elsif Bundler.settings.locations("deployment").keys.&([:global, :local]).any?
|
||||
"bundle config unset deployment"
|
||||
end
|
||||
raise ProductionError, "You are trying to check outdated gems in " \
|
||||
"deployment mode. Run `bundle outdated` elsewhere.\n" \
|
||||
"\nIf this is a development machine, remove the " \
|
||||
"#{Bundler.default_gemfile} freeze" \
|
||||
"\nby running `#{suggested_command}`."
|
||||
end
|
||||
|
||||
def update_present_via_semver_portions(current_spec, active_spec, options)
|
||||
current_major = current_spec.version.segments.first
|
||||
active_major = active_spec.version.segments.first
|
||||
|
||||
update_present = false
|
||||
update_present = active_major > current_major if options["filter-major"]
|
||||
|
||||
if !update_present && (options["filter-minor"] || options["filter-patch"]) && current_major == active_major
|
||||
current_minor = get_version_semver_portion_value(current_spec, 1)
|
||||
active_minor = get_version_semver_portion_value(active_spec, 1)
|
||||
|
||||
update_present = active_minor > current_minor if options["filter-minor"]
|
||||
|
||||
if !update_present && options["filter-patch"] && current_minor == active_minor
|
||||
current_patch = get_version_semver_portion_value(current_spec, 2)
|
||||
active_patch = get_version_semver_portion_value(active_spec, 2)
|
||||
|
||||
update_present = active_patch > current_patch
|
||||
end
|
||||
end
|
||||
|
||||
update_present
|
||||
end
|
||||
|
||||
def get_version_semver_portion_value(spec, version_portion_index)
|
||||
version_section = spec.version.segments[version_portion_index, 1]
|
||||
version_section.to_a[0].to_i
|
||||
end
|
||||
|
||||
def print_indented(matrix)
|
||||
header = matrix[0]
|
||||
data = matrix[1..-1]
|
||||
|
||||
column_sizes = Array.new(header.size) do |index|
|
||||
matrix.max_by {|row| row[index].length }[index].length
|
||||
end
|
||||
|
||||
Bundler.ui.info justify(header, column_sizes)
|
||||
|
||||
data.sort_by! {|row| row[0] }
|
||||
|
||||
data.each do |row|
|
||||
Bundler.ui.info justify(row, column_sizes)
|
||||
end
|
||||
end
|
||||
|
||||
def table_header
|
||||
header = ["Gem", "Current", "Latest", "Requested", "Groups"]
|
||||
header << "Path" if Bundler.ui.debug?
|
||||
header
|
||||
end
|
||||
|
||||
def justify(row, sizes)
|
||||
row.each_with_index.map do |element, index|
|
||||
element.ljust(sizes[index])
|
||||
end.join(" ").strip + "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,48 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Platform
|
||||
attr_reader :options
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
ruby_version = if Bundler.locked_gems
|
||||
Bundler.locked_gems.ruby_version&.gsub(/p\d+\Z/, "")
|
||||
else
|
||||
Bundler.definition.ruby_version&.single_version_string
|
||||
end
|
||||
|
||||
output = []
|
||||
|
||||
if options[:ruby]
|
||||
if ruby_version
|
||||
output << ruby_version
|
||||
else
|
||||
output << "No ruby version specified"
|
||||
end
|
||||
else
|
||||
platforms = Bundler.definition.platforms.map {|p| "* #{p}" }
|
||||
|
||||
output << "Your platform is: #{Gem::Platform.local}"
|
||||
output << "Your app has gems that work on these platforms:\n#{platforms.join("\n")}"
|
||||
|
||||
if ruby_version
|
||||
output << "Your Gemfile specifies a Ruby version requirement:\n* #{ruby_version}"
|
||||
|
||||
begin
|
||||
Bundler.definition.validate_runtime!
|
||||
output << "Your current platform satisfies the Ruby version requirement."
|
||||
rescue RubyVersionMismatch => e
|
||||
output << e.message
|
||||
end
|
||||
else
|
||||
output << "Your Gemfile does not specify a Ruby version requirement."
|
||||
end
|
||||
end
|
||||
|
||||
Bundler.ui.info output.join("\n\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../vendored_thor"
|
||||
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), 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 (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
|
||||
|
||||
desc "uninstall PLUGINS", "Uninstall the plugins"
|
||||
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."
|
||||
def uninstall(*plugins)
|
||||
Bundler::Plugin.uninstall(plugins, options)
|
||||
end
|
||||
|
||||
desc "list", "List the installed plugins and available commands"
|
||||
def list
|
||||
Bundler::Plugin.list
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,60 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Pristine
|
||||
def initialize(gems)
|
||||
@gems = gems
|
||||
end
|
||||
|
||||
def run
|
||||
CLI::Common.ensure_all_gems_in_lockfile!(@gems)
|
||||
definition = Bundler.definition
|
||||
definition.validate_runtime!
|
||||
installer = Bundler::Installer.new(Bundler.root, definition)
|
||||
|
||||
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
|
||||
|
||||
true
|
||||
end.map(&:name)
|
||||
|
||||
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
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Remove
|
||||
def initialize(gems, options)
|
||||
@gems = gems
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
raise InvalidOption, "Please specify gems to remove." if @gems.empty?
|
||||
|
||||
Injector.remove(@gems, {})
|
||||
Installer.install(Bundler.root, Bundler.definition)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,75 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Show
|
||||
attr_reader :options, :gem_name, :latest_specs
|
||||
def initialize(options, gem_name)
|
||||
@options = options
|
||||
@gem_name = gem_name
|
||||
@verbose = options[:verbose] || options[:outdated]
|
||||
@latest_specs = fetch_latest_specs if @verbose
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.ui.silence do
|
||||
Bundler.definition.validate_runtime!
|
||||
Bundler.load.lock
|
||||
end
|
||||
|
||||
if gem_name
|
||||
if gem_name == "bundler"
|
||||
path = File.expand_path("../../..", __dir__)
|
||||
else
|
||||
spec = Bundler::CLI::Common.select_spec(gem_name, :regex_match)
|
||||
return unless spec
|
||||
path = spec.full_gem_path
|
||||
unless File.directory?(path)
|
||||
return Bundler.ui.warn "The gem #{gem_name} has been deleted. It was installed at: #{path}"
|
||||
end
|
||||
end
|
||||
return Bundler.ui.info(path)
|
||||
end
|
||||
|
||||
if options[:paths]
|
||||
Bundler.load.specs.sort_by(&:name).map do |s|
|
||||
Bundler.ui.info s.full_gem_path
|
||||
end
|
||||
else
|
||||
Bundler.ui.info "Gems included by the bundle:"
|
||||
Bundler.load.specs.sort_by(&:name).each do |s|
|
||||
desc = " * #{s.name} (#{s.version}#{s.git_version})"
|
||||
if @verbose
|
||||
latest = latest_specs.find {|l| l.name == s.name }
|
||||
Bundler.ui.info <<~END
|
||||
#{desc.lstrip}
|
||||
\tSummary: #{s.summary || "No description available."}
|
||||
\tHomepage: #{s.homepage || "No website available."}
|
||||
\tStatus: #{outdated?(s, latest) ? "Outdated - #{s.version} < #{latest.version}" : "Up to date"}
|
||||
END
|
||||
else
|
||||
Bundler.ui.info desc
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_latest_specs
|
||||
definition = Bundler.definition(true)
|
||||
if options[:outdated]
|
||||
Bundler.ui.info "Fetching remote specs for outdated check...\n\n"
|
||||
Bundler.ui.silence { definition.resolve_remotely! }
|
||||
else
|
||||
definition.resolve_with_cache!
|
||||
end
|
||||
Bundler.reset!
|
||||
definition.specs
|
||||
end
|
||||
|
||||
def outdated?(current, latest)
|
||||
return false unless latest
|
||||
Gem::Version.new(current.version) < Gem::Version.new(latest.version)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,123 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Update
|
||||
attr_reader :options, :gems
|
||||
def initialize(options, gems)
|
||||
@options = options
|
||||
@gems = gems
|
||||
end
|
||||
|
||||
def run
|
||||
Bundler.ui.level = "warn" if options[:quiet]
|
||||
|
||||
update_bundler = options[:bundler]
|
||||
|
||||
Bundler.self_manager.update_bundler_and_restart_with_it_if_needed(update_bundler) if update_bundler
|
||||
|
||||
Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?
|
||||
|
||||
sources = Array(options[:source])
|
||||
groups = Array(options[:group]).map(&:to_sym)
|
||||
|
||||
full_update = gems.empty? && sources.empty? && groups.empty? && !options[:ruby] && !update_bundler
|
||||
|
||||
if full_update && !options[:all]
|
||||
if Bundler.feature_flag.update_requires_all_flag?
|
||||
raise InvalidOption, "To update everything, pass the `--all` flag."
|
||||
end
|
||||
SharedHelpers.major_deprecation 3, "Pass --all to `bundle update` to update everything"
|
||||
elsif !full_update && options[:all]
|
||||
raise InvalidOption, "Cannot specify --all along with specific options."
|
||||
end
|
||||
|
||||
conservative = options[:conservative]
|
||||
|
||||
if full_update
|
||||
if conservative
|
||||
Bundler.definition(conservative: conservative)
|
||||
else
|
||||
Bundler.definition(true)
|
||||
end
|
||||
else
|
||||
unless Bundler.default_lockfile.exist?
|
||||
raise GemfileLockNotFound, "This Bundle hasn't been installed yet. " \
|
||||
"Run `bundle install` to update and install the bundled gems."
|
||||
end
|
||||
Bundler::CLI::Common.ensure_all_gems_in_lockfile!(gems)
|
||||
|
||||
if groups.any?
|
||||
deps = Bundler.definition.dependencies.select {|d| (d.groups & groups).any? }
|
||||
gems.concat(deps.map(&:name))
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
Bundler::Fetcher.disable_endpoint = options["full-index"]
|
||||
|
||||
opts = options.dup
|
||||
opts["update"] = true
|
||||
opts["local"] = options[:local]
|
||||
opts["force"] = options[:redownload]
|
||||
|
||||
Bundler.settings.set_command_option_if_given :jobs, opts["jobs"]
|
||||
|
||||
Bundler.definition.validate_runtime!
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
installer = Installer.install Bundler.root, Bundler.definition, opts
|
||||
Bundler.load.cache if Bundler.app_cache.exist?
|
||||
|
||||
if CLI::Common.clean_after_install?
|
||||
require_relative "clean"
|
||||
Bundler::CLI::Clean.new(options).run
|
||||
end
|
||||
|
||||
if locked_gems
|
||||
gems.each do |name|
|
||||
locked_info = previous_locked_info[name]
|
||||
next unless locked_info
|
||||
|
||||
locked_spec = locked_info[:spec]
|
||||
new_spec = Bundler.definition.specs[name].first
|
||||
unless new_spec
|
||||
unless locked_spec.match_platform(Bundler.local_platform)
|
||||
Bundler.ui.warn "Bundler attempted to update #{name} but it was not considered because it is for a different platform from the current one"
|
||||
end
|
||||
|
||||
next
|
||||
end
|
||||
|
||||
locked_source = locked_info[:source]
|
||||
new_source = new_spec.source.identifier
|
||||
next if locked_source != new_source
|
||||
|
||||
new_version = new_spec.version
|
||||
locked_version = locked_info[:version]
|
||||
if new_version < locked_version
|
||||
Bundler.ui.warn "Note: #{name} version regressed from #{locked_version} to #{new_version}"
|
||||
elsif new_version == locked_version
|
||||
Bundler.ui.warn "Bundler attempted to update #{name} but its version stayed the same"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Bundler.ui.confirm "Bundle updated!"
|
||||
Bundler::CLI::Common.output_without_groups_message(:update)
|
||||
Bundler::CLI::Common.output_post_install_messages installer.post_install_messages
|
||||
|
||||
Bundler::CLI::Common.output_fund_metadata_summary
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CLI::Viz
|
||||
attr_reader :options, :gem_name
|
||||
def initialize(options)
|
||||
@options = options
|
||||
end
|
||||
|
||||
def run
|
||||
# make sure we get the right `graphviz`. There is also a `graphviz`
|
||||
# gem we're not built to support
|
||||
gem "ruby-graphviz"
|
||||
require "graphviz"
|
||||
|
||||
options[:without] = options[:without].join(":").tr(" ", ":").split(":")
|
||||
output_file = File.expand_path(options[:file])
|
||||
|
||||
graph = Graph.new(Bundler.load, output_file, options[:version], options[:requirements], options[:format], options[:without])
|
||||
graph.viz
|
||||
rescue LoadError => e
|
||||
Bundler.ui.error e.inspect
|
||||
Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
|
||||
Bundler.ui.warn "`gem install ruby-graphviz`"
|
||||
rescue StandardError => e
|
||||
raise unless e.message.to_s.include?("GraphViz not installed or dot not in PATH")
|
||||
Bundler.ui.error e.message
|
||||
Bundler.ui.warn "Please install GraphViz. On a Mac with Homebrew, you can run `brew install graphviz`."
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,126 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "pathname"
|
||||
require "set"
|
||||
|
||||
module Bundler
|
||||
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
|
||||
|
||||
def self.debug
|
||||
return unless ENV["DEBUG_COMPACT_INDEX"]
|
||||
DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") }
|
||||
end
|
||||
|
||||
class Error < StandardError; end
|
||||
|
||||
require_relative "compact_index_client/cache"
|
||||
require_relative "compact_index_client/cache_file"
|
||||
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
|
||||
end
|
||||
|
||||
def names
|
||||
Bundler::CompactIndexClient.debug { "/names" }
|
||||
update("names", @cache.names_path, @cache.names_etag_path)
|
||||
@cache.names
|
||||
end
|
||||
|
||||
def versions
|
||||
Bundler::CompactIndexClient.debug { "/versions" }
|
||||
update("versions", @cache.versions_path, @cache.versions_etag_path)
|
||||
versions, @info_checksums_by_name = @cache.versions
|
||||
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)
|
||||
end
|
||||
|
||||
def update_and_parse_checksums!
|
||||
Bundler::CompactIndexClient.debug { "update_and_parse_checksums!" }
|
||||
return @info_checksums_by_name if @parsed_checksums
|
||||
update("versions", @cache.versions_path, @cache.versions_etag_path)
|
||||
@info_checksums_by_name = @cache.checksums
|
||||
@parsed_checksums = true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update(remote_path, local_path, local_etag_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(url(remote_path), local_path, local_etag_path)
|
||||
end
|
||||
|
||||
def update_info(name)
|
||||
Bundler::CompactIndexClient.debug { "update_info(#{name})" }
|
||||
path = @cache.info_path(name)
|
||||
unless existing = @info_checksums_by_name[name]
|
||||
Bundler::CompactIndexClient.debug { "skipping updating info for #{name} since it is missing from versions" }
|
||||
return
|
||||
end
|
||||
checksum = SharedHelpers.checksum_for_file(path, :MD5)
|
||||
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("info/#{name}", path, @cache.info_etag_path(name))
|
||||
end
|
||||
|
||||
def url(path)
|
||||
path
|
||||
end
|
||||
|
||||
def synchronize
|
||||
@mutex.synchronize { yield }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,121 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "gem_parser"
|
||||
|
||||
module Bundler
|
||||
class CompactIndexClient
|
||||
class Cache
|
||||
attr_reader :directory
|
||||
|
||||
def initialize(directory)
|
||||
@directory = Pathname.new(directory).expand_path
|
||||
info_roots.each {|dir| mkdir(dir) }
|
||||
mkdir(info_etag_root)
|
||||
end
|
||||
|
||||
def names
|
||||
lines(names_path)
|
||||
end
|
||||
|
||||
def names_path
|
||||
directory.join("names")
|
||||
end
|
||||
|
||||
def names_etag_path
|
||||
directory.join("names.etag")
|
||||
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(",") 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, info_checksums_by_name]
|
||||
end
|
||||
|
||||
def versions_path
|
||||
directory.join("versions")
|
||||
end
|
||||
|
||||
def versions_etag_path
|
||||
directory.join("versions.etag")
|
||||
end
|
||||
|
||||
def checksums
|
||||
checksums = {}
|
||||
|
||||
lines(versions_path).each do |line|
|
||||
name, _, checksum = line.split(" ", 3)
|
||||
checksums[name] = checksum
|
||||
end
|
||||
|
||||
checksums
|
||||
end
|
||||
|
||||
def dependencies(name)
|
||||
lines(info_path(name)).map do |line|
|
||||
parse_gem(line)
|
||||
end
|
||||
end
|
||||
|
||||
def info_path(name)
|
||||
name = name.to_s
|
||||
if /[^a-z0-9_-]/.match?(name)
|
||||
name += "-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}"
|
||||
info_roots.last.join(name)
|
||||
else
|
||||
info_roots.first.join(name)
|
||||
end
|
||||
end
|
||||
|
||||
def info_etag_path(name)
|
||||
name = name.to_s
|
||||
info_etag_root.join("#{name}-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mkdir(dir)
|
||||
SharedHelpers.filesystem_access(dir) do
|
||||
FileUtils.mkdir_p(dir)
|
||||
end
|
||||
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
|
||||
end
|
||||
|
||||
def parse_gem(line)
|
||||
@dependency_parser ||= GemParser.new
|
||||
@dependency_parser.parse(line)
|
||||
end
|
||||
|
||||
def info_roots
|
||||
[
|
||||
directory.join("info"),
|
||||
directory.join("info-special-characters"),
|
||||
]
|
||||
end
|
||||
|
||||
def info_etag_root
|
||||
directory.join("info-etags")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,153 @@
|
||||
# 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
|
||||
|
||||
# remove this method when we stop generating md5 digests for legacy etags
|
||||
def md5
|
||||
@digests && @digests["md5"]
|
||||
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
|
||||
@@ -0,0 +1,32 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CompactIndexClient
|
||||
if defined?(Gem::Resolver::APISet::GemParser)
|
||||
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) } : EMPTY_ARRAY
|
||||
requirements = requirements ? requirements.map! {|d| parse_dependency(d) } : EMPTY_ARRAY
|
||||
[version, platform, dependencies, requirements]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_dependency(string)
|
||||
dependency = string.split(":")
|
||||
dependency[-1] = dependency[-1].split("&") if dependency.size > 1
|
||||
dependency[0] = -dependency[0]
|
||||
dependency
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,115 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class CompactIndexClient
|
||||
class Updater
|
||||
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
|
||||
|
||||
def initialize(fetcher)
|
||||
@fetcher = fetcher
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
def append(remote_path, local_path, etag_path)
|
||||
return false unless local_path.file? && local_path.size.nonzero?
|
||||
|
||||
CacheFile.copy(local_path) do |file|
|
||||
etag = etag_path.read.tap(&:chomp!) if etag_path.file?
|
||||
etag ||= generate_etag(etag_path, file) # Remove this after 2.5.0 has been out for a while.
|
||||
|
||||
# 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)
|
||||
|
||||
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
|
||||
file.write(response.body)
|
||||
end
|
||||
CacheFile.write(etag_path, etag_from_response(response))
|
||||
true
|
||||
end
|
||||
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
|
||||
|
||||
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_request(etag_path)
|
||||
etag_path.read.tap(&:chomp!) if etag_path.file?
|
||||
end
|
||||
|
||||
# When first releasing this opaque etag feature, we want to generate the old MD5 etag
|
||||
# based on the content of the file. After that it will always use the saved opaque etag.
|
||||
# This transparently saves existing users with good caches from updating a bunch of files.
|
||||
# Remove this behavior after 2.5.0 has been out for a while.
|
||||
def generate_etag(etag_path, file)
|
||||
etag = file.md5.hexdigest
|
||||
CacheFile.write(etag_path, etag)
|
||||
etag
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
# 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
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
WINDOWS = RbConfig::CONFIG["host_os"] =~ /(msdos|mswin|djgpp|mingw)/
|
||||
FREEBSD = RbConfig::CONFIG["host_os"].to_s.include?("bsd")
|
||||
NULL = File::NULL
|
||||
end
|
||||
@@ -0,0 +1,92 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
# Returns current version of Ruby
|
||||
#
|
||||
# @return [CurrentRuby] Current version of Ruby
|
||||
def self.current_ruby
|
||||
@current_ruby ||= CurrentRuby.new
|
||||
end
|
||||
|
||||
class CurrentRuby
|
||||
KNOWN_MINOR_VERSIONS = %w[
|
||||
1.8
|
||||
1.9
|
||||
2.0
|
||||
2.1
|
||||
2.2
|
||||
2.3
|
||||
2.4
|
||||
2.5
|
||||
2.6
|
||||
2.7
|
||||
3.0
|
||||
3.1
|
||||
3.2
|
||||
3.3
|
||||
].freeze
|
||||
|
||||
KNOWN_MAJOR_VERSIONS = KNOWN_MINOR_VERSIONS.map {|v| v.split(".", 2).first }.uniq.freeze
|
||||
|
||||
KNOWN_PLATFORMS = %w[
|
||||
jruby
|
||||
maglev
|
||||
mingw
|
||||
mri
|
||||
mswin
|
||||
mswin64
|
||||
rbx
|
||||
ruby
|
||||
truffleruby
|
||||
windows
|
||||
x64_mingw
|
||||
].freeze
|
||||
|
||||
def 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
|
||||
|
||||
def mri?
|
||||
!windows? && RUBY_ENGINE == "ruby"
|
||||
end
|
||||
|
||||
def rbx?
|
||||
ruby? && RUBY_ENGINE == "rbx"
|
||||
end
|
||||
|
||||
def jruby?
|
||||
RUBY_ENGINE == "jruby"
|
||||
end
|
||||
|
||||
def maglev?
|
||||
RUBY_ENGINE == "maglev"
|
||||
end
|
||||
|
||||
def truffleruby?
|
||||
RUBY_ENGINE == "truffleruby"
|
||||
end
|
||||
|
||||
def windows?
|
||||
Gem.win_platform?
|
||||
end
|
||||
alias_method :mswin?, :windows?
|
||||
alias_method :mswin64?, :windows?
|
||||
alias_method :mingw?, :windows?
|
||||
alias_method :x64_mingw?, :windows?
|
||||
|
||||
(KNOWN_MINOR_VERSIONS + KNOWN_MAJOR_VERSIONS).each do |version|
|
||||
trimmed_version = version.tr(".", "")
|
||||
define_method(:"on_#{trimmed_version}?") do
|
||||
RUBY_VERSION.start_with?("#{version}.")
|
||||
end
|
||||
|
||||
KNOWN_PLATFORMS.each do |platform|
|
||||
define_method(:"#{platform}_#{trimmed_version}?") do
|
||||
send(:"#{platform}?") && send(:"on_#{trimmed_version}?")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rubygems/dependency"
|
||||
require_relative "shared_helpers"
|
||||
require_relative "rubygems_ext"
|
||||
|
||||
module Bundler
|
||||
class Dependency < Gem::Dependency
|
||||
attr_reader :autorequire
|
||||
attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref
|
||||
|
||||
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],
|
||||
# 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]],
|
||||
}.each_with_object({}) do |(platform, spec), hash|
|
||||
hash[platform] = spec[0]
|
||||
spec[1]&.each {|version| hash[:"#{platform}_#{version}"] = spec[0] }
|
||||
end.freeze
|
||||
|
||||
def initialize(name, version, options = {}, &blk)
|
||||
type = options["type"] || :runtime
|
||||
super(name, version, type)
|
||||
|
||||
@autorequire = nil
|
||||
@groups = Array(options["group"] || :default).map(&:to_sym)
|
||||
@source = options["source"]
|
||||
@path = options["path"]
|
||||
@git = options["git"]
|
||||
@github = options["github"]
|
||||
@branch = options["branch"]
|
||||
@ref = options["ref"]
|
||||
@platforms = Array(options["platforms"])
|
||||
@env = options["env"]
|
||||
@should_include = options.fetch("should_include", true)
|
||||
@gemfile = options["gemfile"]
|
||||
@force_ruby_platform = options["force_ruby_platform"] if options.key?("force_ruby_platform")
|
||||
|
||||
@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 RUBY_PLATFORM_ARRAY if force_ruby_platform
|
||||
return valid_platforms if @platforms.empty?
|
||||
|
||||
valid_platforms.select {|p| expanded_platforms.include?(GemHelpers.generic(p)) }
|
||||
end
|
||||
|
||||
def expanded_platforms
|
||||
@expanded_platforms ||= @platforms.map {|pl| PLATFORM_MAP[pl] }.compact.flatten.uniq
|
||||
end
|
||||
|
||||
def should_include?
|
||||
@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)
|
||||
@env.all? do |key, val|
|
||||
ENV[key.to_s] && (val.is_a?(String) ? ENV[key.to_s] == val : ENV[key.to_s] =~ val)
|
||||
end
|
||||
else
|
||||
ENV[@env.to_s]
|
||||
end
|
||||
end
|
||||
|
||||
def current_platform?
|
||||
return true if @platforms.empty?
|
||||
@platforms.any? do |p|
|
||||
Bundler.current_ruby.send("#{p}?")
|
||||
end
|
||||
end
|
||||
|
||||
def to_lock
|
||||
out = super
|
||||
out << "!" if source
|
||||
out
|
||||
end
|
||||
|
||||
def specific?
|
||||
super
|
||||
rescue NoMethodError
|
||||
requirement != ">= 0"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,69 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "shared_helpers"
|
||||
Bundler::SharedHelpers.major_deprecation 2, "Bundler no longer integrates with " \
|
||||
"Capistrano, but Capistrano provides its own integration with " \
|
||||
"Bundler via the capistrano-bundler gem. Use it instead."
|
||||
|
||||
module Bundler
|
||||
class Deployment
|
||||
def self.define_task(context, task_method = :task, opts = {})
|
||||
if defined?(Capistrano) && context.is_a?(Capistrano::Configuration)
|
||||
context_name = "capistrano"
|
||||
role_default = "{:except => {:no_release => true}}"
|
||||
error_type = ::Capistrano::CommandError
|
||||
else
|
||||
context_name = "vlad"
|
||||
role_default = "[:app]"
|
||||
error_type = ::Rake::CommandFailedError
|
||||
end
|
||||
|
||||
roles = context.fetch(:bundle_roles, false)
|
||||
opts[:roles] = roles if roles
|
||||
|
||||
context.send :namespace, :bundle do
|
||||
send :desc, <<-DESC
|
||||
Install the current Bundler environment. By default, gems will be \
|
||||
installed to the shared/bundle path. Gems in the development and \
|
||||
test group will not be installed. The install command is executed \
|
||||
with the --deployment and --quiet flags. If the bundle cmd cannot \
|
||||
be found then you can override the bundle_cmd variable to specify \
|
||||
which one it should use. The base path to the app is fetched from \
|
||||
the :latest_release variable. Set it for custom deploy layouts.
|
||||
|
||||
You can override any of these defaults by setting the variables shown below.
|
||||
|
||||
N.B. bundle_roles must be defined before you require 'bundler/#{context_name}' \
|
||||
in your deploy.rb file.
|
||||
|
||||
set :bundle_gemfile, "Gemfile"
|
||||
set :bundle_dir, File.join(fetch(:shared_path), 'bundle')
|
||||
set :bundle_flags, "--deployment --quiet"
|
||||
set :bundle_without, [:development, :test]
|
||||
set :bundle_with, [:mysql]
|
||||
set :bundle_cmd, "bundle" # e.g. "/opt/ruby/bin/bundle"
|
||||
set :bundle_roles, #{role_default} # e.g. [:app, :batch]
|
||||
DESC
|
||||
send task_method, :install, opts do
|
||||
bundle_cmd = context.fetch(:bundle_cmd, "bundle")
|
||||
bundle_flags = context.fetch(:bundle_flags, "--deployment --quiet")
|
||||
bundle_dir = context.fetch(:bundle_dir, File.join(context.fetch(:shared_path), "bundle"))
|
||||
bundle_gemfile = context.fetch(:bundle_gemfile, "Gemfile")
|
||||
bundle_without = [*context.fetch(:bundle_without, [:development, :test])].compact
|
||||
bundle_with = [*context.fetch(:bundle_with, [])].compact
|
||||
app_path = context.fetch(:latest_release)
|
||||
if app_path.to_s.empty?
|
||||
raise error_type.new("Cannot detect current release path - make sure you have deployed at least once.")
|
||||
end
|
||||
args = ["--gemfile #{File.join(app_path, bundle_gemfile)}"]
|
||||
args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
|
||||
args << bundle_flags.to_s
|
||||
args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?
|
||||
args << "--with #{bundle_with.join(" ")}" unless bundle_with.empty?
|
||||
|
||||
run "cd #{app_path} && #{bundle_cmd} install #{args.join(" ")}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
begin
|
||||
require "rubygems/deprecate"
|
||||
rescue LoadError
|
||||
# it's fine if it doesn't exist on the current RubyGems...
|
||||
nil
|
||||
end
|
||||
|
||||
module Bundler
|
||||
# If Bundler::Deprecate is an autoload constant, we need to define it
|
||||
if defined?(Bundler::Deprecate) && !autoload?(:Deprecate)
|
||||
# nothing to do!
|
||||
elsif defined? ::Deprecate
|
||||
Deprecate = ::Deprecate
|
||||
elsif defined? Gem::Deprecate
|
||||
Deprecate = Gem::Deprecate
|
||||
else
|
||||
class Deprecate
|
||||
end
|
||||
end
|
||||
|
||||
unless Deprecate.respond_to?(:skip_during)
|
||||
def Deprecate.skip_during
|
||||
original = skip
|
||||
self.skip = true
|
||||
yield
|
||||
ensure
|
||||
self.skip = original
|
||||
end
|
||||
end
|
||||
|
||||
unless Deprecate.respond_to?(:skip)
|
||||
def Deprecate.skip
|
||||
@skip ||= false
|
||||
end
|
||||
end
|
||||
|
||||
unless Deprecate.respond_to?(:skip=)
|
||||
def Deprecate.skip=(skip)
|
||||
@skip = skip
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,71 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# This code was extracted from https://github.com/Solistra/ruby-digest which is under public domain
|
||||
module Bundler
|
||||
module Digest
|
||||
# The initial constant values for the 32-bit constant words A, B, C, D, and
|
||||
# E, respectively.
|
||||
SHA1_WORDS = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0].freeze
|
||||
|
||||
# The 8-bit field used for bitwise `AND` masking. Defaults to `0xFFFFFFFF`.
|
||||
SHA1_MASK = 0xFFFFFFFF
|
||||
|
||||
class << self
|
||||
def sha1(string)
|
||||
unless string.is_a?(String)
|
||||
raise TypeError, "can't convert #{string.class.inspect} into String"
|
||||
end
|
||||
|
||||
buffer = string.b
|
||||
|
||||
words = SHA1_WORDS.dup
|
||||
generate_split_buffer(buffer) do |chunk|
|
||||
w = []
|
||||
chunk.each_slice(4) do |a, b, c, d|
|
||||
w << (((a << 8 | b) << 8 | c) << 8 | d)
|
||||
end
|
||||
a, b, c, d, e = *words
|
||||
(16..79).each do |i|
|
||||
w[i] = SHA1_MASK & rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]), 1)
|
||||
end
|
||||
0.upto(79) do |i|
|
||||
case i
|
||||
when 0..19
|
||||
f = ((b & c) | (~b & d))
|
||||
k = 0x5A827999
|
||||
when 20..39
|
||||
f = (b ^ c ^ d)
|
||||
k = 0x6ED9EBA1
|
||||
when 40..59
|
||||
f = ((b & c) | (b & d) | (c & d))
|
||||
k = 0x8F1BBCDC
|
||||
when 60..79
|
||||
f = (b ^ c ^ d)
|
||||
k = 0xCA62C1D6
|
||||
end
|
||||
t = SHA1_MASK & rotate(a, 5) + f + e + k + w[i]
|
||||
a, b, c, d, e = t, a, SHA1_MASK & rotate(b, 30), c, d # rubocop:disable Style/ParallelAssignment
|
||||
end
|
||||
mutated = [a, b, c, d, e]
|
||||
words.map!.with_index {|word, index| SHA1_MASK & (word + mutated[index]) }
|
||||
end
|
||||
|
||||
words.pack("N*").unpack1("H*")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_split_buffer(string, &block)
|
||||
size = string.bytesize * 8
|
||||
buffer = string.bytes << 128
|
||||
buffer << 0 while buffer.size % 64 != 56
|
||||
buffer.concat([size].pack("Q>").bytes)
|
||||
buffer.each_slice(64, &block)
|
||||
end
|
||||
|
||||
def rotate(value, spaces)
|
||||
value << spaces | value >> (32 - spaces)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,619 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "dependency"
|
||||
require_relative "ruby_dsl"
|
||||
|
||||
module Bundler
|
||||
class Dsl
|
||||
include RubyDsl
|
||||
|
||||
def self.evaluate(gemfile, lockfile, unlock)
|
||||
builder = new
|
||||
builder.eval_gemfile(gemfile)
|
||||
builder.to_definition(lockfile, unlock)
|
||||
end
|
||||
|
||||
VALID_PLATFORMS = Bundler::Dependency::PLATFORM_MAP.keys.freeze
|
||||
|
||||
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}
|
||||
GITLAB_MERGE_REQUEST_URL = %r{\Ahttps://gitlab\.com/([A-Za-z0-9_\-\./]+)/-/merge_requests/(\d+)\z}
|
||||
|
||||
attr_reader :gemspecs, :gemfile
|
||||
attr_accessor :dependencies
|
||||
|
||||
def initialize
|
||||
@source = nil
|
||||
@sources = SourceList.new
|
||||
@git_sources = {}
|
||||
@dependencies = []
|
||||
@groups = []
|
||||
@install_conditionals = []
|
||||
@optional_groups = []
|
||||
@platforms = []
|
||||
@env = nil
|
||||
@ruby_version = nil
|
||||
@gemspecs = []
|
||||
@gemfile = nil
|
||||
@gemfiles = []
|
||||
add_git_sources
|
||||
end
|
||||
|
||||
def eval_gemfile(gemfile, contents = nil)
|
||||
expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
|
||||
original_gemfile = @gemfile
|
||||
@gemfile = expanded_gemfile_path
|
||||
@gemfiles << expanded_gemfile_path
|
||||
contents ||= Bundler.read_file(@gemfile.to_s)
|
||||
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"} " \
|
||||
"`#{File.basename gemfile.to_s}`: #{e.message}"
|
||||
|
||||
raise DSLError.new(message, gemfile, e.backtrace, contents)
|
||||
ensure
|
||||
@gemfile = original_gemfile
|
||||
end
|
||||
|
||||
def gemspec(opts = nil)
|
||||
opts ||= {}
|
||||
path = opts[:path] || "."
|
||||
glob = opts[:glob]
|
||||
name = opts[:name]
|
||||
development_group = opts[:development_group] || :development
|
||||
expanded_path = gemfile_root.join(path)
|
||||
|
||||
gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact
|
||||
gemspecs.reject! {|s| s.name != name } if name
|
||||
specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] }
|
||||
|
||||
case specs_by_name_and_version.size
|
||||
when 1
|
||||
specs = specs_by_name_and_version.values.first
|
||||
spec = specs.find {|s| s.match_platform(Bundler.local_platform) } || specs.first
|
||||
|
||||
@gemspecs << spec
|
||||
|
||||
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])
|
||||
end
|
||||
end
|
||||
when 0
|
||||
raise InvalidOption, "There are no gemspecs at #{expanded_path}"
|
||||
else
|
||||
raise InvalidOption, "There are multiple gemspecs at #{expanded_path}. " \
|
||||
"Please use the :name option to specify which one should be used"
|
||||
end
|
||||
end
|
||||
|
||||
def gem(name, *args)
|
||||
options = args.last.is_a?(Hash) ? args.pop.dup : {}
|
||||
options["gemfile"] = @gemfile
|
||||
version = args || [">= 0"]
|
||||
|
||||
normalize_options(name, version, options)
|
||||
|
||||
dep = Dependency.new(name, version, options)
|
||||
|
||||
# if there's already a dependency with this name we try to prefer one
|
||||
if current = @dependencies.find {|d| d.name == dep.name }
|
||||
if current.requirement != dep.requirement
|
||||
current_requirement_open = current.requirements_list.include?(">= 0")
|
||||
|
||||
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_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_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}"
|
||||
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
|
||||
end
|
||||
|
||||
def source(source, *args, &blk)
|
||||
options = args.last.is_a?(Hash) ? args.pop.dup : {}
|
||||
options = normalize_hash(options)
|
||||
source = normalize_source(source)
|
||||
|
||||
if options.key?("type")
|
||||
options["type"] = options["type"].to_s
|
||||
unless Plugin.source?(options["type"])
|
||||
raise InvalidOption, "No plugin sources available for #{options["type"]}"
|
||||
end
|
||||
|
||||
unless block_given?
|
||||
raise InvalidOption, "You need to pass a block to #source with :type option"
|
||||
end
|
||||
|
||||
source_opts = options.merge("uri" => source)
|
||||
with_source(@sources.add_plugin_source(options["type"], source_opts), &blk)
|
||||
elsif block_given?
|
||||
with_source(@sources.add_rubygems_source("remotes" => source), &blk)
|
||||
else
|
||||
@sources.add_global_rubygems_remote(source)
|
||||
end
|
||||
end
|
||||
|
||||
def git_source(name, &block)
|
||||
unless block_given?
|
||||
raise InvalidOption, "You need to pass a block to #git_source"
|
||||
end
|
||||
|
||||
if valid_keys.include?(name.to_s)
|
||||
raise InvalidOption, "You cannot use #{name} as a git source. It " \
|
||||
"is a reserved key. Reserved keys are: #{valid_keys.join(", ")}"
|
||||
end
|
||||
|
||||
@git_sources[name.to_s] = block
|
||||
end
|
||||
|
||||
def path(path, options = {}, &blk)
|
||||
source_options = normalize_hash(options).merge(
|
||||
"path" => Pathname.new(path),
|
||||
"root_path" => gemfile_root,
|
||||
"gemspec" => gemspecs.find {|g| g.name == options["name"] }
|
||||
)
|
||||
|
||||
source_options["global"] = true unless block_given?
|
||||
|
||||
source = @sources.add_path_source(source_options)
|
||||
with_source(source, &blk)
|
||||
end
|
||||
|
||||
def git(uri, options = {}, &blk)
|
||||
unless block_given?
|
||||
msg = "You can no longer specify a git source by itself. Instead, \n" \
|
||||
"either use the :git option on a gem, or specify the gems that \n" \
|
||||
"bundler should find in the git source by passing a block to \n" \
|
||||
"the git method, like: \n\n" \
|
||||
" git 'git://github.com/rails/rails.git' do\n" \
|
||||
" gem 'rails'\n" \
|
||||
" end"
|
||||
raise DeprecatedError, msg
|
||||
end
|
||||
|
||||
with_source(@sources.add_git_source(normalize_hash(options).merge("uri" => uri)), &blk)
|
||||
end
|
||||
|
||||
def github(repo, options = {})
|
||||
raise ArgumentError, "GitHub sources require a block" unless block_given?
|
||||
github_uri = @git_sources["github"].call(repo)
|
||||
git_options = normalize_hash(options).merge("uri" => github_uri)
|
||||
git_source = @sources.add_git_source(git_options)
|
||||
with_source(git_source) { yield }
|
||||
end
|
||||
|
||||
def to_definition(lockfile, unlock)
|
||||
check_primary_source_safety
|
||||
Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version, @optional_groups, @gemfiles)
|
||||
end
|
||||
|
||||
def group(*args, &blk)
|
||||
options = args.last.is_a?(Hash) ? args.pop.dup : {}
|
||||
normalize_group_options(options, args)
|
||||
|
||||
@groups.concat args
|
||||
|
||||
if options["optional"]
|
||||
optional_groups = args - @optional_groups
|
||||
@optional_groups.concat optional_groups
|
||||
end
|
||||
|
||||
yield
|
||||
ensure
|
||||
args.each { @groups.pop }
|
||||
end
|
||||
|
||||
def install_if(*args)
|
||||
@install_conditionals.concat args
|
||||
yield
|
||||
ensure
|
||||
args.each { @install_conditionals.pop }
|
||||
end
|
||||
|
||||
def platforms(*platforms)
|
||||
@platforms.concat platforms
|
||||
yield
|
||||
ensure
|
||||
platforms.each { @platforms.pop }
|
||||
end
|
||||
alias_method :platform, :platforms
|
||||
|
||||
def env(name)
|
||||
old = @env
|
||||
@env = name
|
||||
yield
|
||||
ensure
|
||||
@env = old
|
||||
end
|
||||
|
||||
def plugin(*args)
|
||||
# Pass on
|
||||
end
|
||||
|
||||
def method_missing(name, *args)
|
||||
raise GemfileError, "Undefined local variable or method `#{name}' for Gemfile"
|
||||
end
|
||||
|
||||
def check_primary_source_safety
|
||||
check_path_source_safety
|
||||
check_rubygems_source_safety
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_git_sources
|
||||
git_source(:github) do |repo_name|
|
||||
if repo_name =~ GITHUB_PULL_REQUEST_URL
|
||||
{
|
||||
"git" => "https://github.com/#{$1}.git",
|
||||
"branch" => nil,
|
||||
"ref" => "refs/pull/#{$2}/head",
|
||||
"tag" => nil,
|
||||
}
|
||||
else
|
||||
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
||||
"https://github.com/#{repo_name}.git"
|
||||
end
|
||||
end
|
||||
|
||||
git_source(:gist) do |repo_name|
|
||||
"https://gist.github.com/#{repo_name}.git"
|
||||
end
|
||||
|
||||
git_source(:bitbucket) do |repo_name|
|
||||
user_name, repo_name = repo_name.split("/")
|
||||
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)
|
||||
old_source = @source
|
||||
if block_given?
|
||||
@source = source
|
||||
yield
|
||||
end
|
||||
source
|
||||
ensure
|
||||
@source = old_source
|
||||
end
|
||||
|
||||
def normalize_hash(opts)
|
||||
opts.keys.each do |k|
|
||||
opts[k.to_s] = opts.delete(k) unless k.is_a?(String)
|
||||
end
|
||||
opts
|
||||
end
|
||||
|
||||
def valid_keys
|
||||
@valid_keys ||= VALID_KEYS
|
||||
end
|
||||
|
||||
def normalize_options(name, version, opts)
|
||||
if name.is_a?(Symbol)
|
||||
raise GemfileError, %(You need to specify gem names as Strings. Use 'gem "#{name}"' instead)
|
||||
end
|
||||
if /\s/.match?(name)
|
||||
raise GemfileError, %('#{name}' is not a valid gem name because it contains whitespace)
|
||||
end
|
||||
raise GemfileError, %(an empty gem name is not valid) if name.empty?
|
||||
|
||||
normalize_hash(opts)
|
||||
|
||||
git_names = @git_sources.keys.map(&:to_s)
|
||||
validate_keys("gem '#{name}'", opts, valid_keys + git_names)
|
||||
|
||||
groups = @groups.dup
|
||||
opts["group"] = opts.delete("groups") || opts["group"]
|
||||
groups.concat Array(opts.delete("group"))
|
||||
groups = [:default] if groups.empty?
|
||||
|
||||
install_if = @install_conditionals.dup
|
||||
install_if.concat Array(opts.delete("install_if"))
|
||||
install_if = install_if.reduce(true) do |memo, val|
|
||||
memo && (val.respond_to?(:call) ? val.call : val)
|
||||
end
|
||||
|
||||
platforms = @platforms.dup
|
||||
opts["platforms"] = opts["platform"] || opts["platforms"]
|
||||
platforms.concat Array(opts.delete("platforms"))
|
||||
platforms.map!(&:to_sym)
|
||||
platforms.each do |p|
|
||||
next if VALID_PLATFORMS.include?(p)
|
||||
raise GemfileError, "`#{p}` is not a valid platform. The available options are: #{VALID_PLATFORMS.inspect}"
|
||||
end
|
||||
|
||||
# Save sources passed in a key
|
||||
if opts.key?("source")
|
||||
source = normalize_source(opts["source"])
|
||||
opts["source"] = @sources.add_rubygems_source("remotes" => source)
|
||||
end
|
||||
|
||||
git_name = (git_names & opts.keys).last
|
||||
if @git_sources[git_name]
|
||||
git_opts = @git_sources[git_name].call(opts[git_name])
|
||||
git_opts = { "git" => git_opts } if git_opts.is_a?(String)
|
||||
opts.merge!(git_opts) do |key, _gemfile_value, _git_source_value|
|
||||
raise GemfileError, %(The :#{key} option can't be used with `#{git_name}: #{opts[git_name].inspect}`)
|
||||
end
|
||||
end
|
||||
|
||||
%w[git path].each do |type|
|
||||
next unless param = opts[type]
|
||||
if version.first && version.first =~ /^\s*=?\s*(\d[^\s]*)\s*$/
|
||||
options = opts.merge("name" => name, "version" => $1)
|
||||
else
|
||||
options = opts.dup
|
||||
end
|
||||
source = send(type, param, options) {}
|
||||
opts["source"] = source
|
||||
end
|
||||
|
||||
opts["source"] ||= @source
|
||||
opts["env"] ||= @env
|
||||
opts["platforms"] = platforms.dup
|
||||
opts["group"] = groups
|
||||
opts["should_include"] = install_if
|
||||
end
|
||||
|
||||
def normalize_group_options(opts, groups)
|
||||
normalize_hash(opts)
|
||||
|
||||
groups = groups.map {|group| ":#{group}" }.join(", ")
|
||||
validate_keys("group #{groups}", opts, %w[optional])
|
||||
|
||||
opts["optional"] ||= false
|
||||
end
|
||||
|
||||
def validate_keys(command, opts, valid_keys)
|
||||
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
|
||||
message << "You passed #{invalid_keys.map {|k| ":" + k }.join(", ")} "
|
||||
message << if invalid_keys.size > 1
|
||||
"as options for #{command}, but they are invalid."
|
||||
else
|
||||
"as an option for #{command}, but it is invalid."
|
||||
end
|
||||
|
||||
message << " Valid options are: #{valid_keys.join(", ")}."
|
||||
message << " You may be able to resolve this by upgrading Bundler to the newest version."
|
||||
raise InvalidOption, message
|
||||
end
|
||||
|
||||
def normalize_source(source)
|
||||
case source
|
||||
when :gemcutter, :rubygems, :rubyforge
|
||||
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
|
||||
else
|
||||
raise GemfileError, "Unknown source '#{source}'"
|
||||
end
|
||||
end
|
||||
|
||||
def check_path_source_safety
|
||||
return if @sources.global_path_source.nil?
|
||||
|
||||
msg = "You can no longer specify a path source by itself. Instead, \n" \
|
||||
"either use the :path option on a gem, or specify the gems that \n" \
|
||||
"bundler should find in the path source by passing a block to \n" \
|
||||
"the path method, like: \n\n" \
|
||||
" path 'dir/containing/rails' do\n" \
|
||||
" gem 'rails'\n" \
|
||||
" end\n\n"
|
||||
|
||||
SharedHelpers.major_deprecation(2, msg.strip)
|
||||
end
|
||||
|
||||
def check_rubygems_source_safety
|
||||
if @sources.implicit_global_source?
|
||||
implicit_global_source_warning
|
||||
elsif @sources.aggregate_global_source?
|
||||
multiple_global_source_warning
|
||||
end
|
||||
end
|
||||
|
||||
def implicit_global_source_warning
|
||||
Bundler::SharedHelpers.major_deprecation 2, "This Gemfile does not include an explicit global source. " \
|
||||
"Not using an explicit global source may result in a different lockfile being generated depending on " \
|
||||
"the gems you have installed locally before bundler is run. " \
|
||||
"Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"."
|
||||
end
|
||||
|
||||
def multiple_global_source_warning
|
||||
if Bundler.feature_flag.bundler_3_mode?
|
||||
msg = "This Gemfile contains multiple global sources. " \
|
||||
"Each source after the first must include a block to indicate which gems " \
|
||||
"should come from that source"
|
||||
raise GemfileEvalError, msg
|
||||
else
|
||||
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
|
||||
|
||||
class DSLError < GemfileError
|
||||
# @return [String] the description that should be presented to the user.
|
||||
#
|
||||
attr_reader :description
|
||||
|
||||
# @return [String] the path of the dsl file that raised the exception.
|
||||
#
|
||||
attr_reader :dsl_path
|
||||
|
||||
# @return [Exception] the backtrace of the exception raised by the
|
||||
# evaluation of the dsl file.
|
||||
#
|
||||
attr_reader :backtrace
|
||||
|
||||
# @param [Exception] backtrace @see backtrace
|
||||
# @param [String] dsl_path @see dsl_path
|
||||
#
|
||||
def initialize(description, dsl_path, backtrace, contents = nil)
|
||||
@status_code = $!.respond_to?(:status_code) && $!.status_code
|
||||
|
||||
@description = description
|
||||
@dsl_path = dsl_path
|
||||
@backtrace = backtrace
|
||||
@contents = contents
|
||||
end
|
||||
|
||||
def status_code
|
||||
@status_code || super
|
||||
end
|
||||
|
||||
# @return [String] the contents of the DSL that cause the exception to
|
||||
# be raised.
|
||||
#
|
||||
def contents
|
||||
@contents ||= dsl_path && File.exist?(dsl_path) && File.read(dsl_path)
|
||||
end
|
||||
|
||||
# The message of the exception reports the content of podspec for the
|
||||
# line that generated the original exception.
|
||||
#
|
||||
# @example Output
|
||||
#
|
||||
# Invalid podspec at `RestKit.podspec` - undefined method
|
||||
# `exclude_header_search_paths=' for #<Pod::Specification for
|
||||
# `RestKit/Network (0.9.3)`>
|
||||
#
|
||||
# from spec-repos/master/RestKit/0.9.3/RestKit.podspec:36
|
||||
# -------------------------------------------
|
||||
# # because it would break: #import <CoreData/CoreData.h>
|
||||
# > ns.exclude_header_search_paths = 'Code/RestKit.h'
|
||||
# end
|
||||
# -------------------------------------------
|
||||
#
|
||||
# @return [String] the message of the exception.
|
||||
#
|
||||
def to_s
|
||||
@to_s ||= begin
|
||||
trace_line, description = parse_line_number_from_description
|
||||
|
||||
m = String.new("\n[!] ")
|
||||
m << description
|
||||
m << ". Bundler cannot continue.\n"
|
||||
|
||||
return m unless backtrace && dsl_path && contents
|
||||
|
||||
trace_line = backtrace.find {|l| l.include?(dsl_path.to_s) } || trace_line
|
||||
return m unless trace_line
|
||||
line_numer = trace_line.split(":")[1].to_i - 1
|
||||
return m unless line_numer
|
||||
|
||||
lines = contents.lines.to_a
|
||||
indent = " # "
|
||||
indicator = indent.tr("#", ">")
|
||||
first_line = line_numer.zero?
|
||||
last_line = (line_numer == (lines.count - 1))
|
||||
|
||||
m << "\n"
|
||||
m << "#{indent}from #{trace_line.gsub(/:in.*$/, "")}\n"
|
||||
m << "#{indent}-------------------------------------------\n"
|
||||
m << "#{indent}#{lines[line_numer - 1]}" unless first_line
|
||||
m << "#{indicator}#{lines[line_numer]}"
|
||||
m << "#{indent}#{lines[line_numer + 1]}" unless last_line
|
||||
m << "\n" unless m.end_with?("\n")
|
||||
m << "#{indent}-------------------------------------------\n"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_line_number_from_description
|
||||
description = self.description
|
||||
if dsl_path && description =~ /((#{Regexp.quote File.expand_path(dsl_path)}|#{Regexp.quote dsl_path.to_s}):\d+)/
|
||||
trace_line = Regexp.last_match[1]
|
||||
description = description.sub(/\n.*\n(\.\.\.)? *\^~+$/, "").sub(/#{Regexp.quote trace_line}:\s*/, "").sub("\n", " - ")
|
||||
end
|
||||
[trace_line, description]
|
||||
end
|
||||
end
|
||||
|
||||
def gemfile_root
|
||||
@gemfile ||= Bundler.default_gemfile
|
||||
@gemfile.dirname
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,147 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
# used for Creating Specifications from the Gemcutter Endpoint
|
||||
class EndpointSpecification < Gem::Specification
|
||||
include MatchRemoteMetadata
|
||||
|
||||
attr_reader :name, :version, :platform, :checksum
|
||||
attr_accessor :source, :remote, :dependencies
|
||||
|
||||
def initialize(name, version, platform, spec_fetcher, dependencies, metadata = nil)
|
||||
super()
|
||||
@name = name
|
||||
@version = Gem::Version.create version
|
||||
@platform = Gem::Platform.new(platform)
|
||||
@spec_fetcher = spec_fetcher
|
||||
@dependencies = dependencies.map {|dep, reqs| build_dependency(dep, reqs) }
|
||||
|
||||
@loaded_from = nil
|
||||
@remote_specification = nil
|
||||
|
||||
parse_metadata(metadata)
|
||||
end
|
||||
|
||||
def fetch_platform
|
||||
@platform
|
||||
end
|
||||
|
||||
# needed for standalone, load required_paths from local gemspec
|
||||
# after the gem is installed
|
||||
def require_paths
|
||||
if @remote_specification
|
||||
@remote_specification.require_paths
|
||||
elsif _local_specification
|
||||
_local_specification.require_paths
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# needed for inline
|
||||
def load_paths
|
||||
# remote specs aren't installed, and can't have load_paths
|
||||
if _local_specification
|
||||
_local_specification.load_paths
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# needed for binstubs
|
||||
def executables
|
||||
if @remote_specification
|
||||
@remote_specification.executables
|
||||
elsif _local_specification
|
||||
_local_specification.executables
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# needed for bundle clean
|
||||
def bindir
|
||||
if @remote_specification
|
||||
@remote_specification.bindir
|
||||
elsif _local_specification
|
||||
_local_specification.bindir
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# needed for post_install_messages during install
|
||||
def post_install_message
|
||||
if @remote_specification
|
||||
@remote_specification.post_install_message
|
||||
elsif _local_specification
|
||||
_local_specification.post_install_message
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# needed for "with native extensions" during install
|
||||
def extensions
|
||||
if @remote_specification
|
||||
@remote_specification.extensions
|
||||
elsif _local_specification
|
||||
_local_specification.extensions
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def _local_specification
|
||||
return unless @loaded_from && File.exist?(local_specification_path)
|
||||
eval(File.read(local_specification_path), nil, local_specification_path).tap do |spec|
|
||||
spec.loaded_from = @loaded_from
|
||||
end
|
||||
end
|
||||
|
||||
def __swap__(spec)
|
||||
SharedHelpers.ensure_same_dependencies(self, dependencies, spec.dependencies)
|
||||
@remote_specification = spec
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def _remote_specification
|
||||
@_remote_specification ||= @spec_fetcher.fetch_spec([@name, @version, @platform])
|
||||
end
|
||||
|
||||
def local_specification_path
|
||||
"#{base_dir}/specifications/#{full_name}.gemspec"
|
||||
end
|
||||
|
||||
def parse_metadata(data)
|
||||
unless data
|
||||
@required_ruby_version = nil
|
||||
@required_rubygems_version = nil
|
||||
return
|
||||
end
|
||||
|
||||
data.each do |k, v|
|
||||
next unless v
|
||||
case k.to_s
|
||||
when "checksum"
|
||||
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"
|
||||
@required_ruby_version = Gem::Requirement.new(v)
|
||||
end
|
||||
end
|
||||
rescue StandardError => e
|
||||
raise GemspecError, "There was an error parsing the metadata for the gem #{name} (#{version}): #{e.class}\n#{e}\nThe metadata was #{data.inspect}"
|
||||
end
|
||||
|
||||
def build_dependency(name, requirements)
|
||||
Gem::Dependency.new(name, requirements)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,148 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "rubygems_integration"
|
||||
require_relative "source/git/git_proxy"
|
||||
|
||||
module Bundler
|
||||
class Env
|
||||
def self.write(io)
|
||||
io.write report
|
||||
end
|
||||
|
||||
def self.report(options = {})
|
||||
print_gemfile = options.delete(:print_gemfile) { true }
|
||||
print_gemspecs = options.delete(:print_gemspecs) { true }
|
||||
|
||||
out = String.new
|
||||
append_formatted_table("Environment", environment, out)
|
||||
append_formatted_table("Bundler Build Metadata", BuildMetadata.to_h, out)
|
||||
|
||||
unless Bundler.settings.all.empty?
|
||||
out << "\n## Bundler settings\n\n```\n"
|
||||
Bundler.settings.all.each do |setting|
|
||||
out << setting << "\n"
|
||||
Bundler.settings.pretty_values_for(setting).each do |line|
|
||||
out << " " << line << "\n"
|
||||
end
|
||||
end
|
||||
out << "```\n"
|
||||
end
|
||||
|
||||
return out unless SharedHelpers.in_bundle?
|
||||
|
||||
if print_gemfile
|
||||
gemfiles = [Bundler.default_gemfile]
|
||||
begin
|
||||
gemfiles = Bundler.definition.gemfiles
|
||||
rescue GemfileNotFound
|
||||
nil
|
||||
end
|
||||
|
||||
out << "\n## Gemfile\n"
|
||||
gemfiles.each do |gemfile|
|
||||
out << "\n### #{SharedHelpers.relative_path_to(gemfile)}\n\n"
|
||||
out << "```ruby\n" << read_file(gemfile).chomp << "\n```\n"
|
||||
end
|
||||
|
||||
out << "\n### #{SharedHelpers.relative_path_to(Bundler.default_lockfile)}\n\n"
|
||||
out << "```\n" << read_file(Bundler.default_lockfile).chomp << "\n```\n"
|
||||
end
|
||||
|
||||
if print_gemspecs
|
||||
dsl = Dsl.new.tap {|d| d.eval_gemfile(Bundler.default_gemfile) }
|
||||
out << "\n## Gemspecs\n" unless dsl.gemspecs.empty?
|
||||
dsl.gemspecs.each do |gs|
|
||||
out << "\n### #{File.basename(gs.loaded_from)}"
|
||||
out << "\n\n```ruby\n" << read_file(gs.loaded_from).chomp << "\n```\n"
|
||||
end
|
||||
end
|
||||
|
||||
out
|
||||
end
|
||||
|
||||
def self.read_file(filename)
|
||||
Bundler.read_file(filename.to_s).strip
|
||||
rescue Errno::ENOENT
|
||||
"<No #{filename} found>"
|
||||
rescue RuntimeError => e
|
||||
"#{e.class}: #{e.message}"
|
||||
end
|
||||
|
||||
def self.ruby_version
|
||||
"#{RUBY_VERSION}p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE} revision #{RUBY_REVISION}) [#{Gem::Platform.local}]"
|
||||
end
|
||||
|
||||
def self.git_version
|
||||
Bundler::Source::Git::GitProxy.new(nil, nil).full_version
|
||||
rescue Bundler::Source::Git::GitNotInstalledError
|
||||
"not installed"
|
||||
end
|
||||
|
||||
def self.version_of(script)
|
||||
return "not installed" unless Bundler.which(script)
|
||||
`#{script} --version`.chomp
|
||||
end
|
||||
|
||||
def self.chruby_version
|
||||
return "not installed" unless Bundler.which("chruby-exec")
|
||||
`chruby-exec -- chruby --version`.
|
||||
sub(/.*^chruby: (#{Gem::Version::VERSION_PATTERN}).*/m, '\1')
|
||||
end
|
||||
|
||||
def self.environment
|
||||
out = []
|
||||
|
||||
out << ["Bundler", Bundler::VERSION]
|
||||
out << [" Platforms", Gem.platforms.join(", ")]
|
||||
out << ["Ruby", ruby_version]
|
||||
out << [" Full Path", Gem.ruby]
|
||||
out << [" Config Dir", Pathname.new(Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE).dirname]
|
||||
out << ["RubyGems", Gem::VERSION]
|
||||
out << [" Gem Home", Gem.dir]
|
||||
out << [" Gem Path", Gem.path.join(File::PATH_SEPARATOR)]
|
||||
out << [" User Home", Gem.user_home]
|
||||
out << [" User Path", Gem.user_dir]
|
||||
out << [" Bin Dir", Gem.bindir]
|
||||
if defined?(OpenSSL::SSL)
|
||||
out << ["OpenSSL"]
|
||||
out << [" Compiled", OpenSSL::OPENSSL_VERSION] if defined?(OpenSSL::OPENSSL_VERSION)
|
||||
out << [" Loaded", OpenSSL::OPENSSL_LIBRARY_VERSION] if defined?(OpenSSL::OPENSSL_LIBRARY_VERSION)
|
||||
out << [" Cert File", OpenSSL::X509::DEFAULT_CERT_FILE] if defined?(OpenSSL::X509::DEFAULT_CERT_FILE)
|
||||
out << [" Cert Dir", OpenSSL::X509::DEFAULT_CERT_DIR] if defined?(OpenSSL::X509::DEFAULT_CERT_DIR)
|
||||
end
|
||||
out << ["Tools"]
|
||||
out << [" Git", git_version]
|
||||
out << [" RVM", ENV.fetch("rvm_version") { version_of("rvm") }]
|
||||
out << [" rbenv", version_of("rbenv")]
|
||||
out << [" chruby", chruby_version]
|
||||
|
||||
%w[rubygems-bundler open_gem].each do |name|
|
||||
specs = Bundler.rubygems.find_name(name)
|
||||
out << [" #{name}", "(#{specs.map(&:version).join(",")})"] unless specs.empty?
|
||||
end
|
||||
if (exe = caller.last.split(":").first)&.match? %r{(exe|bin)/bundler?\z}
|
||||
shebang = File.read(exe).lines.first
|
||||
shebang.sub!(/^#!\s*/, "")
|
||||
unless shebang.start_with?(Gem.ruby, "/usr/bin/env ruby")
|
||||
out << ["Gem.ruby", Gem.ruby]
|
||||
out << ["bundle #!", shebang]
|
||||
end
|
||||
end
|
||||
|
||||
out
|
||||
end
|
||||
|
||||
def self.append_formatted_table(title, pairs, out)
|
||||
return if pairs.empty?
|
||||
out << "\n" unless out.empty?
|
||||
out << "## #{title}\n\n```\n"
|
||||
ljust = pairs.map {|k, _v| k.to_s.length }.max
|
||||
pairs.each do |k, v|
|
||||
out << "#{k.to_s.ljust(ljust)} #{v}\n"
|
||||
end
|
||||
out << "```\n"
|
||||
end
|
||||
|
||||
private_class_method :read_file, :ruby_version, :git_version, :append_formatted_table, :version_of, :chruby_version
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,86 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class EnvironmentPreserver
|
||||
INTENTIONALLY_NIL = "BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL"
|
||||
BUNDLER_KEYS = %w[
|
||||
BUNDLE_BIN_PATH
|
||||
BUNDLE_GEMFILE
|
||||
BUNDLER_VERSION
|
||||
BUNDLER_SETUP
|
||||
GEM_HOME
|
||||
GEM_PATH
|
||||
MANPATH
|
||||
PATH
|
||||
RB_USER_INSTALL
|
||||
RUBYLIB
|
||||
RUBYOPT
|
||||
].map(&:freeze).freeze
|
||||
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 }
|
||||
end
|
||||
|
||||
# @param env [Hash]
|
||||
# @param keys [Array<String>]
|
||||
def initialize(env, keys)
|
||||
@original = env
|
||||
@keys = keys
|
||||
@prefix = BUNDLER_PREFIX
|
||||
end
|
||||
|
||||
# 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 }
|
||||
end
|
||||
|
||||
# @return [Hash]
|
||||
def backup
|
||||
env = @original.clone
|
||||
@keys.each do |key|
|
||||
value = env[key]
|
||||
if !value.nil?
|
||||
env[@prefix + key] ||= value
|
||||
else
|
||||
env[@prefix + key] ||= INTENTIONALLY_NIL
|
||||
end
|
||||
end
|
||||
env
|
||||
end
|
||||
|
||||
# @return [Hash]
|
||||
def restore
|
||||
env = @original.clone
|
||||
@keys.each do |key|
|
||||
value_original = env[@prefix + key]
|
||||
next if value_original.nil?
|
||||
if value_original == INTENTIONALLY_NIL
|
||||
env.delete(key)
|
||||
else
|
||||
env[key] = value_original
|
||||
end
|
||||
env.delete(@prefix + key)
|
||||
end
|
||||
env
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,233 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class BundlerError < StandardError
|
||||
def self.status_code(code)
|
||||
define_method(:status_code) { code }
|
||||
if match = BundlerError.all_errors.find {|_k, v| v == code }
|
||||
error, _ = match
|
||||
raise ArgumentError,
|
||||
"Trying to register #{self} for status code #{code} but #{error} is already registered"
|
||||
end
|
||||
BundlerError.all_errors[self] = code
|
||||
end
|
||||
|
||||
def self.all_errors
|
||||
@all_errors ||= {}
|
||||
end
|
||||
end
|
||||
|
||||
class GemfileError < BundlerError; status_code(4); end
|
||||
class InstallError < BundlerError; status_code(5); end
|
||||
|
||||
# Internal error, should be rescued
|
||||
class SolveFailure < BundlerError; status_code(6); end
|
||||
|
||||
class GemNotFound < BundlerError; status_code(7); end
|
||||
class InstallHookError < BundlerError; status_code(8); end
|
||||
class GemfileNotFound < BundlerError; status_code(10); end
|
||||
class GitError < BundlerError; status_code(11); end
|
||||
class DeprecatedError < BundlerError; status_code(12); end
|
||||
class PathError < BundlerError; status_code(13); end
|
||||
class GemspecError < BundlerError; status_code(14); end
|
||||
class InvalidOption < BundlerError; status_code(15); end
|
||||
class ProductionError < BundlerError; status_code(16); end
|
||||
|
||||
class HTTPError < BundlerError
|
||||
status_code(17)
|
||||
def filter_uri(uri)
|
||||
URICredentialsFilter.credential_filtered_uri(uri)
|
||||
end
|
||||
end
|
||||
|
||||
class RubyVersionMismatch < BundlerError; status_code(18); end
|
||||
class SecurityError < BundlerError; status_code(19); end
|
||||
class LockfileError < BundlerError; status_code(20); end
|
||||
class CyclicDependencyError < BundlerError; status_code(21); end
|
||||
class GemfileLockNotFound < BundlerError; status_code(22); end
|
||||
class PluginError < BundlerError; status_code(29); end
|
||||
class ThreadCreationError < BundlerError; status_code(33); end
|
||||
class APIResponseMismatchError < BundlerError; status_code(34); end
|
||||
class APIResponseInvalidDependenciesError < BundlerError; status_code(35); end
|
||||
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
|
||||
@permission_type = permission_type
|
||||
end
|
||||
|
||||
def action
|
||||
case @permission_type
|
||||
when :read then "read from"
|
||||
when :write then "write to"
|
||||
when :executable, :exec then "execute"
|
||||
else @permission_type.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def permission_type
|
||||
case @permission_type
|
||||
when :create
|
||||
"executable permissions for all parent directories and write permissions for `#{parent_folder}`"
|
||||
else
|
||||
"#{@permission_type} permissions for that path"
|
||||
end
|
||||
end
|
||||
|
||||
def parent_folder
|
||||
File.dirname(@path)
|
||||
end
|
||||
|
||||
def message
|
||||
"There was an error while trying to #{action} `#{@path}`. " \
|
||||
"It is likely that you need to grant #{permission_type}."
|
||||
end
|
||||
|
||||
status_code(23)
|
||||
end
|
||||
|
||||
class GemRequireError < BundlerError
|
||||
attr_reader :orig_exception
|
||||
|
||||
def initialize(orig_exception, msg)
|
||||
full_message = msg + "\nGem Load Error is: #{orig_exception.message}\n"\
|
||||
"Backtrace for gem load error is:\n"\
|
||||
"#{orig_exception.backtrace.join("\n")}\n"\
|
||||
"Bundler Error Backtrace:\n"
|
||||
super(full_message)
|
||||
@orig_exception = orig_exception
|
||||
end
|
||||
|
||||
status_code(24)
|
||||
end
|
||||
|
||||
class YamlSyntaxError < BundlerError
|
||||
attr_reader :orig_exception
|
||||
|
||||
def initialize(orig_exception, msg)
|
||||
super(msg)
|
||||
@orig_exception = orig_exception
|
||||
end
|
||||
|
||||
status_code(25)
|
||||
end
|
||||
|
||||
class TemporaryResourceError < PermissionError
|
||||
def message
|
||||
"There was an error while trying to #{action} `#{@path}`. " \
|
||||
"Some resource was temporarily unavailable. It's suggested that you try" \
|
||||
"the operation again."
|
||||
end
|
||||
|
||||
status_code(26)
|
||||
end
|
||||
|
||||
class VirtualProtocolError < BundlerError
|
||||
def message
|
||||
"There was an error relating to virtualization and file access. " \
|
||||
"It is likely that you need to grant access to or mount some file system correctly."
|
||||
end
|
||||
|
||||
status_code(27)
|
||||
end
|
||||
|
||||
class OperationNotSupportedError < PermissionError
|
||||
def message
|
||||
"Attempting to #{action} `#{@path}` is unsupported by your OS."
|
||||
end
|
||||
|
||||
status_code(28)
|
||||
end
|
||||
|
||||
class NoSpaceOnDeviceError < PermissionError
|
||||
def message
|
||||
"There was an error while trying to #{action} `#{@path}`. " \
|
||||
"There was insufficient space remaining on the device."
|
||||
end
|
||||
|
||||
status_code(31)
|
||||
end
|
||||
|
||||
class GenericSystemCallError < BundlerError
|
||||
attr_reader :underlying_error
|
||||
|
||||
def initialize(underlying_error, message)
|
||||
@underlying_error = underlying_error
|
||||
super("#{message}\nThe underlying system error is #{@underlying_error.class}: #{@underlying_error}")
|
||||
end
|
||||
|
||||
status_code(32)
|
||||
end
|
||||
|
||||
class DirectoryRemovalError < BundlerError
|
||||
def initialize(orig_exception, msg)
|
||||
full_message = "#{msg}.\n" \
|
||||
"The underlying error was #{orig_exception.class}: #{orig_exception.message}, with backtrace:\n" \
|
||||
" #{orig_exception.backtrace.join("\n ")}\n\n" \
|
||||
"Bundler Error Backtrace:"
|
||||
super(full_message)
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class FeatureFlag
|
||||
def self.settings_flag(flag, &default)
|
||||
unless Bundler::Settings::BOOL_KEYS.include?(flag.to_s)
|
||||
raise "Cannot use `#{flag}` as a settings feature flag since it isn't a bool key"
|
||||
end
|
||||
|
||||
settings_method("#{flag}?", flag, &default)
|
||||
end
|
||||
private_class_method :settings_flag
|
||||
|
||||
def self.settings_option(key, &default)
|
||||
settings_method(key, key, &default)
|
||||
end
|
||||
private_class_method :settings_option
|
||||
|
||||
def self.settings_method(name, key, &default)
|
||||
define_method(name) do
|
||||
value = Bundler.settings[key]
|
||||
value = instance_eval(&default) if value.nil?
|
||||
value
|
||||
end
|
||||
end
|
||||
private_class_method :settings_method
|
||||
|
||||
(1..10).each {|v| define_method("bundler_#{v}_mode?") { major_version >= v } }
|
||||
|
||||
settings_flag(:allow_offline_install) { bundler_3_mode? }
|
||||
settings_flag(:auto_clean_without_path) { bundler_3_mode? }
|
||||
settings_flag(:cache_all) { bundler_3_mode? }
|
||||
settings_flag(:default_install_uses_path) { bundler_3_mode? }
|
||||
settings_flag(:forget_cli_options) { bundler_3_mode? }
|
||||
settings_flag(:global_gem_cache) { bundler_3_mode? }
|
||||
settings_flag(:path_relative_to_cwd) { bundler_3_mode? }
|
||||
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(:update_requires_all_flag) { bundler_4_mode? }
|
||||
|
||||
settings_option(:default_cli_command) { bundler_3_mode? ? :cli_help : :install }
|
||||
|
||||
def initialize(bundler_version)
|
||||
@bundler_version = Gem::Version.create(bundler_version)
|
||||
end
|
||||
|
||||
def major_version
|
||||
@bundler_version.segments.first
|
||||
end
|
||||
private :major_version
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,324 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "vendored_persistent"
|
||||
require_relative "vendored_timeout"
|
||||
require "cgi"
|
||||
require "securerandom"
|
||||
require "zlib"
|
||||
|
||||
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__)
|
||||
autoload :Index, File.expand_path("fetcher/index", __dir__)
|
||||
|
||||
# This error is raised when it looks like the network is down
|
||||
class NetworkDownError < HTTPError; end
|
||||
# This error is raised if we should rate limit our requests to the API
|
||||
class TooManyRequestsError < HTTPError; end
|
||||
# This error is raised if the API returns a 413 (only printed in verbose)
|
||||
class FallbackError < HTTPError; end
|
||||
|
||||
# This is the error raised if OpenSSL fails the cert verification
|
||||
class CertificateFailureError < HTTPError
|
||||
def initialize(remote_uri)
|
||||
remote_uri = filter_uri(remote_uri)
|
||||
super "Could not verify the SSL certificate for #{remote_uri}.\nThere" \
|
||||
" is a chance you are experiencing a man-in-the-middle attack, but" \
|
||||
" most likely your system doesn't have the CA certificates needed" \
|
||||
" for verification. For information about OpenSSL certificates, see" \
|
||||
" https://railsapps.github.io/openssl-certificate-verify-failed.html."
|
||||
end
|
||||
end
|
||||
|
||||
# This is the error raised when a source is HTTPS and OpenSSL didn't load
|
||||
class SSLError < HTTPError
|
||||
def initialize(msg = nil)
|
||||
super msg || "Could not load OpenSSL.\n" \
|
||||
"You must recompile Ruby with OpenSSL support."
|
||||
end
|
||||
end
|
||||
|
||||
# This error is raised if HTTP authentication is required, but not provided.
|
||||
class AuthenticationRequiredError < HTTPError
|
||||
def initialize(remote_uri)
|
||||
remote_uri = filter_uri(remote_uri)
|
||||
super "Authentication is required for #{remote_uri}.\n" \
|
||||
"Please supply credentials for this source. You can do this by running:\n" \
|
||||
"`bundle config set --global #{remote_uri} username:password`\n" \
|
||||
"or by storing the credentials in the `#{Settings.key_for(remote_uri)}` environment variable"
|
||||
end
|
||||
end
|
||||
|
||||
# This error is raised if HTTP authentication is provided, but incorrect.
|
||||
class BadAuthenticationError < HTTPError
|
||||
def initialize(remote_uri)
|
||||
remote_uri = filter_uri(remote_uri)
|
||||
super "Bad username or password for #{remote_uri}.\n" \
|
||||
"Please double-check your credentials and correct them."
|
||||
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,
|
||||
:HTTPForbidden, :HTTPInsufficientStorage, :HTTPMethodNotAllowed,
|
||||
:HTTPMovedPermanently, :HTTPNoContent, :HTTPNotFound,
|
||||
:HTTPNotImplemented, :HTTPPreconditionFailed, :HTTPRequestEntityTooLarge,
|
||||
:HTTPRequestURITooLong, :HTTPUnauthorized, :HTTPUnprocessableEntity,
|
||||
:HTTPUnsupportedMediaType, :HTTPVersionNotSupported].freeze
|
||||
FAIL_ERRORS = begin
|
||||
fail_errors = [AuthenticationRequiredError, BadAuthenticationError, AuthenticationForbiddenError, FallbackError, SecurityError]
|
||||
fail_errors << Gem::Requirement::BadRequirementError
|
||||
fail_errors.concat(NET_ERRORS.map {|e| Gem::Net.const_get(e) })
|
||||
end.freeze
|
||||
|
||||
class << self
|
||||
attr_accessor :disable_endpoint, :api_timeout, :redirect_limit, :max_retries
|
||||
end
|
||||
|
||||
self.redirect_limit = Bundler.settings[:redirect] # How many redirects to allow in one request
|
||||
self.api_timeout = Bundler.settings[:timeout] # How long to wait for each API call
|
||||
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
|
||||
connection # create persistent connection
|
||||
end
|
||||
|
||||
def uri
|
||||
@remote.anonymized_uri
|
||||
end
|
||||
|
||||
# fetch a gem specification
|
||||
def fetch_spec(spec)
|
||||
spec -= [nil, "ruby", ""]
|
||||
spec_file_name = "#{spec.join "-"}.gemspec"
|
||||
|
||||
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."
|
||||
end
|
||||
|
||||
# return the specs in the bundler format as an index with retries
|
||||
def specs_with_retry(gem_names, source)
|
||||
Bundler::Retry.new("fetcher", FAIL_ERRORS).attempts do
|
||||
specs(gem_names, source)
|
||||
end
|
||||
end
|
||||
|
||||
# return the specs in the bundler format as an index
|
||||
def specs(gem_names, source)
|
||||
index = Bundler::Index.new
|
||||
|
||||
fetch_specs(gem_names).each do |name, version, platform, dependencies, metadata|
|
||||
spec = if dependencies
|
||||
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
|
||||
spec.source = source
|
||||
spec.remote = @remote
|
||||
index << spec
|
||||
end
|
||||
|
||||
index
|
||||
rescue CertificateFailureError
|
||||
Bundler.ui.info "" if gem_names && api_fetcher? # newline after dots
|
||||
raise
|
||||
end
|
||||
|
||||
def user_agent
|
||||
@user_agent ||= begin
|
||||
ruby = Bundler::RubyVersion.system
|
||||
|
||||
agent = String.new("bundler/#{Bundler::VERSION}")
|
||||
agent << " rubygems/#{Gem::VERSION}"
|
||||
agent << " ruby/#{ruby.versions_string(ruby.versions)}"
|
||||
agent << " (#{ruby.host})"
|
||||
agent << " command/#{ARGV.first}"
|
||||
|
||||
if ruby.engine != "ruby"
|
||||
# engine_version raises on unknown engines
|
||||
engine_version = begin
|
||||
ruby.engine_versions
|
||||
rescue RuntimeError
|
||||
"???"
|
||||
end
|
||||
agent << " #{ruby.engine}/#{ruby.versions_string(engine_version)}"
|
||||
end
|
||||
|
||||
agent << " options/#{Bundler.settings.all.join(",")}"
|
||||
|
||||
agent << " ci/#{cis.join(",")}" if cis.any?
|
||||
|
||||
# add a random ID so we can consolidate runs server-side
|
||||
agent << " " << SecureRandom.hex(8)
|
||||
|
||||
# add any user agent strings set in the config
|
||||
extra_ua = Bundler.settings[:user_agent]
|
||||
agent << " " << extra_ua if extra_ua
|
||||
|
||||
agent
|
||||
end
|
||||
end
|
||||
|
||||
def http_proxy
|
||||
return unless uri = connection.proxy_uri
|
||||
uri.to_s
|
||||
end
|
||||
|
||||
def inspect
|
||||
"#<#{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
|
||||
|
||||
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
|
||||
@cis ||= Bundler::CIDetector.ci_strings
|
||||
end
|
||||
|
||||
def connection
|
||||
@connection ||= begin
|
||||
needs_ssl = remote_uri.scheme == "https" ||
|
||||
Bundler.settings[:ssl_verify_mode] ||
|
||||
Bundler.settings[:ssl_client_cert]
|
||||
raise SSLError if needs_ssl && !defined?(OpenSSL::SSL)
|
||||
|
||||
con = Gem::Net::HTTP::Persistent.new name: "bundler", proxy: :ENV
|
||||
if gem_proxy = Gem.configuration[:http_proxy]
|
||||
con.proxy = Gem::URI.parse(gem_proxy) if gem_proxy != :no_proxy
|
||||
end
|
||||
|
||||
if remote_uri.scheme == "https"
|
||||
con.verify_mode = (Bundler.settings[:ssl_verify_mode] ||
|
||||
OpenSSL::SSL::VERIFY_PEER)
|
||||
con.cert_store = bundler_cert_store
|
||||
end
|
||||
|
||||
ssl_client_cert = Bundler.settings[:ssl_client_cert] ||
|
||||
(Gem.configuration.ssl_client_cert if
|
||||
Gem.configuration.respond_to?(:ssl_client_cert))
|
||||
if ssl_client_cert
|
||||
pem = File.read(ssl_client_cert)
|
||||
con.cert = OpenSSL::X509::Certificate.new(pem)
|
||||
con.key = OpenSSL::PKey::RSA.new(pem)
|
||||
end
|
||||
|
||||
con.read_timeout = Fetcher.api_timeout
|
||||
con.open_timeout = Fetcher.api_timeout
|
||||
con.override_headers["User-Agent"] = user_agent
|
||||
con.override_headers["X-Gemfile-Source"] = @remote.original_uri.to_s if @remote.original_uri
|
||||
con
|
||||
end
|
||||
end
|
||||
|
||||
# cached gem specification path, if one exists
|
||||
def gemspec_cached_path(spec_file_name)
|
||||
paths = Bundler.rubygems.spec_cache_dirs.map {|dir| File.join(dir, spec_file_name) }
|
||||
paths.find {|path| File.file? path }
|
||||
end
|
||||
|
||||
HTTP_ERRORS = [
|
||||
Gem::Timeout::Error, EOFError, SocketError, Errno::ENETDOWN, Errno::ENETUNREACH,
|
||||
Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EAGAIN,
|
||||
Gem::Net::HTTPBadResponse, Gem::Net::HTTPHeaderSyntaxError, Gem::Net::ProtocolError,
|
||||
Gem::Net::HTTP::Persistent::Error, Zlib::BufError, Errno::EHOSTUNREACH
|
||||
].freeze
|
||||
|
||||
def bundler_cert_store
|
||||
store = OpenSSL::X509::Store.new
|
||||
ssl_ca_cert = Bundler.settings[:ssl_ca_cert] ||
|
||||
(Gem.configuration.ssl_ca_cert if
|
||||
Gem.configuration.respond_to?(:ssl_ca_cert))
|
||||
if ssl_ca_cert
|
||||
if File.directory? ssl_ca_cert
|
||||
store.add_path ssl_ca_cert
|
||||
else
|
||||
store.add_file ssl_ca_cert
|
||||
end
|
||||
else
|
||||
store.set_default_paths
|
||||
require "rubygems/request"
|
||||
Gem::Request.get_cert_files.each {|c| store.add_file c }
|
||||
end
|
||||
store
|
||||
end
|
||||
|
||||
def remote_uri
|
||||
@remote.uri
|
||||
end
|
||||
|
||||
def downloader
|
||||
@downloader ||= Downloader.new(connection, self.class.redirect_limit)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class Fetcher
|
||||
class Base
|
||||
attr_reader :downloader
|
||||
attr_reader :display_uri
|
||||
attr_reader :remote
|
||||
attr_reader :gem_remote_fetcher
|
||||
|
||||
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
|
||||
@remote.uri
|
||||
end
|
||||
|
||||
def fetch_uri
|
||||
@fetch_uri ||= if remote_uri.host == "rubygems.org"
|
||||
uri = remote_uri.dup
|
||||
uri.host = "index.rubygems.org"
|
||||
uri
|
||||
else
|
||||
remote_uri
|
||||
end
|
||||
end
|
||||
|
||||
def available?
|
||||
true
|
||||
end
|
||||
|
||||
def api_fetcher?
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def log_specs(&block)
|
||||
if Bundler.ui.debug?
|
||||
Bundler.ui.debug yield
|
||||
else
|
||||
Bundler.ui.info ".", false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,129 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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)
|
||||
method = instance_method(method_name)
|
||||
undef_method(method_name)
|
||||
define_method(method_name) do |*args, &blk|
|
||||
method.bind(self).call(*args, &blk)
|
||||
rescue NetworkDownError, CompactIndexClient::Updater::MismatchedChecksumError => e
|
||||
raise HTTPError, e.message
|
||||
rescue AuthenticationRequiredError, BadAuthenticationError
|
||||
# Fail since we got a 401 from the server.
|
||||
raise
|
||||
rescue HTTPError => e
|
||||
Bundler.ui.trace(e)
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def specs(gem_names)
|
||||
specs_for_names(gem_names)
|
||||
end
|
||||
compact_index_request :specs
|
||||
|
||||
def specs_for_names(gem_names)
|
||||
gem_info = []
|
||||
complete_gems = []
|
||||
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.flat_map {|d| d[3].flat_map(&:first) }.uniq
|
||||
deps.each {|dep| gem_info << dep }
|
||||
complete_gems.concat(deps.map(&:first)).uniq!
|
||||
remaining_gems = next_gems - complete_gems
|
||||
end
|
||||
@bundle_worker&.stop
|
||||
@bundle_worker = nil # reset it. Not sure if necessary
|
||||
|
||||
gem_info
|
||||
end
|
||||
|
||||
def available?
|
||||
unless SharedHelpers.md5_available?
|
||||
Bundler.ui.debug("FIPS mode is enabled, bundler can't use the CompactIndex API")
|
||||
return nil
|
||||
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
|
||||
Bundler.ui.debug(e.message)
|
||||
nil
|
||||
end
|
||||
compact_index_request :available?
|
||||
|
||||
def api_fetcher?
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def compact_index_client
|
||||
@compact_index_client ||=
|
||||
SharedHelpers.filesystem_access(cache_path) do
|
||||
CompactIndexClient.new(cache_path, client_fetcher)
|
||||
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
|
||||
end
|
||||
|
||||
def serial_compact_index_client
|
||||
compact_index_client.sequential_execution_mode!
|
||||
compact_index_client
|
||||
end
|
||||
|
||||
def bundle_worker(func = nil)
|
||||
@bundle_worker ||= begin
|
||||
worker_name = "Compact Index (#{display_uri.host})"
|
||||
Bundler::Worker.new(Bundler.settings.processor_count, worker_name, func)
|
||||
end
|
||||
@bundle_worker.tap do |worker|
|
||||
worker.instance_variable_set(:@func, func) if func
|
||||
end
|
||||
end
|
||||
|
||||
def cache_path
|
||||
Bundler.user_cache.join("compact_index", remote.cache_slug)
|
||||
end
|
||||
|
||||
def client_fetcher
|
||||
ClientFetcher.new(self, Bundler.ui)
|
||||
end
|
||||
|
||||
ClientFetcher = Struct.new(:fetcher, :ui) do
|
||||
def call(path, headers)
|
||||
fetcher.downloader.fetch(fetcher.fetch_uri + path, headers)
|
||||
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}"
|
||||
Gem::Net::HTTPNotModified.new(nil, nil, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,78 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "base"
|
||||
require "cgi"
|
||||
|
||||
module Bundler
|
||||
class Fetcher
|
||||
class Dependency < Base
|
||||
def available?
|
||||
@available ||= fetch_uri.scheme != "file" && downloader.fetch(dependency_api_uri)
|
||||
rescue NetworkDownError => e
|
||||
raise HTTPError, e.message
|
||||
rescue AuthenticationRequiredError
|
||||
# Fail since we got a 401 from the server.
|
||||
raise
|
||||
rescue HTTPError
|
||||
false
|
||||
end
|
||||
|
||||
def api_fetcher?
|
||||
true
|
||||
end
|
||||
|
||||
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}" }
|
||||
|
||||
return last_spec_list if query_list.empty?
|
||||
|
||||
spec_list, deps_list = Bundler::Retry.new("dependency api", FAIL_ERRORS).attempts do
|
||||
dependency_specs(query_list)
|
||||
end
|
||||
|
||||
returned_gems = spec_list.map(&:first).uniq
|
||||
specs(deps_list, full_dependency_list + returned_gems, spec_list + last_spec_list)
|
||||
rescue MarshalError, HTTPError, GemspecError
|
||||
Bundler.ui.info "" unless Bundler.ui.debug? # new line now that the dots are over
|
||||
Bundler.ui.debug "could not fetch from the dependency API, trying the full index"
|
||||
nil
|
||||
end
|
||||
|
||||
def dependency_specs(gem_names)
|
||||
Bundler.ui.debug "Query Gemcutter Dependency Endpoint API: #{gem_names.join(",")}"
|
||||
|
||||
gem_list = unmarshalled_dep_gems(gem_names)
|
||||
get_formatted_specs_and_deps(gem_list)
|
||||
end
|
||||
|
||||
def unmarshalled_dep_gems(gem_names)
|
||||
gem_list = []
|
||||
gem_names.each_slice(Source::Rubygems::API_REQUEST_SIZE) do |names|
|
||||
marshalled_deps = downloader.fetch(dependency_api_uri(names)).body
|
||||
gem_list.concat(Bundler.safe_load_marshal(marshalled_deps))
|
||||
end
|
||||
gem_list
|
||||
end
|
||||
|
||||
def get_formatted_specs_and_deps(gem_list)
|
||||
deps_list = []
|
||||
spec_list = []
|
||||
|
||||
gem_list.each do |s|
|
||||
deps_list.concat(s[:dependencies].map(&:first))
|
||||
deps = s[:dependencies].map {|n, d| [n, d.split(", ")] }
|
||||
spec_list.push([s[:name], s[:number], s[:platform], deps])
|
||||
end
|
||||
[spec_list, deps_list]
|
||||
end
|
||||
|
||||
def dependency_api_uri(gem_names = [])
|
||||
uri = fetch_uri + "api/v1/dependencies"
|
||||
uri.query = "gems=#{CGI.escape(gem_names.sort.join(","))}" if gem_names.any?
|
||||
uri
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,91 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class Fetcher
|
||||
class Downloader
|
||||
attr_reader :connection
|
||||
attr_reader :redirect_limit
|
||||
|
||||
def initialize(connection, redirect_limit)
|
||||
@connection = connection
|
||||
@redirect_limit = redirect_limit
|
||||
end
|
||||
|
||||
def fetch(uri, headers = {}, counter = 0)
|
||||
raise HTTPError, "Too many redirects" if counter >= redirect_limit
|
||||
|
||||
filtered_uri = URICredentialsFilter.credential_filtered_uri(uri)
|
||||
|
||||
response = request(uri, headers)
|
||||
Bundler.ui.debug("HTTP #{response.code} #{response.message} #{filtered_uri}")
|
||||
|
||||
case response
|
||||
when Gem::Net::HTTPSuccess, Gem::Net::HTTPNotModified
|
||||
response
|
||||
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 Gem::Net::HTTPRequestedRangeNotSatisfiable
|
||||
new_headers = headers.dup
|
||||
new_headers.delete("Range")
|
||||
new_headers["Accept-Encoding"] = "gzip"
|
||||
fetch(uri, new_headers)
|
||||
when Gem::Net::HTTPRequestEntityTooLarge
|
||||
raise FallbackError, response.body
|
||||
when Gem::Net::HTTPTooManyRequests
|
||||
raise TooManyRequestsError, response.body
|
||||
when Gem::Net::HTTPUnauthorized
|
||||
raise BadAuthenticationError, uri.host if uri.userinfo
|
||||
raise AuthenticationRequiredError, uri.host
|
||||
when Gem::Net::HTTPForbidden
|
||||
raise AuthenticationForbiddenError, uri.host
|
||||
when Gem::Net::HTTPNotFound
|
||||
raise FallbackError, "Gem::Net::HTTPNotFound: #{filtered_uri}"
|
||||
else
|
||||
message = "Gem::#{response.class.name.gsub(/\AGem::/, "")}"
|
||||
message += ": #{response.body}" unless response.body.empty?
|
||||
raise HTTPError, message
|
||||
end
|
||||
end
|
||||
|
||||
def request(uri, headers)
|
||||
validate_uri_scheme!(uri)
|
||||
|
||||
filtered_uri = URICredentialsFilter.credential_filtered_uri(uri)
|
||||
|
||||
Bundler.ui.debug "HTTP GET #{filtered_uri}"
|
||||
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
|
||||
req.basic_auth(user, password)
|
||||
end
|
||||
connection.request(uri, req)
|
||||
rescue OpenSSL::SSL::SSLError
|
||||
raise CertificateFailureError.new(uri)
|
||||
rescue *HTTP_ERRORS => e
|
||||
Bundler.ui.trace e
|
||||
if e.is_a?(SocketError) || e.message.to_s.include?("host down:")
|
||||
raise NetworkDownError, "Could not reach host #{uri.host}. Check your network " \
|
||||
"connection and try again."
|
||||
else
|
||||
raise HTTPError, "Network error while fetching #{filtered_uri}" \
|
||||
" (#{e})"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def validate_uri_scheme!(uri)
|
||||
return if /\Ahttps?\z/.match?(uri.scheme)
|
||||
raise InvalidOption,
|
||||
"The request uri `#{uri}` has an invalid scheme (`#{uri.scheme}`). " \
|
||||
"Did you mean `http` or `https`?"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "base"
|
||||
|
||||
module Bundler
|
||||
class Fetcher
|
||||
class Index < Base
|
||||
def specs(_gem_names)
|
||||
Bundler.rubygems.fetch_all_remote_specs(remote, gem_remote_fetcher)
|
||||
rescue Gem::RemoteFetcher::FetchError => e
|
||||
case e.message
|
||||
when /certificate verify failed/
|
||||
raise CertificateFailureError.new(display_uri)
|
||||
when /401/
|
||||
raise BadAuthenticationError, remote_uri if remote_uri.userinfo
|
||||
raise AuthenticationRequiredError, remote_uri
|
||||
when /403/
|
||||
raise AuthenticationForbiddenError, remote_uri
|
||||
else
|
||||
raise HTTPError, "Could not fetch specs from #{display_uri} due to underlying error <#{e.message}>"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
module ForcePlatform
|
||||
private
|
||||
|
||||
# The `:force_ruby_platform` value used by dependencies for resolution, and
|
||||
# by locked specifications for materialization is `false` by default, except
|
||||
# for TruffleRuby. TruffleRuby generally needs to force the RUBY platform
|
||||
# variant unless the name is explicitly allowlisted.
|
||||
|
||||
def default_force_ruby_platform
|
||||
return false unless RUBY_ENGINE == "truffleruby"
|
||||
|
||||
!Gem::Platform::REUSE_AS_BINARY_ON_TRUFFLERUBY.include?(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,126 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "vendored_thor"
|
||||
|
||||
module Bundler
|
||||
module FriendlyErrors
|
||||
module_function
|
||||
|
||||
def enable!
|
||||
@disabled = false
|
||||
end
|
||||
|
||||
def disabled?
|
||||
@disabled
|
||||
end
|
||||
|
||||
def disable!
|
||||
@disabled = true
|
||||
end
|
||||
|
||||
def log_error(error)
|
||||
case error
|
||||
when YamlSyntaxError
|
||||
Bundler.ui.error error.message
|
||||
Bundler.ui.trace error.orig_exception
|
||||
when Dsl::DSLError, GemspecError
|
||||
Bundler.ui.error error.message
|
||||
when GemRequireError
|
||||
Bundler.ui.error error.message
|
||||
Bundler.ui.trace error.orig_exception
|
||||
when BundlerError
|
||||
if Bundler.ui.debug?
|
||||
Bundler.ui.trace error
|
||||
else
|
||||
Bundler.ui.error error.message, wrap: true
|
||||
end
|
||||
when Thor::Error
|
||||
Bundler.ui.error error.message
|
||||
when Interrupt
|
||||
Bundler.ui.error "\nQuitting..."
|
||||
Bundler.ui.trace error
|
||||
when Gem::InvalidSpecificationException
|
||||
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. " \
|
||||
"You can decrease the amount of memory Bundler needs by removing gems from your Gemfile, " \
|
||||
"especially large gems. (Gems can be as large as hundreds of megabytes, and Bundler has to read those files!). " \
|
||||
"Alternatively, you can increase the amount of memory the JVM is able to use by running Bundler with jruby -J-Xmx1024m -S bundle (JRuby defaults to 500MB)."
|
||||
else request_issue_report_for(error)
|
||||
end
|
||||
end
|
||||
|
||||
def exit_status(error)
|
||||
case error
|
||||
when BundlerError then error.status_code
|
||||
when Thor::Error then 15
|
||||
when SystemExit then error.status
|
||||
else 1
|
||||
end
|
||||
end
|
||||
|
||||
def request_issue_report_for(e)
|
||||
Bundler.ui.error <<~EOS, nil, nil
|
||||
--- ERROR REPORT TEMPLATE -------------------------------------------------------
|
||||
|
||||
```
|
||||
#{exception_message(e)}
|
||||
```
|
||||
|
||||
#{Bundler::Env.report}
|
||||
--- TEMPLATE END ----------------------------------------------------------------
|
||||
|
||||
EOS
|
||||
|
||||
Bundler.ui.error "Unfortunately, an unexpected error occurred, and Bundler cannot continue."
|
||||
|
||||
Bundler.ui.error <<~EOS, nil, :yellow
|
||||
|
||||
First, try this link to see if there are any existing issue reports for this error:
|
||||
#{issues_url(e)}
|
||||
|
||||
If there aren't any reports for this error yet, please fill in the new issue form located at #{new_issue_url}, and copy and paste the report template above in there.
|
||||
EOS
|
||||
end
|
||||
|
||||
def exception_message(error)
|
||||
message = serialized_exception_for(error)
|
||||
cause = error.cause
|
||||
return message unless cause
|
||||
|
||||
message + serialized_exception_for(cause)
|
||||
end
|
||||
|
||||
def serialized_exception_for(e)
|
||||
<<~EOS
|
||||
#{e.class}: #{e.message}
|
||||
#{e.backtrace&.join("\n ")&.chomp}
|
||||
EOS
|
||||
end
|
||||
|
||||
def issues_url(exception)
|
||||
message = exception.message.lines.first.tr(":", " ").chomp
|
||||
message = message.split("-").first if exception.is_a?(Errno)
|
||||
require "cgi"
|
||||
"https://github.com/rubygems/rubygems/search?q=" \
|
||||
"#{CGI.escape(message)}&type=Issues"
|
||||
end
|
||||
|
||||
def new_issue_url
|
||||
"https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md"
|
||||
end
|
||||
end
|
||||
|
||||
def self.with_friendly_errors
|
||||
FriendlyErrors.enable!
|
||||
yield
|
||||
rescue SignalException
|
||||
raise
|
||||
rescue Exception => e # rubocop:disable Lint/RescueException
|
||||
raise if FriendlyErrors.disabled?
|
||||
|
||||
FriendlyErrors.log_error(e)
|
||||
exit FriendlyErrors.exit_status(e)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,237 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../bundler"
|
||||
require "shellwords"
|
||||
|
||||
module Bundler
|
||||
class GemHelper
|
||||
include Rake::DSL if defined? Rake::DSL
|
||||
|
||||
class << self
|
||||
# set when install'd.
|
||||
attr_accessor :instance
|
||||
|
||||
def install_tasks(opts = {})
|
||||
new(opts[:dir], opts[:name]).install
|
||||
end
|
||||
|
||||
def tag_prefix=(prefix)
|
||||
instance.tag_prefix = prefix
|
||||
end
|
||||
|
||||
def gemspec(&block)
|
||||
gemspec = instance.gemspec
|
||||
block&.call(gemspec)
|
||||
gemspec
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :spec_path, :base, :gemspec
|
||||
|
||||
attr_writer :tag_prefix
|
||||
|
||||
def initialize(base = nil, name = nil)
|
||||
@base = File.expand_path(base || SharedHelpers.pwd)
|
||||
gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Gem::Util.glob_files_in_dir("{,*}.gemspec", @base)
|
||||
raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
|
||||
@spec_path = gemspecs.first
|
||||
@gemspec = Bundler.load_gemspec(@spec_path)
|
||||
@tag_prefix = ""
|
||||
end
|
||||
|
||||
def install
|
||||
built_gem_path = nil
|
||||
|
||||
desc "Build #{name}-#{version}.gem into the pkg directory."
|
||||
task "build" do
|
||||
built_gem_path = build_gem
|
||||
end
|
||||
|
||||
desc "Generate SHA512 checksum if #{name}-#{version}.gem into the checksums directory."
|
||||
task "build:checksum" => "build" do
|
||||
build_checksum(built_gem_path)
|
||||
end
|
||||
|
||||
desc "Build and install #{name}-#{version}.gem into system gems."
|
||||
task "install" => "build" do
|
||||
install_gem(built_gem_path)
|
||||
end
|
||||
|
||||
desc "Build and install #{name}-#{version}.gem into system gems without network access."
|
||||
task "install:local" => "build" do
|
||||
install_gem(built_gem_path, :local)
|
||||
end
|
||||
|
||||
desc "Create tag #{version_tag} and build and push #{name}-#{version}.gem to #{gem_push_host}\n" \
|
||||
"To prevent publishing in RubyGems use `gem_push=no rake release`"
|
||||
task "release", [:remote] => ["build", "release:guard_clean",
|
||||
"release:source_control_push", "release:rubygem_push"] do
|
||||
end
|
||||
|
||||
task "release:guard_clean" do
|
||||
guard_clean
|
||||
end
|
||||
|
||||
task "release:source_control_push", [:remote] do |_, args|
|
||||
tag_version { git_push(args[:remote]) } unless already_tagged?
|
||||
end
|
||||
|
||||
task "release:rubygem_push" => "build" do
|
||||
rubygem_push(built_gem_path) if gem_push?
|
||||
end
|
||||
|
||||
GemHelper.instance = self
|
||||
end
|
||||
|
||||
def build_gem
|
||||
file_name = nil
|
||||
sh([*gem_command, "build", "-V", spec_path]) do
|
||||
file_name = File.basename(built_gem_path)
|
||||
SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) }
|
||||
FileUtils.mv(built_gem_path, "pkg")
|
||||
Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}."
|
||||
end
|
||||
File.join(base, "pkg", file_name)
|
||||
end
|
||||
|
||||
def install_gem(built_gem_path = nil, local = false)
|
||||
built_gem_path ||= build_gem
|
||||
cmd = [*gem_command, "install", built_gem_path.to_s]
|
||||
cmd << "--local" if local
|
||||
sh(cmd)
|
||||
Bundler.ui.confirm "#{name} (#{version}) installed."
|
||||
end
|
||||
|
||||
def build_checksum(built_gem_path = nil)
|
||||
built_gem_path ||= build_gem
|
||||
SharedHelpers.filesystem_access(File.join(base, "checksums")) {|p| FileUtils.mkdir_p(p) }
|
||||
file_name = "#{File.basename(built_gem_path)}.sha512"
|
||||
require "digest/sha2"
|
||||
checksum = ::Digest::SHA512.file(built_gem_path).hexdigest
|
||||
target = File.join(base, "checksums", file_name)
|
||||
File.write(target, checksum + "\n")
|
||||
Bundler.ui.confirm "#{name} #{version} checksum written to checksums/#{file_name}."
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def rubygem_push(path)
|
||||
cmd = [*gem_command, "push", path]
|
||||
cmd << "--key" << gem_key if gem_key
|
||||
cmd << "--host" << allowed_push_host if allowed_push_host
|
||||
sh_with_input(cmd)
|
||||
Bundler.ui.confirm "Pushed #{name} #{version} to #{gem_push_host}"
|
||||
end
|
||||
|
||||
def built_gem_path
|
||||
Gem::Util.glob_files_in_dir("#{name}-*.gem", base).sort_by {|f| File.mtime(f) }.last
|
||||
end
|
||||
|
||||
def git_push(remote = nil)
|
||||
remote ||= default_remote
|
||||
sh("git push #{remote} refs/heads/#{current_branch}".shellsplit)
|
||||
sh("git push #{remote} refs/tags/#{version_tag}".shellsplit)
|
||||
Bundler.ui.confirm "Pushed git commits and release tag."
|
||||
end
|
||||
|
||||
def default_remote
|
||||
remote_for_branch, status = sh_with_status(%W[git config --get branch.#{current_branch}.remote])
|
||||
return "origin" unless status.success?
|
||||
|
||||
remote_for_branch.strip
|
||||
end
|
||||
|
||||
def current_branch
|
||||
# We can replace this with `git branch --show-current` once we drop support for git < 2.22.0
|
||||
sh(%w[git rev-parse --abbrev-ref HEAD]).gsub(%r{\Aheads/}, "").strip
|
||||
end
|
||||
|
||||
def allowed_push_host
|
||||
@gemspec.metadata["allowed_push_host"] if @gemspec.respond_to?(:metadata)
|
||||
end
|
||||
|
||||
def gem_push_host
|
||||
env_rubygems_host = ENV["RUBYGEMS_HOST"]
|
||||
env_rubygems_host = nil if env_rubygems_host&.empty?
|
||||
|
||||
allowed_push_host || env_rubygems_host || "rubygems.org"
|
||||
end
|
||||
|
||||
def already_tagged?
|
||||
return false unless sh(%w[git tag]).split(/\n/).include?(version_tag)
|
||||
Bundler.ui.confirm "Tag #{version_tag} has already been created."
|
||||
true
|
||||
end
|
||||
|
||||
def guard_clean
|
||||
clean? && committed? || raise("There are files that need to be committed first.")
|
||||
end
|
||||
|
||||
def clean?
|
||||
sh_with_status(%w[git diff --exit-code])[1].success?
|
||||
end
|
||||
|
||||
def committed?
|
||||
sh_with_status(%w[git diff-index --quiet --cached HEAD])[1].success?
|
||||
end
|
||||
|
||||
def tag_version
|
||||
sh %W[git tag -m Version\ #{version} #{version_tag}]
|
||||
Bundler.ui.confirm "Tagged #{version_tag}."
|
||||
yield if block_given?
|
||||
rescue RuntimeError
|
||||
Bundler.ui.error "Untagging #{version_tag} due to error."
|
||||
sh_with_status %W[git tag -d #{version_tag}]
|
||||
raise
|
||||
end
|
||||
|
||||
def version
|
||||
gemspec.version
|
||||
end
|
||||
|
||||
def version_tag
|
||||
"#{@tag_prefix}v#{version}"
|
||||
end
|
||||
|
||||
def name
|
||||
gemspec.name
|
||||
end
|
||||
|
||||
def sh_with_input(cmd)
|
||||
Bundler.ui.debug(cmd)
|
||||
SharedHelpers.chdir(base) do
|
||||
abort unless Kernel.system(*cmd)
|
||||
end
|
||||
end
|
||||
|
||||
def sh(cmd, &block)
|
||||
out, status = sh_with_status(cmd, &block)
|
||||
unless status.success?
|
||||
raise("Running `#{cmd.shelljoin}` failed with the following output:\n\n#{out}\n")
|
||||
end
|
||||
out
|
||||
end
|
||||
|
||||
def sh_with_status(cmd, &block)
|
||||
Bundler.ui.debug(cmd)
|
||||
SharedHelpers.chdir(base) do
|
||||
outbuf = IO.popen(cmd, err: [:child, :out], &:read)
|
||||
status = $?
|
||||
block&.call(outbuf) if status.success?
|
||||
[outbuf, status]
|
||||
end
|
||||
end
|
||||
|
||||
def gem_key
|
||||
Bundler.settings["gem.push_key"].to_s.downcase if Bundler.settings["gem.push_key"]
|
||||
end
|
||||
|
||||
def gem_push?
|
||||
!%w[n no nil false off 0].include?(ENV["gem_push"].to_s.downcase)
|
||||
end
|
||||
|
||||
def gem_command
|
||||
ENV["GEM_COMMAND"]&.shellsplit || ["gem"]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,127 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
module GemHelpers
|
||||
GENERIC_CACHE = { Gem::Platform::RUBY => Gem::Platform::RUBY } # rubocop:disable Style/MutableConstant
|
||||
GENERICS = [
|
||||
[Gem::Platform.new("java"), Gem::Platform.new("java")],
|
||||
[Gem::Platform.new("mswin32"), Gem::Platform.new("mswin32")],
|
||||
[Gem::Platform.new("mswin64"), Gem::Platform.new("mswin64")],
|
||||
[Gem::Platform.new("universal-mingw32"), Gem::Platform.new("universal-mingw32")],
|
||||
[Gem::Platform.new("x64-mingw32"), Gem::Platform.new("x64-mingw32")],
|
||||
[Gem::Platform.new("x86_64-mingw32"), Gem::Platform.new("x64-mingw32")],
|
||||
[Gem::Platform.new("x64-mingw-ucrt"), Gem::Platform.new("x64-mingw-ucrt")],
|
||||
[Gem::Platform.new("mingw32"), Gem::Platform.new("x86-mingw32")],
|
||||
].freeze
|
||||
|
||||
def generic(p)
|
||||
GENERIC_CACHE[p] ||= begin
|
||||
_, found = GENERICS.find do |match, _generic|
|
||||
p.os == match.os && (!match.cpu || p.cpu == match.cpu)
|
||||
end
|
||||
found || Gem::Platform::RUBY
|
||||
end
|
||||
end
|
||||
module_function :generic
|
||||
|
||||
def generic_local_platform
|
||||
generic(local_platform)
|
||||
end
|
||||
module_function :generic_local_platform
|
||||
|
||||
def local_platform
|
||||
Bundler.local_platform
|
||||
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)
|
||||
|
||||
PlatformMatch.specificity_score(spec_platform, user_platform)
|
||||
end
|
||||
module_function :platform_specificity_match
|
||||
|
||||
def select_best_platform_match(specs, platform)
|
||||
matching = specs.select {|spec| spec.match_platform(platform) }
|
||||
|
||||
sort_best_platform_match(matching, platform)
|
||||
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?
|
||||
|
||||
sorted_matching = matching.sort_by {|spec| platform_specificity_match(spec.platform, platform) }
|
||||
exemplary_spec = sorted_matching.first
|
||||
|
||||
sorted_matching.take_while {|spec| same_specificity(platform, spec, exemplary_spec) && same_deps(spec, exemplary_spec) }
|
||||
end
|
||||
module_function :sort_best_platform_match
|
||||
|
||||
class PlatformMatch
|
||||
def self.specificity_score(spec_platform, user_platform)
|
||||
return -1 if spec_platform == user_platform
|
||||
return 1_000_000 if spec_platform.nil? || spec_platform == Gem::Platform::RUBY || user_platform == Gem::Platform::RUBY
|
||||
|
||||
os_match(spec_platform, user_platform) +
|
||||
cpu_match(spec_platform, user_platform) * 10 +
|
||||
platform_version_match(spec_platform, user_platform) * 100
|
||||
end
|
||||
|
||||
def self.os_match(spec_platform, user_platform)
|
||||
if spec_platform.os == user_platform.os
|
||||
0
|
||||
else
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
def self.cpu_match(spec_platform, user_platform)
|
||||
if spec_platform.cpu == user_platform.cpu
|
||||
0
|
||||
elsif spec_platform.cpu == "arm" && user_platform.cpu.to_s.start_with?("arm")
|
||||
0
|
||||
elsif spec_platform.cpu.nil? || spec_platform.cpu == "universal"
|
||||
1
|
||||
else
|
||||
2
|
||||
end
|
||||
end
|
||||
|
||||
def self.platform_version_match(spec_platform, user_platform)
|
||||
if spec_platform.version == user_platform.version
|
||||
0
|
||||
elsif spec_platform.version.nil?
|
||||
1
|
||||
else
|
||||
2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def same_specificity(platform, spec, exemplary_spec)
|
||||
platform_specificity_match(spec.platform, platform) == platform_specificity_match(exemplary_spec.platform, platform)
|
||||
end
|
||||
module_function :same_specificity
|
||||
|
||||
def same_deps(spec, exemplary_spec)
|
||||
same_runtime_deps = spec.dependencies.sort == exemplary_spec.dependencies.sort
|
||||
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
|
||||
module_function :same_deps
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rake/clean"
|
||||
CLOBBER.include "pkg"
|
||||
|
||||
require_relative "gem_helper"
|
||||
Bundler::GemHelper.install_tasks
|
||||
@@ -0,0 +1,149 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
# This class contains all of the logic for determining the next version of a
|
||||
# Gem to update to based on the requested level (patch, minor, major).
|
||||
# Primarily designed to work with Resolver which will provide it the list of
|
||||
# available dependency versions as found in its index, before returning it to
|
||||
# to the resolution engine to select the best version.
|
||||
class GemVersionPromoter
|
||||
attr_reader :level
|
||||
attr_accessor :pre
|
||||
|
||||
# By default, strict is false, meaning every available version of a gem
|
||||
# is returned from sort_versions. The order gives preference to the
|
||||
# requested level (:patch, :minor, :major) but in complicated requirement
|
||||
# cases some gems will by necessity be promoted past the requested level,
|
||||
# or even reverted to older versions.
|
||||
#
|
||||
# If strict is set to true, the results from sort_versions will be
|
||||
# truncated, eliminating any version outside the current level scope.
|
||||
# This can lead to unexpected outcomes or even VersionConflict exceptions
|
||||
# that report a version of a gem not existing for versions that indeed do
|
||||
# existing in the referenced source.
|
||||
attr_accessor :strict
|
||||
|
||||
# Creates a GemVersionPromoter instance.
|
||||
#
|
||||
# @return [GemVersionPromoter]
|
||||
def initialize
|
||||
@level = :major
|
||||
@strict = false
|
||||
@pre = false
|
||||
end
|
||||
|
||||
# @param value [Symbol] One of three Symbols: :major, :minor or :patch.
|
||||
def level=(value)
|
||||
v = case value
|
||||
when String, Symbol
|
||||
value.to_sym
|
||||
end
|
||||
|
||||
raise ArgumentError, "Unexpected level #{v}. Must be :major, :minor or :patch" unless [:major, :minor, :patch].include?(v)
|
||||
@level = v
|
||||
end
|
||||
|
||||
# Given a Resolver::Package and an Array of Specifications of available
|
||||
# versions for a gem, this method will return the Array of Specifications
|
||||
# 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.
|
||||
def sort_versions(package, specs)
|
||||
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? || 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.
|
||||
def major?
|
||||
level == :major
|
||||
end
|
||||
|
||||
# @return [bool] Convenience method for testing value of level variable.
|
||||
def minor?
|
||||
level == :minor
|
||||
end
|
||||
|
||||
# @return [bool] Convenience method for testing value of pre variable.
|
||||
def pre?
|
||||
pre == true
|
||||
end
|
||||
|
||||
# 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
|
||||
|
||||
locked_version = package.locked_version
|
||||
return specs if locked_version.nil? || major?
|
||||
|
||||
specs.select do |spec|
|
||||
gsv = spec.version
|
||||
|
||||
must_match = minor? ? [0] : [0, 1]
|
||||
|
||||
all_match = must_match.all? {|idx| gsv.segments[idx] == locked_version.segments[idx] }
|
||||
all_match && gsv >= locked_version
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def either_version_older_than_locked?(a, b, locked_version)
|
||||
a.version < locked_version || b.version < locked_version
|
||||
end
|
||||
|
||||
def segments_do_not_match?(a, b, level)
|
||||
index = [:major, :minor].index(level)
|
||||
a.segments[index] != b.segments[index]
|
||||
end
|
||||
|
||||
# Specific version moves can't always reliably be done during sorting
|
||||
# as not all elements are compared against each other.
|
||||
def post_sort(result, unlock, locked_version)
|
||||
# default :major behavior in Bundler does not do this
|
||||
return result if major?
|
||||
if unlock || locked_version.nil?
|
||||
result
|
||||
else
|
||||
move_version_to_beginning(result, locked_version)
|
||||
end
|
||||
end
|
||||
|
||||
def move_version_to_beginning(result, version)
|
||||
move, keep = result.partition {|s| s.version.to_s == version.to_s }
|
||||
move.concat(keep)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,152 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "set"
|
||||
module Bundler
|
||||
class Graph
|
||||
GRAPH_NAME = :Gemfile
|
||||
|
||||
def initialize(env, output_file, show_version = false, show_requirements = false, output_format = "png", without = [])
|
||||
@env = env
|
||||
@output_file = output_file
|
||||
@show_version = show_version
|
||||
@show_requirements = show_requirements
|
||||
@output_format = output_format
|
||||
@without_groups = without.map(&:to_sym)
|
||||
|
||||
@groups = []
|
||||
@relations = Hash.new {|h, k| h[k] = Set.new }
|
||||
@node_options = {}
|
||||
@edge_options = {}
|
||||
|
||||
_populate_relations
|
||||
end
|
||||
|
||||
attr_reader :groups, :relations, :node_options, :edge_options, :output_file, :output_format
|
||||
|
||||
def viz
|
||||
GraphVizClient.new(self).run
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def _populate_relations
|
||||
parent_dependencies = _groups.values.to_set.flatten
|
||||
loop do
|
||||
break if parent_dependencies.empty?
|
||||
|
||||
tmp = Set.new
|
||||
parent_dependencies.each do |dependency|
|
||||
child_dependencies = spec_for_dependency(dependency).runtime_dependencies.to_set
|
||||
@relations[dependency.name] += child_dependencies.map(&:name).to_set
|
||||
tmp += child_dependencies
|
||||
|
||||
@node_options[dependency.name] = _make_label(dependency, :node)
|
||||
child_dependencies.each do |c_dependency|
|
||||
@edge_options["#{dependency.name}_#{c_dependency.name}"] = _make_label(c_dependency, :edge)
|
||||
end
|
||||
end
|
||||
parent_dependencies = tmp
|
||||
end
|
||||
end
|
||||
|
||||
def _groups
|
||||
relations = Hash.new {|h, k| h[k] = Set.new }
|
||||
@env.current_dependencies.each do |dependency|
|
||||
dependency.groups.each do |group|
|
||||
next if @without_groups.include?(group)
|
||||
|
||||
relations[group.to_s].add(dependency)
|
||||
@relations[group.to_s].add(dependency.name)
|
||||
|
||||
@node_options[group.to_s] ||= _make_label(group, :node)
|
||||
@edge_options["#{group}_#{dependency.name}"] = _make_label(dependency, :edge)
|
||||
end
|
||||
end
|
||||
@groups = relations.keys
|
||||
relations
|
||||
end
|
||||
|
||||
def _make_label(symbol_or_string_or_dependency, element_type)
|
||||
case element_type.to_sym
|
||||
when :node
|
||||
if symbol_or_string_or_dependency.is_a?(Gem::Dependency)
|
||||
label = symbol_or_string_or_dependency.name.dup
|
||||
label << "\n#{spec_for_dependency(symbol_or_string_or_dependency).version}" if @show_version
|
||||
else
|
||||
label = symbol_or_string_or_dependency.to_s
|
||||
end
|
||||
when :edge
|
||||
label = nil
|
||||
if symbol_or_string_or_dependency.respond_to?(:requirements_list) && @show_requirements
|
||||
tmp = symbol_or_string_or_dependency.requirements_list.join(", ")
|
||||
label = tmp if tmp != ">= 0"
|
||||
end
|
||||
else
|
||||
raise ArgumentError, "2nd argument is invalid"
|
||||
end
|
||||
label.nil? ? {} : { label: label }
|
||||
end
|
||||
|
||||
def spec_for_dependency(dependency)
|
||||
@env.requested_specs.find {|s| s.name == dependency.name }
|
||||
end
|
||||
|
||||
class GraphVizClient
|
||||
def initialize(graph_instance)
|
||||
@graph_name = graph_instance.class::GRAPH_NAME
|
||||
@groups = graph_instance.groups
|
||||
@relations = graph_instance.relations
|
||||
@node_options = graph_instance.node_options
|
||||
@edge_options = graph_instance.edge_options
|
||||
@output_file = graph_instance.output_file
|
||||
@output_format = graph_instance.output_format
|
||||
end
|
||||
|
||||
def 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
|
||||
end
|
||||
end
|
||||
|
||||
def run
|
||||
@groups.each do |group|
|
||||
g.add_nodes(
|
||||
group, {
|
||||
style: "filled",
|
||||
fillcolor: "#B9B9D5",
|
||||
shape: "box3d",
|
||||
fontsize: 16,
|
||||
}.merge(@node_options[group])
|
||||
)
|
||||
end
|
||||
|
||||
@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}"]))
|
||||
else
|
||||
g.add_nodes(child, @node_options[child])
|
||||
g.add_edges(parent, child, @edge_options["#{parent}_#{child}"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @output_format.to_s == "debug"
|
||||
$stdout.puts g.output none: String
|
||||
Bundler.ui.info "debugging bundle viz..."
|
||||
else
|
||||
begin
|
||||
g.output @output_format.to_sym => "#{@output_file}.#{@output_format}"
|
||||
Bundler.ui.info "#{@output_file}.#{@output_format}"
|
||||
rescue ArgumentError => e
|
||||
warn "Unsupported output format. See Ruby-Graphviz/lib/graphviz/constants.rb"
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,205 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class Index
|
||||
include Enumerable
|
||||
|
||||
def self.build
|
||||
i = new
|
||||
yield i
|
||||
i
|
||||
end
|
||||
|
||||
attr_reader :specs, :duplicates, :sources
|
||||
protected :specs, :duplicates
|
||||
|
||||
RUBY = "ruby"
|
||||
NULL = "\0"
|
||||
|
||||
def initialize
|
||||
@sources = []
|
||||
@cache = {}
|
||||
@specs = {}
|
||||
@duplicates = {}
|
||||
end
|
||||
|
||||
def initialize_copy(o)
|
||||
@sources = o.sources.dup
|
||||
@cache = {}
|
||||
@specs = {}
|
||||
@duplicates = {}
|
||||
|
||||
o.specs.each do |name, hash|
|
||||
@specs[name] = hash.dup
|
||||
end
|
||||
o.duplicates.each do |name, array|
|
||||
@duplicates[name] = array.dup
|
||||
end
|
||||
end
|
||||
|
||||
def inspect
|
||||
"#<#{self.class}:0x#{object_id} sources=#{sources.map(&:inspect)} specs.size=#{specs.size}>"
|
||||
end
|
||||
|
||||
def empty?
|
||||
each { return false }
|
||||
true
|
||||
end
|
||||
|
||||
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
|
||||
# about, returning all of the results.
|
||||
def search(query)
|
||||
results = local_search(query)
|
||||
return results unless @sources.any?
|
||||
|
||||
@sources.each do |source|
|
||||
results = safe_concat(results, source.search(query))
|
||||
end
|
||||
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)
|
||||
when String then specs_by_name(query)
|
||||
when Array then specs_by_name_and_version(*query)
|
||||
else
|
||||
raise "You can't search for a #{query.inspect}."
|
||||
end
|
||||
end
|
||||
|
||||
def add(spec)
|
||||
(@specs[spec.name] ||= {}).store(spec.full_name, spec)
|
||||
end
|
||||
alias_method :<<, :add
|
||||
|
||||
def each(&blk)
|
||||
return enum_for(:each) unless blk
|
||||
specs.values.each do |spec_sets|
|
||||
spec_sets.values.each(&blk)
|
||||
end
|
||||
sources.each {|s| s.each(&blk) }
|
||||
self
|
||||
end
|
||||
|
||||
def spec_names
|
||||
names = specs.keys + sources.map(&:spec_names)
|
||||
names.uniq!
|
||||
names
|
||||
end
|
||||
|
||||
def unmet_dependency_names
|
||||
dependency_names.select do |name|
|
||||
search(name).empty?
|
||||
end
|
||||
end
|
||||
|
||||
def dependency_names
|
||||
names = []
|
||||
each do |spec|
|
||||
spec.dependencies.each do |dep|
|
||||
next if dep.type == :development
|
||||
names << dep.name
|
||||
end
|
||||
end
|
||||
names.uniq
|
||||
end
|
||||
|
||||
# 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 |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
|
||||
add spec
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def size
|
||||
@sources.inject(@specs.size) do |size, source|
|
||||
size += source.size
|
||||
end
|
||||
end
|
||||
|
||||
# Whether all the specs in self are in other
|
||||
def subset?(other)
|
||||
all? do |spec|
|
||||
other_spec = other[spec].first
|
||||
other_spec && dependencies_eql?(spec, other_spec) && spec.source == other_spec.source
|
||||
end
|
||||
end
|
||||
|
||||
def dependencies_eql?(spec, other_spec)
|
||||
deps = spec.dependencies.select {|d| d.type != :development }
|
||||
other_deps = other_spec.dependencies.select {|d| d.type != :development }
|
||||
deps.sort == other_deps.sort
|
||||
end
|
||||
|
||||
def add_source(index)
|
||||
raise ArgumentError, "Source must be an index, not #{index.class}" unless index.is_a?(Index)
|
||||
@sources << index
|
||||
@sources.uniq! # need to use uniq! here instead of checking for the item before adding
|
||||
end
|
||||
|
||||
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)
|
||||
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 || EMPTY_SEARCH
|
||||
end
|
||||
|
||||
EMPTY_SEARCH = [].freeze
|
||||
|
||||
def search_by_spec(spec)
|
||||
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
|
||||
@@ -0,0 +1,287 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class Injector
|
||||
INJECTED_GEMS = "injected gems"
|
||||
|
||||
def self.inject(new_deps, options = {})
|
||||
injector = new(new_deps, options)
|
||||
injector.inject(Bundler.default_gemfile, Bundler.default_lockfile)
|
||||
end
|
||||
|
||||
def self.remove(gems, options = {})
|
||||
injector = new(gems, options)
|
||||
injector.remove(Bundler.default_gemfile, Bundler.default_lockfile)
|
||||
end
|
||||
|
||||
def initialize(deps, options = {})
|
||||
@deps = deps
|
||||
@options = options
|
||||
end
|
||||
|
||||
# @param [Pathname] gemfile_path The Gemfile in which to inject the new dependency.
|
||||
# @param [Pathname] lockfile_path The lockfile in which to inject the new dependency.
|
||||
# @return [Array]
|
||||
def inject(gemfile_path, lockfile_path)
|
||||
if Bundler.frozen_bundle?
|
||||
# ensure the lock and Gemfile are synced
|
||||
Bundler.definition.ensure_equivalent_gemfile_and_lockfile(true)
|
||||
end
|
||||
|
||||
# temporarily unfreeze
|
||||
Bundler.settings.temporary(deployment: false, frozen: false) do
|
||||
# evaluate the Gemfile we have now
|
||||
builder = Dsl.new
|
||||
builder.eval_gemfile(gemfile_path)
|
||||
|
||||
# don't inject any gems that are already in the Gemfile
|
||||
@deps -= builder.dependencies
|
||||
|
||||
# add new deps to the end of the in-memory Gemfile
|
||||
# Set conservative versioning to false because
|
||||
# we want to let the resolver resolve the version first
|
||||
builder.eval_gemfile(INJECTED_GEMS, build_gem_lines(false)) if @deps.any?
|
||||
|
||||
# resolve to see if the new deps broke anything
|
||||
@definition = builder.to_definition(lockfile_path, {})
|
||||
@definition.resolve_remotely!
|
||||
|
||||
# since nothing broke, we can add those gems to the gemfile
|
||||
append_to(gemfile_path, build_gem_lines(@options[:conservative_versioning])) if @deps.any?
|
||||
|
||||
# since we resolved successfully, write out the lockfile
|
||||
@definition.lock
|
||||
|
||||
# invalidate the cached Bundler.definition
|
||||
Bundler.reset_paths!
|
||||
|
||||
# return an array of the deps that we added
|
||||
@deps
|
||||
end
|
||||
end
|
||||
|
||||
# @param [Pathname] gemfile_path The Gemfile from which to remove dependencies.
|
||||
# @param [Pathname] lockfile_path The lockfile from which to remove dependencies.
|
||||
# @return [Array]
|
||||
def remove(gemfile_path, lockfile_path)
|
||||
# remove gems from each gemfiles we have
|
||||
Bundler.definition.gemfiles.each do |path|
|
||||
deps = remove_deps(path)
|
||||
|
||||
show_warning("No gems were removed from the gemfile.") if deps.empty?
|
||||
|
||||
deps.each {|dep| Bundler.ui.confirm "#{SharedHelpers.pretty_dependency(dep)} was removed." }
|
||||
end
|
||||
|
||||
# Invalidate the cached Bundler.definition.
|
||||
# This prevents e.g. `bundle remove ...` from using outdated information.
|
||||
Bundler.reset_paths!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def conservative_version(spec)
|
||||
version = spec.version
|
||||
return ">= 0" if version.nil?
|
||||
segments = version.segments
|
||||
seg_end_index = version >= Gem::Version.new("1.0") ? 1 : 2
|
||||
|
||||
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
|
||||
|
||||
def version_prefix
|
||||
if @options[:strict]
|
||||
"= "
|
||||
elsif @options[:optimistic]
|
||||
">= "
|
||||
else
|
||||
"~> "
|
||||
end
|
||||
end
|
||||
|
||||
def build_gem_lines(conservative_versioning)
|
||||
@deps.map do |d|
|
||||
name = d.name.dump
|
||||
|
||||
requirement = if conservative_versioning
|
||||
", \"#{conservative_version(@definition.specs[d.name][0])}\""
|
||||
else
|
||||
", #{d.requirement.as_list.map(&:dump).join(", ")}"
|
||||
end
|
||||
|
||||
if d.groups != Array(:default)
|
||||
group = d.groups.size == 1 ? ", :group => #{d.groups.first.inspect}" : ", :groups => #{d.groups.inspect}"
|
||||
end
|
||||
|
||||
source = ", :source => \"#{d.source}\"" unless d.source.nil?
|
||||
path = ", :path => \"#{d.path}\"" unless d.path.nil?
|
||||
git = ", :git => \"#{d.git}\"" unless d.git.nil?
|
||||
github = ", :github => \"#{d.github}\"" unless d.github.nil?
|
||||
branch = ", :branch => \"#{d.branch}\"" unless d.branch.nil?
|
||||
ref = ", :ref => \"#{d.ref}\"" unless d.ref.nil?
|
||||
require_path = ", :require => #{convert_autorequire(d.autorequire)}" unless d.autorequire.nil?
|
||||
|
||||
%(gem #{name}#{requirement}#{group}#{source}#{path}#{git}#{github}#{branch}#{ref}#{require_path})
|
||||
end.join("\n")
|
||||
end
|
||||
|
||||
def append_to(gemfile_path, new_gem_lines)
|
||||
gemfile_path.open("a") do |f|
|
||||
f.puts
|
||||
f.puts new_gem_lines
|
||||
end
|
||||
end
|
||||
|
||||
# evaluates a gemfile to remove the specified gem
|
||||
# from it.
|
||||
def remove_deps(gemfile_path)
|
||||
initial_gemfile = File.readlines(gemfile_path)
|
||||
|
||||
Bundler.ui.info "Removing gems from #{gemfile_path}"
|
||||
|
||||
# evaluate the Gemfile we have
|
||||
builder = Dsl.new
|
||||
builder.eval_gemfile(gemfile_path)
|
||||
|
||||
removed_deps = remove_gems_from_dependencies(builder, @deps, gemfile_path)
|
||||
|
||||
# abort the operation if no gems were removed
|
||||
# no need to operate on gemfile further
|
||||
return [] if removed_deps.empty?
|
||||
|
||||
cleaned_gemfile = remove_gems_from_gemfile(@deps, gemfile_path)
|
||||
|
||||
SharedHelpers.write_to_gemfile(gemfile_path, cleaned_gemfile)
|
||||
|
||||
# check for errors
|
||||
# including extra gems being removed
|
||||
# or some gems not being removed
|
||||
# and return the actual removed deps
|
||||
cross_check_for_errors(gemfile_path, builder.dependencies, removed_deps, initial_gemfile)
|
||||
end
|
||||
|
||||
# @param [Dsl] builder Dsl object of current Gemfile.
|
||||
# @param [Array] gems Array of names of gems to be removed.
|
||||
# @param [Pathname] gemfile_path Path of the Gemfile.
|
||||
# @return [Array] Array of removed dependencies.
|
||||
def remove_gems_from_dependencies(builder, gems, gemfile_path)
|
||||
removed_deps = []
|
||||
|
||||
gems.each do |gem_name|
|
||||
deleted_dep = builder.dependencies.find {|d| d.name == gem_name }
|
||||
|
||||
if deleted_dep.nil?
|
||||
raise GemfileError, "`#{gem_name}` is not specified in #{gemfile_path} so it could not be removed."
|
||||
end
|
||||
|
||||
builder.dependencies.delete(deleted_dep)
|
||||
|
||||
removed_deps << deleted_dep
|
||||
end
|
||||
|
||||
removed_deps
|
||||
end
|
||||
|
||||
# @param [Array] gems Array of names of gems to be removed.
|
||||
# @param [Pathname] gemfile_path The Gemfile from which to remove dependencies.
|
||||
def remove_gems_from_gemfile(gems, gemfile_path)
|
||||
patterns = /gem\s+(['"])#{Regexp.union(gems)}\1|gem\s*\((['"])#{Regexp.union(gems)}\2\)/
|
||||
new_gemfile = []
|
||||
multiline_removal = false
|
||||
File.readlines(gemfile_path).each do |line|
|
||||
match_data = line.match(patterns)
|
||||
if match_data && is_not_within_comment?(line, match_data)
|
||||
multiline_removal = line.rstrip.end_with?(",")
|
||||
# skip lines which match the regex
|
||||
next
|
||||
end
|
||||
|
||||
# skip followup lines until line does not end with ','
|
||||
new_gemfile << line unless multiline_removal
|
||||
multiline_removal = line.rstrip.end_with?(",") if multiline_removal
|
||||
end
|
||||
|
||||
# remove line \n and append them with other strings
|
||||
new_gemfile.each_with_index do |_line, index|
|
||||
if new_gemfile[index + 1] == "\n"
|
||||
new_gemfile[index] += new_gemfile[index + 1]
|
||||
new_gemfile.delete_at(index + 1)
|
||||
end
|
||||
end
|
||||
|
||||
%w[group source env install_if].each {|block| remove_nested_blocks(new_gemfile, block) }
|
||||
|
||||
new_gemfile.join.chomp
|
||||
end
|
||||
|
||||
# @param [String] line Individual line of gemfile content.
|
||||
# @param [MatchData] match_data Data about Regex match.
|
||||
def is_not_within_comment?(line, match_data)
|
||||
match_start_index = match_data.offset(0).first
|
||||
!line[0..match_start_index].include?("#")
|
||||
end
|
||||
|
||||
# @param [Array] gemfile Array of gemfile contents.
|
||||
# @param [String] block_name Name of block name to look for.
|
||||
def remove_nested_blocks(gemfile, block_name)
|
||||
nested_blocks = 0
|
||||
|
||||
# count number of nested blocks
|
||||
gemfile.each_with_index {|line, index| nested_blocks += 1 if !gemfile[index + 1].nil? && gemfile[index + 1].include?(block_name) && line.include?(block_name) }
|
||||
|
||||
while nested_blocks >= 0
|
||||
nested_blocks -= 1
|
||||
|
||||
gemfile.each_with_index do |line, index|
|
||||
next unless !line.nil? && line.strip.start_with?(block_name)
|
||||
if /^\s*end\s*$/.match?(gemfile[index + 1])
|
||||
gemfile[index] = nil
|
||||
gemfile[index + 1] = nil
|
||||
end
|
||||
end
|
||||
|
||||
gemfile.compact!
|
||||
end
|
||||
end
|
||||
|
||||
# @param [Pathname] gemfile_path The Gemfile from which to remove dependencies.
|
||||
# @param [Array] original_deps Array of original dependencies.
|
||||
# @param [Array] removed_deps Array of removed dependencies.
|
||||
# @param [Array] initial_gemfile Contents of original Gemfile before any operation.
|
||||
def cross_check_for_errors(gemfile_path, original_deps, removed_deps, initial_gemfile)
|
||||
# evaluate the new gemfile to look for any failure cases
|
||||
builder = Dsl.new
|
||||
builder.eval_gemfile(gemfile_path)
|
||||
|
||||
# record gems which were removed but not requested
|
||||
extra_removed_gems = original_deps - builder.dependencies
|
||||
|
||||
# if some extra gems were removed then raise error
|
||||
# and revert Gemfile to original
|
||||
unless extra_removed_gems.empty?
|
||||
SharedHelpers.write_to_gemfile(gemfile_path, initial_gemfile.join)
|
||||
|
||||
raise InvalidOption, "Gems could not be removed. #{extra_removed_gems.join(", ")} would also have been removed. Bundler cannot continue."
|
||||
end
|
||||
|
||||
# record gems which could not be removed due to some reasons
|
||||
errored_deps = builder.dependencies.select {|d| d.gemfile == gemfile_path } & removed_deps.select {|d| d.gemfile == gemfile_path }
|
||||
|
||||
show_warning "#{errored_deps.map(&:name).join(", ")} could not be removed." unless errored_deps.empty?
|
||||
|
||||
# return actual removed dependencies
|
||||
removed_deps - errored_deps
|
||||
end
|
||||
|
||||
def show_warning(message)
|
||||
Bundler.ui.info Bundler.ui.add_color(message, :yellow)
|
||||
end
|
||||
|
||||
def convert_autorequire(autorequire)
|
||||
autorequire = autorequire.first
|
||||
return autorequire if autorequire == "false"
|
||||
autorequire.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,73 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Allows for declaring a Gemfile inline in a ruby script, optionally installing
|
||||
# any gems that aren't already installed on the user's system.
|
||||
#
|
||||
# @note Every gem that is specified in this 'Gemfile' will be `require`d, as if
|
||||
# the user had manually called `Bundler.require`. To avoid a requested gem
|
||||
# being automatically required, add the `:require => false` option to the
|
||||
# `gem` dependency declaration.
|
||||
#
|
||||
# @param install [Boolean] whether gems that aren't already installed on the
|
||||
# user's system should be installed.
|
||||
# Defaults to `false`.
|
||||
#
|
||||
# @param gemfile [Proc] a block that is evaluated as a `Gemfile`.
|
||||
#
|
||||
# @example Using an inline Gemfile
|
||||
#
|
||||
# #!/usr/bin/env ruby
|
||||
#
|
||||
# require 'bundler/inline'
|
||||
#
|
||||
# gemfile do
|
||||
# source 'https://rubygems.org'
|
||||
# gem 'json', require: false
|
||||
# gem 'nap', require: 'rest'
|
||||
# gem 'cocoapods', '~> 0.34.1'
|
||||
# end
|
||||
#
|
||||
# puts Pod::VERSION # => "0.34.4"
|
||||
#
|
||||
def gemfile(install = false, options = {}, &gemfile)
|
||||
require_relative "../bundler"
|
||||
Bundler.reset!
|
||||
|
||||
opts = options.dup
|
||||
ui = opts.delete(:ui) { Bundler::UI::Shell.new }
|
||||
ui.level = "silent" if opts.delete(:quiet) || !install
|
||||
Bundler.ui = ui
|
||||
raise ArgumentError, "Unknown options: #{opts.keys.join(", ")}" unless opts.empty?
|
||||
|
||||
Bundler.with_unbundled_env do
|
||||
Bundler.instance_variable_set(:@bundle_path, Pathname.new(Gem.dir))
|
||||
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", "Gemfile"
|
||||
|
||||
Bundler::Plugin.gemfile_install(&gemfile) if Bundler.feature_flag.plugins?
|
||||
builder = Bundler::Dsl.new
|
||||
builder.instance_eval(&gemfile)
|
||||
builder.check_primary_source_safety
|
||||
|
||||
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)
|
||||
installer.post_install_messages.each do |name, message|
|
||||
Bundler.ui.info "Post-install message from #{name}:\n#{message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
runtime = Bundler::Runtime.new(nil, definition)
|
||||
runtime.setup.require
|
||||
end
|
||||
end
|
||||
|
||||
if ENV["BUNDLE_GEMFILE"].nil?
|
||||
ENV["BUNDLE_GEMFILE"] = ""
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,267 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "worker"
|
||||
require_relative "installer/parallel_installer"
|
||||
require_relative "installer/standalone"
|
||||
require_relative "installer/gem_installer"
|
||||
|
||||
module Bundler
|
||||
class Installer
|
||||
class << self
|
||||
attr_accessor :ambiguous_gems
|
||||
|
||||
Installer.ambiguous_gems = []
|
||||
end
|
||||
|
||||
attr_reader :post_install_messages, :definition
|
||||
|
||||
# Begins the installation process for Bundler.
|
||||
# For more information see the #run method on this class.
|
||||
def self.install(root, definition, options = {})
|
||||
installer = new(root, definition)
|
||||
Plugin.hook(Plugin::Events::GEM_BEFORE_INSTALL_ALL, definition.dependencies)
|
||||
installer.run(options)
|
||||
Plugin.hook(Plugin::Events::GEM_AFTER_INSTALL_ALL, definition.dependencies)
|
||||
installer
|
||||
end
|
||||
|
||||
def initialize(root, definition)
|
||||
@root = root
|
||||
@definition = definition
|
||||
@post_install_messages = {}
|
||||
end
|
||||
|
||||
# Runs the install procedures for a specific Gemfile.
|
||||
#
|
||||
# Firstly, this method will check to see if `Bundler.bundle_path` exists
|
||||
# and if not then Bundler will create the directory. This is usually the same
|
||||
# location as RubyGems which typically is the `~/.gem` directory
|
||||
# unless other specified.
|
||||
#
|
||||
# Secondly, it checks if Bundler has been configured to be "frozen".
|
||||
# Frozen ensures that the Gemfile and the Gemfile.lock file are matching.
|
||||
# This stops a situation where a developer may update the Gemfile but may not run
|
||||
# `bundle install`, which leads to the Gemfile.lock file not being correctly updated.
|
||||
# If this file is not correctly updated then any other developer running
|
||||
# `bundle install` will potentially not install the correct gems.
|
||||
#
|
||||
# Thirdly, Bundler checks if there are any dependencies specified in the Gemfile.
|
||||
# If there are no dependencies specified then Bundler returns a warning message stating
|
||||
# so and this method returns.
|
||||
#
|
||||
# Fourthly, Bundler checks if the Gemfile.lock exists, and if so
|
||||
# then proceeds to set up a definition based on the Gemfile and the Gemfile.lock.
|
||||
# During this step Bundler will also download information about any new gems
|
||||
# that are not in the Gemfile.lock and resolve any dependencies if needed.
|
||||
#
|
||||
# Fifthly, Bundler resolves the dependencies either through a cache of gems or by remote.
|
||||
# This then leads into the gems being installed, along with stubs for their executables,
|
||||
# but only if the --binstubs option has been passed or Bundler.options[:bin] has been set
|
||||
# earlier.
|
||||
#
|
||||
# Sixthly, a new Gemfile.lock is created from the installed gems to ensure that the next time
|
||||
# that a user runs `bundle install` they will receive any updates from this process.
|
||||
#
|
||||
# Finally, if the user has specified the standalone flag, Bundler will generate the needed
|
||||
# require paths and save them in a `setup.rb` file. See `bundle standalone --help` for more
|
||||
# information.
|
||||
def run(options)
|
||||
Bundler.create_bundle_path
|
||||
|
||||
ProcessLock.lock do
|
||||
if Bundler.frozen_bundle?
|
||||
@definition.ensure_equivalent_gemfile_and_lockfile(options[:deployment])
|
||||
end
|
||||
|
||||
if @definition.dependencies.empty?
|
||||
Bundler.ui.warn "The Gemfile specifies no dependencies"
|
||||
lock
|
||||
return
|
||||
end
|
||||
|
||||
if resolve_if_needed(options)
|
||||
ensure_specs_are_compatible!
|
||||
load_plugins
|
||||
options.delete(:jobs)
|
||||
else
|
||||
options[:jobs] = 1 # to avoid the overhead of Bundler::Worker
|
||||
end
|
||||
install(options)
|
||||
|
||||
Gem::Specification.reset # invalidate gem specification cache so that installed gems are immediately available
|
||||
|
||||
lock
|
||||
Standalone.new(options[:standalone], @definition).generate if options[:standalone]
|
||||
end
|
||||
end
|
||||
|
||||
def generate_bundler_executable_stubs(spec, options = {})
|
||||
if options[:binstubs_cmd] && spec.executables.empty?
|
||||
options = {}
|
||||
spec.runtime_dependencies.each do |dep|
|
||||
bins = @definition.specs[dep].first.executables
|
||||
options[dep.name] = bins unless bins.empty?
|
||||
end
|
||||
if options.any?
|
||||
Bundler.ui.warn "#{spec.name} has no executables, but you may want " \
|
||||
"one from a gem it depends on."
|
||||
options.each {|name, bins| Bundler.ui.warn " #{name} has: #{bins.join(", ")}" }
|
||||
else
|
||||
Bundler.ui.warn "There are no executables for the gem #{spec.name}."
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
# double-assignment to avoid warnings about variables that will be used by ERB
|
||||
bin_path = Bundler.bin_path
|
||||
bin_path = bin_path
|
||||
relative_gemfile_path = Bundler.default_gemfile.relative_path_from(bin_path)
|
||||
relative_gemfile_path = relative_gemfile_path
|
||||
ruby_command = Thor::Util.ruby_command
|
||||
ruby_command = ruby_command
|
||||
template_path = File.expand_path("templates/Executable", __dir__)
|
||||
if spec.name == "bundler"
|
||||
template_path += ".bundler"
|
||||
spec.executables = %(bundle)
|
||||
end
|
||||
template = File.read(template_path)
|
||||
|
||||
exists = []
|
||||
spec.executables.each do |executable|
|
||||
binstub_path = "#{bin_path}/#{executable}"
|
||||
if File.exist?(binstub_path) && !options[:force]
|
||||
exists << executable
|
||||
next
|
||||
end
|
||||
|
||||
mode = Gem.win_platform? ? "wb:UTF-8" : "w"
|
||||
require "erb"
|
||||
content = ERB.new(template, trim_mode: "-").result(binding)
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
if options[:binstubs_cmd] && exists.any?
|
||||
case exists.size
|
||||
when 1
|
||||
Bundler.ui.warn "Skipped #{exists[0]} since it already exists."
|
||||
when 2
|
||||
Bundler.ui.warn "Skipped #{exists.join(" and ")} since they already exist."
|
||||
else
|
||||
items = exists[0...-1].empty? ? nil : exists[0...-1].join(", ")
|
||||
skipped = [items, exists[-1]].compact.join(" and ")
|
||||
Bundler.ui.warn "Skipped #{skipped} since they already exist."
|
||||
end
|
||||
Bundler.ui.warn "If you want to overwrite skipped stubs, use --force."
|
||||
end
|
||||
end
|
||||
|
||||
def generate_standalone_bundler_executable_stubs(spec, options = {})
|
||||
# double-assignment to avoid warnings about variables that will be used by ERB
|
||||
bin_path = Bundler.bin_path
|
||||
unless path = Bundler.settings[:path]
|
||||
raise "Can't standalone without an explicit path set"
|
||||
end
|
||||
standalone_path = Bundler.root.join(path).relative_path_from(bin_path)
|
||||
standalone_path = standalone_path
|
||||
template = File.read(File.expand_path("templates/Executable.standalone", __dir__))
|
||||
ruby_command = Thor::Util.ruby_command
|
||||
ruby_command = ruby_command
|
||||
|
||||
spec.executables.each do |executable|
|
||||
next if executable == "bundle"
|
||||
executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path)
|
||||
executable_path = executable_path
|
||||
|
||||
mode = Gem.win_platform? ? "wb:UTF-8" : "w"
|
||||
require "erb"
|
||||
content = ERB.new(template, trim_mode: "-").result(binding)
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# the order that the resolver provides is significant, since
|
||||
# dependencies might affect the installation of a gem.
|
||||
# that said, it's a rare situation (other than rake), and parallel
|
||||
# installation is SO MUCH FASTER. so we let people opt in.
|
||||
def install(options)
|
||||
force = options["force"]
|
||||
jobs = installation_parallelization(options)
|
||||
install_in_parallel jobs, options[:standalone], force
|
||||
end
|
||||
|
||||
def installation_parallelization(options)
|
||||
if jobs = options.delete(:jobs)
|
||||
return jobs
|
||||
end
|
||||
|
||||
if jobs = Bundler.settings[:jobs]
|
||||
return jobs
|
||||
end
|
||||
|
||||
Bundler.settings.processor_count
|
||||
end
|
||||
|
||||
def load_plugins
|
||||
Gem.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
|
||||
Gem.load_plugin_files(path_plugin_files)
|
||||
Gem.load_env_plugins
|
||||
end
|
||||
|
||||
def ensure_specs_are_compatible!
|
||||
@definition.specs.each do |spec|
|
||||
unless spec.matches_current_ruby?
|
||||
raise InstallError, "#{spec.full_name} requires ruby version #{spec.required_ruby_version}, " \
|
||||
"which is incompatible with the current version, #{Gem.ruby_version}"
|
||||
end
|
||||
unless spec.matches_current_rubygems?
|
||||
raise InstallError, "#{spec.full_name} requires rubygems version #{spec.required_rubygems_version}, " \
|
||||
"which is incompatible with the current version, #{Gem.rubygems_version}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def install_in_parallel(size, standalone, force = false)
|
||||
spec_installations = ParallelInstaller.call(self, @definition.specs, size, standalone, force)
|
||||
spec_installations.each do |installation|
|
||||
post_install_messages[installation.name] = installation.post_install_message if installation.has_post_install_message?
|
||||
end
|
||||
end
|
||||
|
||||
# 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?
|
||||
end
|
||||
|
||||
@definition.setup_sources_for_resolve
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def lock
|
||||
@definition.lock
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,84 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class GemInstaller
|
||||
attr_reader :spec, :standalone, :worker, :force, :installer
|
||||
|
||||
def initialize(spec, installer, standalone = false, worker = 0, force = false)
|
||||
@spec = spec
|
||||
@installer = installer
|
||||
@standalone = standalone
|
||||
@worker = worker
|
||||
@force = force
|
||||
end
|
||||
|
||||
def install_from_spec
|
||||
post_install_message = install
|
||||
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, Bundler::InsecureInstallPathError
|
||||
raise
|
||||
rescue Errno::ENOSPC
|
||||
[false, out_of_space_message]
|
||||
rescue Bundler::BundlerError, Gem::InstallError => e
|
||||
[false, specific_failure_message(e)]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def specific_failure_message(e)
|
||||
message = "#{e.class}: #{e.message}\n"
|
||||
message += " " + e.backtrace.join("\n ") + "\n\n"
|
||||
message = message.lines.first + Bundler.ui.add_color(message.lines.drop(1).join, :clear)
|
||||
message + Bundler.ui.add_color(failure_message, :red)
|
||||
end
|
||||
|
||||
def failure_message
|
||||
install_error_message
|
||||
end
|
||||
|
||||
def install_error_message
|
||||
"An error occurred while installing #{spec.name} (#{spec.version}), and Bundler cannot continue."
|
||||
end
|
||||
|
||||
def spec_settings
|
||||
# Fetch the build settings, if there are any
|
||||
if settings = Bundler.settings["build.#{spec.name}"]
|
||||
require "shellwords"
|
||||
Shellwords.shellsplit(settings)
|
||||
end
|
||||
end
|
||||
|
||||
def install
|
||||
spec.source.install(
|
||||
spec,
|
||||
force: force,
|
||||
ensure_builtin_gems_cached: standalone,
|
||||
build_args: Array(spec_settings),
|
||||
previous_spec: previous_spec,
|
||||
)
|
||||
end
|
||||
|
||||
def previous_spec
|
||||
locked_gems = installer.definition.locked_gems
|
||||
return unless locked_gems
|
||||
|
||||
locked_gems.specs.find {|s| s.name == spec.name }
|
||||
end
|
||||
|
||||
def out_of_space_message
|
||||
"#{install_error_message}\nYour disk is out of space. Free some space to be able to install your bundle."
|
||||
end
|
||||
|
||||
def generate_executable_stubs
|
||||
return if Bundler.feature_flag.forget_cli_options?
|
||||
return if Bundler.settings[:inline]
|
||||
if Bundler.settings[:bin] && standalone
|
||||
installer.generate_standalone_bundler_executable_stubs(spec)
|
||||
elsif Bundler.settings[:bin]
|
||||
installer.generate_bundler_executable_stubs(spec, force: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,202 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "../worker"
|
||||
require_relative "gem_installer"
|
||||
|
||||
module Bundler
|
||||
class ParallelInstaller
|
||||
class SpecInstallation
|
||||
attr_accessor :spec, :name, :full_name, :post_install_message, :state, :error
|
||||
def initialize(spec)
|
||||
@spec = spec
|
||||
@name = spec.name
|
||||
@full_name = spec.full_name
|
||||
@state = :none
|
||||
@post_install_message = ""
|
||||
@error = nil
|
||||
end
|
||||
|
||||
def installed?
|
||||
state == :installed
|
||||
end
|
||||
|
||||
def enqueued?
|
||||
state == :enqueued
|
||||
end
|
||||
|
||||
def failed?
|
||||
state == :failed
|
||||
end
|
||||
|
||||
def ready_to_enqueue?
|
||||
state == :none
|
||||
end
|
||||
|
||||
def has_post_install_message?
|
||||
!post_install_message.empty?
|
||||
end
|
||||
|
||||
def ignorable_dependency?(dep)
|
||||
dep.type == :development || dep.name == @name
|
||||
end
|
||||
|
||||
# Checks installed dependencies against spec's dependencies to make
|
||||
# sure needed dependencies have been installed.
|
||||
def dependencies_installed?(installed_specs)
|
||||
dependencies.all? {|d| installed_specs.include? d.name }
|
||||
end
|
||||
|
||||
# Represents only the non-development dependencies, the ones that are
|
||||
# itself and are in the total list.
|
||||
def dependencies
|
||||
@dependencies ||= all_dependencies.reject {|dep| ignorable_dependency? dep }
|
||||
end
|
||||
|
||||
# Represents all dependencies
|
||||
def all_dependencies
|
||||
@spec.dependencies
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#<#{self.class} #{full_name} (#{state})>"
|
||||
end
|
||||
end
|
||||
|
||||
def self.call(*args, **kwargs)
|
||||
new(*args, **kwargs).call
|
||||
end
|
||||
|
||||
attr_reader :size
|
||||
|
||||
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" unless s.installed? }
|
||||
end
|
||||
|
||||
def call
|
||||
if @rake
|
||||
do_install(@rake, 0)
|
||||
Gem::Specification.reset
|
||||
end
|
||||
|
||||
if @size > 1
|
||||
install_with_worker
|
||||
else
|
||||
install_serially
|
||||
end
|
||||
|
||||
handle_error if failed_specs.any?
|
||||
@specs
|
||||
ensure
|
||||
worker_pool&.stop
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def failed_specs
|
||||
@specs.select(&:failed?)
|
||||
end
|
||||
|
||||
def install_with_worker
|
||||
enqueue_specs
|
||||
process_specs until finished_installing?
|
||||
end
|
||||
|
||||
def install_serially
|
||||
until finished_installing?
|
||||
raise "failed to find a spec to enqueue while installing serially" unless spec_install = @specs.find(&:ready_to_enqueue?)
|
||||
spec_install.state = :enqueued
|
||||
do_install(spec_install, 0)
|
||||
end
|
||||
end
|
||||
|
||||
def worker_pool
|
||||
@worker_pool ||= Bundler::Worker.new @size, "Parallel Installer", lambda {|spec_install, worker_num|
|
||||
do_install(spec_install, worker_num)
|
||||
}
|
||||
end
|
||||
|
||||
def do_install(spec_install, worker_num)
|
||||
Plugin.hook(Plugin::Events::GEM_BEFORE_INSTALL, spec_install)
|
||||
gem_installer = Bundler::GemInstaller.new(
|
||||
spec_install.spec, @installer, @standalone, worker_num, @force
|
||||
)
|
||||
success, message = gem_installer.install_from_spec
|
||||
if success
|
||||
spec_install.state = :installed
|
||||
spec_install.post_install_message = message unless message.nil?
|
||||
else
|
||||
spec_install.error = "#{message}\n\n#{require_tree_for_spec(spec_install.spec)}"
|
||||
spec_install.state = :failed
|
||||
end
|
||||
Plugin.hook(Plugin::Events::GEM_AFTER_INSTALL, spec_install)
|
||||
spec_install
|
||||
end
|
||||
|
||||
# Dequeue a spec and save its post-install message and then enqueue the
|
||||
# remaining specs.
|
||||
# Some specs might've had to wait til this spec was installed to be
|
||||
# processed so the call to `enqueue_specs` is important after every
|
||||
# dequeue.
|
||||
def process_specs
|
||||
worker_pool.deq
|
||||
enqueue_specs
|
||||
end
|
||||
|
||||
def finished_installing?
|
||||
@specs.all? do |spec|
|
||||
return true if spec.failed?
|
||||
spec.installed?
|
||||
end
|
||||
end
|
||||
|
||||
def handle_error
|
||||
errors = failed_specs.map(&:error)
|
||||
if exception = errors.find {|e| e.is_a?(Bundler::BundlerError) }
|
||||
raise exception
|
||||
end
|
||||
raise Bundler::InstallError, errors.join("\n\n")
|
||||
end
|
||||
|
||||
def require_tree_for_spec(spec)
|
||||
tree = @spec_set.what_required(spec)
|
||||
t = String.new("In #{File.basename(SharedHelpers.default_gemfile)}:\n")
|
||||
tree.each_with_index do |s, depth|
|
||||
t << " " * depth.succ << s.name
|
||||
unless tree.last == s
|
||||
t << %( was resolved to #{s.version}, which depends on)
|
||||
end
|
||||
t << %(\n)
|
||||
end
|
||||
t
|
||||
end
|
||||
|
||||
# Keys in the remains hash represent uninstalled gems specs.
|
||||
# We enqueue all gem specs that do not have any dependencies.
|
||||
# Later we call this lambda again to install specs that depended on
|
||||
# previously installed specifications. We continue until all specs
|
||||
# are installed.
|
||||
def enqueue_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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,116 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class Standalone
|
||||
def initialize(groups, definition)
|
||||
@specs = definition.specs_for(groups)
|
||||
end
|
||||
|
||||
def generate
|
||||
SharedHelpers.filesystem_access(bundler_path) do |p|
|
||||
FileUtils.mkdir_p(p)
|
||||
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|
|
||||
if Pathname.new(path).absolute?
|
||||
file.puts %($:.unshift "#{path}")
|
||||
else
|
||||
file.puts %($:.unshift File.expand_path("\#{__dir__}/#{path}"))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def paths
|
||||
@specs.map do |spec|
|
||||
next if spec.name == "bundler"
|
||||
Array(spec.require_paths).map do |path|
|
||||
gem_path(path, spec).
|
||||
sub(version_dir, '#{RUBY_ENGINE}/#{Gem.ruby_api_version}').
|
||||
sub(extensions_dir, 'extensions/\k<platform>/#{Gem.extension_api_version}')
|
||||
# This is a static string intentionally. It's interpolated at a later time.
|
||||
end
|
||||
end.flatten.compact
|
||||
end
|
||||
|
||||
def version_dir
|
||||
"#{RUBY_ENGINE}/#{Gem.ruby_api_version}"
|
||||
end
|
||||
|
||||
def extensions_dir
|
||||
%r{extensions/(?<platform>[^/]+)/#{Regexp.escape(Gem.extension_api_version)}}
|
||||
end
|
||||
|
||||
def bundler_path
|
||||
Bundler.root.join(Bundler.settings[:path].to_s, "bundler")
|
||||
end
|
||||
|
||||
def gem_path(path, spec)
|
||||
full_path = Pathname.new(path).absolute? ? path : File.join(spec.full_gem_path, path)
|
||||
if spec.source.instance_of?(Source::Path) && spec.source.path.absolute?
|
||||
full_path
|
||||
else
|
||||
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)
|
||||
module Gem
|
||||
def self.ruby_api_version
|
||||
RbConfig::CONFIG["ruby_version"]
|
||||
end
|
||||
|
||||
def self.extension_api_version
|
||||
if 'no' == RbConfig::CONFIG['ENABLE_SHARED']
|
||||
"#{ruby_api_version}-static"
|
||||
else
|
||||
ruby_api_version
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
END
|
||||
end
|
||||
|
||||
def reverse_rubygems_kernel_mixin
|
||||
<<~END
|
||||
if Gem.respond_to?(:discover_gems_on_require=)
|
||||
Gem.discover_gems_on_require = false
|
||||
else
|
||||
[::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)
|
||||
k.send(:define_method, :require, k.instance_method(:gem_original_require))
|
||||
k.send(:private, :require) if private_require
|
||||
end
|
||||
end
|
||||
end
|
||||
END
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,172 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "force_platform"
|
||||
|
||||
module Bundler
|
||||
class LazySpecification
|
||||
include MatchPlatform
|
||||
include ForcePlatform
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def full_name
|
||||
@full_name ||= if platform == Gem::Platform::RUBY
|
||||
"#{@name}-#{@version}"
|
||||
else
|
||||
"#{@name}-#{@version}-#{platform}"
|
||||
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
|
||||
|
||||
def eql?(other)
|
||||
full_name.eql?(other.full_name)
|
||||
end
|
||||
|
||||
def hash
|
||||
full_name.hash
|
||||
end
|
||||
|
||||
##
|
||||
# Does this locked specification satisfy +dependency+?
|
||||
#
|
||||
# NOTE: Rubygems default requirement is ">= 0", which doesn't match
|
||||
# prereleases of 0 versions, like "0.0.0.dev" or "0.0.0.SNAPSHOT". However,
|
||||
# bundler users expect those to work. We need to make sure that Gemfile
|
||||
# dependencies without explicit requirements (which use ">= 0" under the
|
||||
# hood by default) are still valid for locked specs using this kind of
|
||||
# versions. The method implements an ad-hoc fix for that. A better solution
|
||||
# might be to change default rubygems requirement of dependencies to be ">=
|
||||
# 0.A" but that's a major refactoring likely to break things. Hopefully we
|
||||
# can attempt it in the future.
|
||||
#
|
||||
|
||||
def satisfies?(dependency)
|
||||
effective_requirement = dependency.requirement == Gem::Requirement.default ? Gem::Requirement.new(">= 0.A") : dependency.requirement
|
||||
|
||||
@name == dependency.name && effective_requirement.satisfied_by?(Gem::Version.new(@version))
|
||||
end
|
||||
|
||||
def to_lock
|
||||
out = String.new
|
||||
out << " #{lock_name}\n"
|
||||
|
||||
dependencies.sort_by(&:to_s).uniq.each do |dep|
|
||||
next if dep.type == :development
|
||||
out << " #{dep.to_lock}\n"
|
||||
end
|
||||
|
||||
out
|
||||
end
|
||||
|
||||
def materialize_for_installation
|
||||
source.local!
|
||||
|
||||
matching_specs = source.specs.search(use_exact_resolved_specifications? ? self : [name, version])
|
||||
return self if matching_specs.empty?
|
||||
|
||||
candidates = if use_exact_resolved_specifications?
|
||||
matching_specs
|
||||
else
|
||||
target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform
|
||||
|
||||
installable_candidates = GemHelpers.select_best_platform_match(matching_specs, target_platform)
|
||||
|
||||
specification = __materialize__(installable_candidates, fallback_to_non_installable: false)
|
||||
return specification unless specification.nil?
|
||||
|
||||
if target_platform != platform
|
||||
installable_candidates = GemHelpers.select_best_platform_match(matching_specs, platform)
|
||||
end
|
||||
|
||||
installable_candidates
|
||||
end
|
||||
|
||||
__materialize__(candidates)
|
||||
end
|
||||
|
||||
# If in frozen mode, we fallback to a non-installable candidate because by
|
||||
# doing this we avoid re-resolving and potentially end up changing the
|
||||
# lock file, which is not allowed. In that case, we will give a proper error
|
||||
# about the mismatch higher up the stack, right before trying to install the
|
||||
# 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_metadata?
|
||||
end
|
||||
if search.nil? && fallback_to_non_installable
|
||||
search = candidates.last
|
||||
else
|
||||
search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification))
|
||||
end
|
||||
search
|
||||
end
|
||||
|
||||
def to_s
|
||||
lock_name
|
||||
end
|
||||
|
||||
def git_version
|
||||
return unless source.is_a?(Bundler::Source::Git)
|
||||
" #{source.revision[0..6]}"
|
||||
end
|
||||
|
||||
def force_ruby_platform!
|
||||
@force_ruby_platform = true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def use_exact_resolved_specifications?
|
||||
@use_exact_resolved_specifications ||= !source.is_a?(Source::Path) && ruby_platform_materializes_to_ruby_platform?
|
||||
end
|
||||
|
||||
#
|
||||
# For backwards compatibility with existing lockfiles, if the most specific
|
||||
# locked platform is not a specific platform like x86_64-linux or
|
||||
# universal-java-11, then we keep the previous behaviour of resolving the
|
||||
# best platform variant at materiliazation time. For previous bundler
|
||||
# versions (before 2.2.0) this was always the case (except when the lockfile
|
||||
# only included non-ruby platforms), but we're also keeping this behaviour
|
||||
# on newer bundlers unless users generate the lockfile from scratch or
|
||||
# explicitly add a more specific platform.
|
||||
#
|
||||
def ruby_platform_materializes_to_ruby_platform?
|
||||
generic_platform = generic_local_platform == Gem::Platform::JAVA ? Gem::Platform::JAVA : Gem::Platform::RUBY
|
||||
|
||||
!Bundler.most_specific_locked_platform?(generic_platform) || force_ruby_platform || Bundler.settings[:force_ruby_platform]
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,104 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class LockfileGenerator
|
||||
attr_reader :definition
|
||||
attr_reader :out
|
||||
|
||||
# @private
|
||||
def initialize(definition)
|
||||
@definition = definition
|
||||
@out = String.new
|
||||
end
|
||||
|
||||
def self.generate(definition)
|
||||
new(definition).generate!
|
||||
end
|
||||
|
||||
def generate!
|
||||
add_sources
|
||||
add_platforms
|
||||
add_dependencies
|
||||
add_checksums
|
||||
add_locked_ruby_version
|
||||
add_bundled_with
|
||||
|
||||
out
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_sources
|
||||
definition.send(:sources).lock_sources.each_with_index do |source, idx|
|
||||
out << "\n" unless idx.zero?
|
||||
|
||||
# Add the source header
|
||||
out << source.to_lock
|
||||
|
||||
# Find all specs for this source
|
||||
specs = definition.resolve.select {|s| source.can_lock?(s) }
|
||||
add_specs(specs)
|
||||
end
|
||||
end
|
||||
|
||||
def add_specs(specs)
|
||||
# This needs to be sorted by full name so that
|
||||
# gems with the same name, but different platform
|
||||
# are ordered consistently
|
||||
specs.sort_by(&:full_name).each do |spec|
|
||||
next if spec.name == "bundler"
|
||||
out << spec.to_lock
|
||||
end
|
||||
end
|
||||
|
||||
def add_platforms
|
||||
add_section("PLATFORMS", definition.platforms)
|
||||
end
|
||||
|
||||
def add_dependencies
|
||||
out << "\nDEPENDENCIES\n"
|
||||
|
||||
handled = []
|
||||
definition.dependencies.sort_by(&:to_s).each do |dep|
|
||||
next if handled.include?(dep.name)
|
||||
out << dep.to_lock << "\n"
|
||||
handled << dep.name
|
||||
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", definition.bundler_version_to_lock.to_s)
|
||||
end
|
||||
|
||||
def add_section(name, value)
|
||||
out << "\n#{name}\n"
|
||||
case value
|
||||
when Array
|
||||
value.map(&:to_s).sort.each do |val|
|
||||
out << " #{val}\n"
|
||||
end
|
||||
when Hash
|
||||
value.to_a.sort_by {|k, _| k.to_s }.each do |key, val|
|
||||
out << " #{key}: #{val}\n"
|
||||
end
|
||||
when String
|
||||
out << " #{value}\n"
|
||||
else
|
||||
raise ArgumentError, "#{value.inspect} can't be serialized in a lockfile"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,289 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Bundler
|
||||
class LockfileParser
|
||||
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"
|
||||
GEM = "GEM"
|
||||
PATH = "PATH"
|
||||
PLUGIN = "PLUGIN SOURCE"
|
||||
SPECS = " specs:"
|
||||
OPTIONS = /^ ([a-z]+): (.*)$/i
|
||||
SOURCE = [GIT, GEM, PATH, PLUGIN].freeze
|
||||
|
||||
SECTIONS_BY_VERSION_INTRODUCED = {
|
||||
Gem::Version.create("1.0") => [DEPENDENCIES, PLATFORMS, GIT, GEM, PATH].freeze,
|
||||
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
|
||||
|
||||
ENVIRONMENT_VERSION_SECTIONS = [BUNDLED, RUBY].freeze
|
||||
deprecate_constant(:ENVIRONMENT_VERSION_SECTIONS)
|
||||
|
||||
def self.sections_in_lockfile(lockfile_contents)
|
||||
sections = lockfile_contents.scan(/^\w[\w ]*$/)
|
||||
sections.uniq!
|
||||
sections
|
||||
end
|
||||
|
||||
def self.unknown_sections_in_lockfile(lockfile_contents)
|
||||
sections_in_lockfile(lockfile_contents) - KNOWN_SECTIONS
|
||||
end
|
||||
|
||||
def self.sections_to_ignore(base_version = nil)
|
||||
base_version &&= base_version.release
|
||||
base_version ||= Gem::Version.create("1.0")
|
||||
attributes = []
|
||||
SECTIONS_BY_VERSION_INTRODUCED.each do |version, introduced|
|
||||
next if version <= base_version
|
||||
attributes += introduced
|
||||
end
|
||||
attributes
|
||||
end
|
||||
|
||||
def self.bundled_with
|
||||
lockfile = Bundler.default_lockfile
|
||||
return unless lockfile.file?
|
||||
|
||||
lockfile_contents = Bundler.read_file(lockfile)
|
||||
return unless lockfile_contents.include?(BUNDLED)
|
||||
|
||||
lockfile_contents.split(BUNDLED).last.strip
|
||||
end
|
||||
|
||||
def initialize(lockfile)
|
||||
@platforms = []
|
||||
@sources = []
|
||||
@dependencies = {}
|
||||
@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 #{@lockfile_path} contains merge conflicts.\n" \
|
||||
"Run `git checkout HEAD -- #{@lockfile_path}` first to get a clean lock."
|
||||
end
|
||||
|
||||
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)
|
||||
@parse_method = :parse_source
|
||||
parse_source(line)
|
||||
elsif line == DEPENDENCIES
|
||||
@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
|
||||
@parse_method = :parse_platform
|
||||
elsif line == RUBY
|
||||
@parse_method = :parse_ruby
|
||||
elsif line == BUNDLED
|
||||
@parse_method = :parse_bundled_with
|
||||
elsif /^[^\s]/.match?(line)
|
||||
@parse_method = nil
|
||||
elsif @parse_method
|
||||
send(@parse_method, line)
|
||||
end
|
||||
@pos.advance!(line)
|
||||
end
|
||||
@specs = @specs.values.sort_by!(&:full_name)
|
||||
rescue ArgumentError => e
|
||||
Bundler.ui.debug(e)
|
||||
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?
|
||||
bundler_version.nil? || bundler_version < Gem::Version.new("1.16.2")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
TYPES = {
|
||||
GIT => Bundler::Source::Git,
|
||||
GEM => Bundler::Source::Rubygems,
|
||||
PATH => Bundler::Source::Path,
|
||||
PLUGIN => Bundler::Plugin,
|
||||
}.freeze
|
||||
|
||||
def parse_source(line)
|
||||
case line
|
||||
when SPECS
|
||||
return unless TYPES.key?(@type)
|
||||
@current_source = TYPES[@type].from_lock(@opts)
|
||||
@sources << @current_source
|
||||
when OPTIONS
|
||||
value = $2
|
||||
value = true if value == "true"
|
||||
value = false if value == "false"
|
||||
|
||||
key = $1
|
||||
|
||||
if @opts[key]
|
||||
@opts[key] = Array(@opts[key])
|
||||
@opts[key] << value
|
||||
else
|
||||
@opts[key] = value
|
||||
end
|
||||
when *SOURCE
|
||||
@current_source = nil
|
||||
@opts = {}
|
||||
@type = line
|
||||
else
|
||||
parse_spec(line)
|
||||
end
|
||||
end
|
||||
|
||||
space = / /
|
||||
NAME_VERSION = /
|
||||
^(#{space}{2}|#{space}{4}|#{space}{6})(?!#{space}) # Exactly 2, 4, or 6 spaces at the start of the line
|
||||
(.*?) # Name
|
||||
(?:#{space}\(([^-]*) # Space, followed by version
|
||||
(?:-(.*))?\))? # Optional platform
|
||||
(!)? # Optional pinned marker
|
||||
(?:#{space}([^ ]+))? # Optional checksum
|
||||
$ # Line end
|
||||
/xo
|
||||
|
||||
def parse_dependency(line)
|
||||
return unless line =~ NAME_VERSION
|
||||
spaces = $1
|
||||
return unless spaces.size == 2
|
||||
name = -$2
|
||||
version = $3
|
||||
pinned = $5
|
||||
|
||||
version = version.split(",").each(&:strip!) if version
|
||||
|
||||
dep = Bundler::Dependency.new(name, version)
|
||||
|
||||
if pinned && dep.name != "bundler"
|
||||
spec = @specs.find {|_, v| v.name == dep.name }
|
||||
dep.source = spec.last.source if spec
|
||||
|
||||
# Path sources need to know what the default name / version
|
||||
# to use in the case that there are no gemspecs present. A fake
|
||||
# gemspec is created based on the version set on the dependency
|
||||
# TODO: Use the version from the spec instead of from the dependency
|
||||
if version && version.size == 1 && version.first =~ /^\s*= (.+)\s*$/ && dep.source.is_a?(Bundler::Source::Path)
|
||||
dep.source.name = name
|
||||
dep.source.version = $1
|
||||
end
|
||||
end
|
||||
|
||||
@dependencies[dep.name] = dep
|
||||
end
|
||||
|
||||
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_source)
|
||||
@current_source.add_dependency_names(name)
|
||||
|
||||
@specs[@current_spec.full_name] = @current_spec
|
||||
elsif spaces.size == 6
|
||||
version = version.split(",").each(&:strip!) if version
|
||||
dep = Gem::Dependency.new(name, version)
|
||||
@current_spec.dependencies << dep
|
||||
end
|
||||
end
|
||||
|
||||
def parse_platform(line)
|
||||
@platforms << Gem::Platform.new($1) if line =~ /^ (.*)$/
|
||||
end
|
||||
|
||||
def parse_bundled_with(line)
|
||||
line.strip!
|
||||
return unless Gem::Version.correct?(line)
|
||||
@bundler_version = Gem::Version.create(line)
|
||||
end
|
||||
|
||||
def parse_ruby(line)
|
||||
line.strip!
|
||||
@ruby_version = line
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1 @@
|
||||
# Ignore all files in this directory
|
||||
@@ -0,0 +1,59 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-ADD" "1" "March 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\.
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
bundle-add(1) -- Add gem to the Gemfile and run bundle install
|
||||
================================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle add` <GEM_NAME> [--group=GROUP] [--version=VERSION] [--source=SOURCE] [--path=PATH] [--git=GIT] [--github=GITHUB] [--branch=BRANCH] [--ref=REF] [--skip-install] [--strict] [--optimistic]
|
||||
|
||||
## DESCRIPTION
|
||||
Adds the named gem to the Gemfile and run `bundle install`. `bundle install` can be avoided by using the flag `--skip-install`.
|
||||
|
||||
Example:
|
||||
|
||||
bundle add rails
|
||||
|
||||
bundle add rails --version "< 3.0, > 1.1"
|
||||
|
||||
bundle add rails --version "~> 5.0.0" --source "https://gems.example.com" --group "development"
|
||||
|
||||
bundle add rails --skip-install
|
||||
|
||||
bundle add rails --group "development, test"
|
||||
|
||||
## OPTIONS
|
||||
* `--version`, `-v`:
|
||||
Specify version requirements(s) for the added gem.
|
||||
|
||||
* `--group`, `-g`:
|
||||
Specify the group(s) for the added gem. Multiple groups should be separated by commas.
|
||||
|
||||
* `--source`, `-s`:
|
||||
Specify the source for the added gem.
|
||||
|
||||
* `--require`, `-r`:
|
||||
Adds require path to gem. Provide false, or a path as a string.
|
||||
|
||||
* `--path`:
|
||||
Specify the file system path for the added gem.
|
||||
|
||||
* `--git`:
|
||||
Specify the git source for the added gem.
|
||||
|
||||
* `--github`:
|
||||
Specify the github source for the added gem.
|
||||
|
||||
* `--branch`:
|
||||
Specify the git branch for the added gem.
|
||||
|
||||
* `--ref`:
|
||||
Specify the git ref for the added gem.
|
||||
|
||||
* `--skip-install`:
|
||||
Adds the gem to the Gemfile but does not install it.
|
||||
|
||||
* `--optimistic`:
|
||||
Adds optimistic declaration of version.
|
||||
|
||||
* `--strict`:
|
||||
Adds strict declaration of version.
|
||||
@@ -0,0 +1,30 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-BINSTUBS" "1" "March 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')
|
||||
.TP
|
||||
\fB\-\-all\fR
|
||||
Create binstubs for all gems in the bundle\.
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
bundle-binstubs(1) -- Install the binstubs of the listed gems
|
||||
=============================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle binstubs` <GEM_NAME> [--force] [--path PATH] [--standalone]
|
||||
|
||||
## 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 `bin/`. Binstubs are a shortcut-or alternative-
|
||||
to always using `bundle exec`. This gives you a file that can be run
|
||||
directly, and one that will always run the correct gem version
|
||||
used by the application.
|
||||
|
||||
For example, if you run `bundle binstubs rspec-core`, Bundler will create
|
||||
the file `bin/rspec`. That file will contain enough code to load Bundler,
|
||||
tell it to load the bundled gems, and then run rspec.
|
||||
|
||||
This command generates binstubs for executables in `GEM_NAME`.
|
||||
Binstubs are put into `bin`, or the `--path` directory if one has been set.
|
||||
Calling binstubs with [GEM [GEM]] will create binstubs for all given gems.
|
||||
|
||||
## OPTIONS
|
||||
|
||||
* `--force`:
|
||||
Overwrite existing binstubs if they exist.
|
||||
|
||||
* `--path`:
|
||||
The location to install the specified binstubs to. This defaults to `bin`.
|
||||
|
||||
* `--standalone`:
|
||||
Makes binstubs that can work without depending on Rubygems or Bundler at
|
||||
runtime.
|
||||
|
||||
* `--shebang`:
|
||||
Specify a different shebang executable name than the default (default 'ruby')
|
||||
|
||||
* `--all`:
|
||||
Create binstubs for all gems in the bundle.
|
||||
@@ -0,0 +1,40 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-CACHE" "1" "March 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\.
|
||||
@@ -0,0 +1,79 @@
|
||||
bundle-cache(1) -- Package your needed `.gem` files into your application
|
||||
===========================================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle cache`
|
||||
|
||||
alias: `package`, `pack`
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
Copy all of the `.gem` files needed to run the application into the
|
||||
`vendor/cache` directory. In the future, when running [`bundle install(1)`](bundle-install.1.html),
|
||||
use the gems in the cache in preference to the ones on `rubygems.org`.
|
||||
|
||||
## GIT AND PATH GEMS
|
||||
|
||||
The `bundle cache` command can also package `:git` and `:path` dependencies
|
||||
besides .gem files. This needs to be explicitly enabled via the `--all` option.
|
||||
Once used, the `--all` option will be remembered.
|
||||
|
||||
## 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 `vendor/cache`. This needs to be enabled via
|
||||
the `--all-platforms` option. This setting will be remembered in your local
|
||||
bundler configuration.
|
||||
|
||||
## REMOTE FETCHING
|
||||
|
||||
By default, if you run [`bundle install(1)`](bundle-install.1.html) after running
|
||||
[bundle cache(1)](bundle-cache.1.html), bundler will still connect to `rubygems.org`
|
||||
to check whether a platform-specific gem exists for any of the gems
|
||||
in `vendor/cache`.
|
||||
|
||||
For instance, consider this Gemfile(5):
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "nokogiri"
|
||||
|
||||
If you run `bundle cache` under C Ruby, bundler will retrieve
|
||||
the version of `nokogiri` for the `"ruby"` platform. If you deploy
|
||||
to JRuby and run `bundle install`, bundler is forced to check to
|
||||
see whether a `"java"` platformed `nokogiri` exists.
|
||||
|
||||
Even though the `nokogiri` gem for the Ruby platform is
|
||||
_technically_ acceptable on JRuby, it has a C extension
|
||||
that does not run on JRuby. As a result, bundler will, by default,
|
||||
still connect to `rubygems.org` to check whether it has a version
|
||||
of one of your gems more specific to your platform.
|
||||
|
||||
This problem is also not limited to the `"java"` 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.
|
||||
|
||||
If you know for sure that the gems packaged in `vendor/cache`
|
||||
are appropriate for the platform you are on, you can run
|
||||
`bundle install --local` to skip checking for more appropriate
|
||||
gems, and use the ones in `vendor/cache`.
|
||||
|
||||
One way to be sure that you have the right platformed versions
|
||||
of all your gems is to run `bundle cache` on an identical
|
||||
machine and check in the gems. For instance, you can run
|
||||
`bundle cache` on an identical staging box during your
|
||||
staging process, and check in the `vendor/cache` before
|
||||
deploying to production.
|
||||
|
||||
By default, [bundle cache(1)](bundle-cache.1.html) fetches and also
|
||||
installs the gems to the default location. To package the
|
||||
dependencies to `vendor/cache` without installing them to the
|
||||
local install location, you can run `bundle cache --no-install`.
|
||||
|
||||
## HISTORY
|
||||
|
||||
In Bundler 2.1, `cache` took in the functionalities of `package` and now
|
||||
`package` and `pack` are aliases of `cache`.
|
||||
@@ -0,0 +1,22 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-CHECK" "1" "March 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\.
|
||||
.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\.
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
bundle-check(1) -- Verifies if dependencies are satisfied by installed gems
|
||||
===========================================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle check` [--dry-run]
|
||||
[--gemfile=FILE]
|
||||
[--path=PATH]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
`check` 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.
|
||||
|
||||
If not, the first missing gem is listed and Bundler exits status 1.
|
||||
|
||||
## OPTIONS
|
||||
|
||||
* `--dry-run`:
|
||||
Locks the [`Gemfile(5)`][Gemfile(5)] before running the command.
|
||||
* `--gemfile`:
|
||||
Use the specified gemfile instead of the [`Gemfile(5)`][Gemfile(5)].
|
||||
* `--path`:
|
||||
Specify a different path than the system default (`$BUNDLE_PATH` or `$GEM_HOME`).
|
||||
Bundler will remember this value for future installs on this machine.
|
||||
@@ -0,0 +1,17 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-CLEAN" "1" "March 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\.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
bundle-clean(1) -- Cleans up unused gems in your bundler directory
|
||||
==================================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle clean` [--dry-run] [--force]
|
||||
|
||||
## 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.
|
||||
|
||||
## OPTIONS
|
||||
|
||||
* `--dry-run`:
|
||||
Print the changes, but do not clean the unused gems.
|
||||
* `--force`:
|
||||
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.
|
||||
@@ -0,0 +1,321 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-CONFIG" "1" "March 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\.
|
||||
.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)\.
|
||||
.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)\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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
|
||||
\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\.
|
||||
.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\.
|
||||
.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 underscore (\fB___\fR) in the corresponding environment variable\.
|
||||
.IP "\(bu" 4
|
||||
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\.
|
||||
.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
|
||||
.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
|
||||
|
||||
@@ -0,0 +1,411 @@
|
||||
bundle-config(1) -- Set bundler configuration options
|
||||
=====================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle config` list<br>
|
||||
`bundle config` [get] NAME<br>
|
||||
`bundle config` [set] NAME VALUE<br>
|
||||
`bundle config` unset NAME
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
This command allows you to interact with Bundler's configuration system.
|
||||
|
||||
Bundler loads configuration settings in this order:
|
||||
|
||||
1. Local config (`<project_root>/.bundle/config` or `$BUNDLE_APP_CONFIG/config`)
|
||||
2. Environmental variables (`ENV`)
|
||||
3. Global config (`~/.bundle/config`)
|
||||
4. Bundler default config
|
||||
|
||||
Executing `bundle config list` will print a list of all bundler
|
||||
configuration for the current bundle, and where that configuration
|
||||
was set.
|
||||
|
||||
Executing `bundle config get <name>` will print the value of that configuration
|
||||
setting, and where it was set.
|
||||
|
||||
Executing `bundle config set <name> <value>` defaults to setting `local`
|
||||
configuration if executing from within a local application, otherwise it will
|
||||
set `global` configuration. See `--local` and `--global` options below.
|
||||
|
||||
Executing `bundle config set --local <name> <value>` will set that configuration
|
||||
in the directory for the local application. The configuration will be stored in
|
||||
`<project_root>/.bundle/config`. If `BUNDLE_APP_CONFIG` is set, the configuration
|
||||
will be stored in `$BUNDLE_APP_CONFIG/config`.
|
||||
|
||||
Executing `bundle config set --global <name> <value>` will set that
|
||||
configuration to the value specified for all bundles executed as the current
|
||||
user. The configuration will be stored in `~/.bundle/config`. If <name> already
|
||||
is set, <name> will be overridden and user will be warned.
|
||||
|
||||
Executing `bundle config unset <name>` will delete the configuration in both
|
||||
local and global sources.
|
||||
|
||||
Executing `bundle config unset --global <name>` will delete the configuration
|
||||
only from the user configuration.
|
||||
|
||||
Executing `bundle config unset --local <name>` will delete the configuration
|
||||
only from the local application.
|
||||
|
||||
Executing bundle with the `BUNDLE_IGNORE_CONFIG` environment variable set will
|
||||
cause it to ignore all configuration.
|
||||
|
||||
## REMEMBERING OPTIONS
|
||||
|
||||
Flags passed to `bundle install` or the Bundler runtime, such as `--path foo` or
|
||||
`--without production`, are remembered between commands and saved to your local
|
||||
application's configuration (normally, `./.bundle/config`).
|
||||
|
||||
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
|
||||
`bundle config` (e.g., `bundle config set --local path foo`).
|
||||
|
||||
The options that can be configured are:
|
||||
|
||||
* `bin`:
|
||||
Creates a directory (defaults to `~/bin`) 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 `PATH` variable. For instance, if the
|
||||
`rails` gem comes with a `rails` executable, this flag will create a
|
||||
`bin/rails` executable that ensures that all referred dependencies will be
|
||||
resolved using the bundled gems.
|
||||
|
||||
* `deployment`:
|
||||
In deployment mode, Bundler will 'roll-out' the bundle for
|
||||
`production` use. Please check carefully if you want to have this option
|
||||
enabled in `development` or `test` environments.
|
||||
|
||||
* `only`:
|
||||
A space-separated list of groups to install only gems of the specified groups.
|
||||
|
||||
* `path`:
|
||||
The location to install the specified gems to. This defaults to Rubygems'
|
||||
setting. Bundler shares this location with Rubygems, `gem install ...` will
|
||||
have gem installed there, too. Therefore, gems installed without a
|
||||
`--path ...` setting will show up by calling `gem list`. Accordingly, gems
|
||||
installed to other locations will not get listed.
|
||||
|
||||
* `without`:
|
||||
A space-separated list of groups referencing gems to skip during installation.
|
||||
|
||||
* `with`:
|
||||
A space-separated list of **optional** groups referencing gems to include during installation.
|
||||
|
||||
## BUILD OPTIONS
|
||||
|
||||
You can use `bundle config` to give Bundler the flags to pass to the gem
|
||||
installer every time bundler tries to install a particular gem.
|
||||
|
||||
A very common example, the `mysql` gem, requires Snow Leopard users to
|
||||
pass configuration flags to `gem install` to specify where to find the
|
||||
`mysql_config` executable.
|
||||
|
||||
gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
||||
|
||||
Since the specific location of that executable can change from machine
|
||||
to machine, you can specify these flags on a per-machine basis.
|
||||
|
||||
bundle config set --global build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
|
||||
|
||||
After running this command, every time bundler needs to install the
|
||||
`mysql` gem, it will pass along the flags you specified.
|
||||
|
||||
## CONFIGURATION KEYS
|
||||
|
||||
Configuration keys in bundler have two forms: the canonical form and the
|
||||
environment variable form.
|
||||
|
||||
For instance, passing the `--without` flag to [bundle install(1)](bundle-install.1.html)
|
||||
prevents Bundler from installing certain groups specified in the Gemfile(5). Bundler
|
||||
persists this value in `app/.bundle/config` so that calls to `Bundler.setup`
|
||||
do not try to find gems from the `Gemfile` that you didn't install. Additionally,
|
||||
subsequent calls to [bundle install(1)](bundle-install.1.html) remember this setting
|
||||
and skip those groups.
|
||||
|
||||
The canonical form of this configuration is `"without"`. To convert the canonical
|
||||
form to the environment variable form, capitalize it, and prepend `BUNDLE_`. The
|
||||
environment variable form of `"without"` is `BUNDLE_WITHOUT`.
|
||||
|
||||
Any periods in the configuration keys must be replaced with two underscores when
|
||||
setting it via environment variables. The configuration key `local.rack` becomes
|
||||
the environment variable `BUNDLE_LOCAL__RACK`.
|
||||
|
||||
## 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)](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`):
|
||||
Automatically run `bundle clean` after installing when an explicit `path`
|
||||
has not been set and Bundler is not installing into the system gems.
|
||||
* `auto_install` (`BUNDLE_AUTO_INSTALL`):
|
||||
Automatically run `bundle install` when gems are missing.
|
||||
* `bin` (`BUNDLE_BIN`):
|
||||
Install executables from gems in the bundle to the specified directory.
|
||||
Defaults to `false`.
|
||||
* `cache_all` (`BUNDLE_CACHE_ALL`):
|
||||
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.
|
||||
* `cache_all_platforms` (`BUNDLE_CACHE_ALL_PLATFORMS`):
|
||||
Cache gems for all platforms.
|
||||
* `cache_path` (`BUNDLE_CACHE_PATH`):
|
||||
The directory that bundler will place cached gems in when running
|
||||
<code>bundle package</code>, and that bundler will look in when installing gems.
|
||||
Defaults to `vendor/cache`.
|
||||
* `clean` (`BUNDLE_CLEAN`):
|
||||
Whether Bundler should run `bundle clean` automatically after
|
||||
`bundle install`.
|
||||
* `console` (`BUNDLE_CONSOLE`):
|
||||
The console that `bundle console` starts. Defaults to `irb`.
|
||||
* `default_install_uses_path` (`BUNDLE_DEFAULT_INSTALL_USES_PATH`):
|
||||
Whether a `bundle install` without an explicit `--path` argument defaults
|
||||
to installing gems in `.bundle`.
|
||||
* `deployment` (`BUNDLE_DEPLOYMENT`):
|
||||
Disallow changes to the `Gemfile`. When the `Gemfile` is changed and the
|
||||
lockfile has not been updated, running Bundler commands will be blocked.
|
||||
* `disable_checksum_validation` (`BUNDLE_DISABLE_CHECKSUM_VALIDATION`):
|
||||
Allow installing gems even if they do not match the checksum provided by
|
||||
RubyGems.
|
||||
* `disable_exec_load` (`BUNDLE_DISABLE_EXEC_LOAD`):
|
||||
Stop Bundler from using `load` to launch an executable in-process in
|
||||
`bundle exec`.
|
||||
* `disable_local_branch_check` (`BUNDLE_DISABLE_LOCAL_BRANCH_CHECK`):
|
||||
Allow Bundler to use a local git override without a branch specified in the
|
||||
Gemfile.
|
||||
* `disable_local_revision_check` (`BUNDLE_DISABLE_LOCAL_REVISION_CHECK`):
|
||||
Allow Bundler to use a local git override without checking if the revision
|
||||
present in the lockfile is present in the repository.
|
||||
* `disable_shared_gems` (`BUNDLE_DISABLE_SHARED_GEMS`):
|
||||
Stop Bundler from accessing gems installed to RubyGems' normal location.
|
||||
* `disable_version_check` (`BUNDLE_DISABLE_VERSION_CHECK`):
|
||||
Stop Bundler from checking if a newer Bundler version is available on
|
||||
rubygems.org.
|
||||
* `force_ruby_platform` (`BUNDLE_FORCE_RUBY_PLATFORM`):
|
||||
Ignore the current machine's platform and install only `ruby` platform gems.
|
||||
As a result, gems with native extensions will be compiled from source.
|
||||
* `frozen` (`BUNDLE_FROZEN`):
|
||||
Disallow changes to the `Gemfile`. When the `Gemfile` is changed and the
|
||||
lockfile has not been updated, running Bundler commands will be blocked.
|
||||
Defaults to `true` when `--deployment` is used.
|
||||
* `gem.github_username` (`BUNDLE_GEM__GITHUB_USERNAME`):
|
||||
Sets a GitHub username or organization to be used in `README` file when you
|
||||
create a new gem via `bundle gem` command. It can be overridden by passing an
|
||||
explicit `--github-username` flag to `bundle gem`.
|
||||
* `gem.push_key` (`BUNDLE_GEM__PUSH_KEY`):
|
||||
Sets the `--key` parameter for `gem push` when using the `rake release`
|
||||
command with a private gemstash server.
|
||||
* `gemfile` (`BUNDLE_GEMFILE`):
|
||||
The name of the file that bundler should use as the `Gemfile`. This location
|
||||
of this file also sets the root of the project, which is used to resolve
|
||||
relative paths in the `Gemfile`, among other things. By default, bundler
|
||||
will search up from the current working directory until it finds a
|
||||
`Gemfile`.
|
||||
* `global_gem_cache` (`BUNDLE_GLOBAL_GEM_CACHE`):
|
||||
Whether Bundler should cache all gems globally, rather than locally to the
|
||||
installing Ruby installation.
|
||||
* `ignore_funding_requests` (`BUNDLE_IGNORE_FUNDING_REQUESTS`):
|
||||
When set, no funding requests will be printed.
|
||||
* `ignore_messages` (`BUNDLE_IGNORE_MESSAGES`):
|
||||
When set, no post install messages will be printed. To silence a single gem,
|
||||
use dot notation like `ignore_messages.httparty true`.
|
||||
* `init_gems_rb` (`BUNDLE_INIT_GEMS_RB`):
|
||||
Generate a `gems.rb` instead of a `Gemfile` when running `bundle init`.
|
||||
* `jobs` (`BUNDLE_JOBS`):
|
||||
The number of gems Bundler can install in parallel. Defaults to the number of
|
||||
available processors.
|
||||
* `no_install` (`BUNDLE_NO_INSTALL`):
|
||||
Whether `bundle package` should skip installing gems.
|
||||
* `no_prune` (`BUNDLE_NO_PRUNE`):
|
||||
Whether Bundler should leave outdated gems unpruned when caching.
|
||||
* `only` (`BUNDLE_ONLY`):
|
||||
A space-separated list of groups to install only gems of the specified groups.
|
||||
* `path` (`BUNDLE_PATH`):
|
||||
The location on disk where all gems in your bundle will be located regardless
|
||||
of `$GEM_HOME` or `$GEM_PATH` values. Bundle gems not found in this location
|
||||
will be installed by `bundle install`. Defaults to `Gem.dir`. When --deployment
|
||||
is used, defaults to vendor/bundle.
|
||||
* `path.system` (`BUNDLE_PATH__SYSTEM`):
|
||||
Whether Bundler will install gems into the default system path (`Gem.dir`).
|
||||
* `path_relative_to_cwd` (`BUNDLE_PATH_RELATIVE_TO_CWD`)
|
||||
Makes `--path` relative to the CWD instead of the `Gemfile`.
|
||||
* `plugins` (`BUNDLE_PLUGINS`):
|
||||
Enable Bundler's experimental plugin system.
|
||||
* `prefer_patch` (BUNDLE_PREFER_PATCH):
|
||||
Prefer updating only to next patch version during updates. Makes `bundle update` calls equivalent to `bundler update --patch`.
|
||||
* `print_only_version_number` (`BUNDLE_PRINT_ONLY_VERSION_NUMBER`):
|
||||
Print only version number from `bundler --version`.
|
||||
* `redirect` (`BUNDLE_REDIRECT`):
|
||||
The number of redirects allowed for network requests. Defaults to `5`.
|
||||
* `retry` (`BUNDLE_RETRY`):
|
||||
The number of times to retry failed network requests. Defaults to `3`.
|
||||
* `setup_makes_kernel_gem_public` (`BUNDLE_SETUP_MAKES_KERNEL_GEM_PUBLIC`):
|
||||
Have `Bundler.setup` make the `Kernel#gem` method public, even though
|
||||
RubyGems declares it as private.
|
||||
* `shebang` (`BUNDLE_SHEBANG`):
|
||||
The program name that should be invoked for generated binstubs. Defaults to
|
||||
the ruby install name used to generate the binstub.
|
||||
* `silence_deprecations` (`BUNDLE_SILENCE_DEPRECATIONS`):
|
||||
Whether Bundler should silence deprecation warnings for behavior that will
|
||||
be changed in the next major version.
|
||||
* `silence_root_warning` (`BUNDLE_SILENCE_ROOT_WARNING`):
|
||||
Silence the warning Bundler prints when installing gems as root.
|
||||
* `ssl_ca_cert` (`BUNDLE_SSL_CA_CERT`):
|
||||
Path to a designated CA certificate file or folder containing multiple
|
||||
certificates for trusted CAs in PEM format.
|
||||
* `ssl_client_cert` (`BUNDLE_SSL_CLIENT_CERT`):
|
||||
Path to a designated file containing a X.509 client certificate
|
||||
and key in PEM format.
|
||||
* `ssl_verify_mode` (`BUNDLE_SSL_VERIFY_MODE`):
|
||||
The SSL verification mode Bundler uses when making HTTPS requests.
|
||||
Defaults to verify peer.
|
||||
* `system_bindir` (`BUNDLE_SYSTEM_BINDIR`):
|
||||
The location where RubyGems installs binstubs. Defaults to `Gem.bindir`.
|
||||
* `timeout` (`BUNDLE_TIMEOUT`):
|
||||
The seconds allowed before timing out for network requests. Defaults to `10`.
|
||||
* `update_requires_all_flag` (`BUNDLE_UPDATE_REQUIRES_ALL_FLAG`):
|
||||
Require passing `--all` to `bundle update` when everything should be updated,
|
||||
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`):
|
||||
A `:`-separated list of groups whose gems bundler should not install.
|
||||
|
||||
In general, you should set these settings per-application by using the applicable
|
||||
flag to the [bundle install(1)](bundle-install.1.html) or [bundle cache(1)](bundle-cache.1.html) command.
|
||||
|
||||
You can set them globally either via environment variables or `bundle config`,
|
||||
whichever is preferable for your setup. If you use both, environment variables
|
||||
will take preference over global settings.
|
||||
|
||||
## 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:
|
||||
|
||||
bundle config set --local local.GEM_NAME /path/to/local/git/repository
|
||||
|
||||
For example, in order to use a local Rack repository, a developer could call:
|
||||
|
||||
bundle config set --local local.rack ~/Work/git/rack
|
||||
|
||||
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 `Gemfile.lock` 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.
|
||||
|
||||
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 `Gemfile` in order to use this feature. If the branch
|
||||
specified in the `Gemfile` 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.
|
||||
|
||||
Finally, Bundler also ensures that the current revision in the
|
||||
`Gemfile.lock` exists in the local git repository. By doing this, Bundler
|
||||
forces you to fetch the latest changes in the remotes.
|
||||
|
||||
## 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.
|
||||
|
||||
bundle config set --global mirror.SOURCE_URL MIRROR_URL
|
||||
|
||||
For example, to use a mirror of https://rubygems.org hosted at https://example.org:
|
||||
|
||||
bundle config set --global mirror.https://rubygems.org https://example.org
|
||||
|
||||
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.
|
||||
|
||||
bundle config set --global mirror.SOURCE_URL.fallback_timeout TIMEOUT
|
||||
|
||||
For example, to fall back to rubygems.org after 3 seconds:
|
||||
|
||||
bundle config set --global mirror.https://rubygems.org.fallback_timeout 3
|
||||
|
||||
The default fallback timeout is 0.1 seconds, but the setting can currently
|
||||
only accept whole seconds (for example, 1, 15, or 30).
|
||||
|
||||
## CREDENTIALS FOR GEM SOURCES
|
||||
|
||||
Bundler allows you to configure credentials for any gem source, which allows
|
||||
you to avoid putting secrets into your Gemfile.
|
||||
|
||||
bundle config set --global SOURCE_HOSTNAME USERNAME:PASSWORD
|
||||
|
||||
For example, to save the credentials of user `claudette` for the gem source at
|
||||
`gems.longerous.com`, you would run:
|
||||
|
||||
bundle config set --global gems.longerous.com claudette:s00pers3krit
|
||||
|
||||
Or you can set the credentials as an environment variable like this:
|
||||
|
||||
export BUNDLE_GEMS__LONGEROUS__COM="claudette:s00pers3krit"
|
||||
|
||||
For gems with a git source with HTTP(S) URL you can specify credentials like so:
|
||||
|
||||
bundle config set --global https://github.com/rubygems/rubygems.git username:password
|
||||
|
||||
Or you can set the credentials as an environment variable like so:
|
||||
|
||||
export BUNDLE_GITHUB__COM=username:password
|
||||
|
||||
This is especially useful for private repositories on hosts such as GitHub,
|
||||
where you can use personal OAuth tokens:
|
||||
|
||||
export BUNDLE_GITHUB__COM=abcd0123generatedtoken:x-oauth-basic
|
||||
|
||||
Note that any configured credentials will be redacted by informative commands
|
||||
such as `bundle config list` or `bundle config get`, unless you use the
|
||||
`--parseable` flag. This is to avoid unintentionally leaking credentials when
|
||||
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 underscore (`___`) in the
|
||||
corresponding environment variable.
|
||||
|
||||
* 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
|
||||
use the `BUNDLE_MY__GEM___HOST__COM` variable to configure credentials for it
|
||||
through ENV.
|
||||
|
||||
## 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
|
||||
`~/.bundle`, which all directories inherit from by default. The following
|
||||
outlines the available environment variables and their default values
|
||||
|
||||
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
|
||||
@@ -0,0 +1,35 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-CONSOLE" "1" "March 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\|\.\|\.\|\.
|
||||
[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
|
||||
@@ -0,0 +1,44 @@
|
||||
bundle-console(1) -- Deprecated way to open an IRB session with the bundle pre-loaded
|
||||
=====================================================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle console` [GROUP]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
Starts an interactive Ruby console session in the context of the current bundle.
|
||||
|
||||
If no `GROUP` is specified, all gems in the `default` group in the [Gemfile(5)](https://bundler.io/man/gemfile.5.html) are
|
||||
preliminarily loaded.
|
||||
|
||||
If `GROUP` is specified, all gems in the given group in the Gemfile in addition
|
||||
to the gems in `default` group are loaded. Even if the given group does not
|
||||
exist in the Gemfile, IRB console starts without any warning or error.
|
||||
|
||||
The environment variable `BUNDLE_CONSOLE` or `bundle config set console` can be used to change
|
||||
the shell from the following:
|
||||
|
||||
* `irb` (default)
|
||||
* `pry` (https://github.com/pry/pry)
|
||||
* `ripl` (https://github.com/cldwalker/ripl)
|
||||
|
||||
`bundle console` uses irb by default. An alternative Pry or Ripl can be used with
|
||||
`bundle console` by adjusting the `console` Bundler setting. Also make sure that
|
||||
`pry` or `ripl` is in your Gemfile.
|
||||
|
||||
## EXAMPLE
|
||||
|
||||
$ bundle config set console pry
|
||||
$ bundle console
|
||||
Resolving dependencies...
|
||||
[1] pry(main)>
|
||||
|
||||
## NOTES
|
||||
|
||||
This command was deprecated in Bundler 2.1 and will be removed in 3.0.
|
||||
Use `bin/console` script, which can be generated by `bundle gem <NAME>`.
|
||||
|
||||
## SEE ALSO
|
||||
|
||||
[Gemfile(5)](https://bundler.io/man/gemfile.5.html)
|
||||
@@ -0,0 +1,30 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-DOCTOR" "1" "March 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\.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
bundle-doctor(1) -- Checks the bundle for common problems
|
||||
=========================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle doctor` [--quiet]
|
||||
[--gemfile=GEMFILE]
|
||||
|
||||
## 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.
|
||||
|
||||
Examples of common problems caught by bundle-doctor include:
|
||||
|
||||
* Invalid Bundler settings
|
||||
* Mismatched Ruby versions
|
||||
* Mismatched platforms
|
||||
* Uninstalled gems
|
||||
* Missing dependencies
|
||||
|
||||
## OPTIONS
|
||||
|
||||
* `--quiet`:
|
||||
Only output warnings and errors.
|
||||
|
||||
* `--gemfile=<gemfile>`:
|
||||
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 `Gemfile.lock` and `vendor/cache` relative
|
||||
to this location.
|
||||
@@ -0,0 +1,104 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-EXEC" "1" "March 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\.
|
||||
.SH "OPTIONS"
|
||||
.TP
|
||||
\fB\-\-keep\-file\-descriptors\fR
|
||||
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)
|
||||
.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
|
||||
.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\.
|
||||
.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:
|
||||
.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')
|
||||
.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')"
|
||||
.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)\.
|
||||
@@ -0,0 +1,151 @@
|
||||
bundle-exec(1) -- Execute a command in the context of the bundle
|
||||
================================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle exec` [--keep-file-descriptors] <command>
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
This command executes the command, making all gems specified in the
|
||||
[`Gemfile(5)`][Gemfile(5)] available to `require` in Ruby programs.
|
||||
|
||||
Essentially, if you would normally have run something like
|
||||
`rspec spec/my_spec.rb`, and you want to use the gems specified
|
||||
in the [`Gemfile(5)`][Gemfile(5)] and installed via [bundle install(1)](bundle-install.1.html), you
|
||||
should run `bundle exec rspec spec/my_spec.rb`.
|
||||
|
||||
Note that `bundle exec` does not require that an executable is
|
||||
available on your shell's `$PATH`.
|
||||
|
||||
## OPTIONS
|
||||
|
||||
* `--keep-file-descriptors`:
|
||||
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
|
||||
|
||||
If you use the `--binstubs` flag in [bundle install(1)](bundle-install.1.html), Bundler will
|
||||
automatically create a directory (which defaults to `app_root/bin`)
|
||||
containing all of the executables available from gems in the bundle.
|
||||
|
||||
After using `--binstubs`, `bin/rspec spec/my_spec.rb` is identical
|
||||
to `bundle exec rspec spec/my_spec.rb`.
|
||||
|
||||
## ENVIRONMENT MODIFICATIONS
|
||||
|
||||
`bundle exec` makes a number of changes to the shell environment,
|
||||
then executes the command you specify in full.
|
||||
|
||||
* make sure that it's still possible to shell out to `bundle`
|
||||
from inside a command invoked by `bundle exec` (using
|
||||
`$BUNDLE_BIN_PATH`)
|
||||
* put the directory containing executables (like `rails`, `rspec`,
|
||||
`rackup`) for your bundle on `$PATH`
|
||||
* make sure that if bundler is invoked in the subshell, it uses
|
||||
the same `Gemfile` (by setting `BUNDLE_GEMFILE`)
|
||||
* add `-rbundler/setup` to `$RUBYOPT`, which makes sure that
|
||||
Ruby programs invoked in the subshell can see the gems in
|
||||
the bundle
|
||||
|
||||
It also modifies Rubygems:
|
||||
|
||||
* disallow loading additional gems not in the bundle
|
||||
* modify the `gem` method to be a no-op if a gem matching
|
||||
the requirements is in the bundle, and to raise a
|
||||
`Gem::LoadError` if it's not
|
||||
* Define `Gem.refresh` 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
|
||||
* Override `Gem.bin_path` to use the gems in the bundle,
|
||||
making system executables work
|
||||
* Add all gems in the bundle into Gem.loaded_specs
|
||||
|
||||
Finally, `bundle exec` also implicitly modifies `Gemfile.lock` if the lockfile
|
||||
and the Gemfile do not match. Bundler needs the Gemfile to determine things
|
||||
such as a gem's groups, `autorequire`, and platforms, etc., and that
|
||||
information isn't stored in the lockfile. The Gemfile and lockfile must be
|
||||
synced in order to `bundle exec` successfully, so `bundle exec`
|
||||
updates the lockfile beforehand.
|
||||
|
||||
### Loading
|
||||
|
||||
By default, when attempting to `bundle exec` to a file with a ruby shebang,
|
||||
Bundler will `Kernel.load` that file instead of using `Kernel.exec`. 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 `$0` or `__FILE__`) and the optimization can be disabled by enabling
|
||||
the `disable_exec_load` setting.
|
||||
|
||||
### Shelling out
|
||||
|
||||
Any Ruby code that opens a subshell (like `system`, backticks, or `%x{}`) 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
|
||||
`with_unbundled_env` 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:
|
||||
|
||||
Bundler.with_unbundled_env do
|
||||
`brew install wget`
|
||||
end
|
||||
|
||||
Using `with_unbundled_env` 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 `with_unbundled_env`.
|
||||
|
||||
Bundler.with_unbundled_env do
|
||||
Dir.chdir "/other/bundler/project" do
|
||||
`bundle exec ./script`
|
||||
end
|
||||
end
|
||||
|
||||
Bundler provides convenience helpers that wrap `system` and `exec`, and they
|
||||
can be used like this:
|
||||
|
||||
Bundler.clean_system('brew install wget')
|
||||
Bundler.clean_exec('brew install wget')
|
||||
|
||||
|
||||
## RUBYGEMS PLUGINS
|
||||
|
||||
At present, the Rubygems plugin system requires all files
|
||||
named `rubygems_plugin.rb` on the load path of _any_ installed
|
||||
gem when any Ruby code requires `rubygems.rb`. This includes
|
||||
executables installed into the system, like `rails`, `rackup`,
|
||||
and `rspec`.
|
||||
|
||||
Since Rubygems plugins can contain arbitrary Ruby code, they
|
||||
commonly end up activating themselves or their dependencies.
|
||||
|
||||
For instance, the `gemcutter 0.5` gem depended on `json_pure`.
|
||||
If you had that version of gemcutter installed (even if
|
||||
you _also_ had a newer version without this problem), Rubygems
|
||||
would activate `gemcutter 0.5` and `json_pure <latest>`.
|
||||
|
||||
If your Gemfile(5) also contained `json_pure` (or a gem
|
||||
with a dependency on `json_pure`), the latest version on
|
||||
your system might conflict with the version in your
|
||||
Gemfile(5), or the snapshot version in your `Gemfile.lock`.
|
||||
|
||||
If this happens, bundler will say:
|
||||
|
||||
You have already activated json_pure 1.4.6 but your Gemfile
|
||||
requires json_pure 1.4.3. Consider using bundle exec.
|
||||
|
||||
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 `gemcutter`
|
||||
gem) have released newer versions that are more careful in
|
||||
their plugins.
|
||||
|
||||
You can find a list of all the gems containing gem plugins
|
||||
by running
|
||||
|
||||
ruby -e "puts Gem.find_files('rubygems_plugin.rb')"
|
||||
|
||||
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 (`gem uninstall gem_name`).
|
||||
@@ -0,0 +1,69 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-GEM" "1" "March 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:
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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\.
|
||||
.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:
|
||||
.IP
|
||||
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\.
|
||||
.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
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
bundle-gem(1) -- Generate a project skeleton for creating a rubygem
|
||||
====================================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle gem` <GEM_NAME> [OPTIONS]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
Generates a directory named `GEM_NAME` with a `Rakefile`, `GEM_NAME.gemspec`,
|
||||
and other supporting files and directories that can be used to develop a
|
||||
rubygem with that name.
|
||||
|
||||
Run `rake -T` in the resulting project for a list of Rake tasks that can be used
|
||||
to test and publish the gem to rubygems.org.
|
||||
|
||||
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:
|
||||
|
||||
* `gem.coc`
|
||||
* `gem.mit`
|
||||
* `gem.test`
|
||||
|
||||
## OPTIONS
|
||||
|
||||
* `--exe` or `-b` or `--bin`:
|
||||
Specify that Bundler should create a binary executable (as `exe/GEM_NAME`)
|
||||
in the generated rubygem project. This binary will also be added to the
|
||||
`GEM_NAME.gemspec` manifest. This behavior is disabled by default.
|
||||
|
||||
* `--no-exe`:
|
||||
Do not create a binary (overrides `--exe` specified in the global config).
|
||||
|
||||
* `--coc`:
|
||||
Add a `CODE_OF_CONDUCT.md` 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 `bundle gem` use.
|
||||
|
||||
* `--no-coc`:
|
||||
Do not create a `CODE_OF_CONDUCT.md` (overrides `--coc` specified in the
|
||||
global config).
|
||||
|
||||
* `--ext=c`, `--ext=rust`
|
||||
Add boilerplate for C or Rust (currently [magnus](https://docs.rs/magnus) based) extension code to the generated project. This behavior
|
||||
is disabled by default.
|
||||
|
||||
* `--no-ext`:
|
||||
Do not add extension code (overrides `--ext` specified in the global
|
||||
config).
|
||||
|
||||
* `--mit`:
|
||||
Add an MIT license to a `LICENSE.txt` 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
|
||||
`bundle gem` use.
|
||||
|
||||
* `--no-mit`:
|
||||
Do not create a `LICENSE.txt` (overrides `--mit` specified in the global
|
||||
config).
|
||||
|
||||
* `-t`, `--test=minitest`, `--test=rspec`, `--test=test-unit`:
|
||||
Specify the test framework that Bundler should use when generating the
|
||||
project. Acceptable values are `minitest`, `rspec` and `test-unit`. The
|
||||
`GEM_NAME.gemspec` will be configured and a skeleton test/spec directory will
|
||||
be created based on this option. Given no option is specified:
|
||||
|
||||
When Bundler is configured to generate tests, this defaults to Bundler's
|
||||
global config setting `gem.test`.
|
||||
|
||||
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.
|
||||
|
||||
When Bundler is unconfigured, an interactive prompt will be displayed and
|
||||
the answer will be saved in Bundler's global config for future `bundle gem`
|
||||
use.
|
||||
|
||||
* `--ci`, `--ci=github`, `--ci=gitlab`, `--ci=circle`:
|
||||
Specify the continuous integration service that Bundler should use when
|
||||
generating the project. Acceptable values are `github`, `gitlab`
|
||||
and `circle`. A configuration file will be generated in the project directory.
|
||||
Given no option is specified:
|
||||
|
||||
When Bundler is configured to generate CI files, this defaults to Bundler's
|
||||
global config setting `gem.ci`.
|
||||
|
||||
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.
|
||||
|
||||
When Bundler is unconfigured, an interactive prompt will be displayed and
|
||||
the answer will be saved in Bundler's global config for future `bundle gem`
|
||||
use.
|
||||
|
||||
* `--linter`, `--linter=rubocop`, `--linter=standard`:
|
||||
Specify the linter and code formatter that Bundler should add to the
|
||||
project's development dependencies. Acceptable values are `rubocop` and
|
||||
`standard`. A configuration file will be generated in the project directory.
|
||||
Given no option is specified:
|
||||
|
||||
When Bundler is configured to add a linter, this defaults to Bundler's
|
||||
global config setting `gem.linter`.
|
||||
|
||||
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.
|
||||
|
||||
When Bundler is unconfigured, an interactive prompt will be displayed and
|
||||
the answer will be saved in Bundler's global config for future `bundle gem`
|
||||
use.
|
||||
|
||||
* `-e`, `--edit[=EDITOR]`:
|
||||
Open the resulting GEM_NAME.gemspec in EDITOR, or the default editor if not
|
||||
specified. The default is `$BUNDLER_EDITOR`, `$VISUAL`, or `$EDITOR`.
|
||||
|
||||
## SEE ALSO
|
||||
|
||||
* [bundle config(1)](bundle-config.1.html)
|
||||
@@ -0,0 +1,9 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-HELP" "1" "March 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\.
|
||||
@@ -0,0 +1,12 @@
|
||||
bundle-help(1) -- Displays detailed help for each subcommand
|
||||
============================================================
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
`bundle help` [COMMAND]
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
Displays detailed help for the given subcommand.
|
||||
You can specify a single `COMMAND` at the same time.
|
||||
When `COMMAND` is omitted, help for `help` command will be displayed.
|
||||
@@ -0,0 +1,14 @@
|
||||
.\" generated with nRonn/v0.11.1
|
||||
.\" https://github.com/n-ronn/nronn/tree/0.11.1
|
||||
.TH "BUNDLE\-INFO" "1" "March 2024" ""
|
||||
.SH "NAME"
|
||||
\fBbundle\-info\fR \- Show information for the given gem in your bundle
|
||||
.SH "SYNOPSIS"
|
||||
\fBbundle info\fR [GEM_NAME] [\-\-path]
|
||||
.SH "DESCRIPTION"
|
||||
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
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user