mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor(embedded): Move package to normalization
This commit is contained in:
parent
8a40b36fdc
commit
3582b788cd
@ -87,19 +87,17 @@ fn expand_manifest_(manifest: &str, path: &std::path::Path) -> CargoResult<toml:
|
||||
// Prevent looking for a workspace by `read_manifest_from_str`
|
||||
manifest.insert("workspace".to_owned(), toml::Table::new().into());
|
||||
|
||||
let package = manifest
|
||||
.entry("package".to_owned())
|
||||
.or_insert_with(|| toml::Table::new().into())
|
||||
.as_table_mut()
|
||||
.ok_or_else(|| anyhow::format_err!("`package` must be a table"))?;
|
||||
for key in ["workspace", "build", "links"]
|
||||
.iter()
|
||||
.chain(AUTO_FIELDS.iter())
|
||||
{
|
||||
if package.contains_key(*key) {
|
||||
anyhow::bail!("`package.{key}` is not allowed in embedded manifests")
|
||||
if let Some(package) = manifest.get("package").and_then(|v| v.as_table()) {
|
||||
for key in ["workspace", "build", "links"]
|
||||
.iter()
|
||||
.chain(AUTO_FIELDS.iter())
|
||||
{
|
||||
if package.contains_key(*key) {
|
||||
anyhow::bail!("`package.{key}` is not allowed in embedded manifests")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HACK: Using an absolute path while `hacked_path` is in use
|
||||
let bin_path = path.to_string_lossy().into_owned();
|
||||
let file_stem = path
|
||||
@ -541,8 +539,6 @@ fn main() {}
|
||||
name = "test-"
|
||||
path = "/home/me/test.rs"
|
||||
|
||||
[package]
|
||||
|
||||
[workspace]
|
||||
|
||||
"#]]
|
||||
@ -568,8 +564,6 @@ path = [..]
|
||||
[dependencies]
|
||||
time = "0.1.25"
|
||||
|
||||
[package]
|
||||
|
||||
[workspace]
|
||||
|
||||
"#]]
|
||||
|
@ -1,4 +1,5 @@
|
||||
use annotate_snippets::{Level, Snippet};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
||||
use std::ffi::OsStr;
|
||||
use std::path::{Path, PathBuf};
|
||||
@ -319,9 +320,20 @@ fn normalize_toml(
|
||||
_unused_keys: Default::default(),
|
||||
};
|
||||
|
||||
if let Some(original_package) = original_toml.package() {
|
||||
let normalized_package =
|
||||
normalize_package_toml(original_package, manifest_file, is_embedded, gctx, &inherit)?;
|
||||
if let Some(original_package) = original_toml.package().map(Cow::Borrowed).or_else(|| {
|
||||
if is_embedded {
|
||||
Some(Cow::Owned(Box::new(manifest::TomlPackage::default())))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}) {
|
||||
let normalized_package = normalize_package_toml(
|
||||
&original_package,
|
||||
manifest_file,
|
||||
is_embedded,
|
||||
gctx,
|
||||
&inherit,
|
||||
)?;
|
||||
let package_name = &normalized_package
|
||||
.normalized_name()
|
||||
.expect("previously normalized")
|
||||
|
Loading…
x
Reference in New Issue
Block a user