Skip to content

Commit e975158

Browse files
committed
Auto merge of #13486 - weihanglo:config-cleanup, r=epage
refactor: clean up for `GlobalContext` rename
2 parents 2b302a5 + 75dbb86 commit e975158

File tree

16 files changed

+121
-120
lines changed

16 files changed

+121
-120
lines changed

crates/mdman/src/hbs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl HelperDef for ManLinkHelper<'_> {
167167
&self,
168168
h: &Helper<'rc>,
169169
_r: &'reg Handlebars<'reg>,
170-
_gctx: &'rc Context,
170+
_ctx: &'rc Context,
171171
_rc: &mut RenderContext<'reg, 'rc>,
172172
out: &mut dyn Output,
173173
) -> HelperResult {
@@ -200,7 +200,7 @@ impl HelperDef for ManLinkHelper<'_> {
200200
fn set_decorator(
201201
d: &Decorator<'_>,
202202
_: &Handlebars<'_>,
203-
_gctx: &Context,
203+
_ctx: &Context,
204204
rc: &mut RenderContext<'_, '_>,
205205
) -> Result<(), RenderError> {
206206
let data_to_set = d.hash();

src/bin/cargo/cli.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult {
2525

2626
// Update the process-level notion of cwd
2727
if let Some(new_cwd) = args.get_one::<std::path::PathBuf>("directory") {
28-
// This is a temporary hack. This cannot access `Config`, so this is a bit messy.
28+
// This is a temporary hack.
29+
// This cannot access `GlobalContext`, so this is a bit messy.
2930
// This does not properly parse `-Z` flags that appear after the subcommand.
3031
// The error message is not as helpful as the standard one.
3132
let nightly_features_allowed = matches!(&*features::channel(), "nightly" | "dev");

src/bin/cargo/commands/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
111111
// In general, we try to avoid normalizing paths in Cargo,
112112
// but in these particular cases we need it to fix rust-lang/cargo#10283.
113113
// (Handle `SourceId::for_path` and `Workspace::new`,
114-
// but not `Config::reload_rooted_at` which is always cwd)
114+
// but not `GlobalContext::reload_rooted_at` which is always cwd)
115115
let path = path.map(|p| paths::normalize_path(&p));
116116

117117
let version = args.get_one::<VersionReq>("version");

src/cargo/core/compiler/job_queue/job_state.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ pub struct JobState<'a, 'gctx> {
2828
/// output messages are processed on the same thread as they are sent from. `output`
2929
/// defines where to output in this case.
3030
///
31-
/// Currently the `Shell` inside `Config` is wrapped in a `RefCell` and thus can't be passed
32-
/// between threads. This means that it isn't possible for multiple output messages to be
33-
/// interleaved. In the future, it may be wrapped in a `Mutex` instead. In this case
31+
/// Currently the [`Shell`] inside [`GlobalContext`] is wrapped in a `RefCell` and thus can't
32+
/// be passed between threads. This means that it isn't possible for multiple output messages
33+
/// to be interleaved. In the future, it may be wrapped in a `Mutex` instead. In this case
3434
/// interleaving is still prevented as the lock would be held for the whole printing of an
3535
/// output message.
36+
///
37+
/// [`Shell`]: crate::core::Shell
38+
/// [`GlobalContext`]: crate::GlobalContext
3639
output: Option<&'a DiagDedupe<'gctx>>,
3740

3841
/// The job id that this state is associated with, used when sending

src/cargo/core/gc.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ fn auto_gc_inner(gctx: &GlobalContext) -> CargoResult<()> {
8686
debug_assert!(deferred.is_empty());
8787
let mut global_cache_tracker = gctx.global_cache_tracker()?;
8888
let mut gc = Gc::new(gctx, &mut global_cache_tracker)?;
89-
let mut clean_gctx = CleanContext::new(gctx);
90-
gc.auto(&mut clean_gctx)?;
89+
let mut clean_ctx = CleanContext::new(gctx);
90+
gc.auto(&mut clean_ctx)?;
9191
Ok(())
9292
}
9393

@@ -256,7 +256,7 @@ impl<'a, 'gctx> Gc<'a, 'gctx> {
256256
///
257257
/// This returns immediately without doing work if garbage collection has
258258
/// been performed recently (since `gc.auto.frequency`).
259-
fn auto(&mut self, clean_gctx: &mut CleanContext<'gctx>) -> CargoResult<()> {
259+
fn auto(&mut self, clean_ctx: &mut CleanContext<'gctx>) -> CargoResult<()> {
260260
if !self.gctx.cli_unstable().gc {
261261
return Ok(());
262262
}
@@ -279,20 +279,16 @@ impl<'a, 'gctx> Gc<'a, 'gctx> {
279279
}
280280
let mut gc_opts = GcOpts::default();
281281
gc_opts.update_for_auto_gc_config(&auto_config)?;
282-
self.gc(clean_gctx, &gc_opts)?;
283-
if !clean_gctx.dry_run {
282+
self.gc(clean_ctx, &gc_opts)?;
283+
if !clean_ctx.dry_run {
284284
self.global_cache_tracker.set_last_auto_gc()?;
285285
}
286286
Ok(())
287287
}
288288

289289
/// Performs garbage collection based on the given options.
290-
pub fn gc(
291-
&mut self,
292-
clean_gctx: &mut CleanContext<'gctx>,
293-
gc_opts: &GcOpts,
294-
) -> CargoResult<()> {
295-
self.global_cache_tracker.clean(clean_gctx, gc_opts)?;
290+
pub fn gc(&mut self, clean_ctx: &mut CleanContext<'gctx>, gc_opts: &GcOpts) -> CargoResult<()> {
291+
self.global_cache_tracker.clean(clean_ctx, gc_opts)?;
296292
// In the future, other gc operations go here, such as target cleaning.
297293
Ok(())
298294
}

src/cargo/core/global_cache_tracker.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -547,22 +547,18 @@ impl GlobalCacheTracker {
547547
}
548548

549549
/// Deletes files from the global cache based on the given options.
550-
pub fn clean(
551-
&mut self,
552-
clean_gctx: &mut CleanContext<'_>,
553-
gc_opts: &GcOpts,
554-
) -> CargoResult<()> {
555-
self.clean_inner(clean_gctx, gc_opts)
550+
pub fn clean(&mut self, clean_ctx: &mut CleanContext<'_>, gc_opts: &GcOpts) -> CargoResult<()> {
551+
self.clean_inner(clean_ctx, gc_opts)
556552
.with_context(|| "failed to clean entries from the global cache")
557553
}
558554

559555
fn clean_inner(
560556
&mut self,
561-
clean_gctx: &mut CleanContext<'_>,
557+
clean_ctx: &mut CleanContext<'_>,
562558
gc_opts: &GcOpts,
563559
) -> CargoResult<()> {
564560
let _p = crate::util::profile::start("cleaning global cache files");
565-
let gctx = clean_gctx.gctx;
561+
let gctx = clean_ctx.gctx;
566562
let base = BasePaths {
567563
index: gctx.registry_index_path().into_path_unlocked(),
568564
git_db: gctx.git_db_path().into_path_unlocked(),
@@ -657,9 +653,9 @@ impl GlobalCacheTracker {
657653
Self::get_registry_items_to_clean_size_both(&tx, max_size, &base, &mut delete_paths)?;
658654
}
659655

660-
clean_gctx.remove_paths(&delete_paths)?;
656+
clean_ctx.remove_paths(&delete_paths)?;
661657

662-
if clean_gctx.dry_run {
658+
if clean_ctx.dry_run {
663659
tx.rollback()?;
664660
} else {
665661
tx.commit()?;

src/cargo/core/resolver/errors.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl From<(PackageId, ConflictReason)> for ActivateError {
7070
}
7171

7272
pub(super) fn activation_error(
73-
resolver_gctx: &ResolverContext,
73+
resolver_ctx: &ResolverContext,
7474
registry: &mut dyn Registry,
7575
parent: &Summary,
7676
dep: &Dependency,
@@ -81,7 +81,7 @@ pub(super) fn activation_error(
8181
let to_resolve_err = |err| {
8282
ResolveError::new(
8383
err,
84-
resolver_gctx
84+
resolver_ctx
8585
.parents
8686
.path_to_bottom(&parent.package_id())
8787
.into_iter()
@@ -95,7 +95,7 @@ pub(super) fn activation_error(
9595
let mut msg = format!("failed to select a version for `{}`.", dep.package_name());
9696
msg.push_str("\n ... required by ");
9797
msg.push_str(&describe_path_in_context(
98-
resolver_gctx,
98+
resolver_ctx,
9999
&parent.package_id(),
100100
));
101101

@@ -141,7 +141,7 @@ pub(super) fn activation_error(
141141
msg.push_str("`, but it conflicts with a previous package which links to `");
142142
msg.push_str(link);
143143
msg.push_str("` as well:\n");
144-
msg.push_str(&describe_path_in_context(resolver_gctx, p));
144+
msg.push_str(&describe_path_in_context(resolver_ctx, p));
145145
msg.push_str("\nOnly one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. ");
146146
msg.push_str("Try to adjust your dependencies so that only one package uses the `links = \"");
147147
msg.push_str(link);
@@ -210,7 +210,7 @@ pub(super) fn activation_error(
210210
for (p, r) in &conflicting_activations {
211211
if let ConflictReason::Semver = r {
212212
msg.push_str("\n\n previously selected ");
213-
msg.push_str(&describe_path_in_context(resolver_gctx, p));
213+
msg.push_str(&describe_path_in_context(resolver_ctx, p));
214214
}
215215
}
216216
}
@@ -279,7 +279,7 @@ pub(super) fn activation_error(
279279
);
280280
msg.push_str("required by ");
281281
msg.push_str(&describe_path_in_context(
282-
resolver_gctx,
282+
resolver_ctx,
283283
&parent.package_id(),
284284
));
285285

@@ -364,7 +364,7 @@ pub(super) fn activation_error(
364364
msg.push_str(&format!("location searched: {}\n", dep.source_id()));
365365
msg.push_str("required by ");
366366
msg.push_str(&describe_path_in_context(
367-
resolver_gctx,
367+
resolver_ctx,
368368
&parent.package_id(),
369369
));
370370

src/cargo/ops/cargo_clean.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub struct CleanContext<'gctx> {
4040
pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
4141
let mut target_dir = ws.target_dir();
4242
let gctx = opts.gctx;
43-
let mut clean_gctx = CleanContext::new(gctx);
44-
clean_gctx.dry_run = opts.dry_run;
43+
let mut clean_ctx = CleanContext::new(gctx);
44+
clean_ctx.dry_run = opts.dry_run;
4545

4646
if opts.doc {
4747
if !opts.spec.is_empty() {
@@ -55,7 +55,7 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
5555
}
5656
// If the doc option is set, we just want to delete the doc directory.
5757
target_dir = target_dir.join("doc");
58-
clean_gctx.remove_paths(&[target_dir.into_path_unlocked()])?;
58+
clean_ctx.remove_paths(&[target_dir.into_path_unlocked()])?;
5959
} else {
6060
let profiles = Profiles::new(&ws, opts.requested_profile)?;
6161

@@ -73,13 +73,13 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
7373
// Note that we don't bother grabbing a lock here as we're just going to
7474
// blow it all away anyway.
7575
if opts.spec.is_empty() {
76-
clean_gctx.remove_paths(&[target_dir.into_path_unlocked()])?;
76+
clean_ctx.remove_paths(&[target_dir.into_path_unlocked()])?;
7777
} else {
78-
clean_specs(&mut clean_gctx, &ws, &profiles, &opts.targets, &opts.spec)?;
78+
clean_specs(&mut clean_ctx, &ws, &profiles, &opts.targets, &opts.spec)?;
7979
}
8080
}
8181

82-
clean_gctx.display_summary()?;
82+
clean_ctx.display_summary()?;
8383
Ok(())
8484
}
8585

src/cargo/sources/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'gctx> SourceConfigMap<'gctx> {
120120
Ok(base)
121121
}
122122

123-
/// Returns the `Config` this source config map is associated with.
123+
/// Returns the [`GlobalContext`] this source config map is associated with.
124124
pub fn gctx(&self) -> &'gctx GlobalContext {
125125
self.gctx
126126
}

src/cargo/util/cache_lock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! There is a global [`CacheLocker`] held inside cargo's venerable
1010
//! [`GlobalContext`]. The `CacheLocker` manages creating and tracking the locks
11-
//! being held. There are methods on `Config` for managing the locks:
11+
//! being held. There are methods on [`GlobalContext`] for managing the locks:
1212
//!
1313
//! - [`GlobalContext::acquire_package_cache_lock`] --- Acquires a lock. May block if
1414
//! another process holds a lock.
@@ -468,7 +468,7 @@ pub struct CacheLocker {
468468
/// The state of the locker.
469469
///
470470
/// [`CacheLocker`] uses interior mutability because it is stuffed inside
471-
/// the global `Config`, which does not allow mutation.
471+
/// [`GlobalContext`], which does not allow mutation.
472472
state: RefCell<CacheState>,
473473
}
474474

src/cargo/util/config/de.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::collections::HashSet;
88
use std::vec;
99

1010
/// Serde deserializer used to convert config values to a target type using
11-
/// `Config::get`.
11+
/// [`GlobalContext::get`].
1212
#[derive(Clone)]
1313
pub(super) struct Deserializer<'gctx> {
1414
pub(super) gctx: &'gctx GlobalContext,

src/cargo/util/config/environment.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ fn make_case_insensitive_and_normalized_env(
2828
(case_insensitive_env, normalized_env)
2929
}
3030

31-
/// A snapshot of the environment variables available to [`super::GlobalContext`].
31+
/// A snapshot of the environment variables available to [`GlobalContext`].
3232
///
33-
/// Currently, the [`Context`](super::GlobalContext) supports lookup of environment variables
33+
/// Currently, the [`GlobalContext`] supports lookup of environment variables
3434
/// through two different means:
3535
///
36-
/// - [`Context::get_env`](super::GlobalContext::get_env)
37-
/// and [`Context::get_env_os`](super::GlobalContext::get_env_os)
36+
/// - [`GlobalContext::get_env`](super::GlobalContext::get_env)
37+
/// and [`GlobalContext::get_env_os`](super::GlobalContext::get_env_os)
3838
/// for process environment variables (similar to [`std::env::var`] and [`std::env::var_os`]),
39-
/// - Typed Config Value API via [`Context::get`](super::GlobalContext::get).
39+
/// - Typed Config Value API via [`GlobalContext::get`](super::GlobalContext::get).
4040
/// This is only available for `CARGO_` prefixed environment keys.
4141
///
4242
/// This type contains the env var snapshot and helper methods for both APIs.
43+
///
44+
/// [`GlobalContext`]: super::GlobalContext
4345
#[derive(Debug)]
4446
pub struct Env {
4547
/// A snapshot of the process's environment variables.
@@ -68,8 +70,8 @@ impl Env {
6870
pub fn new() -> Self {
6971
// ALLOWED: This is the only permissible usage of `std::env::vars{_os}`
7072
// within cargo. If you do need access to individual variables without
71-
// interacting with `Config` system, please use `std::env::var{_os}`
72-
// and justify the validity of the usage.
73+
// interacting with the config system in [`GlobalContext`], please use
74+
// `std::env::var{_os}` and justify the validity of the usage.
7375
#[allow(clippy::disallowed_methods)]
7476
let env: HashMap<_, _> = std::env::vars_os().collect();
7577
let (case_insensitive_env, normalized_env) = make_case_insensitive_and_normalized_env(&env);
@@ -105,9 +107,10 @@ impl Env {
105107
self.env.keys().filter_map(|k| k.to_str())
106108
}
107109

108-
/// Get the value of environment variable `key` through the `Config` snapshot.
110+
/// Get the value of environment variable `key` through the snapshot in
111+
/// [`GlobalContext`](super::GlobalContext).
109112
///
110-
/// This can be used similarly to `std::env::var_os`.
113+
/// This can be used similarly to [`std::env::var_os`].
111114
/// On Windows, we check for case mismatch since environment keys are case-insensitive.
112115
pub fn get_env_os(&self, key: impl AsRef<OsStr>) -> Option<OsString> {
113116
match self.env.get(key.as_ref()) {
@@ -152,7 +155,7 @@ impl Env {
152155
/// Get the value of environment variable `key` as a `&str`.
153156
/// Returns `None` if `key` is not in `self.env` or if the value is not valid UTF-8.
154157
///
155-
/// This is intended for use in private methods of `Config`,
158+
/// This is intended for use in private methods of [`GlobalContext`](super::GlobalContext),
156159
/// and does not check for env key case mismatch.
157160
///
158161
/// This is case-sensitive on Windows (even though environment keys on Windows are usually
@@ -172,7 +175,7 @@ impl Env {
172175

173176
/// Check if the environment contains `key`.
174177
///
175-
/// This is intended for use in private methods of `Config`,
178+
/// This is intended for use in private methods of [`GlobalContext`](super::GlobalContext),
176179
/// and does not check for env key case mismatch.
177180
/// See the docstring of [`Env::get_str`] for more context.
178181
pub(super) fn contains_key(&self, key: impl AsRef<OsStr>) -> bool {

0 commit comments

Comments
 (0)