Skip to content

Commit b97cffe

Browse files
committed
Auto merge of #13080 - epage:toml, r=weihanglo
refactor(toml): Decouple logic from schema ### What does this PR try to resolve? This tries to decouple cargo logic from the schemas so we can split the schemas out into a separate crate for #12801 Profile layering was one of the few pieces of logic I kept in the schema, assuming its general enough / decoupled enough from cargo policies. ### How should we test and review this PR? Each step is broken down into its own commit for easier analysis ### Additional information
2 parents 78109c0 + 9bb7c97 commit b97cffe

File tree

7 files changed

+1580
-1618
lines changed

7 files changed

+1580
-1618
lines changed

src/cargo/core/features.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub const SEE_CHANNELS: &str =
168168
/// - Update [`CLI_VALUES`] to include the new edition.
169169
/// - Set [`LATEST_UNSTABLE`] to Some with the new edition.
170170
/// - Add an unstable feature to the [`features!`] macro invocation below for the new edition.
171-
/// - Gate on that new feature in [`TomlManifest::to_real_manifest`].
171+
/// - Gate on that new feature in [`toml::to_real_manifest`].
172172
/// - Update the shell completion files.
173173
/// - Update any failing tests (hopefully there are very few).
174174
/// - Update unstable.md to add a new section for this new edition (see [this example]).
@@ -195,7 +195,7 @@ pub const SEE_CHANNELS: &str =
195195
/// [`LATEST_STABLE`]: Edition::LATEST_STABLE
196196
/// [this example]: https://github.com/rust-lang/cargo/blob/3ebb5f15a940810f250b68821149387af583a79e/src/doc/src/reference/unstable.md?plain=1#L1238-L1264
197197
/// [`is_stable`]: Edition::is_stable
198-
/// [`TomlManifest::to_real_manifest`]: crate::util::toml::schema::TomlManifest::to_real_manifest
198+
/// [`toml::to_real_manifest`]: crate::util::toml::to_real_manifest
199199
/// [`features!`]: macro.features.html
200200
#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, Eq, PartialEq, Serialize, Deserialize)]
201201
pub enum Edition {

src/cargo/core/package.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::util::network::http::http_handle_and_timeout;
3131
use crate::util::network::http::HttpTimeout;
3232
use crate::util::network::retry::{Retry, RetryResult};
3333
use crate::util::network::sleep::SleepTracker;
34+
use crate::util::toml::prepare_for_publish;
3435
use crate::util::RustVersion;
3536
use crate::util::{self, internal, Config, Progress, ProgressStyle};
3637

@@ -197,10 +198,7 @@ impl Package {
197198
}
198199

199200
pub fn to_registry_toml(&self, ws: &Workspace<'_>) -> CargoResult<String> {
200-
let manifest = self
201-
.manifest()
202-
.original()
203-
.prepare_for_publish(ws, self.root())?;
201+
let manifest = prepare_for_publish(self.manifest().original(), ws, self.root())?;
204202
let toml = toml::to_string_pretty(&manifest)?;
205203
Ok(format!("{}\n{}", MANIFEST_PREAMBLE, toml))
206204
}

src/cargo/core/profiles.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::util::toml::schema::TomlTrimPathsValue;
3232
use crate::util::toml::schema::{
3333
ProfilePackageSpec, StringOrBool, TomlDebugInfo, TomlProfile, TomlProfiles,
3434
};
35+
use crate::util::toml::validate_profile;
3536
use crate::util::{closest_msg, config, CargoResult, Config};
3637
use anyhow::{bail, Context as _};
3738
use std::collections::{BTreeMap, HashMap, HashSet};
@@ -1235,20 +1236,19 @@ fn get_config_profile(ws: &Workspace<'_>, name: &str) -> CargoResult<Option<Toml
12351236
return Ok(None);
12361237
};
12371238
let mut warnings = Vec::new();
1238-
profile
1239-
.val
1240-
.validate(
1241-
name,
1242-
ws.config().cli_unstable(),
1243-
ws.unstable_features(),
1244-
&mut warnings,
1239+
validate_profile(
1240+
&profile.val,
1241+
name,
1242+
ws.config().cli_unstable(),
1243+
ws.unstable_features(),
1244+
&mut warnings,
1245+
)
1246+
.with_context(|| {
1247+
format!(
1248+
"config profile `{}` is not valid (defined in `{}`)",
1249+
name, profile.definition
12451250
)
1246-
.with_context(|| {
1247-
format!(
1248-
"config profile `{}` is not valid (defined in `{}`)",
1249-
name, profile.definition
1250-
)
1251-
})?;
1251+
})?;
12521252
for warning in warnings {
12531253
ws.config().shell().warn(warning)?;
12541254
}

src/cargo/core/workspace.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ impl<'cfg> Workspace<'cfg> {
437437
url,
438438
deps.iter()
439439
.map(|(name, dep)| {
440-
dep.to_dependency_split(
440+
crate::util::toml::to_dependency(
441+
dep,
441442
name,
442443
source,
443444
&mut nested_paths,

src/cargo/ops/cargo_package.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::sources::PathSource;
1616
use crate::util::cache_lock::CacheLockMode;
1717
use crate::util::config::JobsConfig;
1818
use crate::util::errors::CargoResult;
19-
use crate::util::toml::schema::TomlManifest;
19+
use crate::util::toml::{prepare_for_publish, to_real_manifest};
2020
use crate::util::{self, human_readable_bytes, restricted_names, Config, FileLock};
2121
use crate::{drop_println, ops};
2222
use anyhow::Context as _;
@@ -454,14 +454,11 @@ fn build_lock(ws: &Workspace<'_>, orig_pkg: &Package) -> CargoResult<String> {
454454
let orig_resolve = ops::load_pkg_lockfile(ws)?;
455455

456456
// Convert Package -> TomlManifest -> Manifest -> Package
457-
let toml_manifest = orig_pkg
458-
.manifest()
459-
.original()
460-
.prepare_for_publish(ws, orig_pkg.root())?;
457+
let toml_manifest = prepare_for_publish(orig_pkg.manifest().original(), ws, orig_pkg.root())?;
461458
let package_root = orig_pkg.root();
462459
let source_id = orig_pkg.package_id().source_id();
463460
let (manifest, _nested_paths) =
464-
TomlManifest::to_real_manifest(toml_manifest, false, source_id, package_root, config)?;
461+
to_real_manifest(toml_manifest, false, source_id, package_root, config)?;
465462
let new_pkg = Package::new(manifest, orig_pkg.manifest_path());
466463

467464
let max_rust_version = new_pkg.rust_version().cloned();

0 commit comments

Comments
 (0)