Commit graph

280 commits

Author SHA1 Message Date
David Rodríguez
e2fbd01714 [rubygems/rubygems] Remove unnecessary endless loop detection
Fixes a TODO now that no reports have been reported in a while.

f10dc84e7b
2025-07-30 11:19:32 +09:00
David Rodríguez
e42f1aaa5a [rubygems/rubygems] Fix truffleruby failing to install sorbet-static when there's no lockfile
The generic Ruby platform was getting unconditionally added in
truffleruby, preventing resolution in situations where there's no
generic ruby version (sorbet-static). Instead, the generic platform
should be considered per dependency, not globally.

a96afc5351
2025-07-30 11:19:26 +09:00
Randy Stauner
b5beb19825 [rubygems/rubygems] Validate dependencies when doing bundle install
b0983f392f
2025-06-11 08:48:55 +09:00
Samuel Giddins
c0a1e877b3
Move most of Bundler::GemHelpers to Gem::Platform
This will help centralize wheel platform selection logic eventually

Signed-off-by: Samuel Giddins <segiddins@segiddins.me>
2025-06-06 10:22:18 +09:00
David Rodríguez
b9e3edb3e6 [rubygems/rubygems] Slightly simplify locked specification source replacement
22f0a07377
2025-06-05 19:12:46 +09:00
David Rodríguez
970eac1530 [rubygems/rubygems] Fix git source unlocking for multi-gem repositories like Rails
If you have

```
gem "rails", git: "https://github.com/rails/rails"
```

and then explicitly pin to an older ref, like

```
gem "rails", git: "https://github.com/rails/rails", ref: "99bacb5aa8"
```

Then `bundle install` fails, because locked sources fail to be updated
to use the new source.

This commit fixes the problem by making sure get their source properly
replaced.

5de8c2e0cf
2025-06-05 19:12:46 +09:00
David Rodríguez
b8b4c15695 [rubygems/rubygems] Let bundle lock --normalize-platforms remove invalid platforms
c39d2f84fd
2025-04-15 16:47:22 +09:00
David Rodríguez
1929e73a36 [rubygems/rubygems] Raise an error if bundle lock target platform is incompatible
282e4a8593
2025-04-15 16:47:21 +09:00
David Rodríguez
1b18810ed9 [rubygems/rubygems] Rename resolution_packages to resolution_base
It handles resolution packages but also other stuff.

4baec92c20
2025-04-15 16:47:21 +09:00
David Rodríguez
38024772ca [rubygems/rubygems] Refine bundle update --verbose logs
Don't mention "Found changes from the lockfile" because that's not
really true in general.

0181c278e8
2025-04-14 16:17:50 +09:00
David Rodríguez
c4a2f72b1b [rubygems/rubygems] Fix bundle lock --normalize-platforms regression
458fa5dc4c
2025-04-14 16:17:48 +09:00
David Rodríguez
dea505dea0
[rubygems/rubygems] Allow ruby platform to be remove also when dependencies have changed
Since we will now add it back if the final resolution is compatible, we
can also get this kind of edge case (`bundle add`) working.

cdc5ebec77
2025-03-31 09:39:22 +09:00
David Rodríguez
b2bcd36044
[rubygems/rubygems] Remove edge cases for not removing invalid platforms
Instead, remove them anytime we find dependencies don't match the
lockfile for a platform, and then add them back after resolution if
they ended up being valid.

220bd77887
2025-03-31 09:39:22 +09:00
David Rodríguez
f72d5effb7
[rubygems/rubygems] SpecSet#add_extra_platforms! doesn't need to return anything
9fd92ade54
2025-03-31 09:39:22 +09:00
David Rodríguez
91df1795c5
[rubygems/rubygems] Split finding and removing invalid platforms
I don't like traversing the array and modifying it at the same time
while it seems to work.

6551c74c27
2025-03-31 09:39:22 +09:00
David Rodríguez
1427629a5f [rubygems/rubygems] Remove specs with bad sources when converging dependencies
a0f7851451
2025-03-25 10:36:33 +09:00
David Rodríguez
fd43aca13b [rubygems/rubygems] Tweak to check specs size just once
4497555023
2025-03-25 10:36:33 +09:00
David Rodríguez
55930987e1 [rubygems/rubygems] Raise an error in frozen mode if CHECKSUMS entries are missing
054a0cd76c
2025-03-24 13:25:07 +09:00
David Rodríguez
131559f671 [rubygems/rubygems] Rename block variable
It's a dependency, not a specification.

9d78f5aa14
2025-03-24 13:25:07 +09:00
David Rodríguez
5bff692346 [rubygems/rubygems] Refactor replacing locked specification path sources
Instead of doing an explicit pass, let sources be replaced while checking
if specifications are up to date.

676271e804
2025-03-24 13:25:07 +09:00
David Rodríguez
28943c2820 [rubygems/rubygems] Refactor replacement of locked path sources
Instead of doing an explicit pass to preserve the source from the
Gemfile when it's a `Source::Gemspec`, add a special case to our generic
source replacement method.

20c8c42380
2025-03-24 13:25:07 +09:00
David Rodríguez
164952cef3 [rubygems/rubygems] Remove unnecessary replacement of locked dependencies sources
The `converge_dependencies` method already replaces the source of the
dependency with an equivalent source from the Gemfile if possible.

a449e7ba19
2025-03-24 13:25:07 +09:00
David Rodríguez
20f57c5dc1 [rubygems/rubygems] Refactor Path vs Gemspec source comparison
58e9bd9962
2025-03-24 13:25:07 +09:00
David Rodríguez
c55cc01b1e [rubygems/rubygems] Remove unused default value
e9f4d1e5c2
2025-03-24 13:25:07 +09:00
David Rodríguez
afda30774c [rubygems/rubygems] Reword log message about current platform being missing
It reads better this way I think.

ce9743290d
2025-03-24 13:25:07 +09:00
David Rodríguez
4e1df25b15 [rubygems/rubygems] Improve grammar of some error messages
558a4765c7
2025-03-24 13:25:07 +09:00
David Rodríguez
bb1b5877a7 [rubygems/rubygems] Consistently use "lockfile" over "lock file"
e891be9197
2025-03-24 13:25:07 +09:00
David Rodríguez
33201adf68 [rubygems/rubygems] Fix frozen error message incorrectly mentioning the Gemfile
It meant to mention the lockfile here.

2f0233a0fb
2025-03-24 13:25:07 +09:00
David Rodríguez
3e78a2f58e
[rubygems/rubygems] Improve error message when on read-only filesystems
If we fail to write the lockfile, give a better error.

81a08d6eda
2025-02-27 13:32:32 +09:00
David Rodríguez
158e4cc4ec [rubygems/rubygems] Improve log message about adding a new platform
This message is printed when running `bundle lock --add-platform`. This
command affects the lockfile, not the gemfile, and I think it's better
to use "You are adding" rather than "You added", because the addition is
happening during the current invocation (as opposed to other log
messages that talk about a change made to the Gemfile prior to running
the command).

aba1e55f5b
2025-02-25 15:36:46 +09:00
David Rodríguez
5284719273 [rubygems/rubygems] Refactor handling platform removals
And make it consistent with platform additions.

64342ae404
2025-02-25 15:36:46 +09:00
David Rodríguez
8b952e6489 [rubygems/rubygems] Improve log message when resolving due to local platform not in lockfile
Current it says "you added a new platform to your gemfile", but that's
not actually the case here.

1e39527a38
2025-02-25 15:36:46 +09:00
David Rodríguez
63600d79dc [rubygems/rubygems] Fix lockfile platforms inconveniently added on JRuby
When working with our repository on JRuby locally, I get the following
changes when running `bin/rake setup` in all of our lockfiles

```diff
diff --git a/tool/bundler/dev_gems.rb.lock b/tool/bundler/dev_gems.rb.lock
index 74550b2a40 100644
--- a/tool/bundler/dev_gems.rb.lock
+++ b/tool/bundler/dev_gems.rb.lock
@@ -66,6 +66,7 @@ PLATFORMS
   java
   ruby
   universal-java
+  universal-java-22
   x64-mingw-ucrt
   x86-linux
   x86_64-darwin
```

This is inconvenient, so I applied the same strategy we already use on
non JRuby implementations to not add the current platform to the
lockfile if a less specific platform is already there.

812b9cd1e8
2025-02-20 12:58:44 +09:00
David Rodríguez
507de2226b [rubygems/rubygems] Fix Bundler incorrectly downgrading direct dependencies
There's no reason to call `converge_specs` when adding additional
lower bound requirements to prevent downgrades, and it actually causes
the extra requirements to be missed sometimes.

Loop over the originally locked specs directly, adding the additional
precaution of not adding the requirement if the Gemfile dependency has
changed and it no longer matches the locked spec.

5154506912
2025-02-18 12:12:54 +09:00
David Rodríguez
c5cdabc14a [rubygems/rubygems] Don't try to skip requirements to prevent downgrades
These don't really hurt, so I'm not sure why I introduced it.

85b6b405ac
2025-02-18 12:12:52 +09:00
David Rodríguez
c77354157f [rubygems/rubygems] Fix locked gems being upgraded when locked dependencies are incorrect
Resolver had internal logic to prioritize locked versions when sorting
versions, however part of it was not being actually hit because of how
unlocking worked in the resolver: a package was allow to be unlocked
when that was explicit requested or when the list of unlocks was empty.
That did not make a lot of sense and other cases were working because
the explicit list of unlocks was getting "artificially filled".

Now we consider a package unlocked when explicitly requested (`bundle
update <package>`), or when everything is being unlocked (`bundle
install` with no lockfile or `bundle update`).

This makes things simpler and gets the edge case added as a test case
working as expected.

b8e55087f0
2025-02-18 12:12:51 +09:00
David Rodríguez
592eb02d6c [rubygems/rubygems] Refactor finding dependency changes
d8c4754d8f
2025-02-18 12:12:49 +09:00
David Rodríguez
533e894cb5 [rubygems/rubygems] Improve processing and categorizing unlock information
516430c3ec
2025-02-18 12:12:48 +09:00
David Rodríguez
c8f4df4ae9 [rubygems/rubygems] Make Bundler never instantiate development dependencies
Bundler does not really have a concept of "development dependencies",
like RubyGems has. Bundler has the more generic concept of "groups".

Under the hood, the `gemspec` DSL will put gemspec development
dependencies under a `:development` Gemfile group, but there's no reason
to instantiate these as development dependencies, they are regular
runtime dependencies, except that they belong in a group named
:development.

By never instantiating development dependencies at all, we avoid having
to introduce hacks to "undo" the type Bundler does not know about, and I
also think the error messages read better.

9a06fa5bda
2025-02-17 11:04:39 +09:00
David Rodríguez
e59c90118e
[rubygems/rubygems] Raise error when lockfile is missing deps in frozen mode
And avoid installing any gems.

c12700c7e4
2025-02-14 16:13:27 +09:00
David Rodríguez
151b436c9d
[rubygems/rubygems] Fix incorrect error message in frozen mode
When Bundler refuses to install in frozen mode, sometimes it would
incorrectly claim that some dependencies have been added to the Gemfile
when that's not really the case. Fix that by making sure
`locked_dependencies` always has all locked dependencies, even when
unlocking,

Additionally, the suggestion to run `bundle install` is also confusing
when unlocking, since `bundle update` is what has been run. So skip that
part as well when unlocking.

64d84ad7d8
2025-02-13 09:37:51 +09:00
David Rodríguez
ee7b74799c [rubygems/rubygems] Fix --prefer-local not respecting default gems
3df86cd9c6
2025-01-20 13:50:27 +09:00
David Rodríguez
0b1b8bc3ec [rubygems/rubygems] Don't remove platform specific variants from the lockfile unless necessary
Even if they don't match the current Ruby version, they could still work
in other rubies. So it's better to keep them.

9a3e583b0c
2025-01-14 12:24:37 +09:00
David Rodríguez
ae75c8877a [rubygems/rubygems] Extract SpecSet#version_for
a76fd6d3bf
2025-01-14 12:24:37 +09:00
David Rodríguez
29d3ea1e84 [rubygems/rubygems] Fix bundle lock --add-checksums when gems are already installed
a087c452ad
2024-12-16 19:51:16 +00:00
David Rodríguez
10de74b75b [rubygems/rubygems] Avoid needing a second pass to ignore unlocked gems
When converging locked specifications to select the ones that should be
preserved while resolving, we can avoid having to do a second pass to
ignore the ones that have been explicitly unlocked.

411742703e
2024-11-26 15:11:05 +09:00
David Rodríguez
44ad2e3f38 [rubygems/rubygems] Allow some materialized specs to be missing
As long as some spec in the materialization is complete.

9a673b0bbb
2024-11-26 15:11:05 +09:00
David Rodríguez
36fb7994fe [rubygems/rubygems] Deprecate check parameter to Bundler::SpecSet#for
3041b3d784
2024-11-26 15:11:05 +09:00
David Rodríguez
c76b1ea2a6 [rubygems/rubygems] Keep track of materializations in the original resolve
This gives more flexibility to allow further improvements.

f11a890f5e
2024-11-26 15:11:05 +09:00
David Rodríguez
e15921c694 [rubygems/rubygems] Create LazySpecifications directly with most_specific_locked_platform
So there's no need to pass it around in so many places.

784ab7481b
2024-11-26 15:11:05 +09:00