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