mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
refactor(embedded): Move package.edition to normalization
This commit is contained in:
parent
f6b9c8f874
commit
911f174832
@ -6,8 +6,6 @@ use crate::util::restricted_names;
|
||||
use crate::CargoResult;
|
||||
use crate::GlobalContext;
|
||||
|
||||
const DEFAULT_EDITION: crate::core::features::Edition =
|
||||
crate::core::features::Edition::LATEST_STABLE;
|
||||
const AUTO_FIELDS: &[&str] = &[
|
||||
"autolib",
|
||||
"autobins",
|
||||
@ -64,24 +62,20 @@ pub(super) fn expand_manifest(
|
||||
}
|
||||
cargo_util::paths::write_if_changed(&hacked_path, hacked_source)?;
|
||||
|
||||
let manifest = expand_manifest_(&frontmatter, &hacked_path, gctx)
|
||||
let manifest = expand_manifest_(&frontmatter, &hacked_path)
|
||||
.with_context(|| format!("failed to parse manifest at `{}`", path.display()))?;
|
||||
let manifest = toml::to_string_pretty(&manifest)?;
|
||||
Ok(manifest)
|
||||
} else {
|
||||
let frontmatter = "";
|
||||
let manifest = expand_manifest_(frontmatter, path, gctx)
|
||||
let manifest = expand_manifest_(frontmatter, path)
|
||||
.with_context(|| format!("failed to parse manifest at `{}`", path.display()))?;
|
||||
let manifest = toml::to_string_pretty(&manifest)?;
|
||||
Ok(manifest)
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_manifest_(
|
||||
manifest: &str,
|
||||
path: &std::path::Path,
|
||||
gctx: &GlobalContext,
|
||||
) -> CargoResult<toml::Table> {
|
||||
fn expand_manifest_(manifest: &str, path: &std::path::Path) -> CargoResult<toml::Table> {
|
||||
let mut manifest: toml::Table = toml::from_str(&manifest)?;
|
||||
|
||||
for key in ["workspace", "lib", "bin", "example", "test", "bench"] {
|
||||
@ -117,13 +111,6 @@ fn expand_manifest_(
|
||||
package
|
||||
.entry("name".to_owned())
|
||||
.or_insert(toml::Value::String(name));
|
||||
package.entry("edition".to_owned()).or_insert_with(|| {
|
||||
let _ = gctx.shell().warn(format_args!(
|
||||
"`package.edition` is unspecified, defaulting to `{}`",
|
||||
DEFAULT_EDITION
|
||||
));
|
||||
toml::Value::String(DEFAULT_EDITION.to_string())
|
||||
});
|
||||
|
||||
let mut bin = toml::Table::new();
|
||||
bin.insert("name".to_owned(), toml::Value::String(bin_name));
|
||||
@ -558,7 +545,6 @@ name = "test-"
|
||||
path = "/home/me/test.rs"
|
||||
|
||||
[package]
|
||||
edition = "2024"
|
||||
name = "test-"
|
||||
|
||||
[workspace]
|
||||
@ -587,7 +573,6 @@ path = [..]
|
||||
time = "0.1.25"
|
||||
|
||||
[package]
|
||||
edition = "2024"
|
||||
name = "test-"
|
||||
|
||||
[workspace]
|
||||
|
@ -321,7 +321,7 @@ fn normalize_toml(
|
||||
|
||||
if let Some(original_package) = original_toml.package() {
|
||||
let normalized_package =
|
||||
normalize_package_toml(original_package, manifest_file, is_embedded, &inherit)?;
|
||||
normalize_package_toml(original_package, manifest_file, is_embedded, gctx, &inherit)?;
|
||||
let package_name = &normalized_package.name.clone();
|
||||
let edition = normalized_package
|
||||
.normalized_edition()
|
||||
@ -550,6 +550,7 @@ fn normalize_package_toml<'a>(
|
||||
original_package: &manifest::TomlPackage,
|
||||
manifest_file: &Path,
|
||||
is_embedded: bool,
|
||||
gctx: &GlobalContext,
|
||||
inherit: &dyn Fn() -> CargoResult<&'a InheritableFields>,
|
||||
) -> CargoResult<Box<manifest::TomlPackage>> {
|
||||
let package_root = manifest_file.parent().unwrap();
|
||||
@ -559,7 +560,22 @@ fn normalize_package_toml<'a>(
|
||||
.clone()
|
||||
.map(|value| field_inherit_with(value, "edition", || inherit()?.edition()))
|
||||
.transpose()?
|
||||
.map(manifest::InheritableField::Value);
|
||||
.map(manifest::InheritableField::Value)
|
||||
.or_else(|| {
|
||||
if is_embedded {
|
||||
const DEFAULT_EDITION: crate::core::features::Edition =
|
||||
crate::core::features::Edition::LATEST_STABLE;
|
||||
let _ = gctx.shell().warn(format_args!(
|
||||
"`package.edition` is unspecified, defaulting to `{}`",
|
||||
DEFAULT_EDITION
|
||||
));
|
||||
Some(manifest::InheritableField::Value(
|
||||
DEFAULT_EDITION.to_string(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
let rust_version = original_package
|
||||
.rust_version
|
||||
.clone()
|
||||
|
Loading…
x
Reference in New Issue
Block a user