Commit graph

96 commits

Author SHA1 Message Date
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
David Rodríguez
e1896c1910
[rubygems/rubygems] Lock specs don't need the real rake gem
d795b8fcb4
2025-07-02 10:34:18 +09:00
David Rodríguez
ca1c46d33c [rubygems/rubygems] Ignore local specifications if they have incorrect dependencies
Currently ruby-dev installs an incorrect gemspec for rdoc, that does not
declare its dependency on psych.

This seems like a ruby-core bug, but it seems best for Bundler to ignore
it, go with the remote specification instead, and print a warning.

227cafd657
2025-06-06 10:22:29 +09:00
Nicholas La Roux
869a52f33a
[rubygems/rubygems] Partially phase out x64-mingw32 in favour of x64-mingw-ucrt (platforms)
- the x64-mingw32 platform has been superseded by x64-mingw-ucrt
- the mingw-ucrt platform is present as of Windows 10, which was released 10 years ago in 2015 and all versions prior to 10 are end-of-life and 10 will be by mid October 2025
- newer rubies use the mingw-ucrt platform instead of the mingw32 platform, meaning using the deprecated platform can cause issues during gem installation

b9d871022e
2025-06-03 07:47:14 +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
c4a2f72b1b [rubygems/rubygems] Fix bundle lock --normalize-platforms regression
458fa5dc4c
2025-04-14 16:17:48 +09:00
David Rodríguez
f656d34f10 [rubygems/rubygems] Refactor specs to not try to remove folders that don't exist
This has the following benefits:

* Avoid duplicated work in some specs that first build a repo, and then
  overwrite it with a completely different set of gems.
* Reduce RSpec nesting and improve readability.
* The change also made surfaces several specs that were incorrect since
  they were unintentionally not testing the right thing.

ed430883e0
2025-03-12 18:02:09 +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
63657565eb [rubygems/rubygems] Extract a TheBundle#locked_specs test helper
8cbe6573b4
2025-02-18 12:12:48 +09:00
David Rodríguez
09b04fefb7 [rubygems/rubygems] Remove unnecessary platform helpers
I think they add unnecessary indirection and inconsistency to the specs.

609924d985
2025-01-28 15:31:49 +09:00
David Rodríguez
22359cda1c [rubygems/rubygems] Refactor specs to use platform strings directly
d24c0c20e3
2025-01-28 15:31:47 +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
62b9da7088 [rubygems/rubygems] Fix bundle lock --add-checksums
Due to a typo in the spec, the issue was not caught initially. If
Bundler does not need to re-resolve, `bundle lock` is a noop so Bundler
does not add checksums.

To fix the issue, we do something similar to what `bundle install` does,
just without actually installation. First set the domain (local or
remote) according to whether a re-resolve is necessary, and then
materialize lazy specifications into real specifications, so that
checksums are actually fetched from each source.

84b6f4ee96
2024-11-25 18:14:32 +00:00
David Rodríguez
db0c7be642 [rubygems/rubygems] Add a lockfile_checksums configuration to include checksums in fresh lockfiles
50b9ef8589
2024-11-11 19:24:42 +00:00
David Rodríguez
f7b334e002 [rubygems/rubygems] Add bundle lock --add-checksums to add checksums to an existing lockfile
0a9c1ce60d
2024-11-08 10:27:03 +00:00
David Rodríguez
6dee0d3fb0 [rubygems/rubygems] Reject unknown platforms when running bundle lock --add-platform
1f93a2bdc5
2024-08-29 09:59:26 +00:00
Matt Brictson
7c794c287e [rubygems/rubygems] Emit progress to stderr when --print is passed to bundle lock
`bundle lock --print --update` can take a long time to fetch sources and
resolve the lock file.

Before, `--print` caused output to be completely silenced, so nothing
was printed at all until the resolved lock file is finally emitted to
stdout.

With this change, `--print` now prints progress to stderr. E.g.:

```
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
```

This provides a better user experience, especially when
`lock --print --update` takes several seconds or more.

The lock file is still printed to stdout, so tools consuming the lock
file on stdout will not be affected.

6719baa700
2024-08-26 14:56:26 +00:00
David Rodríguez
3005ed6816 [rubygems/rubygems] Don't remove existing platform gems when PLATFORMS section is badly indented
ec099ebf1e
2024-08-05 17:28:11 +00:00
David Rodríguez
7285e76493
Fix truffleruby removing gems from lockfile
When resolving on truffleruby, and multiple platforms are included in
the lockfile, Bundler will not respect existing platforms, but always
force ruby variants. That means removal of existing version specific
variants, introducing lockfile churn between implementations.

To prevent this, we introduce the distinction between
`Dependency#force_ruby_platform`, only settable via Gemfile, and
`Dependency#default_force_ruby_platform`, which is always true on
truffleruby for certain dependency names. This way, when resolving
lockfile gems for other platforms on truffleruby, we keep platform
specific variants in the lockfile.

However, that introduces the problem that if only platform specific
variants are locked in the lockfile, Bundler won't be able to
materialize on truffleruby because the generic variant will be missing.
To fix this additional problem, we make sure the generic "ruby" platform
is always added when resolving on truffleruby.
2024-08-05 11:58:07 +09:00
David Rodríguez
997642cfbd [rubygems/rubygems] The simulate_platform helper can take a string
680bafac1a
2024-07-30 14:02:02 +00:00
David Rodríguez
481c83453b [rubygems/rubygems] Enable checksums on Bundler 3 for fresh lockfiles
And get specs passing.

c23b5f5b84
2024-07-23 19:40:09 +00:00
David Rodríguez
3c3cce13c6 [rubygems/rubygems] Fix another case of bundle lock --add-platform doing nothing
0629e27dda
2024-07-17 11:14:53 +00:00
David Rodríguez
dd05191bc3 [rubygems/rubygems] Resolve all platforms directly
Instead of having to do a complete pass after resolve.

To do this, we add to the ruby group all the platform specs with the
same dependencies as the ruby specs.

e50415f2a6
2024-07-09 16:34:08 +00:00
David Rodríguez
5fdfdc30f1 [rubygems/rubygems] Let resolver consider unique specs from the beginning
It results in more consistent error messages.

a4b34361cc
2024-07-09 16:34:07 +00:00
David Rodríguez
a333e867aa [rubygems/rubygems] Fix spec to also pass outside of Linux
fc8c853345
2024-07-09 16:34:06 +00:00
David Rodríguez
cd57c1294d [rubygems/rubygems] Only remove current platform when added right before resolution
If it has been explicitly added by `bundle lock --add-platform`, we
don't want to remove it.

09cf921dd6
2024-07-02 19:53:54 +00:00
David Rodríguez
c36eb10d8b [rubygems/rubygems] Normalize dummy test server name
18b38ca6b4
2024-07-02 19:53:54 +00:00
David Rodríguez
98c923ff4b
Synchronize Bundler & RubyGems (#11071) 2024-06-28 10:12:29 -04:00
David Rodríguez
eef125fd09 [rubygems/rubygems] Fix error messages to not mention cached gems when they were not used
5ce9a7ff17
2024-05-24 15:02:30 +00:00
David Rodríguez
744dd5a362 [rubygems/rubygems] Fix performance regression on applications with a local cache
Even if all gems are properly installed and no resolve is needed, we
recently started always reading all packages in `vendor/cache` and
extracting specifications from them.

This commit fixes the problem by longer making considering cached specs
the default and only enable them when a resolve is actually needed.

edeb2c42bf
2024-05-24 15:02:30 +00:00
David Rodriguez
435f449b4e [rubygems/rubygems] Make sure to force latest resolvable version explicitly
To make sure we can always update to the latest resolvable version for
each gem explicitly requested for update, we first run a full update,
and then add explicit exact requirements to the resolved versions. This
may lead into conflicts, but our resolver already automatically parses
those and unlocks additional gems to fix them.

01c0bf34f0
2024-04-29 10:29:29 +00:00
David Rodriguez
e2a1d0b53d [rubygems/rubygems] Improve error message when strict resolution filters out everything
1ea44b3749
2024-04-01 15:03:28 +00:00
David Rodriguez
7b3ef370f8 [rubygems/rubygems] Fix incorrect bundle update --bundler message
146de56353
2024-03-22 13:14:42 +00:00
David Rodríguez
67940b135c [rubygems/rubygems] Bump rake version used by tests
And make it easier to update next time.

1ea4bfa5d8
2023-12-12 17:16:19 +00:00
Franz Liedke
0ec88b54f3 [rubygems/rubygems] bundle lock: Always touch the lockfile
fd2e71dfdb
2023-12-12 01:08:19 +00:00
David Rodríguez
2755cb1b2f [rubygems/rubygems] Use modern hashes consistently
bb66253f2c
2023-12-07 22:29:33 +00:00
Martin Emde
5f0ea3f590 [rubygems/rubygems] Converts Bundler lockfile checksum validation to opt-in only
Looks for the CHECKSUMS section in the lockfile, activating the feature
only if the section exists. Without a CHECKSUMS section, Bundler will
continue as normal, validating checksums when gems are installed while
checksums from the compact index are present.

2353cc93a4
2023-12-05 21:09:53 +00:00
David Rodríguez
435eb56f61 [rubygems/rubygems] Automatically lock extra ruby platforms
Since we started locking the specific platform in the lockfile, that has
created an annoying situation for users that don't develop on Linux.
They will create a lockfile on their machines, locking their local
platform, for example, darwin. But then that lockfile won't work
automatically when deploying to Heroku for example, because the lockfile
is frozen and the Linux platform is not included.

There's the chance though that resolving against two platforms (Linux +
the local platform) won't succeed while resolving for just the current
platform will. So, instead, we check other platform specific variants
available for the resolution we initially found, and lock those
platforms and specs too if they satisfy the resolution.

This is only done when generating new lockfiles from scratch, existing
lockfiles should keep working as before, and it's only done for "ruby
platforms", i.e., not Java or Windows which have their own complexities,
and so are excluded.

With this change, we expect that MacOS users can bundle locally and
deploy to Heroku without needing to do anything special.

5f24f06bc5
2023-11-13 11:06:10 +09:00
David Rodriguez
59b361aaca [rubygems/rubygems] Refactor platform test helpers
7ab4c203f9
2023-11-13 11:06:10 +09:00
David Rodríguez
a1d0c048df
[rubygems/rubygems] Fix daily Bundler CI
Daily Bundler CI against ruby-head is failing because ruby-head now
uses bigdecimal 3.1.5, so that gets locked by this spec.

This change should make the test stable until bigdecimal 99.1.5 is
bundled with Ruby :)

830326041f
2023-11-09 10:34:48 +09:00
Martin Emde
6dcd4e90d8
[rubygems/rubygems] Handle base64 encoded checksums in lockfile for future compatibility.
Save checksums using = as separator.

a36ad7d160
2023-10-23 13:59:01 +09:00
Martin Emde
c667de72ff
[rubygems/rubygems] Improve errors and register checksums reliably
Improve error reporting for checksums, raises a new error class.

Solve for multi-source checksum errors.

Add CHECKSUMS to tool/bundler/(dev|standard|rubocop)26_gems.rb

26ceee0e76

Co-authored-by: Samuel Giddins <segiddins@segiddins.me>
2023-10-23 13:59:01 +09:00
Martin Emde
92f23a48e3
[rubygems/rubygems] Refactor Checksum classes and methods to reduce
code.
(https://github.com/rubygems/rubygems/pull/6917)

2238bdaadc
2023-10-23 13:59:01 +09:00
Samuel Giddins
c5fd94073f
[rubygems/rubygems] Refactor to checksums stored via source
This gets the specs passing, and handles the fact that we expect
checkums to be pinned only to a particular source

This also avoids reading in .gem files during lockfile generation,
instead allowing us to query the source for each resolved gem to grab
the checksum

Finally, this opens up a route to having user-stored checksum databases,
similar to how other package managers do this!

Add checksums to dev lockfiles

Handle full name conflicts from different original_platforms when adding checksums to store from compact index

Specs passing on Bundler 3

86c7084e1c
2023-10-23 13:59:01 +09:00
Mercedes Bernard
69d7e9a12e
[rubygems/rubygems] Use the server checksum, then calculate from gem on disk if possible
1. Use the checksum provided by the server if provided: provides security
knowing if the gem you downloaded matches the gem on the server

2. Calculate the checksum from the gem on disk: provides security knowing
if the gem has changed between installs

3. In some cases, neither is possible in which case we don't put anything
in the checksum and we maintain functionality as it is today

Add the checksums to specs in the index if we already have them

Prior to checksums, we didn't lose any information when overwriting specs
in the index with stubs. But now when we overwrite EndpointSpecifications
or RemoteSpecifications with more generic specs, we could lose checksum
info. This manually sets checksum info so we keep it in the index.

de00a4f153
2023-10-23 13:59:01 +09:00
Thong Kuah
ad08674d8d
[rubygems/rubygems] Add CHECKSUMS for each gem in lockfile
We lock the checksum for each resolved spec under a new CHECKSUMS
section in the lockfile.

If the locked spec does not resolve for the local platform, we preserve
the locked checksum, similar to how we preserve specs.

Checksum locking only makes sense on install. The compact index
information is only available then.

bde37ca6bf
2023-10-23 13:59:01 +09:00
David Rodríguez
a05904c8ce [rubygems/rubygems] The lock command should not be affected by frozen setting
The `lock` command is specifically designed to manage the lockfile, so
running it should take precedence over any "frozen" setting.

Besides that, "frozen" is not specifically designed as "lockfile cannot
be updated" but as "installation of gems should be prevented if gemfile
is not in sync with the lockfile".

The lock command does not install any gems and preserves the property of
the lockfile being in sycn with its gemfile, so I think frozen should
not influence it.

The current behavior is quite confusing when frozen is set. On an app
where rubocop can get lockfile updates

```
$ bundle lock --update rubocop
Writing lockfile to /path/to/Gemfile.lock
```

Completely silent, it makes you think that it has written the lockfile,
but still no updates.

In verbose mode, it gives a bit more information, but still confusing
and unexpected, and does not change the lockfile:

```
$ bundle lock --update rubocop --verbose
Running `bundle lock --update "rubocop" --verbose` with bundler 2.4.20
Frozen, using resolution from the lockfile
Writing lockfile to /path/to/Gemfile.lock
```

With this commit, it updates the lockfile as expected.

1d501ae8ea
2023-10-16 13:52:12 +09:00
David Rodriguez
57c3e45ee8 [rubygems/rubygems] Fix bundle lock --minor --update <dep> edge case
When the latest allowed minor of `dep` adds a new dependency, that new
dependency would be incorrectly resolved to the latest minor of the
first major version.

fd50c9d4f3
2023-09-27 03:29:37 +00:00
David Rodríguez
c31a9cf829 [rubygems/rubygems] Refactor spec helpers for reading lockfiles
ea2a30ba08
2023-07-24 14:59:33 +09:00