diff --git a/src/cargo/core/gc.rs b/src/cargo/core/gc.rs
index 5f403e73426..fd15d9b44f4 100644
--- a/src/cargo/core/gc.rs
+++ b/src/cargo/core/gc.rs
@@ -49,9 +49,6 @@ const DEFAULT_AUTO_FREQUENCY: &str = "1 day";
/// It should be cheap to call this multiple times (subsequent calls are
/// ignored), but try not to abuse that.
pub fn auto_gc(gctx: &GlobalContext) {
- if !gctx.cli_unstable().gc {
- return;
- }
if !gctx.network_allowed() {
// As a conservative choice, auto-gc is disabled when offline. If the
// user is indefinitely offline, we don't want to delete things they
@@ -176,49 +173,74 @@ impl GcOpts {
let auto_config = gctx
.get::>("gc.auto")?
.unwrap_or_default();
- self.update_for_auto_gc_config(&auto_config)
+ self.update_for_auto_gc_config(&auto_config, gctx.cli_unstable().gc)
}
- fn update_for_auto_gc_config(&mut self, auto_config: &AutoConfig) -> CargoResult<()> {
+ fn update_for_auto_gc_config(
+ &mut self,
+ auto_config: &AutoConfig,
+ unstable_allowed: bool,
+ ) -> CargoResult<()> {
+ macro_rules! config_default {
+ ($auto_config:expr, $field:ident, $default:expr, $unstable_allowed:expr) => {
+ if !unstable_allowed {
+ // These config options require -Zgc
+ $default
+ } else {
+ $auto_config.$field.as_deref().unwrap_or($default)
+ }
+ };
+ }
+
self.max_src_age = newer_time_span_for_config(
self.max_src_age,
"gc.auto.max-src-age",
- auto_config
- .max_src_age
- .as_deref()
- .unwrap_or(DEFAULT_MAX_AGE_EXTRACTED),
+ config_default!(
+ auto_config,
+ max_src_age,
+ DEFAULT_MAX_AGE_EXTRACTED,
+ unstable_allowed
+ ),
)?;
self.max_crate_age = newer_time_span_for_config(
self.max_crate_age,
"gc.auto.max-crate-age",
- auto_config
- .max_crate_age
- .as_deref()
- .unwrap_or(DEFAULT_MAX_AGE_DOWNLOADED),
+ config_default!(
+ auto_config,
+ max_crate_age,
+ DEFAULT_MAX_AGE_DOWNLOADED,
+ unstable_allowed
+ ),
)?;
self.max_index_age = newer_time_span_for_config(
self.max_index_age,
"gc.auto.max-index-age",
- auto_config
- .max_index_age
- .as_deref()
- .unwrap_or(DEFAULT_MAX_AGE_DOWNLOADED),
+ config_default!(
+ auto_config,
+ max_index_age,
+ DEFAULT_MAX_AGE_DOWNLOADED,
+ unstable_allowed
+ ),
)?;
self.max_git_co_age = newer_time_span_for_config(
self.max_git_co_age,
"gc.auto.max-git-co-age",
- auto_config
- .max_git_co_age
- .as_deref()
- .unwrap_or(DEFAULT_MAX_AGE_EXTRACTED),
+ config_default!(
+ auto_config,
+ max_git_co_age,
+ DEFAULT_MAX_AGE_EXTRACTED,
+ unstable_allowed
+ ),
)?;
self.max_git_db_age = newer_time_span_for_config(
self.max_git_db_age,
"gc.auto.max-git-db-age",
- auto_config
- .max_git_db_age
- .as_deref()
- .unwrap_or(DEFAULT_MAX_AGE_DOWNLOADED),
+ config_default!(
+ auto_config,
+ max_git_db_age,
+ DEFAULT_MAX_AGE_DOWNLOADED,
+ unstable_allowed
+ ),
)?;
Ok(())
}
@@ -257,9 +279,6 @@ impl<'a, 'gctx> Gc<'a, 'gctx> {
/// This returns immediately without doing work if garbage collection has
/// been performed recently (since `gc.auto.frequency`).
fn auto(&mut self, clean_ctx: &mut CleanContext<'gctx>) -> CargoResult<()> {
- if !self.gctx.cli_unstable().gc {
- return Ok(());
- }
let auto_config = self
.gctx
.get:: >("gc.auto")?
@@ -278,7 +297,7 @@ impl<'a, 'gctx> Gc<'a, 'gctx> {
return Ok(());
}
let mut gc_opts = GcOpts::default();
- gc_opts.update_for_auto_gc_config(&auto_config)?;
+ gc_opts.update_for_auto_gc_config(&auto_config, self.gctx.cli_unstable().gc)?;
self.gc(clean_ctx, &gc_opts)?;
if !clean_ctx.dry_run {
self.global_cache_tracker.set_last_auto_gc()?;
diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md
index fe3941a7503..9b1599083db 100644
--- a/src/doc/src/reference/config.md
+++ b/src/doc/src/reference/config.md
@@ -95,6 +95,9 @@ ENV_VAR_NAME_3 = { value = "relative/path", relative = true }
[future-incompat-report]
frequency = 'always' # when to display a notification about a future incompat report
+[gc.auto]
+frequency = "1 day" # How often to perform automatic garbage collection
+
[cargo-new]
vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'none')
@@ -663,6 +666,42 @@ Controls how often we display a notification to the terminal when a future incom
* `always` (default): Always display a notification when a command (e.g. `cargo build`) produces a future incompat report
* `never`: Never display a notification
+### `[gc]`
+
+The `[gc]` table defines settings for garbage collection in Cargo's caches, which will delete old, unused files.
+
+#### `[gc.auto]`
+
+The `[gc.auto]` table defines settings for automatic garbage collection in Cargo's caches.
+When running `cargo` commands, Cargo will automatically track which files you are using within the global cache.
+Periodically, Cargo will delete files that have not been used for some period of time.
+Currently it will delete files that have to be downloaded from the network if they have not been used in 3 months. Files that can be generated without network access will be deleted if they have not been used in 1 month.
+
+The automatic deletion of files only occurs when running commands that are already doing a significant amount of work, such as all of the build commands (`cargo build`, `cargo test`, `cargo check`, etc.), and `cargo fetch`.
+
+Automatic deletion is disabled if cargo is offline such as with `--offline` or `--frozen` to avoid deleting artifacts that may need to be used if you are offline for a long period of time.
+
+> **Note**: This tracking is currently only implemented for the global cache in Cargo's home directory.
+> This includes registry indexes and source files downloaded from registries and git dependencies.
+> Support for tracking build artifacts is not yet implemented, and tracked in [cargo#13136](https://github.com/rust-lang/cargo/issues/13136).
+>
+> Additionally, there is an unstable feature to support *manually* triggering garbage collection, and to further customize the configuration options.
+> See the [Unstable chapter](unstable.md#gc) for more information.
+
+##### `gc.auto.frequency`
+* Type: string
+* Default: `"1 day"`
+* Environment: `CARGO_GC_AUTO_FREQUENCY`
+
+This option defines how often Cargo will automatically delete unused files in the global cache.
+This does *not* define how old the files must be, those thresholds are described [above](#gcauto).
+
+It supports the following settings:
+
+* `"never"` --- Never deletes old files.
+* `"always"` --- Checks to delete old files every time Cargo runs.
+* An integer followed by "seconds", "minutes", "hours", "days", "weeks", or "months" --- Checks to delete old files at most the given time frame.
+
### `[http]`
The `[http]` table defines settings for HTTP behavior. This includes fetching
diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md
index 5dafb7bcb3a..5569d60b32e 100644
--- a/src/doc/src/reference/environment-variables.md
+++ b/src/doc/src/reference/environment-variables.md
@@ -101,6 +101,7 @@ In summary, the supported environment variables are:
* `CARGO_BUILD_DEP_INFO_BASEDIR` --- Dep-info relative directory, see [`build.dep-info-basedir`].
* `CARGO_CARGO_NEW_VCS` --- The default source control system with [`cargo new`], see [`cargo-new.vcs`].
* `CARGO_FUTURE_INCOMPAT_REPORT_FREQUENCY` --- How often we should generate a future incompat report notification, see [`future-incompat-report.frequency`].
+* `CARGO_GC_AUTO_FREQUENCY` --- Configures how often automatic garbage collection runs, see [`gc.auto.frequency`].
* `CARGO_HTTP_DEBUG` --- Enables HTTP debugging, see [`http.debug`].
* `CARGO_HTTP_PROXY` --- Enables HTTP proxy, see [`http.proxy`].
* `CARGO_HTTP_TIMEOUT` --- The HTTP timeout, see [`http.timeout`].
@@ -167,6 +168,7 @@ In summary, the supported environment variables are:
[`cargo-new.email`]: config.md#cargo-newemail
[`cargo-new.vcs`]: config.md#cargo-newvcs
[`future-incompat-report.frequency`]: config.md#future-incompat-reportfrequency
+[`gc.auto.frequency`]: config.md#gcautofrequency
[`http.debug`]: config.md#httpdebug
[`http.proxy`]: config.md#httpproxy
[`http.timeout`]: config.md#httptimeout
diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md
index 2062e13fe2c..d56b2801afb 100644
--- a/src/doc/src/reference/unstable.md
+++ b/src/doc/src/reference/unstable.md
@@ -1488,26 +1488,11 @@ This will not affect any hard-coded paths in the source code, such as in strings
* Tracking Issue: [#12633](https://github.com/rust-lang/cargo/issues/12633)
-The `-Zgc` flag enables garbage-collection within cargo's global cache within the cargo home directory.
-This includes downloaded dependencies such as compressed `.crate` files, extracted `src` directories, registry index caches, and git dependencies.
-When `-Zgc` is present, cargo will track the last time any index and dependency was used,
-and then uses those timestamps to manually or automatically delete cache entries that have not been used for a while.
-
-```sh
-cargo build -Zgc
-```
-
-### Automatic garbage collection
-
-Automatic deletion happens on commands that are already doing a significant amount of work,
-such as all of the build commands (`cargo build`, `cargo test`, `cargo check`, etc.), and `cargo fetch`.
-The deletion happens just after resolution and packages have been downloaded.
-Automatic deletion is only done once per day (see `gc.auto.frequency` to configure).
-Automatic deletion is disabled if cargo is offline such as with `--offline` or `--frozen` to avoid deleting artifacts that may need to be used if you are offline for a long period of time.
+The `-Zgc` flag is used to enable certain features related to garbage-collection of cargo's global cache within the cargo home directory.
#### Automatic gc configuration
-The automatic gc behavior can be specified via a cargo configuration setting.
+The `-Zgc` flag will enable Cargo to read extra configuration options related to garbage collection.
The settings available are:
```toml
@@ -1515,9 +1500,6 @@ The settings available are:
# This table defines the behavior for automatic garbage collection.
[gc.auto]
-# The maximum frequency that automatic garbage collection happens.
-# Can be "never" to disable automatic-gc, or "always" to run on every command.
-frequency = "1 day"
# Anything older than this duration will be deleted in the source cache.
max-src-age = "1 month"
# Anything older than this duration will be deleted in the compressed crate cache.
@@ -1530,9 +1512,13 @@ max-git-co-age = "1 month"
max-git-db-age = "3 months"
```
+Note that the [`gc.auto.frequency`] option was stabilized in Rust 1.82.
+
+[`gc.auto.frequency`]: config.md#gcautofrequency
+
### Manual garbage collection with `cargo clean`
-Manual deletion can be done with the `cargo clean gc` command.
+Manual deletion can be done with the `cargo clean gc -Zgc` command.
Deletion of cache contents can be performed by passing one of the cache options:
- `--max-src-age=DURATION` --- Deletes source cache files that have not been used since the given age.
@@ -1551,9 +1537,9 @@ A DURATION is specified in the form "N seconds/minutes/days/weeks/months" where
A SIZE is specified in the form "N *suffix*" where *suffix* is B, kB, MB, GB, kiB, MiB, or GiB, and N is an integer or floating point number. If no suffix is specified, the number is the number of bytes.
```sh
-cargo clean gc
-cargo clean gc --max-download-age=1week
-cargo clean gc --max-git-size=0 --max-download-size=100MB
+cargo clean gc -Zgc
+cargo clean gc -Zgc --max-download-age=1week
+cargo clean gc -Zgc --max-git-size=0 --max-download-size=100MB
```
## open-namespaces
@@ -1991,3 +1977,8 @@ default behavior.
See the [build script documentation](build-scripts.md#rustc-check-cfg) for information
about specifying custom cfgs.
+
+## Automatic garbage collection
+
+Support for automatically deleting old files was stabilized in Rust 1.82.
+More information can be found in the [config chapter](config.md#gcauto).
diff --git a/tests/testsuite/global_cache_tracker.rs b/tests/testsuite/global_cache_tracker.rs
index 8e812fc7256..48a5a317780 100644
--- a/tests/testsuite/global_cache_tracker.rs
+++ b/tests/testsuite/global_cache_tracker.rs
@@ -187,25 +187,6 @@ fn rustup_cargo() -> Execs {
e
}
-#[cargo_test]
-fn auto_gc_gated() {
- // Requires -Zgc to run auto-gc.
- let p = basic_foo_bar_project();
- p.cargo("check")
- .env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
- .run();
- // Check that it created a database.
- let gctx = GlobalContextBuilder::new().build();
- assert!(GlobalCacheTracker::db_path(&gctx)
- .into_path_unlocked()
- .exists());
- assert_eq!(get_index_names().len(), 1);
-
- // Again in the future, shouldn't auto-gc.
- p.cargo("check").run();
- assert_eq!(get_index_names().len(), 1);
-}
-
#[cargo_test]
fn clean_gc_gated() {
cargo_process("clean gc")
@@ -287,8 +268,7 @@ fn auto_gc_defaults() {
.file("src/lib.rs", "")
.build();
// Populate the last-use data.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
assert_eq!(get_registry_names("src"), ["new-1.0.0", "old-1.0.0"]);
@@ -311,8 +291,7 @@ fn auto_gc_defaults() {
new = "1.0"
"#,
);
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(2))
.run();
assert_eq!(get_registry_names("src"), ["new-1.0.0"]);
@@ -322,13 +301,78 @@ fn auto_gc_defaults() {
);
// Run again after the .crate should have aged out.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("check").run();
assert_eq!(get_registry_names("src"), ["new-1.0.0"]);
assert_eq!(get_registry_names("cache"), ["new-1.0.0.crate"]);
}
+#[cargo_test]
+fn auto_gc_config_gated() {
+ // gc.auto config options should be ignored without -Zgc
+ Package::new("old", "1.0.0").publish();
+ Package::new("new", "1.0.0").publish();
+ let p = project()
+ .file(
+ ".cargo/config.toml",
+ r#"
+ [gc.auto]
+ frequency = "always"
+ max-src-age = "1 day"
+ max-crate-age = "3 days"
+ max-index-age = "3 days"
+ max-git-co-age = "1 day"
+ max-git-db-age = "3 days"
+ "#,
+ )
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ edition = "2015"
+
+ [dependencies]
+ old = "1.0"
+ new = "1.0"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .build();
+ // Populate the last-use data.
+ p.cargo("check")
+ .env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(4))
+ .run();
+ assert_eq!(get_registry_names("src"), ["new-1.0.0", "old-1.0.0"]);
+ assert_eq!(
+ get_registry_names("cache"),
+ ["new-1.0.0.crate", "old-1.0.0.crate"]
+ );
+
+ // Run again with just one package. Without -Zgc, it should use the
+ // defaults and ignore the config. Nothing should get deleted since the
+ // defaults are much greater than 4 days.
+ p.change_file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ edition = "2015"
+
+ [dependencies]
+ new = "1.0"
+ "#,
+ );
+
+ p.cargo("check").run();
+ assert_eq!(get_registry_names("src"), ["new-1.0.0", "old-1.0.0"]);
+ assert_eq!(
+ get_registry_names("cache"),
+ ["new-1.0.0.crate", "old-1.0.0.crate"]
+ );
+}
+
#[cargo_test]
fn auto_gc_config() {
// Can configure auto gc settings.
@@ -363,8 +407,7 @@ fn auto_gc_config() {
.file("src/lib.rs", "")
.build();
// Populate the last-use data.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(4))
.run();
assert_eq!(get_registry_names("src"), ["new-1.0.0", "old-1.0.0"]);
@@ -417,8 +460,7 @@ fn frequency() {
"#,
);
// Populate data in the past.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
assert_eq!(get_index_names().len(), 1);
@@ -428,17 +470,14 @@ fn frequency() {
p.change_file("Cargo.toml", &basic_manifest("foo", "0.2.0"));
// Try after the default expiration time, with "never" it shouldn't gc.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("check").run();
assert_eq!(get_index_names().len(), 1);
assert_eq!(get_registry_names("src"), ["bar-1.0.0"]);
assert_eq!(get_registry_names("cache"), ["bar-1.0.0.crate"]);
// Try again with a setting that allows it to run.
- p.cargo("check -Zgc")
+ p.cargo("check")
.env("CARGO_GC_AUTO_FREQUENCY", "1 day")
- .masquerade_as_nightly_cargo(&["gc"])
.run();
assert_eq!(get_index_names().len(), 0);
assert_eq!(get_registry_names("src").len(), 0);
@@ -449,8 +488,7 @@ fn frequency() {
fn auto_gc_index() {
// Deletes the index if it hasn't been used in a while.
let p = basic_foo_bar_project();
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
assert_eq!(get_index_names().len(), 1);
@@ -465,16 +503,13 @@ fn auto_gc_index() {
edition = "2015"
"#,
);
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(2))
.run();
assert_eq!(get_index_names().len(), 1);
// After it expires, it should be deleted.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("check").run();
assert_eq!(get_index_names().len(), 0);
}
@@ -513,8 +548,7 @@ fn auto_gc_git() {
)
.file("src/lib.rs", "")
.build();
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(6))
.run();
let db_names = get_git_db_names();
@@ -529,8 +563,7 @@ fn auto_gc_git() {
git_project.change_file("src/lib.rs", "// modified");
git::add(&git_repo);
git::commit(&git_repo);
- p.cargo("update -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("update")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(6))
.run();
assert_eq!(get_git_db_names().len(), 1);
@@ -540,8 +573,7 @@ fn auto_gc_git() {
assert_eq!(get_git_checkout_names(&db_names[0]), both);
// In the future, using the second checkout should delete the first.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
assert_eq!(get_git_db_names().len(), 1);
@@ -552,9 +584,7 @@ fn auto_gc_git() {
// After three months, the db should get deleted.
p.change_file("Cargo.toml", &basic_manifest("foo", "0.2.0"));
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("check").run();
assert_eq!(get_git_db_names().len(), 0);
assert_eq!(get_git_checkout_names(&db_names[0]).len(), 0);
}
@@ -587,8 +617,6 @@ fn auto_gc_various_commands() {
.build();
// Populate the last-use data.
p.cargo(cmd)
- .arg("-Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
let gctx = GlobalContextBuilder::new().build();
@@ -606,10 +634,7 @@ fn auto_gc_various_commands() {
// After everything is aged out, it should all be deleted.
p.change_file("Cargo.toml", &basic_manifest("foo", "0.2.0"));
- p.cargo(cmd)
- .arg("-Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo(cmd).run();
let lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
.unwrap();
@@ -672,10 +697,7 @@ fn updates_last_use_various_commands() {
.file("src/lib.rs", "")
.build();
// Populate the last-use data.
- p.cargo(cmd)
- .arg("-Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo(cmd).run();
let gctx = GlobalContextBuilder::new().build();
let lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
@@ -722,8 +744,7 @@ fn both_git_and_http_index_cleans() {
.file("src/lib.rs", "")
.build();
- p.cargo("update -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("update")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
let gctx = GlobalContextBuilder::new().build();
@@ -755,8 +776,7 @@ fn clean_gc_dry_run() {
// Basic `clean --gc --dry-run` test.
let p = basic_foo_bar_project();
// Populate the last-use data.
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
@@ -809,8 +829,7 @@ fn clean_default_gc() {
// `clean gc` without options should also gc
let p = basic_foo_bar_project();
// Populate the last-use data.
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
p.cargo("clean gc -v -Zgc")
@@ -854,9 +873,7 @@ fn tracks_sizes() {
)
.file("src/lib.rs", "")
.build();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("fetch").run();
// Check that the crate sizes are the same as on disk.
let gctx = GlobalContextBuilder::new().build();
@@ -1084,9 +1101,7 @@ fn max_size_untracked_src_from_use() {
let (gctx, p) = max_size_untracked_prepare();
// Run a command that will update the db with an unknown src size.
- p.cargo("tree -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("tree").run();
// Check that it is None.
let lock = gctx
.acquire_package_cache_lock(CacheLockMode::MutateExclusive)
@@ -1240,8 +1255,7 @@ fn package_cache_lock_during_build() {
// Start a build that will pause once the build starts.
let mut foo_child = p_foo
- .cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ .cargo("check")
.build_command()
.stdout(Stdio::piped())
.stderr(Stdio::piped())
@@ -1256,8 +1270,7 @@ fn package_cache_lock_during_build() {
//
// Also verify that auto-gc gets disabled.
p_foo2
- .cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ .cargo("check")
.env("CARGO_GC_AUTO_FREQUENCY", "always")
.env("CARGO_LOG", "gc=debug")
.with_stderr_data(str![[r#"
@@ -1310,9 +1323,7 @@ fn read_only_locking_auto_gc() {
// Tests the behavior for auto-gc on a read-only directory.
let p = basic_foo_bar_project();
// Populate cache.
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("fetch").run();
let cargo_home = paths::home().join(".cargo");
let mut perms = std::fs::metadata(&cargo_home).unwrap().permissions();
// Test when it can't update auto-gc db.
@@ -1352,8 +1363,7 @@ fn read_only_locking_auto_gc() {
fn delete_index_also_deletes_crates() {
// Checks that when an index is delete that src and cache directories also get deleted.
let p = basic_foo_bar_project();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
@@ -1396,9 +1406,7 @@ fn clean_syncs_missing_files() {
)
.file("src/lib.rs", "")
.build();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("fetch").run();
// Verify things are tracked.
let gctx = GlobalContextBuilder::new().build();
@@ -1444,15 +1452,13 @@ fn clean_syncs_missing_files() {
fn offline_doesnt_auto_gc() {
// When running offline, auto-gc shouldn't run.
let p = basic_foo_bar_project();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
// Remove the dependency.
p.change_file("Cargo.toml", &basic_manifest("foo", "0.1.0"));
// Run offline, make sure it doesn't delete anything
- p.cargo("check --offline -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check --offline")
.with_stderr_data(str![[r#"
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1462,8 +1468,7 @@ fn offline_doesnt_auto_gc() {
assert_eq!(get_registry_names("src"), ["bar-1.0.0"]);
assert_eq!(get_registry_names("cache"), ["bar-1.0.0.crate"]);
// Run online, make sure auto-gc runs.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1478,8 +1483,7 @@ fn can_handle_future_schema() -> anyhow::Result<()> {
// It should work when a future version of cargo has made schema changes
// to the database.
let p = basic_foo_bar_project();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
// Modify the schema to pretend this is done by a future version of cargo.
@@ -1530,8 +1534,7 @@ fn clean_max_git_age() {
.file("src/lib.rs", "")
.build();
// Populate last-use tracking.
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(4))
.run();
// Update git_a to create a separate checkout.
@@ -1539,8 +1542,7 @@ fn clean_max_git_age() {
git::add(&git_a_repo);
git::commit(&git_a_repo);
// Update last-use tracking, where the first git checkout will stay "old".
- p.cargo("update -p git_a -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("update -p git_a")
.env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(2))
.with_stderr_data(str![[r#"
[UPDATING] git repository `[ROOTURL]/git_a`
@@ -1611,14 +1613,12 @@ fn clean_max_src_crate_age() {
// --max-src-age and --max-crate-age flags
let p = basic_foo_bar_project();
// Populate last-use tracking.
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(4))
.run();
// Update bar to create a separate copy with a different timestamp.
Package::new("bar", "1.0.1").publish();
- p.cargo("update -p bar -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("update -p bar")
.env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(2))
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
@@ -1627,8 +1627,7 @@ fn clean_max_src_crate_age() {
"#]])
.run();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(2))
.with_stderr_data(str![[r#"
[DOWNLOADING] crates ...
@@ -1717,8 +1716,7 @@ fn clean_max_git_size() {
.file("src/lib.rs", "")
.build();
// Fetch and populate db.
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(3))
.run();
@@ -1735,8 +1733,7 @@ fn clean_max_git_size() {
git_project.change_file("src/lib.rs", "// modified");
git::add(&git_repo);
git::commit(&git_repo);
- p.cargo("update -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("update")
// Use a different time so that the first checkout timestamp is less
// than the second.
.env("__CARGO_TEST_LAST_USE_NOW", days_ago_unix(2))
@@ -1859,9 +1856,7 @@ fn clean_max_git_size_deletes_co_from_db() {
fn handles_missing_index() {
// Checks behavior when index is missing.
let p = basic_foo_bar_project();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("fetch").run();
paths::home().join(".cargo/registry/index").rm_rf();
cargo_process("clean gc -v --max-download-size=0 -Zgc")
.masquerade_as_nightly_cargo(&["gc"])
@@ -1902,9 +1897,7 @@ fn handles_missing_git_db() {
)
.file("src/lib.rs", "")
.build();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("fetch").run();
paths::home().join(".cargo/git/db").rm_rf();
cargo_process("clean gc -v --max-git-size=0 -Zgc")
.masquerade_as_nightly_cargo(&["gc"])
@@ -1921,8 +1914,7 @@ fn clean_gc_quiet_is_quiet() {
// Checks that --quiet works with `cargo clean gc`, since there was a
// subtle issue with how the flag is defined as a global flag.
let p = basic_foo_bar_project();
- p.cargo("fetch -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("fetch")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
p.cargo("clean gc --quiet -Zgc --dry-run")
@@ -1968,8 +1960,7 @@ fn compatible_with_older_cargo() {
.file("src/lib.rs", "")
.build();
// Populate the last-use data.
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
+ p.cargo("check")
.env("__CARGO_TEST_LAST_USE_NOW", months_ago_unix(4))
.run();
assert_eq!(
@@ -1995,6 +1986,7 @@ fn compatible_with_older_cargo() {
middle = "1.0"
"#,
);
+ // TODO: Remove -Zgc after 1.82 is stabilized.
rustup_cargo()
.args(&["+stable", "check", "-Zgc"])
.cwd(p.root())
@@ -2021,9 +2013,7 @@ fn compatible_with_older_cargo() {
new = "1.0"
"#,
);
- p.cargo("check -Zgc")
- .masquerade_as_nightly_cargo(&["gc"])
- .run();
+ p.cargo("check").run();
assert_eq!(get_registry_names("src"), ["new-1.0.0"]);
assert_eq!(
get_registry_names("cache"),
@@ -2059,9 +2049,8 @@ fn forward_compatible() {
.build();
rustup_cargo()
- .args(&["+stable", "check", "-Zgc"])
+ .args(&["+stable", "check"])
.cwd(p.root())
- .masquerade_as_nightly_cargo(&["gc"])
.run();
let config = GlobalContextBuilder::new().build();