mirror of
https://github.com/rust-lang/cargo
synced 2024-10-03 22:43:59 +00:00
refactor(core): Expose all of the variants of VirtualManifests
This commit is contained in:
parent
a694ea9777
commit
8152bfbb5e
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -470,7 +470,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cargo-util-schemas"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"semver",
|
||||
"serde",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "cargo-util-schemas"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
rust-version = "1.76.0" # MSRV:1
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
|
|
@ -26,7 +26,7 @@ pub use rust_version::RustVersion;
|
|||
pub use rust_version::RustVersionError;
|
||||
|
||||
/// This type is used to deserialize `Cargo.toml` files.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Default, Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct TomlManifest {
|
||||
// when adding new fields, be sure to check whether `requires_package` should disallow them
|
||||
|
|
|
@ -12,6 +12,7 @@ use crate::util::errors::CargoResult;
|
|||
use crate::GlobalContext;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::BuildConfig;
|
||||
|
||||
|
@ -103,6 +104,10 @@ pub fn resolve_std<'gctx>(
|
|||
/*custom_metadata*/ &None,
|
||||
));
|
||||
let virtual_manifest = crate::core::VirtualManifest::new(
|
||||
Rc::default(),
|
||||
Rc::new(toml_edit::ImDocument::parse("".to_owned()).expect("empty is valid TOML")),
|
||||
Rc::default(),
|
||||
Rc::default(),
|
||||
/*replace*/ Vec::new(),
|
||||
patch,
|
||||
ws_config,
|
||||
|
|
|
@ -88,6 +88,13 @@ pub struct Warnings(Vec<DelayedWarning>);
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct VirtualManifest {
|
||||
// alternate forms of manifests:
|
||||
contents: Rc<String>,
|
||||
document: Rc<toml_edit::ImDocument<String>>,
|
||||
original_toml: Rc<TomlManifest>,
|
||||
resolved_toml: Rc<TomlManifest>,
|
||||
|
||||
// this form of manifest:
|
||||
replace: Vec<(PackageIdSpec, Dependency)>,
|
||||
patch: HashMap<Url, Vec<Dependency>>,
|
||||
workspace: WorkspaceConfig,
|
||||
|
@ -629,6 +636,10 @@ impl Manifest {
|
|||
|
||||
impl VirtualManifest {
|
||||
pub fn new(
|
||||
contents: Rc<String>,
|
||||
document: Rc<toml_edit::ImDocument<String>>,
|
||||
original_toml: Rc<TomlManifest>,
|
||||
resolved_toml: Rc<TomlManifest>,
|
||||
replace: Vec<(PackageIdSpec, Dependency)>,
|
||||
patch: HashMap<Url, Vec<Dependency>>,
|
||||
workspace: WorkspaceConfig,
|
||||
|
@ -637,6 +648,10 @@ impl VirtualManifest {
|
|||
resolve_behavior: Option<ResolveBehavior>,
|
||||
) -> VirtualManifest {
|
||||
VirtualManifest {
|
||||
contents,
|
||||
document,
|
||||
original_toml,
|
||||
resolved_toml,
|
||||
replace,
|
||||
patch,
|
||||
workspace,
|
||||
|
@ -647,6 +662,23 @@ impl VirtualManifest {
|
|||
}
|
||||
}
|
||||
|
||||
/// The raw contents of the original TOML
|
||||
pub fn contents(&self) -> &str {
|
||||
self.contents.as_str()
|
||||
}
|
||||
/// Collection of spans for the original TOML
|
||||
pub fn document(&self) -> &toml_edit::ImDocument<String> {
|
||||
&self.document
|
||||
}
|
||||
/// The [`TomlManifest`] with all fields expanded
|
||||
pub fn original_toml(&self) -> &TomlManifest {
|
||||
&self.original_toml
|
||||
}
|
||||
/// The [`TomlManifest`] with all fields expanded
|
||||
pub fn resolved_toml(&self) -> &TomlManifest {
|
||||
&self.resolved_toml
|
||||
}
|
||||
|
||||
pub fn replace(&self) -> &[(PackageIdSpec, Dependency)] {
|
||||
&self.replace
|
||||
}
|
||||
|
|
|
@ -60,7 +60,8 @@ pub fn read_manifest(
|
|||
to_real_manifest(contents, document, original_toml, source_id, path, gctx)
|
||||
.map(EitherManifest::Real)
|
||||
} else {
|
||||
to_virtual_manifest(original_toml, source_id, path, gctx).map(EitherManifest::Virtual)
|
||||
to_virtual_manifest(contents, document, original_toml, source_id, path, gctx)
|
||||
.map(EitherManifest::Virtual)
|
||||
}
|
||||
})()
|
||||
.map_err(|err| {
|
||||
|
@ -1276,6 +1277,8 @@ fn load_inheritable_fields(
|
|||
}
|
||||
|
||||
fn to_virtual_manifest(
|
||||
contents: String,
|
||||
document: toml_edit::ImDocument<String>,
|
||||
original_toml: manifest::TomlManifest,
|
||||
source_id: SourceId,
|
||||
manifest_file: &Path,
|
||||
|
@ -1362,7 +1365,12 @@ fn to_virtual_manifest(
|
|||
bail!("virtual manifests must be configured with [workspace]");
|
||||
}
|
||||
};
|
||||
let resolved_toml = original_toml.clone();
|
||||
let mut manifest = VirtualManifest::new(
|
||||
Rc::new(contents),
|
||||
Rc::new(document),
|
||||
Rc::new(original_toml),
|
||||
Rc::new(resolved_toml),
|
||||
replace,
|
||||
patch,
|
||||
workspace_config,
|
||||
|
|
Loading…
Reference in a new issue