summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHiroshi SHIBATA <[email protected]>2022-12-22 08:20:23 +0900
committerHiroshi SHIBATA <[email protected]>2022-12-24 16:57:07 +0900
commitf6620037ba1477d2c337d7b511f094d6d0fbb69c ()
tree4d8d38eaf97e6ca88162dd574e7871e1739f22ae /lib
parentd5635dfe36588b04d3dd6065ab4e422f51629b11 (diff)
Merge RubyGems-3.4.0 and Bundler-2.4.0
Notes: Merged: https://.com/ruby/ruby/pull/6987
-rw-r--r--lib/bundler.rb2
-rw-r--r--lib/bundler/cli.rb4
-rw-r--r--lib/bundler/cli/gem.rb27
-rw-r--r--lib/bundler/definition.rb19
-rw-r--r--lib/bundler/dependency.rb6
-rw-r--r--lib/bundler/force_platform.rb18
-rw-r--r--lib/bundler/lazy_specification.rb4
-rw-r--r--lib/bundler/man/bundle-gem.162
-rw-r--r--lib/bundler/man/bundle-gem.1.ronn6
-rw-r--r--lib/bundler/resolver.rb39
-rw-r--r--lib/bundler/rubygems_ext.rb11
-rw-r--r--lib/bundler/source/git/git_proxy.rb33
-rw-r--r--lib/bundler/spec_set.rb10
-rw-r--r--lib/bundler/templates/newgem/Cargo.toml.tt7
-rw-r--r--lib/bundler/templates/newgem/Gemfile.tt3
-rw-r--r--lib/bundler/templates/newgem/README.md.tt10
-rw-r--r--lib/bundler/templates/newgem/Rakefile.tt3
-rw-r--r--lib/bundler/templates/newgem/circleci/config.yml.tt12
-rw-r--r--lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt15
-rw-r--r--lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt (renamed from lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt)0
-rw-r--r--lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt6
-rw-r--r--lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt12
-rw-r--r--lib/bundler/templates/newgem//workflows/main.yml.tt10
-rw-r--r--lib/bundler/templates/newgem/gitignore.tt3
-rw-r--r--lib/bundler/templates/newgem/gitlab-ci.yml.tt8
-rw-r--r--lib/bundler/templates/newgem/newgem.gemspec.tt8
-rw-r--r--lib/bundler/version.rb2
-rw-r--r--lib/mjit/instruction.rb2162
-rw-r--r--lib/rubygems.rb3
-rw-r--r--lib/rubygems/dependency.rb5
-rw-r--r--lib/rubygems/ext/cargo_builder.rb15
-rw-r--r--lib/rubygems/ext/cargo_builder/link_flag_converter.rb14
-rw-r--r--lib/rubygems/specification_policy.rb14
33 files changed, 2440 insertions, 113 deletions
@@ -463,7 +463,7 @@ EOF
end
def local_platform
- return Gem::Platform::RUBY if settings[:force_ruby_platform] || Gem.platforms == [Gem::Platform::RUBY]
Gem::Platform.local
end
@@ -10,7 +10,7 @@ module 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"].freeze
COMMAND_ALIASES = {
"check" => "c",
@@ -762,7 +762,7 @@ module Bundler
# when deprecated version of `--ext` is called
# print out deprecation warning and pretend `--ext=c` was provided
if deprecated_ext_value?(arguments)
- SharedHelpers.major_deprecation 2, "Option `--ext` without explicit value is deprecated. Please pass value like `--ext=c` for C extension. Pretending `--ext=c` was used for now."
arguments[arguments.index("--ext")] = "--ext=c"
end
end
@@ -31,6 +31,7 @@ module Bundler
@extension = options[:ext]
validate_ext_name if @extension
travis_removal_info
end
@@ -73,6 +74,7 @@ module Bundler
:git => use_git,
:_username => _username.empty? ? "[USERNAME]" : _username,
:required_ruby_version => required_ruby_version,
:minitest_constant_name => minitest_constant_name,
}
ensure_safe_gem_name(name, constant_array)
@@ -189,14 +191,23 @@ module Bundler
templates.merge!("exe/newgem.tt" => "exe/#{name}") if config[:exe]
- if extension
templates.merge!(
- "ext/newgem/extconf.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 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]
@@ -415,6 +426,10 @@ module Bundler
thor.run(%(#{editor} "#{file}"))
end
def required_ruby_version
"2.6.0"
end
@@ -427,7 +442,6 @@ module Bundler
"1.3"
end
- #
# TODO: remove at next minor release
def travis_removal_info
if options[:ci] == "travis"
@@ -440,5 +454,12 @@ module Bundler
exit 1
end
end
end
end
@@ -263,10 +263,10 @@ module Bundler
@locked_specs
elsif !unlocking? && nothing_changed?
if deleted_deps.any?
- Bundler.ui.debug("Some dependencies were deleted, using a subset of the resolution from the lockfile")
SpecSet.new(filter_specs(@locked_specs, @dependencies - deleted_deps))
else
- Bundler.ui.debug("Found no changes, using resolution from the lockfile")
if @locked_gems.may_include_redundant_platform_specific_gems?
SpecSet.new(filter_specs(@locked_specs, @dependencies))
else
@@ -274,7 +274,7 @@ module Bundler
end
end
else
- Bundler.ui.debug("Found changes from the lockfile, re-resolving dependencies because #{change_reason}")
start_resolution
end
end
@@ -806,12 +806,13 @@ module Bundler
end
new_spec = new_specs[s].first
-
- # If the spec is no longer in the path source, unlock it. This
- # commonly happens if the version changed in the gemspec
- next unless new_spec
-
- s.dependencies.replace(new_spec.dependencies)
end
if dep.nil? && requested_dependencies.find {|d| s.name == d.name }
@@ -7,7 +7,7 @@ require_relative "rubygems_ext"
module Bundler
class Dependency < Gem::Dependency
attr_reader :autorequire
- attr_reader :groups, :platforms, :gemfile, :path, :git, :, :branch, :ref, :force_ruby_platform
ALL_RUBY_VERSIONS = ((18..27).to_a + (30..31).to_a).freeze
PLATFORM_MAP = {
@@ -42,7 +42,7 @@ module Bundler
@env = options["env"]
@should_include = options.fetch("should_include", true)
@gemfile = options["gemfile"]
- @force_ruby_platform = options["force_ruby_platform"]
@autorequire = Array(options["require"] || []) if options.key?("require")
end
@@ -50,7 +50,7 @@ module Bundler
# Returns the platforms this dependency is valid for, in the same order as
# passed in the `valid_platforms` parameter
def gem_platforms(valid_platforms)
- return [Gem::Platform::RUBY] if @force_ruby_platform
return valid_platforms if @platforms.empty?
valid_platforms.select {|p| expanded_platforms.include?(GemHelpers.generic(p)) }
@@ -0,0 +1,18 @@
@@ -1,8 +1,11 @@
# frozen_string_literal: true
module Bundler
class LazySpecification
include MatchPlatform
attr_reader :name, :version, :dependencies, :platform
attr_accessor :source, :remote, :force_ruby_platform
@@ -14,6 +17,7 @@ module Bundler
@platform = platform || Gem::Platform::RUBY
@source = source
@specification = nil
end
def full_name
@@ -31,41 +31,32 @@ The generated project skeleton can be customized with OPTIONS, as explained belo
.
.SH "OPTIONS"
.
-.TP
-\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\.
.
-.TP
-\fB\-\-no\-exe\fR
-Do not create a binary (overrides \fB\-\-exe\fR specified in the global config)\.
.
-.TP
-\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\.
.
-.TP
-\fB\-\-no\-coc\fR
-Do not create a \fBCODE_OF_CONDUCT\.md\fR (overrides \fB\-\-coc\fR specified in the global config)\.
.
-.TP
-\fB\-\-ext=c\fR
-Add boilerplate for C extension code to the generated project\. This behavior is disabled by default\.
.
-.TP
-\fB\-\-no\-ext\fR
-Do not add C extension code (overrides \fB\-\-ext\fR specified in the global config)\.
.
-.TP
-\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\.
.
-.TP
-\fB\-\-no\-mit\fR
-Do not create a \fBLICENSE\.txt\fR (overrides \fB\-\-mit\fR specified in the global config)\.
.
-.TP
-\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\.
@@ -76,9 +67,8 @@ When Bundler is configured to not generate tests, an interactive prompt will be
.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\.
.
-.TP
-\fB\-\-ci\fR, \fB\-\-ci=\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 \fB\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\.
@@ -89,9 +79,8 @@ When Bundler is configured to not generate CI files, an interactive prompt will
.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\.
.
-.TP
-\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\.
@@ -102,9 +91,10 @@ When Bundler is configured not to add a linter, an interactive prompt will be di
.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\.
.
-.TP
-\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\.
.
.SH "SEE ALSO"
.
@@ -41,12 +41,12 @@ configuration file using the following names:
Do not create a `CODE_OF_CONDUCT.md` (overrides `--coc` specified in the
global config).
-* `--ext=c`:
- Add boilerplate for C extension code to the generated project. This behavior
is disabled by default.
* `--no-ext`:
- Do not add C extension code (overrides `--ext` specified in the global
config).
* `--mit`:
@@ -27,6 +27,17 @@ module Bundler
remove_from_candidates(spec)
end
root = Resolver::Root.new(name_for_explicit_dependency_source)
root_version = Resolver::Candidate.new(0)
@@ -42,24 +53,27 @@ module Bundler
end
end
- root_dependencies = prepare_dependencies(requirements, packages)
@cached_dependencies = Hash.new do |dependencies, package|
dependencies[package] = if package.root?
{ root_version => root_dependencies }
else
Hash.new do |versions, version|
- versions[version] = to_dependency_hash(version.dependencies, packages)
end
end
end
logger = Bundler::UI::Shell.new
logger.level = debug? ? "debug" : "warn"
solver = PubGrub::VersionSolver.new(:source => self, :root => root, :logger => logger)
- before_resolution
result = solver.solve
- after_resolution
result.map {|package, version| version.to_specs(package) }.flatten.uniq
rescue PubGrub::SolveFailure => e
incompatibility = e.incompatibility
@@ -82,8 +96,15 @@ module Bundler
end
end
if names_to_unlock.any?
@base.unlock_names(names_to_unlock)
retry
end
@@ -144,14 +165,6 @@ module Bundler
false
end
- def before_resolution
- Bundler.ui.info "Resolving dependencies...", debug?
- end
-
- def after_resolution
- Bundler.ui.info ""
- end
-
def incompatibilities_for(package, version)
package_deps = @cached_dependencies[package]
sorted_versions = @sorted_versions[package]
@@ -202,7 +215,7 @@ module Bundler
def all_versions_for(package)
name = package.name
- results = @base[name] + @all_specs[name]
locked_requirement = base_requirements[name]
results = filter_matching_specs(results, locked_requirement) if locked_requirement
@@ -16,6 +16,7 @@ require "rubygems/specification"
require "rubygems/source"
require_relative "match_metadata"
require_relative "match_platform"
# Cherry-pick fixes to `Gem.ruby_version` to be useful for modern Bundler
@@ -153,12 +154,16 @@ module Gem
end
class Dependency
attr_accessor :source, :groups
alias_method :eql?, :==
def force_ruby_platform
- false
end
def encode_with(coder)
@@ -277,6 +282,10 @@ module Gem
without_gnu_nor_abi_modifiers
end
end
end
Platform.singleton_class.module_eval do
@@ -176,37 +176,32 @@ module Bundler
@depth = if !supports_fetching_unreachable_refs?
nil
- elsif not_pinned?
1
elsif ref.include?("~")
parsed_depth = ref.split("~").last
parsed_depth.to_i + 1
- elsif abbreviated_ref?
- nil
- else
- 1
end
end
def refspec
- if fully_qualified_ref
- "#{fully_qualified_ref}:#{fully_qualified_ref}"
- elsif ref.include?("~")
- parsed_ref = ref.split("~").first
- "#{parsed_ref}:#{parsed_ref}"
elsif ref.start_with?("refs/")
- "#{ref}:#{ref}"
- elsif abbreviated_ref?
- nil
- else
ref
end
end
def fully_qualified_ref
- return @fully_qualified_ref if defined?(@fully_qualified_ref)
-
- @fully_qualified_ref = if branch
"refs/heads/#{branch}"
elsif tag
"refs/tags/#{tag}"
@@ -219,8 +214,8 @@ module Bundler
branch || tag || ref.nil?
end
- def abbreviated_ref?
- ref =~ /\A\h+\z/ && ref !~ /\A\h{40}\z/
end
def legacy_locked_revision?
@@ -190,12 +190,10 @@ module Bundler
def specs_for_dependency(dep, platform)
specs_for_name = lookup[dep.name]
- if platform.nil?
- matching_specs = specs_for_name.map {|s| s.materialize_for_installation if Gem::Platform.match_spec?(s) }.compact
- GemHelpers.sort_best_platform_match(matching_specs, Bundler.local_platform)
- else
- GemHelpers.select_best_platform_match(specs_for_name, dep.force_ruby_platform ? Gem::Platform::RUBY : platform)
- end
end
def tsort_each_child(s)
@@ -0,0 +1,7 @@
@@ -9,6 +9,9 @@ gem "rake", "~> 13.0"
<%- if config[:ext] -%>
gem "rake-compiler"
<%- end -%>
<%- if config[:test] -%>
@@ -1,18 +1,20 @@
# <%= config[:constant_name] %>
-Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/<%= config[:namespaced_path] %>`. To experiment with that code, run `bin/console` for an interactive prompt.
-TODO: Delete this and the text above, and describe your gem
## Installation
Install the gem and add to the application's Gemfile by executing:
- $ bundle add <%= config[:name] %>
If bundler is not being used to manage dependencies, install the gem by executing:
- $ gem install <%= config[:name] %>
## Usage
@@ -39,7 +39,8 @@ require "standard/rake"
<% end -%>
<% if config[:ext] -%>
-<% default_task_names.unshift(:clobber, :compile) -%>
require "rake/extensiontask"
task build: :compile
@@ -3,8 +3,20 @@ jobs:
build:
docker:
- image: ruby:<%= RUBY_VERSION %>
steps:
- checkout
- run:
name: Run the default task
command: |
@@ -0,0 +1,15 @@
@@ -0,0 +1,6 @@
@@ -0,0 +1,12 @@
@@ -18,10 +18,20 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
@@ -12,6 +12,9 @@
*.o
*.a
mkmf.log
<%- end -%>
<%- if config[:test] == "rspec" -%>
@@ -2,9 +2,17 @@ default:
image: ruby:<%= RUBY_VERSION %>
before_script:
- gem install bundler -v <%= Bundler::VERSION %>
- bundle install
example_job:
script:
- bundle exec rake
@@ -15,6 +15,9 @@ Gem::Specification.new do |spec|
spec.license = "MIT"
<%- end -%>
spec.required_ruby_version = ">= <%= config[:required_ruby_version] %>"
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
@@ -32,9 +35,12 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
-<%- if config[:ext] -%>
spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"]
<%- end -%>
# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"
@@ -1,7 +1,7 @@
# frozen_string_literal: false
module Bundler
- VERSION = "2.4.0.dev".freeze
def self.bundler_major_version
@bundler_major_version ||= VERSION.split(".").first.to_i
@@ -0,0 +1,2162 @@
@@ -8,7 +8,7 @@
require "rbconfig"
module Gem
- VERSION = "3.4.0.dev".freeze
end
# Must be first since it unloads the prelude from 1.9.2
@@ -1297,7 +1297,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/".freeze
- autoload :BundlerVersionFinder, File.expand_path("rubygems/bundler_version_finder", __dir__)
autoload :ConfigFile, File.expand_path("rubygems/config_file", __dir__)
autoload :Dependency, File.expand_path("rubygems/dependency", __dir__)
autoload :DependencyList, File.expand_path("rubygems/dependency_list", __dir__)
@@ -277,7 +277,10 @@ class Gem::Dependency
requirement.satisfied_by?(spec.version) && env_req.satisfied_by?(spec.version)
end.map(&:to_spec)
- Gem::BundlerVersionFinder.prioritize!(matches) if prioritizes_bundler?
if platform_only
matches.reject! do |spec|
@@ -37,7 +37,8 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder
def build_env
build_env = rb_config_env
build_env["RUBY_STATIC"] = "true" if ruby_static? && ENV.key?("RUBY_STATIC")
- build_env["RUSTFLAGS"] = "#{ENV["RUSTFLAGS"]} --cfg=rb_sys_gem".strip
build_env
end
@@ -47,6 +48,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder
cmd = []
cmd += [cargo, "rustc"]
cmd += ["--target", ENV["CARGO_BUILD_TARGET"]] if ENV["CARGO_BUILD_TARGET"]
cmd += ["--target-dir", dest_path]
cmd += ["--manifest-path", manifest]
@@ -103,14 +105,23 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder
# We want to use the same linker that Ruby uses, so that the linker flags from
# mkmf work properly.
def linker_args
- # Have to handle CC="cl /nologo" on mswin
cc_flag = Shellwords.split(makefile_config("CC"))
linker = cc_flag.shift
link_args = cc_flag.flat_map {|a| ["-C", "link-arg=#{a}"] }
["-C", "linker=#{linker}", *link_args]
end
def libruby_args(dest_dir)
libs = makefile_config(ruby_static? ? "LIBRUBYARG_STATIC" : "LIBRUBYARG_SHARED")
raw_libs = Shellwords.split(libs)
@@ -3,20 +3,24 @@
class Gem::Ext::CargoBuilder < Gem::Ext::Builder
# Converts Ruby link flags into something cargo understands
class LinkFlagConverter
def self.convert(arg)
case arg.chomp
when /^-L\s*(.+)$/
["-L", "native=#{$1}"]
when /^--library=(\w+\S+)$/, /^-l\s*(\w+\S+)$/
["-l", $1]
- when /^-l\s*:lib(\S+).a$/
- ["-l", "static=#{$1}"]
- when /^-l\s*:lib(\S+).(so|dylib|dll)$/
- ["-l", "dylib=#{$1}"]
when /^-F\s*(.*)$/
["-l", "framework=#{$1}"]
else
- ["-C", "link_arg=#{arg}"]
end
end
end
@@ -460,6 +460,20 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li
require_relative "ext"
builder = Gem::Ext::Builder.new(@specification)
rake_extension = @specification.extensions.any? {|s| builder.builder_for(s) == Gem::Ext::RakeBuilder }
rake_dependency = @specification.dependencies.any? {|d| d.name == "rake" }