mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
refactor(toml): Centralize cargo-features parsing
This commit is contained in:
parent
5d8bdf4f41
commit
0f5b562e62
@ -59,11 +59,16 @@ pub fn read_manifest(
|
|||||||
.map_err(|e| emit_diagnostic(e.into(), &contents, path, gctx))?;
|
.map_err(|e| emit_diagnostic(e.into(), &contents, path, gctx))?;
|
||||||
|
|
||||||
let mut manifest = (|| {
|
let mut manifest = (|| {
|
||||||
|
let empty = Vec::new();
|
||||||
|
let cargo_features = original_toml.cargo_features.as_ref().unwrap_or(&empty);
|
||||||
|
let features = Features::new(cargo_features, gctx, &mut warnings, source_id.is_path())?;
|
||||||
|
|
||||||
if original_toml.package().is_some() {
|
if original_toml.package().is_some() {
|
||||||
to_real_manifest(
|
to_real_manifest(
|
||||||
contents,
|
contents,
|
||||||
document,
|
document,
|
||||||
original_toml,
|
original_toml,
|
||||||
|
features,
|
||||||
source_id,
|
source_id,
|
||||||
path,
|
path,
|
||||||
gctx,
|
gctx,
|
||||||
@ -76,6 +81,7 @@ pub fn read_manifest(
|
|||||||
contents,
|
contents,
|
||||||
document,
|
document,
|
||||||
original_toml,
|
original_toml,
|
||||||
|
features,
|
||||||
source_id,
|
source_id,
|
||||||
path,
|
path,
|
||||||
gctx,
|
gctx,
|
||||||
@ -222,6 +228,7 @@ pub fn prepare_for_publish(me: &Package, ws: &Workspace<'_>) -> CargoResult<Pack
|
|||||||
let contents = me.manifest().contents();
|
let contents = me.manifest().contents();
|
||||||
let document = me.manifest().document();
|
let document = me.manifest().document();
|
||||||
let toml_manifest = prepare_toml_for_publish(me.manifest().resolved_toml(), ws, me.root())?;
|
let toml_manifest = prepare_toml_for_publish(me.manifest().resolved_toml(), ws, me.root())?;
|
||||||
|
let features = me.manifest().unstable_features().clone();
|
||||||
let source_id = me.package_id().source_id();
|
let source_id = me.package_id().source_id();
|
||||||
let mut warnings = Default::default();
|
let mut warnings = Default::default();
|
||||||
let mut errors = Default::default();
|
let mut errors = Default::default();
|
||||||
@ -230,6 +237,7 @@ pub fn prepare_for_publish(me: &Package, ws: &Workspace<'_>) -> CargoResult<Pack
|
|||||||
contents.to_owned(),
|
contents.to_owned(),
|
||||||
document.clone(),
|
document.clone(),
|
||||||
toml_manifest,
|
toml_manifest,
|
||||||
|
features,
|
||||||
source_id,
|
source_id,
|
||||||
me.manifest_path(),
|
me.manifest_path(),
|
||||||
gctx,
|
gctx,
|
||||||
@ -486,6 +494,7 @@ pub fn to_real_manifest(
|
|||||||
contents: String,
|
contents: String,
|
||||||
document: toml_edit::ImDocument<String>,
|
document: toml_edit::ImDocument<String>,
|
||||||
original_toml: manifest::TomlManifest,
|
original_toml: manifest::TomlManifest,
|
||||||
|
features: Features,
|
||||||
source_id: SourceId,
|
source_id: SourceId,
|
||||||
manifest_file: &Path,
|
manifest_file: &Path,
|
||||||
gctx: &GlobalContext,
|
gctx: &GlobalContext,
|
||||||
@ -501,11 +510,6 @@ pub fn to_real_manifest(
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse features first so they will be available when parsing other parts of the TOML.
|
|
||||||
let empty = Vec::new();
|
|
||||||
let cargo_features = original_toml.cargo_features.as_ref().unwrap_or(&empty);
|
|
||||||
let features = Features::new(cargo_features, gctx, warnings, source_id.is_path())?;
|
|
||||||
|
|
||||||
let original_package = match (&original_toml.package, &original_toml.project) {
|
let original_package = match (&original_toml.package, &original_toml.project) {
|
||||||
(Some(_), Some(project)) => {
|
(Some(_), Some(project)) => {
|
||||||
warnings.push(format!(
|
warnings.push(format!(
|
||||||
@ -1462,6 +1466,7 @@ fn to_virtual_manifest(
|
|||||||
contents: String,
|
contents: String,
|
||||||
document: toml_edit::ImDocument<String>,
|
document: toml_edit::ImDocument<String>,
|
||||||
original_toml: manifest::TomlManifest,
|
original_toml: manifest::TomlManifest,
|
||||||
|
features: Features,
|
||||||
source_id: SourceId,
|
source_id: SourceId,
|
||||||
manifest_file: &Path,
|
manifest_file: &Path,
|
||||||
gctx: &GlobalContext,
|
gctx: &GlobalContext,
|
||||||
@ -1476,13 +1481,9 @@ fn to_virtual_manifest(
|
|||||||
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
|
bail!("this virtual manifest specifies a `{field}` section, which is not allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut deps = Vec::new();
|
|
||||||
let empty = Vec::new();
|
|
||||||
let cargo_features = original_toml.cargo_features.as_ref().unwrap_or(&empty);
|
|
||||||
let features = Features::new(cargo_features, gctx, warnings, source_id.is_path())?;
|
|
||||||
|
|
||||||
resolved_toml._unused_keys = Default::default();
|
resolved_toml._unused_keys = Default::default();
|
||||||
|
|
||||||
|
let mut deps = Vec::new();
|
||||||
let (replace, patch) = {
|
let (replace, patch) = {
|
||||||
let mut manifest_ctx = ManifestContext {
|
let mut manifest_ctx = ManifestContext {
|
||||||
deps: &mut deps,
|
deps: &mut deps,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user