diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/cargo_metadata | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/cargo_metadata')
-rw-r--r-- | vendor/cargo_metadata/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/cargo_metadata/Cargo.toml | 8 | ||||
-rw-r--r-- | vendor/cargo_metadata/clippy.toml | 3 | ||||
-rw-r--r-- | vendor/cargo_metadata/src/lib.rs | 118 | ||||
-rw-r--r-- | vendor/cargo_metadata/src/messages.rs | 135 | ||||
-rw-r--r-- | vendor/cargo_metadata/tests/test_samples.rs | 49 |
6 files changed, 281 insertions, 34 deletions
diff --git a/vendor/cargo_metadata/.cargo-checksum.json b/vendor/cargo_metadata/.cargo-checksum.json index f9382f9be..a2fc9f56f 100644 --- a/vendor/cargo_metadata/.cargo-checksum.json +++ b/vendor/cargo_metadata/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"CHANGELOG.md":"2e68a86864c8d2c00e40f0f9d53a8507cc69bc124f1779e795b5334451ce75bb","Cargo.toml":"f65896251407de9805f19d3825b0ecbe407c83a650d924bacf4909ed38fe131f","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"6be7aaba23d8646b470a966eef2f00c9fa04cf4d1de25cfb71680cef562e1574","src/dependency.rs":"c593ddc73d863c5712e2aba58b5f4d9bd915a5ac0bc17df71642aa79aa93bfdc","src/diagnostic.rs":"fee47d27390f1026ff99ffade5dfd2ab3e9b9839c3f33ce91a7dcde875551374","src/errors.rs":"797afd61efdd843ae570d9e972dd2425d33823d4a78c0c488028493dffb45c7a","src/lib.rs":"d6a2fda234146c23bd9f86be9bb90ba3515b52e3ef7699faf4e12469a41e9bbe","src/messages.rs":"a8e3ee31dc8cce5762b4b085be29fe4d7189a789f3a149ef2b6c17604d94528b","tests/selftest.rs":"73afd494c1bf7dd4e1a99971e9ff66a0e21fc7bf3e327663df15d2350dcdfc70","tests/test_samples.rs":"ee2b4737adfa1930c1610bb3ec0fc94b7f1a3691bb09545da69044eef2f5ba6b"},"package":"eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a"}
\ No newline at end of file +{"files":{"CHANGELOG.md":"2e68a86864c8d2c00e40f0f9d53a8507cc69bc124f1779e795b5334451ce75bb","Cargo.toml":"cc68bf23ad777a381d94a2d0a40758412d7ba5323750965427cb6b4537616fbd","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"6be7aaba23d8646b470a966eef2f00c9fa04cf4d1de25cfb71680cef562e1574","clippy.toml":"0eb773e1a242ba7e06f0ca5c23be71b5989f4952fe18cae35e5322066e706495","src/dependency.rs":"c593ddc73d863c5712e2aba58b5f4d9bd915a5ac0bc17df71642aa79aa93bfdc","src/diagnostic.rs":"fee47d27390f1026ff99ffade5dfd2ab3e9b9839c3f33ce91a7dcde875551374","src/errors.rs":"797afd61efdd843ae570d9e972dd2425d33823d4a78c0c488028493dffb45c7a","src/lib.rs":"f436be9c0ded5ce27198ba145dce70673e37d0d53728e11b12276ef0c55741ec","src/messages.rs":"b16fd1d8a1a7099d371edb5d2e1495871afb61856025b0128a9e2262517e2099","tests/selftest.rs":"73afd494c1bf7dd4e1a99971e9ff66a0e21fc7bf3e327663df15d2350dcdfc70","tests/test_samples.rs":"f5015e6635935b505ad9a09caf8b05b980ff248adaaaf7bde166f8bce2152823"},"package":"e7daec1a2a2129eeba1644b220b4647ec537b0b5d4bfd6876fcc5a540056b592"}
\ No newline at end of file diff --git a/vendor/cargo_metadata/Cargo.toml b/vendor/cargo_metadata/Cargo.toml index a976b5ae0..6ae78b7b0 100644 --- a/vendor/cargo_metadata/Cargo.toml +++ b/vendor/cargo_metadata/Cargo.toml @@ -11,9 +11,9 @@ [package] edition = "2018" -rust-version = "1.42.0" +rust-version = "1.56.0" name = "cargo_metadata" -version = "0.15.4" +version = "0.17.0" authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"] description = "structured access to the output of `cargo metadata`" readme = "README.md" @@ -21,8 +21,8 @@ license = "MIT" repository = "https://github.com/oli-obk/cargo_metadata" [package.metadata.cargo_metadata_test] -some_field = true other_field = "foo" +some_field = true [dependencies.camino] version = "1.0.7" @@ -32,7 +32,7 @@ features = ["serde1"] version = "0.1.2" [dependencies.derive_builder] -version = "0.11.1" +version = "0.12" optional = true [dependencies.semver] diff --git a/vendor/cargo_metadata/clippy.toml b/vendor/cargo_metadata/clippy.toml new file mode 100644 index 000000000..bfb8bfe2d --- /dev/null +++ b/vendor/cargo_metadata/clippy.toml @@ -0,0 +1,3 @@ +disallowed-types = [ + { path = "std::collections::HashMap", reason = "HashMap's key order is unspecified and thus serializing such a type will result in a random output, use BTreeMap instead." } +]
\ No newline at end of file diff --git a/vendor/cargo_metadata/src/lib.rs b/vendor/cargo_metadata/src/lib.rs index 627511773..c222c130e 100644 --- a/vendor/cargo_metadata/src/lib.rs +++ b/vendor/cargo_metadata/src/lib.rs @@ -81,7 +81,7 @@ use camino::Utf8PathBuf; #[cfg(feature = "builder")] use derive_builder::Builder; -use std::collections::{BTreeMap, HashMap}; +use std::collections::BTreeMap; use std::env; use std::ffi::OsString; use std::fmt; @@ -92,7 +92,7 @@ use std::str::from_utf8; pub use camino; pub use semver; -use semver::{Version, VersionReq}; +use semver::Version; #[cfg(feature = "builder")] pub use dependency::DependencyBuilder; @@ -102,14 +102,15 @@ pub use errors::{Error, Result}; #[allow(deprecated)] pub use messages::parse_messages; pub use messages::{ - Artifact, ArtifactProfile, BuildFinished, BuildScript, CompilerMessage, Message, MessageIter, + Artifact, ArtifactDebuginfo, ArtifactProfile, BuildFinished, BuildScript, CompilerMessage, + Message, MessageIter, }; #[cfg(feature = "builder")] pub use messages::{ ArtifactBuilder, ArtifactProfileBuilder, BuildFinishedBuilder, BuildScriptBuilder, CompilerMessageBuilder, }; -use serde::{Deserialize, Serialize, Serializer}; +use serde::{Deserialize, Deserializer, Serialize}; mod dependency; pub mod diagnostic; @@ -117,6 +118,7 @@ mod errors; mod messages; /// An "opaque" identifier for a package. +/// /// It is possible to inspect the `repr` field, if the need arises, but its /// precise format is an implementation detail and is subject to change. /// @@ -128,7 +130,7 @@ pub struct PackageId { pub repr: String, } -impl std::fmt::Display for PackageId { +impl fmt::Display for PackageId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.repr, f) } @@ -139,18 +141,6 @@ fn is_null(value: &serde_json::Value) -> bool { matches!(value, serde_json::Value::Null) } -/// Helper to ensure that hashmaps serialize in sorted order, to make -/// serialization deterministic. -fn sorted_map<S: Serializer, K: Serialize + Ord, V: Serialize>( - value: &HashMap<K, V>, - serializer: S, -) -> std::result::Result<S::Ok, S::Error> { - value - .iter() - .collect::<BTreeMap<_, _>>() - .serialize(serializer) -} - #[derive(Clone, Serialize, Deserialize, Debug)] #[cfg_attr(feature = "builder", derive(Builder))] #[non_exhaustive] @@ -323,8 +313,7 @@ pub struct Package { /// Targets provided by the crate (lib, bin, example, test, ...) pub targets: Vec<Target>, /// Features provided by the crate, mapped to the features required by that feature. - #[serde(serialize_with = "sorted_map")] - pub features: HashMap<String, Vec<String>>, + pub features: BTreeMap<String, Vec<String>>, /// Path containing the `Cargo.toml` pub manifest_path: Utf8PathBuf, /// Categories as given in the `Cargo.toml` @@ -392,7 +381,9 @@ pub struct Package { /// The minimum supported Rust version of this package. /// /// This is always `None` if running with a version of Cargo older than 1.58. - pub rust_version: Option<VersionReq>, + #[serde(default)] + #[serde(deserialize_with = "deserialize_rust_version")] + pub rust_version: Option<Version>, } impl Package { @@ -418,6 +409,9 @@ impl Package { } /// The source of a package such as crates.io. +/// +/// It is possible to inspect the `repr` field, if the need arises, but its +/// precise format is an implementation detail and is subject to change. #[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] #[serde(transparent)] pub struct Source { @@ -432,7 +426,7 @@ impl Source { } } -impl std::fmt::Display for Source { +impl fmt::Display for Source { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.repr, f) } @@ -615,7 +609,7 @@ pub struct MetadataCommand { other_options: Vec<String>, /// Arbitrary environment variables to set when running `cargo`. These will be merged into /// the calling environment, overriding any which clash. - env: HashMap<OsString, OsString>, + env: BTreeMap<OsString, OsString>, /// Show stderr verbose: bool, } @@ -754,7 +748,7 @@ impl MetadataCommand { .or_else(|| env::var("CARGO").map(PathBuf::from).ok()) .unwrap_or_else(|| PathBuf::from("cargo")); let mut cmd = Command::new(cargo); - cmd.args(&["metadata", "--format-version", "1"]); + cmd.args(["metadata", "--format-version", "1"]); if self.no_deps { cmd.arg("--no-deps"); @@ -810,3 +804,81 @@ impl MetadataCommand { Self::parse(stdout) } } + +/// As per the Cargo Book the [`rust-version` field](https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field) must: +/// +/// > be a bare version number with two or three components; +/// > it cannot include semver operators or pre-release identifiers. +/// +/// [`semver::Version`] however requires three components. This function takes +/// care of appending `.0` if the provided version number only has two components +/// and ensuring that it does not contain a pre-release version or build metadata. +fn deserialize_rust_version<'de, D>( + deserializer: D, +) -> std::result::Result<Option<Version>, D::Error> +where + D: Deserializer<'de>, +{ + let mut buf = match Option::<String>::deserialize(deserializer)? { + None => return Ok(None), + Some(buf) => buf, + }; + + for char in buf.chars() { + if char == '-' { + return Err(serde::de::Error::custom( + "pre-release identifiers are not supported in rust-version", + )); + } else if char == '+' { + return Err(serde::de::Error::custom( + "build metadata is not supported in rust-version", + )); + } + } + + if buf.matches('.').count() == 1 { + // e.g. 1.0 -> 1.0.0 + buf.push_str(".0"); + } + + Ok(Some( + Version::parse(&buf).map_err(serde::de::Error::custom)?, + )) +} + +#[cfg(test)] +mod test { + use semver::Version; + + #[derive(Debug, serde::Deserialize)] + struct BareVersion( + #[serde(deserialize_with = "super::deserialize_rust_version")] Option<semver::Version>, + ); + + fn bare_version(str: &str) -> Version { + serde_json::from_str::<BareVersion>(&format!(r#""{}""#, str)) + .unwrap() + .0 + .unwrap() + } + + fn bare_version_err(str: &str) -> String { + serde_json::from_str::<BareVersion>(&format!(r#""{}""#, str)) + .unwrap_err() + .to_string() + } + + #[test] + fn test_deserialize_rust_version() { + assert_eq!(bare_version("1.2"), Version::new(1, 2, 0)); + assert_eq!(bare_version("1.2.0"), Version::new(1, 2, 0)); + assert_eq!( + bare_version_err("1.2.0-alpha"), + "pre-release identifiers are not supported in rust-version" + ); + assert_eq!( + bare_version_err("1.2.0+123"), + "build metadata is not supported in rust-version" + ); + } +} diff --git a/vendor/cargo_metadata/src/messages.rs b/vendor/cargo_metadata/src/messages.rs index ea2abd250..028cd726e 100644 --- a/vendor/cargo_metadata/src/messages.rs +++ b/vendor/cargo_metadata/src/messages.rs @@ -2,8 +2,8 @@ use super::{Diagnostic, PackageId, Target}; use camino::Utf8PathBuf; #[cfg(feature = "builder")] use derive_builder::Builder; -use serde::{Deserialize, Serialize}; -use std::fmt; +use serde::{de, ser, Deserialize, Serialize}; +use std::fmt::{self, Write}; use std::io::{self, BufRead, Read}; /// Profile settings used to determine which compiler flags to use for a @@ -15,8 +15,9 @@ use std::io::{self, BufRead, Read}; pub struct ArtifactProfile { /// Optimization level. Possible values are 0-3, s or z. pub opt_level: String, - /// The amount of debug info. 0 for none, 1 for limited, 2 for full - pub debuginfo: Option<u32>, + /// The kind of debug information. + #[serde(default)] + pub debuginfo: ArtifactDebuginfo, /// State of the `cfg(debug_assertions)` directive, enabling macros like /// `debug_assert!` pub debug_assertions: bool, @@ -26,6 +27,132 @@ pub struct ArtifactProfile { pub test: bool, } +/// The kind of debug information included in the artifact. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum ArtifactDebuginfo { + /// No debug information. + None, + /// Line directives only. + LineDirectivesOnly, + /// Line tables only. + LineTablesOnly, + /// Debug information without type or variable-level information. + Limited, + /// Full debug information. + Full, + /// An unknown integer level. + /// + /// This may be produced by a version of rustc in the future that has + /// additional levels represented by an integer that are not known by this + /// version of `cargo_metadata`. + UnknownInt(i64), + /// An unknown string level. + /// + /// This may be produced by a version of rustc in the future that has + /// additional levels represented by a string that are not known by this + /// version of `cargo_metadata`. + UnknownString(String), +} + +impl Default for ArtifactDebuginfo { + fn default() -> Self { + ArtifactDebuginfo::None + } +} + +impl ser::Serialize for ArtifactDebuginfo { + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> + where + S: ser::Serializer, + { + match self { + Self::None => 0.serialize(serializer), + Self::LineDirectivesOnly => "line-directives-only".serialize(serializer), + Self::LineTablesOnly => "line-tables-only".serialize(serializer), + Self::Limited => 1.serialize(serializer), + Self::Full => 2.serialize(serializer), + Self::UnknownInt(n) => n.serialize(serializer), + Self::UnknownString(s) => s.serialize(serializer), + } + } +} + +impl<'de> de::Deserialize<'de> for ArtifactDebuginfo { + fn deserialize<D>(d: D) -> Result<ArtifactDebuginfo, D::Error> + where + D: de::Deserializer<'de>, + { + struct Visitor; + + impl<'de> de::Visitor<'de> for Visitor { + type Value = ArtifactDebuginfo; + + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + formatter.write_str("an integer or string") + } + + fn visit_i64<E>(self, value: i64) -> Result<ArtifactDebuginfo, E> + where + E: de::Error, + { + let debuginfo = match value { + 0 => ArtifactDebuginfo::None, + 1 => ArtifactDebuginfo::Limited, + 2 => ArtifactDebuginfo::Full, + n => ArtifactDebuginfo::UnknownInt(n), + }; + Ok(debuginfo) + } + + fn visit_u64<E>(self, value: u64) -> Result<ArtifactDebuginfo, E> + where + E: de::Error, + { + self.visit_i64(value as i64) + } + + fn visit_str<E>(self, value: &str) -> Result<ArtifactDebuginfo, E> + where + E: de::Error, + { + let debuginfo = match value { + "none" => ArtifactDebuginfo::None, + "limited" => ArtifactDebuginfo::Limited, + "full" => ArtifactDebuginfo::Full, + "line-directives-only" => ArtifactDebuginfo::LineDirectivesOnly, + "line-tables-only" => ArtifactDebuginfo::LineTablesOnly, + s => ArtifactDebuginfo::UnknownString(s.to_string()), + }; + Ok(debuginfo) + } + + fn visit_unit<E>(self) -> Result<ArtifactDebuginfo, E> + where + E: de::Error, + { + Ok(ArtifactDebuginfo::None) + } + } + + d.deserialize_any(Visitor) + } +} + +impl fmt::Display for ArtifactDebuginfo { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ArtifactDebuginfo::None => f.write_char('0'), + ArtifactDebuginfo::Limited => f.write_char('1'), + ArtifactDebuginfo::Full => f.write_char('2'), + ArtifactDebuginfo::LineDirectivesOnly => f.write_str("line-directives-only"), + ArtifactDebuginfo::LineTablesOnly => f.write_str("line-tables-only"), + ArtifactDebuginfo::UnknownInt(n) => write!(f, "{}", n), + ArtifactDebuginfo::UnknownString(s) => f.write_str(s), + } + } +} + /// A compiler-generated file. #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)] #[cfg_attr(feature = "builder", derive(Builder))] diff --git a/vendor/cargo_metadata/tests/test_samples.rs b/vendor/cargo_metadata/tests/test_samples.rs index 3c747c595..15128b075 100644 --- a/vendor/cargo_metadata/tests/test_samples.rs +++ b/vendor/cargo_metadata/tests/test_samples.rs @@ -4,7 +4,9 @@ extern crate semver; extern crate serde_json; use camino::Utf8PathBuf; -use cargo_metadata::{CargoOpt, DependencyKind, Edition, Metadata, MetadataCommand}; +use cargo_metadata::{ + ArtifactDebuginfo, CargoOpt, DependencyKind, Edition, Message, Metadata, MetadataCommand, +}; #[test] fn old_minimal() { @@ -210,7 +212,7 @@ fn all_the_fields() { if ver >= semver::Version::parse("1.58.0").unwrap() { assert_eq!( all.rust_version, - Some(semver::VersionReq::parse("1.56").unwrap()) + Some(semver::Version::parse("1.56.0").unwrap()) ); } @@ -645,3 +647,46 @@ fn basic_workspace_root_package_exists() { "ex_bin" ); } + +#[test] +fn debuginfo_variants() { + // Checks behavior for the different debuginfo variants. + let variants = [ + ("0", ArtifactDebuginfo::None), + ("1", ArtifactDebuginfo::Limited), + ("2", ArtifactDebuginfo::Full), + ( + "\"line-directives-only\"", + ArtifactDebuginfo::LineDirectivesOnly, + ), + ("\"line-tables-only\"", ArtifactDebuginfo::LineTablesOnly), + ("3", ArtifactDebuginfo::UnknownInt(3)), + ( + "\"abc\"", + ArtifactDebuginfo::UnknownString("abc".to_string()), + ), + ("null", ArtifactDebuginfo::None), + ]; + for (value, expected) in variants { + let s = r#"{"reason":"compiler-artifact","package_id":"cargo_metadata 0.16.0 (path+file:////cargo_metadata)","manifest_path":"/cargo_metadata/Cargo.toml","target":{"kind":["lib"],"crate_types":["lib"],"name":"cargo_metadata","src_path":"/cargo_metadata/src/lib.rs","edition":"2018","doc":true,"doctest":true,"test":true},"profile":{"opt_level":"0","debuginfo":DEBUGINFO,"debug_assertions":true,"overflow_checks":true,"test":false},"features":["default"],"filenames":["/cargo_metadata/target/debug/deps/libcargo_metadata-27f582f7187b9a2c.rmeta"],"executable":null,"fresh":false}"#; + let message: Message = serde_json::from_str(&s.replace("DEBUGINFO", value)).unwrap(); + match message { + Message::CompilerArtifact(artifact) => { + assert_eq!(artifact.profile.debuginfo, expected); + let de_s = serde_json::to_string(&artifact.profile.debuginfo).unwrap(); + // Note: Roundtrip does not retain null value. + if value == "null" { + assert_eq!(artifact.profile.debuginfo.to_string(), "0"); + assert_eq!(de_s, "0"); + } else { + assert_eq!( + artifact.profile.debuginfo.to_string(), + value.trim_matches('"') + ); + assert_eq!(de_s, value); + } + } + _ => panic!("unexpected {:?}", message), + } + } +} |