Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow compatibility with Ruby 2.6 #18

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version: [2.7, "3.0", 3.1, 3.2]
ruby-version: [2.6, 2.7, "3.0", 3.1, 3.2]
bundler-version: [2.4.19, 2.4.22, 2.5.2]
exclude:
- ruby-version: 2.6
bundler-version: 2.5.2
- ruby-version: 2.7
bundler-version: 2.5.2
env:
BUNDLER_VERSION: ${{ matrix.bundler-version }}
BUNDLE_LOCKFILE: active
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/*.gem
/pkg
/.bundle/
/pkg/
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ require:
- rubocop-rake

AllCops:
TargetRubyVersion: 2.7
TargetRubyVersion: 2.6

Bundler/DuplicatedGem:
Enabled: false

Naming/FileName:
Exclude:
Expand Down
21 changes: 21 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,24 @@ source "https://rubygems.org"
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

plugin "bundler-multilock", path: "."
return unless Plugin.installed?("bundler-multilock")

Plugin.send(:load_plugin, "bundler-multilock")

lockfile active: RUBY_VERSION >= "2.7" do
gem "debug", "~> 1.9", require: false
gem "irb", "~> 1.11", require: false
gem "rubocop-inst", "~> 1.0", require: false
gem "rubocop-rake", "~> 0.6", require: false
gem "rubocop-rspec", "~> 2.24", require: false
gem "stringio", "~> 3.1", require: false
end

lockfile "ruby-2.6", active: RUBY_VERSION < "2.7" do
# newer versions of these gems are not compatible with Ruby > 2.6
gem "debug", "1.8.0", require: false
gem "irb", "1.6.3", require: false
gem "stringio", "3.0.6", require: false
end
22 changes: 12 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ GEM
specs:
ast (2.4.2)
base64 (0.1.1)
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
debug (1.9.0)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.0)
io-console (0.6.0)
irb (1.8.1)
io-console (0.7.1)
irb (1.11.0)
rdoc
reline (>= 0.3.8)
json (2.6.3)
Expand All @@ -23,15 +23,15 @@ GEM
parser (3.2.2.3)
ast (~> 2.4.1)
racc
psych (5.1.0)
psych (5.1.2)
stringio
racc (1.7.1)
rainbow (3.1.1)
rake (13.0.6)
rdoc (6.5.0)
rdoc (6.6.2)
psych (>= 4.0.0)
regexp_parser (2.8.1)
reline (0.3.8)
reline (0.4.1)
io-console (~> 0.5)
rexml (3.2.6)
rspec (3.12.0)
Expand Down Expand Up @@ -78,7 +78,7 @@ GEM
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
stringio (3.0.8)
stringio (3.1.0)
unicode-display_width (2.4.2)

PLATFORMS
Expand All @@ -90,12 +90,14 @@ PLATFORMS

DEPENDENCIES
bundler-multilock!
debug (~> 1.8)
debug (~> 1.9)
irb (~> 1.11)
rake (~> 13.0)
rspec (~> 3.12)
rubocop-inst (~> 1.0)
rubocop-rake (~> 0.6)
rubocop-rspec (~> 2.24)
stringio (~> 3.1)

BUNDLED WITH
2.5.2
51 changes: 51 additions & 0 deletions Gemfile.ruby-2.6.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
PATH
remote: .
specs:
bundler-multilock (1.2.1)
bundler (>= 2.4.19, < 2.6)

GEM
remote: https://rubygems.org/
specs:
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
diff-lcs (1.5.0)
io-console (0.7.1)
irb (1.6.3)
reline (>= 0.3.0)
rake (13.0.6)
reline (0.4.1)
io-console (~> 0.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
stringio (3.0.6)

PLATFORMS
aarch64-linux
arm64-darwin
ruby
x86_64-darwin
x86_64-linux

DEPENDENCIES
bundler-multilock!
debug (= 1.8.0)
irb (= 1.6.3)
rake (~> 13.0)
rspec (~> 3.12)
stringio (= 3.0.6)

BUNDLED WITH
2.5.2
6 changes: 1 addition & 5 deletions bundler-multilock.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ Gem::Specification.new do |spec|
spec.files = Dir.glob("lib/**/*") + %w[plugins.rb]
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.7"
spec.required_ruby_version = ">= 2.6"

spec.add_dependency "bundler", ">= 2.4.19", "< 2.6"

spec.add_development_dependency "debug", "~> 1.8"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.12"
spec.add_development_dependency "rubocop-inst", "~> 1.0"
spec.add_development_dependency "rubocop-rake", "~> 0.6"
spec.add_development_dependency "rubocop-rspec", "~> 2.24"
end
3 changes: 2 additions & 1 deletion lib/bundler/multilock/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ def check(lockfile_definition)
private

def cache_reverse_dependencies(lockfile)
reverse_dependencies = Hash.new { |h, k| h[k] = Gem::Requirement.default_prerelease }
# can use Gem::Requirement.default_prelease when Ruby 2.6 support is dropped
reverse_dependencies = Hash.new { |h, k| h[k] = Gem::Requirement.new(">= 0.a") }

lockfile.dependencies.each_value do |spec|
reverse_dependencies[spec.name].requirements.concat(spec.requirement.requirements)
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/multilock/ext/plugin/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module PluginExt
module DSL
::Bundler::Plugin::DSL.include(self)

def lockfile(...)
def lockfile(*, **)
# pass
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/multilock/ext/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Ext
module Source
::Bundler::Source.prepend(self)

def print_using_message(...)
def print_using_message(*)
return if Bundler.settings[:suppress_install_using_messages]

super
Expand Down
62 changes: 31 additions & 31 deletions spec/bundler/multilock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,28 +303,28 @@
it "syncs from a parent lockfile" do
with_gemfile(<<~RUBY) do
lockfile do
gem "activesupport", "~> 7.0.0"
gem "activesupport", "~> 6.1.0"
end

lockfile("6.1") do
gem "activesupport", "~> 6.1.0"
lockfile("6.0") do
gem "activesupport", "~> 6.0.0"
end

lockfile("6.1-alt", parent: "6.1") do
gem "activesupport", "> 6.0", "< 7.2"
lockfile("6.0-alt", parent: "6.0") do
gem "activesupport", "> 5.2", "< 7.2"
end
RUBY
invoke_bundler("install")

default = invoke_bundler("info activesupport").split("\n").first
six_one = invoke_bundler("info activesupport", env: { "BUNDLE_LOCKFILE" => "6.1" }).split("\n").first
alt = invoke_bundler("info activesupport", env: { "BUNDLE_LOCKFILE" => "6.1-alt" }).split("\n").first
default = invoke_bundler("info activesupport")
six_oh = invoke_bundler("info activesupport 2> /dev/null", env: { "BUNDLE_LOCKFILE" => "6.0" })
alt = invoke_bundler("info activesupport 2> /dev/null", env: { "BUNDLE_LOCKFILE" => "6.0-alt" })

expect(default).to include("7.0")
expect(default).not_to eq six_one
expect(six_one).to include("6.1")
# alt is the same as 6.1, even though it should allow 7.1
expect(alt).to eq six_one
expect(default).to include("6.1")
expect(default).not_to eq six_oh
expect(six_oh).to include("6.0")
# alt is the same as 6.0, even though it should allow 6.1
expect(alt).to eq six_oh
end
end

Expand Down Expand Up @@ -359,23 +359,23 @@
it "notifies about mismatched versions between different lockfiles" do
with_gemfile(<<~RUBY) do
lockfile do
gem "activesupport", ">= 6.1", "< 7.2"
gem "activesupport", ">= 6.0", "< 7.0"
end

lockfile("full") do
gem "activesupport", "6.1.7.6"
gem "activesupport", "6.0.6.1"
end
RUBY
expect do
invoke_bundler("install")
end.to raise_error(Regexp.new("activesupport \\(6.1.7.6\\) in Gemfile.full.lock " \
end.to raise_error(Regexp.new("activesupport \\(6.0.6.1\\) in Gemfile.full.lock " \
"does not match the parent lockfile's version"))
end
end

it "notifies about mismatched versions between different lockfiles for sub-dependencies" do
with_gemfile(<<~RUBY) do
gem "activesupport", "7.0.4.3" # depends on tzinfo ~> 2.0, so will get >= 2.0.6
gem "activesupport", "6.1.7.6" # depends on tzinfo ~> 2.0, so will get >= 2.0.6

lockfile("full") do
gem "tzinfo", "2.0.5"
Expand All @@ -392,18 +392,18 @@
it "allows mismatched explicit dependencies by default" do
with_gemfile(<<~RUBY) do
lockfile do
gem "activesupport", "~> 6.1.0"
gem "activesupport", "~> 6.0.0"
end

lockfile("new") do
gem "activesupport", "7.0.4.3"
gem "activesupport", "6.1.7.6"
end
RUBY
invoke_bundler("install") # no error
expect(File.read("Gemfile.lock")).to include("6.1.")
expect(File.read("Gemfile.lock")).not_to include("7.0.4.3")
expect(File.read("Gemfile.new.lock")).not_to include("6.1.")
expect(File.read("Gemfile.new.lock")).to include("7.0.4.3")
expect(File.read("Gemfile.lock")).to include("6.0.")
expect(File.read("Gemfile.lock")).not_to include("6.1.7.6")
expect(File.read("Gemfile.new.lock")).not_to include("6.0.")
expect(File.read("Gemfile.new.lock")).to include("6.1.7.6")
end
end

Expand Down Expand Up @@ -686,8 +686,8 @@
with_gemfile(<<~RUBY) do
gemspec

lockfile("rails-7.0", default: true) do
gem "activesupport", "~> 7.0.0"
lockfile("rails-6.1", default: true) do
gem "activesupport", "~> 6.1.0"
end
RUBY
create_local_gem("test", subdirectory: false)
Expand All @@ -701,11 +701,11 @@
it "does not re-sync lockfiles that have conflicting sub-dependencies" do
with_gemfile(<<~RUBY) do
lockfile do
gem "activemodel", "~> 7.1.0"
gem "activemodel", "~> 6.1.0"
end

lockfile("rails-7.0") do
gem "activemodel", "~> 7.0.0"
lockfile("rails-6.0") do
gem "activemodel", "~> 6.0.0"
end
RUBY
output = invoke_bundler("install")
Expand All @@ -718,15 +718,15 @@

it "removes now-missing explicit dependencies from secondary lockfiles" do
with_gemfile(<<~RUBY) do
gem "inst-jobs", "3.1.13"
gem "inst-jobs", "3.1.6"
gem "activerecord-pg-extensions"

lockfile("alt") {}
RUBY
invoke_bundler("install")

write_gemfile(<<~RUBY)
gem "inst-jobs", "3.1.13"
gem "inst-jobs", "3.1.6"

lockfile("alt") {}
RUBY
Expand All @@ -739,7 +739,7 @@
it "does not evaluate the default lockfile at all if an alternate is active, " \
"without specifying that lockfile explicitly" do
with_gemfile(<<~RUBY) do
gem "inst-jobs", "3.1.13"
gem "inst-jobs", "3.1.6"

lockfile active: ENV["ALTERNATE"] != "1" do
raise "evaluated!" if ENV["ALTERNATE"] == "1"
Expand Down