mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Sync RubyGems
This commit is contained in:
parent
f679202a0f
commit
81da38b308
14 changed files with 100 additions and 46 deletions
|
@ -4,21 +4,26 @@ module Bundler
|
||||||
# Represents metadata from when the Bundler gem was built.
|
# Represents metadata from when the Bundler gem was built.
|
||||||
module BuildMetadata
|
module BuildMetadata
|
||||||
# begin ivars
|
# begin ivars
|
||||||
@release = false
|
@built_at = nil
|
||||||
# end ivars
|
# end ivars
|
||||||
|
|
||||||
# A hash representation of the build metadata.
|
# A hash representation of the build metadata.
|
||||||
def self.to_h
|
def self.to_h
|
||||||
{
|
{
|
||||||
"Built At" => built_at,
|
"Timestamp" => timestamp,
|
||||||
"Git SHA" => git_commit_sha,
|
"Git SHA" => git_commit_sha,
|
||||||
"Released Version" => release?,
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# A timestamp representing the date the bundler gem was built, or the
|
||||||
|
# current time if never built
|
||||||
|
def self.timestamp
|
||||||
|
@timestamp ||= @built_at || Time.now.utc.strftime("%Y-%m-%d").freeze
|
||||||
|
end
|
||||||
|
|
||||||
# A string representing the date the bundler gem was built.
|
# A string representing the date the bundler gem was built.
|
||||||
def self.built_at
|
def self.built_at
|
||||||
@built_at ||= Time.now.utc.strftime("%Y-%m-%d").freeze
|
@built_at
|
||||||
end
|
end
|
||||||
|
|
||||||
# The SHA for the git commit the bundler gem was built from.
|
# The SHA for the git commit the bundler gem was built from.
|
||||||
|
@ -34,10 +39,5 @@ module Bundler
|
||||||
|
|
||||||
@git_commit_sha ||= "unknown"
|
@git_commit_sha ||= "unknown"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Whether this is an official release build of Bundler.
|
|
||||||
def self.release?
|
|
||||||
@release
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -486,7 +486,7 @@ module Bundler
|
||||||
def version
|
def version
|
||||||
cli_help = current_command.name == "cli_help"
|
cli_help = current_command.name == "cli_help"
|
||||||
if cli_help || ARGV.include?("version")
|
if cli_help || ARGV.include?("version")
|
||||||
build_info = " (#{BuildMetadata.built_at} commit #{BuildMetadata.git_commit_sha})"
|
build_info = " (#{BuildMetadata.timestamp} commit #{BuildMetadata.git_commit_sha})"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !cli_help && Bundler.feature_flag.bundler_4_mode?
|
if !cli_help && Bundler.feature_flag.bundler_4_mode?
|
||||||
|
|
6
spec/bin/bundle
Executable file
6
spec/bin/bundle
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative "../bundler/support/activate"
|
||||||
|
|
||||||
|
load File.expand_path("bundle", Spec::Path.exedir)
|
|
@ -6,18 +6,20 @@ require "bundler/build_metadata"
|
||||||
RSpec.describe Bundler::BuildMetadata do
|
RSpec.describe Bundler::BuildMetadata do
|
||||||
before do
|
before do
|
||||||
allow(Time).to receive(:now).and_return(Time.at(0))
|
allow(Time).to receive(:now).and_return(Time.at(0))
|
||||||
Bundler::BuildMetadata.instance_variable_set(:@built_at, nil)
|
Bundler::BuildMetadata.instance_variable_set(:@timestamp, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#built_at" do
|
describe "#timestamp" do
|
||||||
it "returns %Y-%m-%d formatted time" do
|
it "returns %Y-%m-%d formatted current time if built_at not set" do
|
||||||
expect(Bundler::BuildMetadata.built_at).to eq "1970-01-01"
|
Bundler::BuildMetadata.instance_variable_set(:@built_at, nil)
|
||||||
|
expect(Bundler::BuildMetadata.timestamp).to eq "1970-01-01"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
describe "#release?" do
|
it "returns %Y-%m-%d formatted current time if built_at not set" do
|
||||||
it "returns false as default" do
|
Bundler::BuildMetadata.instance_variable_set(:@built_at, "2025-01-01")
|
||||||
expect(Bundler::BuildMetadata.release?).to be_falsey
|
expect(Bundler::BuildMetadata.timestamp).to eq "2025-01-01"
|
||||||
|
ensure
|
||||||
|
Bundler::BuildMetadata.instance_variable_set(:@built_at, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,10 +42,9 @@ RSpec.describe Bundler::BuildMetadata do
|
||||||
describe "#to_h" do
|
describe "#to_h" do
|
||||||
subject { Bundler::BuildMetadata.to_h }
|
subject { Bundler::BuildMetadata.to_h }
|
||||||
|
|
||||||
it "returns a hash includes Built At, Git SHA and Released Version" do
|
it "returns a hash includes Timestamp, and Git SHA" do
|
||||||
expect(subject["Built At"]).to eq "1970-01-01"
|
expect(subject["Timestamp"]).to eq "1970-01-01"
|
||||||
expect(subject["Git SHA"]).to be_instance_of(String)
|
expect(subject["Git SHA"]).to be_instance_of(String)
|
||||||
expect(subject["Released Version"]).to be_falsey
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -423,7 +423,7 @@ RSpec.describe Bundler::SharedHelpers do
|
||||||
it "sets BUNDLE_BIN_PATH to the bundle executable file" do
|
it "sets BUNDLE_BIN_PATH to the bundle executable file" do
|
||||||
subject.set_bundle_environment
|
subject.set_bundle_environment
|
||||||
bin_path = ENV["BUNDLE_BIN_PATH"]
|
bin_path = ENV["BUNDLE_BIN_PATH"]
|
||||||
expect(bin_path).to eq(bindir.join("bundle").to_s)
|
expect(bin_path).to eq(exedir.join("bundle").to_s)
|
||||||
expect(File.exist?(bin_path)).to be true
|
expect(File.exist?(bin_path)).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,13 +32,34 @@ RSpec.describe "bundle version" do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with version" do
|
context "with version" do
|
||||||
it "outputs the version, virtual version if set, and build metadata" do
|
context "when released", :ruby_repo do
|
||||||
bundle "version"
|
before do
|
||||||
expect(out).to match(/\ABundler version #{Regexp.escape(Bundler::VERSION)} \(\d{4}-\d{2}-\d{2} commit #{COMMIT_HASH}\)\z/)
|
system_gems "bundler-2.9.9", released: true
|
||||||
|
end
|
||||||
|
|
||||||
bundle "config simulate_version 4"
|
it "outputs the version, virtual version if set, and build metadata" do
|
||||||
bundle "version"
|
bundle "version"
|
||||||
expect(out).to match(/\A#{Regexp.escape(Bundler::VERSION)} \(simulating Bundler 4\) \(\d{4}-\d{2}-\d{2} commit #{COMMIT_HASH}\)\z/)
|
expect(out).to match(/\ABundler version 2\.9\.9 \(2100-01-01 commit #{COMMIT_HASH}\)\z/)
|
||||||
|
|
||||||
|
bundle "config simulate_version 4"
|
||||||
|
bundle "version"
|
||||||
|
expect(out).to match(/\A2\.9\.9 \(simulating Bundler 4\) \(2100-01-01 commit #{COMMIT_HASH}\)\z/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when not released" do
|
||||||
|
before do
|
||||||
|
system_gems "bundler-2.9.9", released: false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "outputs the version, virtual version if set, and build metadata" do
|
||||||
|
bundle "version"
|
||||||
|
expect(out).to match(/\ABundler version 2\.9\.9 \(20\d{2}-\d{2}-\d{2} commit #{COMMIT_HASH}\)\z/)
|
||||||
|
|
||||||
|
bundle "config simulate_version 4"
|
||||||
|
bundle "version"
|
||||||
|
expect(out).to match(/\A2\.9\.9 \(simulating Bundler 4\) \(20\d{2}-\d{2}-\d{2} commit #{COMMIT_HASH}\)\z/)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -141,8 +141,7 @@ RSpec.shared_examples "bundle install --standalone" do
|
||||||
|
|
||||||
describe "with default gems and a lockfile", :ruby_repo do
|
describe "with default gems and a lockfile", :ruby_repo do
|
||||||
it "works and points to the vendored copies, not to the default copies" do
|
it "works and points to the vendored copies, not to the default copies" do
|
||||||
base_system_gems "psych", "etc", path: scoped_gem_path(bundled_app("bundle"))
|
base_system_gems "stringio", "psych", "etc", path: scoped_gem_path(bundled_app("bundle"))
|
||||||
base_system_gems "stringio", path: scoped_gem_path(bundled_app("bundle")) if Gem.ruby_version < Gem::Version.new("3.3.0.a") || Gem.rubygems_version < Gem::Version.new("3.6.0.a")
|
|
||||||
|
|
||||||
build_gem "foo", "1.0.0", to_system: true, default: true do |s|
|
build_gem "foo", "1.0.0", to_system: true, default: true do |s|
|
||||||
s.add_dependency "bar"
|
s.add_dependency "bar"
|
||||||
|
@ -179,8 +178,7 @@ RSpec.shared_examples "bundle install --standalone" do
|
||||||
|
|
||||||
it "works for gems with extensions and points to the vendored copies, not to the default copies" do
|
it "works for gems with extensions and points to the vendored copies, not to the default copies" do
|
||||||
simulate_platform "arm64-darwin-23" do
|
simulate_platform "arm64-darwin-23" do
|
||||||
base_system_gems "psych", "etc", "shellwords", "open3", path: scoped_gem_path(bundled_app("bundle"))
|
base_system_gems "stringio", "psych", "etc", "shellwords", "open3", path: scoped_gem_path(bundled_app("bundle"))
|
||||||
base_system_gems "stringio", path: scoped_gem_path(bundled_app("bundle")) if Gem.ruby_version < Gem::Version.new("3.3.0.a") || Gem.rubygems_version < Gem::Version.new("3.6.0.a")
|
|
||||||
|
|
||||||
build_gem "baz", "1.0.0", to_system: true, default: true, &:add_c_extension
|
build_gem "baz", "1.0.0", to_system: true, default: true, &:add_c_extension
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,10 @@ module Spec
|
||||||
include Spec::Path
|
include Spec::Path
|
||||||
include Spec::Helpers
|
include Spec::Helpers
|
||||||
|
|
||||||
def write_build_metadata(dir: source_root)
|
def write_build_metadata(dir: source_root, version: Bundler::VERSION)
|
||||||
build_metadata = {
|
build_metadata = {
|
||||||
git_commit_sha: git_commit_sha,
|
git_commit_sha: git_commit_sha,
|
||||||
built_at: loaded_gemspec.date.utc.strftime("%Y-%m-%d"),
|
built_at: release_date_for(version, dir: dir),
|
||||||
release: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
replace_build_metadata(build_metadata, dir: dir)
|
replace_build_metadata(build_metadata, dir: dir)
|
||||||
|
@ -20,7 +19,7 @@ module Spec
|
||||||
|
|
||||||
def reset_build_metadata(dir: source_root)
|
def reset_build_metadata(dir: source_root)
|
||||||
build_metadata = {
|
build_metadata = {
|
||||||
release: false,
|
built_at: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
replace_build_metadata(build_metadata, dir: dir)
|
replace_build_metadata(build_metadata, dir: dir)
|
||||||
|
@ -44,6 +43,11 @@ module Spec
|
||||||
ruby_core_tarball? ? "unknown" : git("rev-parse --short HEAD", source_root).strip
|
ruby_core_tarball? ? "unknown" : git("rev-parse --short HEAD", source_root).strip
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def release_date_for(version, dir:)
|
||||||
|
changelog = File.expand_path("CHANGELOG.md", dir)
|
||||||
|
File.readlines(changelog)[2].scan(/^## #{Regexp.escape(version)} \((.*)\)/).first&.first if File.exist?(changelog)
|
||||||
|
end
|
||||||
|
|
||||||
extend self
|
extend self
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -450,9 +450,10 @@ module Spec
|
||||||
end
|
end
|
||||||
|
|
||||||
@context.replace_version_file(@version, dir: build_path)
|
@context.replace_version_file(@version, dir: build_path)
|
||||||
|
@context.replace_changelog(@version, dir: build_path) if options[:released]
|
||||||
@context.replace_required_ruby_version(@required_ruby_version, dir: build_path) if @required_ruby_version
|
@context.replace_required_ruby_version(@required_ruby_version, dir: build_path) if @required_ruby_version
|
||||||
|
|
||||||
Spec::BuildMetadata.write_build_metadata(dir: build_path)
|
Spec::BuildMetadata.write_build_metadata(dir: build_path, version: @version)
|
||||||
|
|
||||||
@context.gem_command "build #{@context.relative_gemspec}", dir: build_path
|
@context.gem_command "build #{@context.relative_gemspec}", dir: build_path
|
||||||
|
|
||||||
|
|
6
spec/bundler/support/bundle
Executable file
6
spec/bundler/support/bundle
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require_relative "../bundler/support/activate"
|
||||||
|
|
||||||
|
load File.expand_path("bundle", Spec::Path.exedir)
|
|
@ -1,5 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "activate"
|
require_relative "path"
|
||||||
|
|
||||||
load File.expand_path("bundle", Spec::Path.bindir)
|
warn "#{__FILE__} is deprecated. Please use #{Spec::Path.dev_binstub} instead"
|
||||||
|
|
||||||
|
load Spec::Path.dev_binstub
|
||||||
|
|
|
@ -316,7 +316,7 @@ module Spec
|
||||||
gem_name = g.to_s
|
gem_name = g.to_s
|
||||||
if gem_name.start_with?("bundler")
|
if gem_name.start_with?("bundler")
|
||||||
version = gem_name.match(/\Abundler-(?<version>.*)\z/)[:version] if gem_name != "bundler"
|
version = gem_name.match(/\Abundler-(?<version>.*)\z/)[:version] if gem_name != "bundler"
|
||||||
with_built_bundler(version) {|gem_path| install_gem(gem_path, install_dir, default) }
|
with_built_bundler(version, released: options.fetch(:released, false)) {|gem_path| install_gem(gem_path, install_dir, default) }
|
||||||
elsif %r{\A(?:[a-zA-Z]:)?/.*\.gem\z}.match?(gem_name)
|
elsif %r{\A(?:[a-zA-Z]:)?/.*\.gem\z}.match?(gem_name)
|
||||||
install_gem(gem_name, install_dir, default)
|
install_gem(gem_name, install_dir, default)
|
||||||
else
|
else
|
||||||
|
@ -341,10 +341,10 @@ module Spec
|
||||||
gem_command "install #{args} '#{path}'"
|
gem_command "install #{args} '#{path}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_built_bundler(version = nil, &block)
|
def with_built_bundler(version = nil, opts = {}, &block)
|
||||||
require_relative "builders"
|
require_relative "builders"
|
||||||
|
|
||||||
Builders::BundlerBuilder.new(self, "bundler", version)._build(&block)
|
Builders::BundlerBuilder.new(self, "bundler", version)._build(opts, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_gem_path_as(path)
|
def with_gem_path_as(path)
|
||||||
|
|
|
@ -45,8 +45,16 @@ module Spec
|
||||||
@dev_gemfile ||= tool_dir.join("dev_gems.rb")
|
@dev_gemfile ||= tool_dir.join("dev_gems.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dev_binstub
|
||||||
|
@dev_binstub ||= bindir.join("bundle")
|
||||||
|
end
|
||||||
|
|
||||||
def bindir
|
def bindir
|
||||||
@bindir ||= source_root.join(ruby_core? ? "libexec" : "exe")
|
@bindir ||= source_root.join(ruby_core? ? "spec/bin" : "bin")
|
||||||
|
end
|
||||||
|
|
||||||
|
def exedir
|
||||||
|
@exedir ||= source_root.join(ruby_core? ? "libexec" : "exe")
|
||||||
end
|
end
|
||||||
|
|
||||||
def installed_bindir
|
def installed_bindir
|
||||||
|
@ -63,7 +71,7 @@ module Spec
|
||||||
|
|
||||||
def path
|
def path
|
||||||
env_path = ENV["PATH"]
|
env_path = ENV["PATH"]
|
||||||
env_path = env_path.split(File::PATH_SEPARATOR).reject {|path| path == bindir.to_s }.join(File::PATH_SEPARATOR) if ruby_core?
|
env_path = env_path.split(File::PATH_SEPARATOR).reject {|path| path == exedir.to_s }.join(File::PATH_SEPARATOR) if ruby_core?
|
||||||
env_path
|
env_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -280,6 +288,13 @@ module Spec
|
||||||
File.open(gemspec_file, "w") {|f| f << contents }
|
File.open(gemspec_file, "w") {|f| f << contents }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def replace_changelog(version, dir:)
|
||||||
|
changelog = File.expand_path("CHANGELOG.md", dir)
|
||||||
|
contents = File.readlines(changelog)
|
||||||
|
contents = [contents[0], contents[1], "## #{version} (2100-01-01)\n", *contents[3..-1]].join
|
||||||
|
File.open(changelog, "w") {|f| f << contents }
|
||||||
|
end
|
||||||
|
|
||||||
def git_root
|
def git_root
|
||||||
ruby_core? ? source_root : source_root.parent
|
ruby_core? ? source_root : source_root.parent
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,7 +52,7 @@ module Spec
|
||||||
def setup_test_paths
|
def setup_test_paths
|
||||||
ENV["BUNDLE_PATH"] = nil
|
ENV["BUNDLE_PATH"] = nil
|
||||||
ENV["PATH"] = [Path.system_gem_path("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
|
ENV["PATH"] = [Path.system_gem_path("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
|
||||||
ENV["PATH"] = [Path.bindir, ENV["PATH"]].join(File::PATH_SEPARATOR) if Path.ruby_core?
|
ENV["PATH"] = [Path.exedir, ENV["PATH"]].join(File::PATH_SEPARATOR) if Path.ruby_core?
|
||||||
end
|
end
|
||||||
|
|
||||||
def install_test_deps
|
def install_test_deps
|
||||||
|
@ -100,7 +100,7 @@ module Spec
|
||||||
|
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
# We don't use `Open3` here because it does not work on JRuby + Windows
|
# We don't use `Open3` here because it does not work on JRuby + Windows
|
||||||
output = `ruby #{File.expand_path("support/bundle.rb", Path.spec_dir)} #{args.shelljoin}`
|
output = `ruby #{Path.dev_binstub} #{args.shelljoin}`
|
||||||
raise output unless $?.success?
|
raise output unless $?.success?
|
||||||
output
|
output
|
||||||
ensure
|
ensure
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue