Skip to content

Commit 233930e

Browse files
Merge pull request #7795 from rubygems/deivid-rodriguez/truffleruby
Fix truffleruby removing gems from lockfile
2 parents 1c68aaa + b64c980 commit 233930e

File tree

11 files changed

+142
-13
lines changed

11 files changed

+142
-13
lines changed

.github/workflows/ubuntu-lint.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@ permissions: # added using https://github.com/step-security/secure-workflows
1616

1717
jobs:
1818
ubuntu_lint:
19-
name: Lint
19+
name: Lint on ${{ matrix.ruby.name }}
2020
runs-on: ubuntu-22.04
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
ruby:
25+
- { name: ruby, value: 3.3.4 }
26+
- { name: truffleruby, value: truffleruby-24.0.1 }
2127
env:
2228
RUBYOPT: -Ilib
2329
steps:
2430
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2531
- name: Setup ruby
2632
uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0
2733
with:
28-
ruby-version: 3.3.4
34+
ruby-version: ${{ matrix.ruby.value }}
2935
bundler: none
3036
- name: Install Dependencies
3137
run: bin/rake setup

bundler/lib/bundler/definition.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ def materialize(dependencies)
630630
def start_resolution
631631
local_platform_needed_for_resolvability = @most_specific_non_local_locked_ruby_platform && !@platforms.include?(local_platform)
632632
@platforms << local_platform if local_platform_needed_for_resolvability
633+
add_platform(Gem::Platform::RUBY) if RUBY_ENGINE == "truffleruby"
633634

634635
result = SpecSet.new(resolver.start)
635636

bundler/lib/bundler/force_platform.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
module Bundler
44
module ForcePlatform
5-
private
6-
75
# The `:force_ruby_platform` value used by dependencies for resolution, and
86
# by locked specifications for materialization is `false` by default, except
97
# for TruffleRuby. TruffleRuby generally needs to force the RUBY platform

bundler/lib/bundler/rubygems_ext.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,12 @@ class Dependency
237237

238238
include ::Bundler::ForcePlatform
239239

240+
attr_reader :force_ruby_platform
241+
240242
attr_accessor :source, :groups
241243

242244
alias_method :eql?, :==
243245

244-
def force_ruby_platform
245-
return @force_ruby_platform if defined?(@force_ruby_platform) && !@force_ruby_platform.nil?
246-
247-
@force_ruby_platform = default_force_ruby_platform
248-
end
249-
250246
unless method_defined?(:encode_with, false)
251247
def encode_with(coder)
252248
[:@name, :@requirement, :@type, :@prerelease, :@version_requirements].each do |ivar|

bundler/lib/bundler/spec_set.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def specs_for_dependency(dep, platform)
280280
if platform
281281
GemHelpers.select_best_platform_match(specs_for_name, platform, force_ruby: dep.force_ruby_platform)
282282
else
283-
GemHelpers.select_best_local_platform_match(specs_for_name, force_ruby: dep.force_ruby_platform)
283+
GemHelpers.select_best_local_platform_match(specs_for_name, force_ruby: dep.force_ruby_platform || dep.default_force_ruby_platform)
284284
end
285285
end
286286

bundler/spec/commands/lock_spec.rb

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,10 +1797,11 @@
17971797
G
17981798
end
17991799

1800-
it "locks ruby specs" do
1800+
it "locks both ruby and platform specific specs" do
18011801
checksums = checksums_section_when_enabled do |c|
18021802
c.no_checksum "foo", "1.0"
1803-
c.no_checksum "nokogiri", "1.14.2"
1803+
c.checksum gem_repo4, "nokogiri", "1.14.2"
1804+
c.checksum gem_repo4, "nokogiri", "1.14.2", "x86_64-linux"
18041805
end
18051806

18061807
simulate_platform "x86_64-linux" do
@@ -1818,6 +1819,7 @@
18181819
remote: https://gem.repo4/
18191820
specs:
18201821
nokogiri (1.14.2)
1822+
nokogiri (1.14.2-x86_64-linux)
18211823
18221824
PLATFORMS
18231825
ruby
@@ -1830,6 +1832,73 @@
18301832
#{Bundler::VERSION}
18311833
L
18321834
end
1835+
1836+
context "and a lockfile with platform specific gems only already exists" do
1837+
before do
1838+
checksums = checksums_section_when_enabled do |c|
1839+
c.no_checksum "foo", "1.0"
1840+
c.checksum gem_repo4, "nokogiri", "1.14.2", "x86_64-linux"
1841+
end
1842+
1843+
lockfile <<~L
1844+
PATH
1845+
remote: .
1846+
specs:
1847+
foo (1.0)
1848+
nokogiri
1849+
1850+
GEM
1851+
remote: https://gem.repo4/
1852+
specs:
1853+
nokogiri (1.14.2-x86_64-linux)
1854+
1855+
PLATFORMS
1856+
x86_64-linux
1857+
1858+
DEPENDENCIES
1859+
foo!
1860+
#{checksums}
1861+
BUNDLED WITH
1862+
#{Bundler::VERSION}
1863+
L
1864+
end
1865+
1866+
it "keeps platform specific gems" do
1867+
checksums = checksums_section_when_enabled do |c|
1868+
c.no_checksum "foo", "1.0"
1869+
c.checksum gem_repo4, "nokogiri", "1.14.2"
1870+
c.checksum gem_repo4, "nokogiri", "1.14.2", "x86_64-linux"
1871+
end
1872+
1873+
simulate_platform "x86_64-linux" do
1874+
bundle "install"
1875+
end
1876+
1877+
expect(lockfile).to eq <<~L
1878+
PATH
1879+
remote: .
1880+
specs:
1881+
foo (1.0)
1882+
nokogiri
1883+
1884+
GEM
1885+
remote: https://gem.repo4/
1886+
specs:
1887+
nokogiri (1.14.2)
1888+
nokogiri (1.14.2-x86_64-linux)
1889+
1890+
PLATFORMS
1891+
ruby
1892+
x86_64-linux
1893+
1894+
DEPENDENCIES
1895+
foo!
1896+
#{checksums}
1897+
BUNDLED WITH
1898+
#{Bundler::VERSION}
1899+
L
1900+
end
1901+
end
18331902
end
18341903

18351904
context "when adding a new gem that requires unlocking other transitive deps" do

bundler/spec/install/gems/resolving_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,4 +673,55 @@
673673
expect(err).to end_with(nice_error)
674674
end
675675
end
676+
677+
context "when non platform specific gems bring more dependencies", :truffleruby_only do
678+
before do
679+
build_repo4 do
680+
build_gem "foo", "1.0" do |s|
681+
s.add_dependency "bar"
682+
end
683+
684+
build_gem "foo", "2.0" do |s|
685+
s.platform = "x86_64-linux"
686+
end
687+
688+
build_gem "bar"
689+
end
690+
691+
gemfile <<-G
692+
source "https://gem.repo4"
693+
gem "foo"
694+
G
695+
end
696+
697+
it "locks both ruby and current platform, and resolve to ruby variants that install on truffleruby" do
698+
checksums = checksums_section_when_enabled do |c|
699+
c.checksum gem_repo4, "foo", "1.0"
700+
c.checksum gem_repo4, "bar", "1.0"
701+
end
702+
703+
simulate_platform "x86_64-linux" do
704+
bundle "install"
705+
706+
expect(lockfile).to eq <<~L
707+
GEM
708+
remote: https://gem.repo4/
709+
specs:
710+
bar (1.0)
711+
foo (1.0)
712+
bar
713+
714+
PLATFORMS
715+
ruby
716+
x86_64-linux
717+
718+
DEPENDENCIES
719+
foo
720+
#{checksums}
721+
BUNDLED WITH
722+
#{Bundler::VERSION}
723+
L
724+
end
725+
end
726+
end
676727
end

tool/bundler/dev_gems.rb.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ GEM
5757
webrick (1.8.1)
5858

5959
PLATFORMS
60+
aarch64-darwin
6061
arm64-darwin-22
6162
arm64-darwin-23
6263
java
64+
ruby
6365
universal-java-11
6466
universal-java-18
6567
universal-java-19

tool/bundler/release_gems.rb.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ GEM
3838
uri (0.13.0)
3939

4040
PLATFORMS
41+
aarch64-darwin
4142
aarch64-linux
4243
arm64-darwin-20
4344
arm64-darwin-21
4445
arm64-darwin-22
4546
arm64-darwin-23
47+
ruby
4648
universal-java-11
4749
universal-java-18
4850
x86_64-darwin-20

tool/bundler/rubocop_gems.rb.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ GEM
5353
unicode-display_width (2.5.0)
5454

5555
PLATFORMS
56+
aarch64-darwin
5657
aarch64-linux
5758
arm64-darwin-20
5859
arm64-darwin-21
5960
arm64-darwin-22
6061
arm64-darwin-23
62+
ruby
6163
universal-java-11
6264
universal-java-18
6365
universal-java-19

0 commit comments

Comments
 (0)