37 Commits

Author SHA1 Message Date
Eric Huss
1ce8023626 Rustfmt 2024 2025-07-05 19:50:36 -07:00
Eric Huss
5c19611910 Update tests now that 1.88 is stable 2025-06-27 08:19:34 -07:00
Ross Sullivan
30b6707135
chore: Moved remaining cargo_exe logic to testsuite 2025-06-25 23:18:08 +09:00
Ross Sullivan
92d9a94d02
chore: Migrated testsuite to testsuite::prelude 2025-06-25 22:37:24 +09:00
0xPoe
5f900981de refactor: replace InternedString with into() conversions across the codebase
Signed-off-by: 0xPoe <techregister@pm.me>
2025-06-14 23:43:16 +02:00
Eric Huss
659e27413c Stabilize automatic garbage collection. 2025-03-31 09:28:44 -07:00
Eric Huss
efb3419d47 Rename the gc config table
This renames the gc config table to `[cache]` to help avoid some
confusion, and to set up a namespace for possible expansion in the
future for different kind of cache controls.

Low-level settings are stuffed into the `[cache.global-clean]` table,
but we do not expect to stabilize these at this time. Only the top-level
`cache.auto-clean-frequency` setting is expected to be stabilized.

Closes https://github.com/rust-lang/cargo/issues/14292
2025-03-30 04:45:07 -07:00
Ed Page
7e0da417c0 test(gc): Update tests for latest stable 2025-02-20 15:47:19 -06:00
Eric Huss
39cc418c04 Make cache tracking resilient to unexpected files
This makes the cache tracking synchronization code resilient to
unexpected files in the cache directory. Previously the code was
assuming that all entries in paths like `registry/index/*` are
directories. However, in circumstances like opening the directories in
macOS's finder, that can create files called `.DS_Store`. This caused it
to fail to scan within that path, since it isn't a directory.

This could in theory be made stricter, such as expecting directories to
have a particular pattern for its name. However, it seems like we never
enacted restrictions on what names are used for the git directories, so
it wouldn't work very well for that. Though that is something we could
consider in the future.
2025-02-05 14:39:47 -08:00
Eric Huss
dffa757620 Add test for unexpected stray files in the caches 2025-02-05 14:10:43 -08:00
Weihang Lo
5eb7480565
feat(SourceId): use stable hash from rustc-stable-hash
This helps `-Ztrim-paths` build a stable cross-platform path for the
registry and git sources. Sources files then can be found from the same
path when debugging.

It also helps cache registry index all at once for all platforms,
for example the use case in rust-lang/cargo#14795
(despite they should use `cargo vendor` instead IMO).

Some caveats:

* Newer cargo will need to re-download files for global caches
  (index files, git/registry sources).
  The old cache is still kept and used when running with older cargoes.
* Windows is not really covered by the "cross-platform" hash,
  because path prefix components like `C:` are always there.
  That means hashes of some sources kind,
  like local registry and local path,
  are not going to be real cross-platform stable.

There might be hash collisions if you have two registries under the same
domain. This won't happen to crates.io, as the infra would have to
intentionally put another registry on index.crates.io to collide.
We don't consider this is an actual threat model, so we are not going to
use any cryptographically secure hash algorithm like BLAKE3.

See also <https://github.com/rust-lang/cargo/issues/13171#issuecomment-2181465128>
2024-12-10 17:58:02 -05:00
Ed Page
878caf7447 docs: Surround identifiers in backticks
This was mostly done by clippy via `clippy::doc_markdown`.
I then reviewed it to fix words that shouldn't have it or where `--fix`
put the backtick in the wrong location.
2024-11-15 09:33:23 -06:00
Ed Page
f7f7abccf3 test(gc): Update remaining unordered tests to snapbox 2024-11-04 16:05:49 -06:00
Ed Page
e72ef0b10f test: Migrate remaining with_stdout/with_stderr calls 2024-09-23 20:44:14 -05:00
Ed Page
a6cf1be655 test: Switch from allow to expect deprecated
This caught a couple of lingering items.
2024-09-23 20:44:06 -05:00
Ed Page
d2ec764995 fix(resolve): Dont show locking workspace members
This is for `cargo generate-lockfile` and when syncing the lockfile with
the manifest.
We still show it for `cargo update` because of `cargo update
--workspace`.

We hacked around this previously by filtering out the `num_pkgs==1` case
for single packages but this didn't help with workspaces.
2024-08-22 16:57:06 -05:00
Ed Page
f8a9cdaa7e refactor(update): Consolidate status messages
This builds on the prior work to consolidate everything, simplifying the
code and making it clearer what behavior differences exist between
change kinds.
2024-08-21 15:34:36 -05:00
bors
f10c069629 Auto merge of #14266 - epage:path2url, r=weihanglo
fix(test): Move path2url to CargoPathExt::to_url

### What does this PR try to resolve?

This is a small step, like #14243, to improve the clarity of `cargo-test-support`s API.

Overall, I'm trying to make it more obvious on https://docs.rs/cargo-test-support/latest/cargo_test_support/ which items to reach for when.  I figured this is one that could be demoted to `paths` When doing so, I noticed `CargoPathExt`. I figured if we had any extension traits for `Path`, then this is a
reasonable one to add.

### How should we test and review this PR?

### Additional information
2024-07-18 20:57:05 +00:00
Ed Page
3a615ca9c8 feat(test): Add CargoPathExt to prelude 2024-07-18 15:22:29 -05:00
d1t2
86862738d7
test: Migrate global_cache_tracker to snapbox 2024-07-16 23:07:09 +08:00
Ed Page
5b9799c6f4 refactor: Migrate from extern crate to test-support prelude
We now include the prelude in so many places, this simplifies how we can
present how `cargo-test-support` works.

Yes, this included some `use` clean ups but its already painful enough
walking through every test file, I didn't want to do it twice.
2024-07-12 15:57:00 -05:00
Eric Huss
95e8b1cdca Fix compatible_with_older_cargo test. 2024-07-08 14:36:12 -07:00
Ed Page
dc5ac62cab fix(test): Deprecate non-snapbox assertions
While this is noisy and hides other deprecations, I figured deprecations would
make it easier for people to discover what tasks remain and allow us to
divide and conquer this work rather than doing a heroic PR.
In theory, this will be short lived and we'll go back to seeing
deprecations in our tests.
2024-06-10 10:20:52 -05:00
Eric Huss
b44edc5db2 Fix global_cache_tracker::max_download_size test flakiness 2024-05-04 12:25:16 -07:00
Ed Page
e772fc93b4 feat(update): Include a Locking message 2024-04-15 12:36:36 -05:00
Ed Page
4ab2797f36 feat(lock): Print lockfile changes on all commands 2024-03-12 13:39:56 -05:00
Ed Page
14646e6af6 test: Make edition explicit on packages 2024-02-22 11:37:03 -06:00
Eric Huss
39863e7f54 Stabilize global cache data tracking. 2024-02-26 11:37:54 -08:00
Eric Huss
a82794ec4a Fix path issues for running rustup wrapper on Windows.
Cargo likes to modify PATH, which circumvents the ability to choose the
correct "cargo" executable to run on Windows (because Windows uses PATH
for both binary and shared library searching).
2024-02-20 16:27:04 -08:00
Eric Huss
9f71231391 Add global_cache_tracker stability tests.
This adds some tests to ensure that the database used in the global
cache tracker stays compatible across versions. These tests work by
using rustup to run both the current cargo and the stable cargo, and
verifying that when switching versions, everything works as expected.
2024-02-20 12:43:07 -08:00
Scott Schafer
305efa63cc
chore: Rename Config to GlobalContext 2024-02-20 11:55:15 -07:00
cui fliter
5c7fbd80f2 Remove repetitive words
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-12-29 13:55:24 +08:00
Eric Huss
80ffb1de1c Fix --quiet being used with nested subcommands.
This fixes an issue where `--quiet` doesn't work with commands that have
subcommands. This is because `config_configure` only looks at the global
and top-level subcommand, and not deeper subcommands. The issue was that
`--quiet` was not defined as a global flag. This was changed in
https://github.com/rust-lang/cargo/pull/6358 in order to give a better
help message for `cargo test --quiet`. I don't remember if clap just
didn't support overriding at the time, or if we just didn't know how it
worked. Anyways, it seems to work to override it now, so I think it
should be fine to mark it as global.

This should bring in `--quiet` more in-line with how `--verbose` works.
This means that `--quiet` is now accepted with `cargo report`,
`cargo help`, and `cargo config`.

This also fixes `--quiet` with `cargo clean gc`.

This should also help with supporting `--quiet` with the new `cargo
owner` subcommands being added in
https://github.com/rust-lang/cargo/pull/11879.

Fixes #12957
2023-11-12 11:17:43 -08:00
Eric Huss
0cd970b1c0 Move gc options under a cargo clean gc subcommand.
This was requested to separate the interaction of `cargo clean` and the
cleaning of global cache data, and to minimize the impact of this
initial implementation.
2023-11-11 12:36:25 -08:00
Eric Huss
9a41a6110c Remove shared-target gc kind.
This kind is unlikely to be implemented in the foreseeable future, and
we don't really know what it is going to look like.
2023-11-11 10:56:58 -08:00
Eric Huss
ead7904ad4 Add gc tracing target. 2023-11-11 10:56:58 -08:00
Eric Huss
da3ca05677 Add a global cache garbage collector.
This adds a garbage collector which will remove old files from cargo's
global cache.

A general overview of the changes here:

- `cargo::core::global_cache_tracker` contains the `GlobalCacheTracker`
  which handles the interface to a sqlite database which stores
  timestamps of the last time a file was used.
- `DeferredGlobalLastUse` is a type that implements an optimization for
  collecting last-use timestamps so that they can be flushed to disk all
  at once.
- `cargo::core::gc` contains the `Gc` type which is the interface for
  performing garbage collection. It coordinates with the
  `GlobalCacheTracker` for determining what to delete.
- Garbage collection can either be automatic or manual. The automatic
  garbage collection supports some config options for defining when
  it runs and how much it deletes.
- Manual garbage collection can be performed via options to `cargo
  clean`.
- `cargo clean` uses the new package cache locking system to coordinate
  access to the package cache to prevent interference with other cargo
  commands running concurrently.
2023-11-11 10:56:58 -08:00