mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
parent
74e658ca78
commit
2efeeda17b
@ -6,6 +6,7 @@ use std::hash::{Hash, Hasher};
|
|||||||
|
|
||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde::ser;
|
use serde::ser;
|
||||||
|
use toml;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use core::{Dependency, PackageId, PackageIdSpec, SourceId, Summary};
|
use core::{Dependency, PackageId, PackageIdSpec, SourceId, Summary};
|
||||||
@ -30,6 +31,7 @@ pub struct Manifest {
|
|||||||
exclude: Vec<String>,
|
exclude: Vec<String>,
|
||||||
include: Vec<String>,
|
include: Vec<String>,
|
||||||
metadata: ManifestMetadata,
|
metadata: ManifestMetadata,
|
||||||
|
custom_metadata: Option<toml::Value>,
|
||||||
profiles: Profiles,
|
profiles: Profiles,
|
||||||
publish: Option<Vec<String>>,
|
publish: Option<Vec<String>>,
|
||||||
publish_lockfile: bool,
|
publish_lockfile: bool,
|
||||||
@ -265,6 +267,7 @@ impl Manifest {
|
|||||||
include: Vec<String>,
|
include: Vec<String>,
|
||||||
links: Option<String>,
|
links: Option<String>,
|
||||||
metadata: ManifestMetadata,
|
metadata: ManifestMetadata,
|
||||||
|
custom_metadata: Option<toml::Value>,
|
||||||
profiles: Profiles,
|
profiles: Profiles,
|
||||||
publish: Option<Vec<String>>,
|
publish: Option<Vec<String>>,
|
||||||
publish_lockfile: bool,
|
publish_lockfile: bool,
|
||||||
@ -284,6 +287,7 @@ impl Manifest {
|
|||||||
include,
|
include,
|
||||||
links,
|
links,
|
||||||
metadata,
|
metadata,
|
||||||
|
custom_metadata,
|
||||||
profiles,
|
profiles,
|
||||||
publish,
|
publish,
|
||||||
replace,
|
replace,
|
||||||
@ -409,6 +413,10 @@ impl Manifest {
|
|||||||
pub fn edition(&self) -> Edition {
|
pub fn edition(&self) -> Edition {
|
||||||
self.edition
|
self.edition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn custom_metadata(&self) -> Option<&toml::Value> {
|
||||||
|
self.custom_metadata.as_ref()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualManifest {
|
impl VirtualManifest {
|
||||||
|
@ -41,6 +41,7 @@ struct SerializedPackage<'a> {
|
|||||||
targets: &'a [Target],
|
targets: &'a [Target],
|
||||||
features: &'a FeatureMap,
|
features: &'a FeatureMap,
|
||||||
manifest_path: &'a str,
|
manifest_path: &'a str,
|
||||||
|
metadata: Option<&'a toml::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ser::Serialize for Package {
|
impl ser::Serialize for Package {
|
||||||
@ -67,6 +68,7 @@ impl ser::Serialize for Package {
|
|||||||
targets: self.manifest.targets(),
|
targets: self.manifest.targets(),
|
||||||
features: summary.features(),
|
features: summary.features(),
|
||||||
manifest_path: &self.manifest_path.display().to_string(),
|
manifest_path: &self.manifest_path.display().to_string(),
|
||||||
|
metadata: self.manifest.custom_metadata(),
|
||||||
}.serialize(s)
|
}.serialize(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -810,6 +810,7 @@ impl TomlManifest {
|
|||||||
} else {
|
} else {
|
||||||
Edition::Edition2015
|
Edition::Edition2015
|
||||||
};
|
};
|
||||||
|
let custom_metadata = project.metadata.clone();
|
||||||
let mut manifest = Manifest::new(
|
let mut manifest = Manifest::new(
|
||||||
summary,
|
summary,
|
||||||
targets,
|
targets,
|
||||||
@ -817,6 +818,7 @@ impl TomlManifest {
|
|||||||
include,
|
include,
|
||||||
project.links.clone(),
|
project.links.clone(),
|
||||||
metadata,
|
metadata,
|
||||||
|
custom_metadata,
|
||||||
profiles,
|
profiles,
|
||||||
publish,
|
publish,
|
||||||
publish_lockfile,
|
publish_lockfile,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use hamcrest::assert_that;
|
|
||||||
use cargotest::support::registry::Package;
|
use cargotest::support::registry::Package;
|
||||||
use cargotest::support::{basic_bin_manifest, basic_lib_manifest, execs, main_file, project};
|
use cargotest::support::{basic_bin_manifest, basic_lib_manifest, execs, main_file, project};
|
||||||
|
use hamcrest::assert_that;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cargo_metadata_simple() {
|
fn cargo_metadata_simple() {
|
||||||
@ -37,7 +37,8 @@ fn cargo_metadata_simple() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"features": {},
|
"features": {},
|
||||||
"manifest_path": "[..]Cargo.toml"
|
"manifest_path": "[..]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
|
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
|
||||||
@ -122,7 +123,8 @@ crate-type = ["lib", "staticlib"]
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"features": {},
|
"features": {},
|
||||||
"manifest_path": "[..]Cargo.toml"
|
"manifest_path": "[..]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
|
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
|
||||||
@ -197,7 +199,8 @@ optional_feat = []
|
|||||||
"default_feat": [],
|
"default_feat": [],
|
||||||
"optional_feat": []
|
"optional_feat": []
|
||||||
},
|
},
|
||||||
"manifest_path": "[..]Cargo.toml"
|
"manifest_path": "[..]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
|
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
|
||||||
@ -278,7 +281,8 @@ fn cargo_metadata_with_deps_and_version() {
|
|||||||
"src_path": "[..]lib.rs"
|
"src_path": "[..]lib.rs"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": "0.0.1"
|
"version": "0.0.1",
|
||||||
|
"metadata": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
@ -314,7 +318,8 @@ fn cargo_metadata_with_deps_and_version() {
|
|||||||
"src_path": "[..]lib.rs"
|
"src_path": "[..]lib.rs"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": "0.0.1"
|
"version": "0.0.1",
|
||||||
|
"metadata": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
@ -350,7 +355,8 @@ fn cargo_metadata_with_deps_and_version() {
|
|||||||
"src_path": "[..]foo.rs"
|
"src_path": "[..]foo.rs"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": "0.5.0"
|
"version": "0.5.0",
|
||||||
|
"metadata": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
|
"workspace_members": ["foo 0.5.0 (path+file:[..]foo)"],
|
||||||
@ -434,7 +440,8 @@ name = "ex"
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"features": {},
|
"features": {},
|
||||||
"manifest_path": "[..]Cargo.toml"
|
"manifest_path": "[..]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workspace_members": [
|
"workspace_members": [
|
||||||
@ -507,7 +514,8 @@ crate-type = ["rlib", "dylib"]
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"features": {},
|
"features": {},
|
||||||
"manifest_path": "[..]Cargo.toml"
|
"manifest_path": "[..]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workspace_members": [
|
"workspace_members": [
|
||||||
@ -571,7 +579,8 @@ fn workspace_metadata() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"features": {},
|
"features": {},
|
||||||
"manifest_path": "[..]bar[/]Cargo.toml"
|
"manifest_path": "[..]bar[/]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "baz",
|
"name": "baz",
|
||||||
@ -591,7 +600,8 @@ fn workspace_metadata() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"features": {},
|
"features": {},
|
||||||
"manifest_path": "[..]baz[/]Cargo.toml"
|
"manifest_path": "[..]baz[/]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"],
|
"workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"],
|
||||||
@ -658,7 +668,8 @@ fn workspace_metadata_no_deps() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"features": {},
|
"features": {},
|
||||||
"manifest_path": "[..]bar[/]Cargo.toml"
|
"manifest_path": "[..]bar[/]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "baz",
|
"name": "baz",
|
||||||
@ -678,7 +689,8 @@ fn workspace_metadata_no_deps() {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"features": {},
|
"features": {},
|
||||||
"manifest_path": "[..]baz[/]Cargo.toml"
|
"manifest_path": "[..]baz[/]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"],
|
"workspace_members": ["baz 0.5.0 (path+file:[..]baz)", "bar 0.5.0 (path+file:[..]bar)"],
|
||||||
@ -707,7 +719,7 @@ Caused by:
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const MANIFEST_OUTPUT: &'static str = r#"
|
const MANIFEST_OUTPUT: &str = r#"
|
||||||
{
|
{
|
||||||
"packages": [{
|
"packages": [{
|
||||||
"name":"foo",
|
"name":"foo",
|
||||||
@ -725,7 +737,8 @@ const MANIFEST_OUTPUT: &'static str = r#"
|
|||||||
"src_path":"[..][/]foo[/]src[/]foo.rs"
|
"src_path":"[..][/]foo[/]src[/]foo.rs"
|
||||||
}],
|
}],
|
||||||
"features":{},
|
"features":{},
|
||||||
"manifest_path":"[..]Cargo.toml"
|
"manifest_path":"[..]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}],
|
}],
|
||||||
"workspace_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
|
"workspace_members": [ "foo 0.5.0 (path+file:[..]foo)" ],
|
||||||
"resolve": null,
|
"resolve": null,
|
||||||
@ -867,3 +880,63 @@ fn multiple_features() {
|
|||||||
execs().with_status(0),
|
execs().with_status(0),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn package_metadata() {
|
||||||
|
let p = project("foo")
|
||||||
|
.file(
|
||||||
|
"Cargo.toml",
|
||||||
|
r#"
|
||||||
|
[package]
|
||||||
|
name = "foo"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = []
|
||||||
|
|
||||||
|
[package.metadata.bar]
|
||||||
|
baz = "quux"
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file("src/lib.rs", "")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assert_that(
|
||||||
|
p.cargo("metadata").arg("--no-deps"),
|
||||||
|
execs().with_json(
|
||||||
|
r#"
|
||||||
|
{
|
||||||
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "foo",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"id": "foo[..]",
|
||||||
|
"source": null,
|
||||||
|
"dependencies": [],
|
||||||
|
"license": null,
|
||||||
|
"license_file": null,
|
||||||
|
"description": null,
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"kind": [ "lib" ],
|
||||||
|
"crate_types": [ "lib" ],
|
||||||
|
"name": "foo",
|
||||||
|
"src_path": "[..]foo[/]src[/]lib.rs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"features": {},
|
||||||
|
"manifest_path": "[..]foo[/]Cargo.toml",
|
||||||
|
"metadata": {
|
||||||
|
"bar": {
|
||||||
|
"baz": "quux"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"workspace_members": ["foo[..]"],
|
||||||
|
"resolve": null,
|
||||||
|
"target_directory": "[..]foo[/]target",
|
||||||
|
"version": 1,
|
||||||
|
"workspace_root": "[..][/]foo"
|
||||||
|
}"#,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -18,7 +18,8 @@ static MANIFEST_OUTPUT: &'static str = r#"
|
|||||||
"src_path":"[..][/]foo[/]src[/]foo.rs"
|
"src_path":"[..][/]foo[/]src[/]foo.rs"
|
||||||
}],
|
}],
|
||||||
"features":{},
|
"features":{},
|
||||||
"manifest_path":"[..]Cargo.toml"
|
"manifest_path":"[..]Cargo.toml",
|
||||||
|
"metadata": null
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user