Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Clarify more Config -> Context #13506

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/xtask-bump-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
let cli = xtask::cli();
let matches = cli.get_matches();

let mut gctx = cargo::util::config::GlobalContext::default().unwrap_or_else(|e| {
let mut gctx = cargo::util::context::GlobalContext::default().unwrap_or_else(|e| {
let mut eval = cargo::core::shell::Shell::new();
cargo::exit_with_error(e.into(), &mut eval)
});
Expand Down
14 changes: 7 additions & 7 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Context as _};
use cargo::core::{features, CliUnstable};
use cargo::util::config::TermConfig;
use cargo::util::context::TermConfig;
use cargo::{drop_print, drop_println, CargoResult};
use clap::builder::UnknownArgumentValueParser;
use itertools::Itertools;
Expand Down Expand Up @@ -57,21 +57,21 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult {
== Some("help")
{
// Don't let config errors get in the way of parsing arguments
let _ = config_configure(gctx, &expanded_args, None, global_args, None);
let _ = configure_gctx(gctx, &expanded_args, None, global_args, None);
print_zhelp(gctx);
} else if expanded_args.flag("version") {
// Don't let config errors get in the way of parsing arguments
let _ = config_configure(gctx, &expanded_args, None, global_args, None);
let _ = configure_gctx(gctx, &expanded_args, None, global_args, None);
let version = get_version_string(is_verbose);
drop_print!(gctx, "{}", version);
} else if let Some(code) = expanded_args.get_one::<String>("explain") {
// Don't let config errors get in the way of parsing arguments
let _ = config_configure(gctx, &expanded_args, None, global_args, None);
let _ = configure_gctx(gctx, &expanded_args, None, global_args, None);
let mut procss = gctx.load_global_rustc(None)?.process();
procss.arg("--explain").arg(code).exec()?;
} else if expanded_args.flag("list") {
// Don't let config errors get in the way of parsing arguments
let _ = config_configure(gctx, &expanded_args, None, global_args, None);
let _ = configure_gctx(gctx, &expanded_args, None, global_args, None);
print_list(gctx, is_verbose);
} else {
let (cmd, subcommand_args) = match expanded_args.subcommand() {
Expand All @@ -83,7 +83,7 @@ pub fn main(gctx: &mut GlobalContext) -> CliResult {
}
};
let exec = Exec::infer(cmd)?;
config_configure(
configure_gctx(
gctx,
&expanded_args,
Some(subcommand_args),
Expand Down Expand Up @@ -377,7 +377,7 @@ For more information, see issue #12207 <https://github.com/rust-lang/cargo/issue
Ok((args, GlobalArgs::default()))
}

fn config_configure(
fn configure_gctx(
gctx: &mut GlobalContext,
args: &ArgMatches,
subcommand_args: Option<&ArgMatches>,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::core::compiler::CompileKind;
use crate::util::config::JobsConfig;
use crate::util::context::JobsConfig;
use crate::util::interning::InternedString;
use crate::util::{CargoResult, GlobalContext, RustfixDiagnosticServer};
use anyhow::{bail, Context as _};
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::core::compiler::{BuildConfig, CompileKind, Unit};
use crate::core::profiles::Profiles;
use crate::core::PackageSet;
use crate::core::Workspace;
use crate::util::config::GlobalContext;
use crate::util::context::GlobalContext;
use crate::util::errors::CargoResult;
use crate::util::interning::InternedString;
use crate::util::Rustc;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::core::compiler::{
BuildOutput, BuildRunner, CompileKind, CompileMode, CompileTarget, CrateType,
};
use crate::core::{Dependency, Package, Target, TargetKind, Workspace};
use crate::util::config::{GlobalContext, StringList, TargetConfig};
use crate::util::context::{GlobalContext, StringList, TargetConfig};
use crate::util::interning::InternedString;
use crate::util::{CargoResult, Rustc};
use anyhow::Context as _;
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::core::compiler::apply_env_config;
use crate::core::compiler::BuildContext;
use crate::core::compiler::{CompileKind, Metadata, Unit};
use crate::core::Package;
use crate::util::{config, CargoResult, GlobalContext};
use crate::util::{context, CargoResult, GlobalContext};

/// Represents the kind of process we are creating.
#[derive(Debug)]
Expand Down Expand Up @@ -453,7 +453,7 @@ fn target_runner(
// try target.{}.runner
let key = format!("target.{}.runner", target);

if let Some(v) = bcx.gctx.get::<Option<config::PathAndArgs>>(&key)? {
if let Some(v) = bcx.gctx.get::<Option<context::PathAndArgs>>(&key)? {
let path = v.path.resolve_program(bcx.gctx);
return Ok(Some((path, v.args)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
//! and summarize it similar to the other entries. Update the rest of the
//! documentation to add the new feature.
//!
//! [`GlobalContext::cli_unstable`]: crate::util::config::GlobalContext::cli_unstable
//! [`GlobalContext::cli_unstable`]: crate::util::context::GlobalContext::cli_unstable
//! [`fail_if_stable_opt`]: CliUnstable::fail_if_stable_opt
//! [`features!`]: macro.features.html
//! [`unstable_cli_options!`]: macro.unstable_cli_options.html
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::core::{
};
use crate::util::interning::InternedString;
use crate::util::toml::validate_profile;
use crate::util::{closest_msg, config, CargoResult, GlobalContext};
use crate::util::{closest_msg, context, CargoResult, GlobalContext};
use anyhow::{bail, Context as _};
use cargo_util_schemas::manifest::TomlTrimPaths;
use cargo_util_schemas::manifest::TomlTrimPathsValue;
Expand Down Expand Up @@ -1298,7 +1298,7 @@ fn merge_config_profiles(

/// Helper for fetching a profile from config.
fn get_config_profile(ws: &Workspace<'_>, name: &str) -> CargoResult<Option<TomlProfile>> {
let profile: Option<config::Value<TomlProfile>> =
let profile: Option<context::Value<TomlProfile>> =
ws.gctx().get(&format!("profile.{}", name))?;
let Some(profile) = profile else {
return Ok(None);
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use tracing::{debug, trace};

use crate::core::PackageIdSpec;
use crate::core::{Dependency, PackageId, Registry, Summary};
use crate::util::config::GlobalContext;
use crate::util::context::GlobalContext;
use crate::util::errors::CargoResult;
use crate::util::network::PollExt;
use crate::util::profile;
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::sources::source::Source;
use crate::sources::{DirectorySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
use crate::sources::{GitSource, PathSource, RegistrySource};
use crate::util::interning::InternedString;
use crate::util::{config, CanonicalUrl, CargoResult, GlobalContext, IntoUrl};
use crate::util::{context, CanonicalUrl, CargoResult, GlobalContext, IntoUrl};
use anyhow::Context as _;
use serde::de;
use serde::ser;
Expand Down Expand Up @@ -268,7 +268,7 @@ impl SourceId {

/// Returns whether to access crates.io over the sparse protocol.
pub fn crates_io_is_sparse(gctx: &GlobalContext) -> CargoResult<bool> {
let proto: Option<config::Value<String>> = gctx.get("registries.crates-io.protocol")?;
let proto: Option<context::Value<String>> = gctx.get("registries.crates-io.protocol")?;
let is_sparse = match proto.as_ref().map(|v| v.val.as_str()) {
Some("sparse") => true,
Some("git") => false,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::util::edit_distance;
use crate::util::errors::{CargoResult, ManifestError};
use crate::util::interning::InternedString;
use crate::util::toml::{read_manifest, InheritableFields};
use crate::util::{config::ConfigRelativePath, Filesystem, GlobalContext, IntoUrl};
use crate::util::{context::ConfigRelativePath, Filesystem, GlobalContext, IntoUrl};
use cargo_util::paths;
use cargo_util::paths::normalize_path;
use cargo_util_schemas::manifest::RustVersion;
Expand Down
11 changes: 6 additions & 5 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
//! directory.
//! - [`util`]:
//! This directory contains generally-useful utility modules.
//! - [`util::config`]:
//! This directory contains the config parser. It makes heavy use of
//! [serde](https://serde.rs/) to merge and translate config values. The
//! [`util::GlobalContext`] is usually accessed from the
//! - [`util::context`]:
//! This directory contains the global applicaton context.
//! This includes the config parser which makes heavy use of
//! [serde](https://serde.rs/) to merge and translate config values.
//! The [`util::GlobalContext`] is usually accessed from the
//! [`core::Workspace`]
//! though references to it are scattered around for more convenient access.
//! - [`util::toml`]:
Expand Down Expand Up @@ -117,7 +118,7 @@
//! - `src/*/*`: Extracted from `*.crate` by [`sources::registry::RegistrySource`]
//! - `git/`: Git source cache. See [`sources::git`].
//! - `**/.cargo/config.toml`: Environment dependent (env variables, files) configuration. See
//! [`util::config`]
//! [`util::context`]
//!
//! ## Contribute to Cargo documentations
//!
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use crate::core::{PackageId, PackageSet, SourceId, TargetKind, Workspace};
use crate::drop_println;
use crate::ops;
use crate::ops::resolve::WorkspaceResolve;
use crate::util::config::GlobalContext;
use crate::util::context::GlobalContext;
use crate::util::interning::InternedString;
use crate::util::{profile, CargoResult, StableHasher};

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Implementation of `cargo config` subcommand.

use crate::util::config::{ConfigKey, ConfigValue as CV, Definition, GlobalContext};
use crate::util::context::{ConfigKey, ConfigValue as CV, Definition, GlobalContext};
use crate::util::errors::CargoResult;
use crate::{drop_eprintln, drop_println};
use anyhow::{bail, format_err, Error};
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::core::compiler::{Compilation, CompileKind};
use crate::core::{Shell, Workspace};
use crate::ops;
use crate::util::config::{GlobalContext, PathAndArgs};
use crate::util::context::{GlobalContext, PathAndArgs};
use crate::util::CargoResult;
use anyhow::{bail, Error};
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::core::compiler::standard_lib;
use crate::core::compiler::{BuildConfig, CompileMode, RustcTargetData};
use crate::core::{PackageSet, Resolve, Workspace};
use crate::ops;
use crate::util::config::JobsConfig;
use crate::util::context::JobsConfig;
use crate::util::CargoResult;
use crate::util::GlobalContext;
use std::collections::HashSet;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::core::{Resolve, SourceId, Workspace};
use crate::ops;
use crate::sources::source::QueryKind;
use crate::util::cache_lock::CacheLockMode;
use crate::util::config::GlobalContext;
use crate::util::context::GlobalContext;
use crate::util::style;
use crate::util::CargoResult;
use anstyle::Style;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::core::{Feature, Shell, Verbosity, Workspace};
use crate::core::{Package, PackageId, PackageSet, Resolve, SourceId};
use crate::sources::PathSource;
use crate::util::cache_lock::CacheLockMode;
use crate::util::config::JobsConfig;
use crate::util::context::JobsConfig;
use crate::util::errors::CargoResult;
use crate::util::toml::{prepare_for_publish, to_real_manifest};
use crate::util::{self, human_readable_bytes, restricted_names, FileLock, GlobalContext};
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::sources::source::Source;
use crate::sources::{RegistrySource, SourceConfigMap};
use crate::util::auth;
use crate::util::cache_lock::CacheLockMode;
use crate::util::config::{GlobalContext, PathAndArgs};
use crate::util::context::{GlobalContext, PathAndArgs};
use crate::util::errors::CargoResult;
use crate::util::network::http::http_handle;

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::sources::SourceConfigMap;
use crate::sources::CRATES_IO_REGISTRY;
use crate::util::auth;
use crate::util::cache_lock::CacheLockMode;
use crate::util::config::JobsConfig;
use crate::util::context::JobsConfig;
use crate::util::Progress;
use crate::util::ProgressStyle;
use crate::CargoResult;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/registry/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cargo_credential::Operation;
use cargo_credential::Secret;

use crate::core::Workspace;
use crate::util::config::GlobalContext;
use crate::util::context::GlobalContext;
use crate::util::errors::CargoResult;
use crate::util::important_paths::find_root_manifest_for_wd;

Expand Down
4 changes: 2 additions & 2 deletions src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::core::{GitReference, PackageId, SourceId};
use crate::sources::source::Source;
use crate::sources::{ReplacedSource, CRATES_IO_REGISTRY};
use crate::util::config::{self, ConfigRelativePath, OptValue};
use crate::util::context::{self, ConfigRelativePath, OptValue};
use crate::util::errors::CargoResult;
use crate::util::{GlobalContext, IntoUrl};
use anyhow::{bail, Context as _};
Expand Down Expand Up @@ -311,7 +311,7 @@ restore the source replacement configuration to continue the build

return Ok(());

fn url(val: &config::Value<String>, key: &str) -> CargoResult<Url> {
fn url(val: &context::Value<String>, key: &str) -> CargoResult<Url> {
let url = val.val.into_url().with_context(|| {
format!(
"configuration key `{}` specified an invalid \
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/sources/git/known_hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//! added (it just adds a little complexity). For example, hostname patterns,
//! and revoked markers. See "FIXME" comments littered in this file.

use crate::util::config::{Definition, GlobalContext, Value};
use crate::util::context::{Definition, GlobalContext, Value};
use base64::engine::general_purpose::STANDARD;
use base64::engine::general_purpose::STANDARD_NO_PAD;
use base64::Engine as _;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/sources/git/oxide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub fn cargo_config_to_gitoxide_overrides(gctx: &GlobalContext) -> CargoResult<V
Http::USER_AGENT.validated_assignment_fmt(&format!("cargo {}", crate::version()))
}?);
if let Some(ssl_version) = &http.ssl_version {
use crate::util::config::SslVersionConfig;
use crate::util::context::SslVersionConfig;
match ssl_version {
SslVersionConfig::Single(version) => {
values.push(Http::SSL_VERSION.validated_assignment_fmt(&version)?);
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/util/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
core::features::cargo_docs_link,
util::{config::ConfigKey, CanonicalUrl, CargoResult, GlobalContext, IntoUrl},
util::{context::ConfigKey, CanonicalUrl, CargoResult, GlobalContext, IntoUrl},
};
use anyhow::{bail, Context as _};
use cargo_credential::{
Expand All @@ -17,12 +17,12 @@ use time::{Duration, OffsetDateTime};
use url::Url;

use crate::core::SourceId;
use crate::util::config::Value;
use crate::util::context::Value;
use crate::util::credential::adaptor::BasicProcessCredential;
use crate::util::credential::paseto::PasetoCredential;

use super::{
config::{CredentialCacheValue, OptValue, PathAndArgs},
context::{CredentialCacheValue, OptValue, PathAndArgs},
credential::process::CredentialProcessCredential,
credential::token::TokenCredential,
};
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use clap::{value_parser, Arg, ArgAction, ArgMatches};

pub use clap::Command;

use super::config::JobsConfig;
use super::context::JobsConfig;
use super::IntoUrl;

pub mod heading {
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/util/config/de.rs → src/cargo/util/context/de.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Support for deserializing configuration via `serde`

use crate::util::config::value;
use crate::util::config::{ConfigError, ConfigKey, GlobalContext};
use crate::util::config::{ConfigValue as CV, Definition, Value};
use crate::util::context::value;
use crate::util::context::{ConfigError, ConfigKey, GlobalContext};
use crate::util::context::{ConfigValue as CV, Definition, Value};
use serde::{de, de::IntoDeserializer};
use std::collections::HashSet;
use std::vec;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! from configuration, but also record where it was deserialized from when it
//! was read.

use crate::util::config::GlobalContext;
use crate::util::context::GlobalContext;
use serde::de;
use std::cmp::Ordering;
use std::fmt;
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/util/credential/paseto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use url::Url;
use crate::{
core::SourceId,
ops::RegistryCredentialConfig,
util::{auth::registry_credential_config_raw, command_prelude::opt, config},
util::{auth::registry_credential_config_raw, command_prelude::opt, context},
GlobalContext,
};

Expand Down Expand Up @@ -196,12 +196,12 @@ impl<'a> Credential for PasetoCredential<'a> {
None => old_key_subject,
},
));
config::save_credentials(self.gctx, Some(new_token), &sid)?;
context::save_credentials(self.gctx, Some(new_token), &sid)?;
Ok(CredentialResponse::Login)
}
Action::Logout => {
if reg_cfg.and_then(|c| c.secret_key).is_some() {
config::save_credentials(self.gctx, None, &sid)?;
context::save_credentials(self.gctx, None, &sid)?;
let reg_name = sid.display_registry_name();
let _ = self.gctx.shell().status(
"Logout",
Expand Down
Loading