summaryrefslogtreecommitdiffstats
path: root/vendor/cargo_metadata
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
commit2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch)
treed325add32978dbdc1db975a438b3a77d571b1ab8 /vendor/cargo_metadata
parentReleasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff)
downloadrustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz
rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip
Merging upstream version 1.69.0+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.json2
-rw-r--r--vendor/cargo_metadata/CHANGELOG.md38
-rw-r--r--vendor/cargo_metadata/Cargo.toml5
-rw-r--r--vendor/cargo_metadata/src/errors.rs82
-rw-r--r--vendor/cargo_metadata/src/lib.rs154
-rw-r--r--vendor/cargo_metadata/src/messages.rs3
-rw-r--r--vendor/cargo_metadata/tests/test_samples.rs27
7 files changed, 224 insertions, 87 deletions
diff --git a/vendor/cargo_metadata/.cargo-checksum.json b/vendor/cargo_metadata/.cargo-checksum.json
index 2d183cd80..7838a4a29 100644
--- a/vendor/cargo_metadata/.cargo-checksum.json
+++ b/vendor/cargo_metadata/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"1ea11e47024269503340c3764c13c6e0d47f45eb9f2eef3ea75eedee64c02e98","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"d51a5b3347bed2441b20986be81bfd4611ca2c5614f950116b273199a9bcf2de","src/dependency.rs":"c593ddc73d863c5712e2aba58b5f4d9bd915a5ac0bc17df71642aa79aa93bfdc","src/diagnostic.rs":"fee47d27390f1026ff99ffade5dfd2ab3e9b9839c3f33ce91a7dcde875551374","src/errors.rs":"2d67e46ef8f29a9ae2dd00ce39cc50e6ccae4dec9a09a9bad7c36bd8be4f62cc","src/lib.rs":"41b0d89ec02f698b8fdeab9c1f76536a4ba34c2a4361b2c921340a10288e002d","src/messages.rs":"caaa7c906595768587007c72fcc3ac32880bbb02293b004f498a296e078fbbff","tests/selftest.rs":"73afd494c1bf7dd4e1a99971e9ff66a0e21fc7bf3e327663df15d2350dcdfc70","tests/test_samples.rs":"3374f4a054d440f8fc567b233c9d680be98aa481c622845ae1dc5cb28aa5f804"},"package":"3abb7553d5b9b8421c6de7cb02606ff15e0c6eea7d8eadd75ef013fd636bec36"} \ No newline at end of file
+{"files":{"CHANGELOG.md":"8b3e29799cdedf02f169bb519072ace2e2b6b9413f4ce8fa0666c2d1d964084e","Cargo.toml":"57d432cd172cc87ee4c31b0e4c21c52d06ba1a48da9decd34581b2671c47d71d","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"d51a5b3347bed2441b20986be81bfd4611ca2c5614f950116b273199a9bcf2de","src/dependency.rs":"c593ddc73d863c5712e2aba58b5f4d9bd915a5ac0bc17df71642aa79aa93bfdc","src/diagnostic.rs":"fee47d27390f1026ff99ffade5dfd2ab3e9b9839c3f33ce91a7dcde875551374","src/errors.rs":"797afd61efdd843ae570d9e972dd2425d33823d4a78c0c488028493dffb45c7a","src/lib.rs":"5ec701f3589c5d71c152b5abe7ad5f222aee4d4a5f9992bced1d357bad36e227","src/messages.rs":"a8e3ee31dc8cce5762b4b085be29fe4d7189a789f3a149ef2b6c17604d94528b","tests/selftest.rs":"73afd494c1bf7dd4e1a99971e9ff66a0e21fc7bf3e327663df15d2350dcdfc70","tests/test_samples.rs":"ee2b4737adfa1930c1610bb3ec0fc94b7f1a3691bb09545da69044eef2f5ba6b"},"package":"08a1ec454bc3eead8719cb56e15dbbfecdbc14e4b3a3ae4936cc6e31f5fc0d07"} \ No newline at end of file
diff --git a/vendor/cargo_metadata/CHANGELOG.md b/vendor/cargo_metadata/CHANGELOG.md
new file mode 100644
index 000000000..fcc0b2642
--- /dev/null
+++ b/vendor/cargo_metadata/CHANGELOG.md
@@ -0,0 +1,38 @@
+# Changelog
+
+## Unreleased
+
+### Added
+
+- Re-exported `semver` crate directly.
+
+### Changed
+
+- Made `parse_stream` more versatile by accepting anything that implements `Read`.
+
+### Removed
+
+- Removed re-exports for `BuildMetadata` and `Prerelease` from `semver` crate.
+
+### Fixed
+
+- Added missing `manifest_path` field to `Artifact`. Fixes #187.
+
+## [0.15.0] - 2022-06-22
+
+### Added
+
+- Re-exported `BuildMetadata` and `Prerelease` from `semver` crate.
+- Added `workspace_packages` function.
+- Added `Edition` enum to better parse edition field.
+- Added `rust-version` field to Cargo manifest.
+
+### Changed
+
+- Bumped msrv from `1.40.0` to `1.42.0`.
+
+### Internal Changes
+
+- Updated `derive_builder` to the latest version.
+- Made use of `matches!` macros where possible.
+- Fixed some tests
diff --git a/vendor/cargo_metadata/Cargo.toml b/vendor/cargo_metadata/Cargo.toml
index 90f1b1ce0..25a28ef4f 100644
--- a/vendor/cargo_metadata/Cargo.toml
+++ b/vendor/cargo_metadata/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2018"
rust-version = "1.42.0"
name = "cargo_metadata"
-version = "0.15.0"
+version = "0.15.3"
authors = ["Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>"]
description = "structured access to the output of `cargo metadata`"
readme = "README.md"
@@ -47,6 +47,9 @@ features = ["derive"]
version = "1.0.79"
features = ["unbounded_depth"]
+[dependencies.thiserror]
+version = "1.0.31"
+
[features]
builder = ["derive_builder"]
default = []
diff --git a/vendor/cargo_metadata/src/errors.rs b/vendor/cargo_metadata/src/errors.rs
index 7172057e7..4d08200c8 100644
--- a/vendor/cargo_metadata/src/errors.rs
+++ b/vendor/cargo_metadata/src/errors.rs
@@ -1,7 +1,4 @@
-use std::fmt;
-use std::io;
-use std::str::Utf8Error;
-use std::string::FromUtf8Error;
+use std::{io, str::Utf8Error, string::FromUtf8Error};
/// Custom result type for `cargo_metadata::Error`
pub type Result<T> = ::std::result::Result<T, Error>;
@@ -24,87 +21,32 @@ pub type Result<T> = ::std::result::Result<T, Error>;
/// really want to. (Either through foreign_links or by making it a field
/// value of a `ErrorKind` variant).
///
-#[derive(Debug)]
+#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Error during execution of `cargo metadata`
+ #[error("`cargo metadata` exited with an error: {stderr}")]
CargoMetadata {
/// stderr returned by the `cargo metadata` command
stderr: String,
},
/// IO Error during execution of `cargo metadata`
- Io(io::Error),
+ #[error("failed to start `cargo metadata`: {0}")]
+ Io(#[from] io::Error),
/// Output of `cargo metadata` was not valid utf8
- Utf8(Utf8Error),
+ #[error("cannot convert the stdout of `cargo metadata`: {0}")]
+ Utf8(#[from] Utf8Error),
/// Error output of `cargo metadata` was not valid utf8
- ErrUtf8(FromUtf8Error),
+ #[error("cannot convert the stderr of `cargo metadata`: {0}")]
+ ErrUtf8(#[from] FromUtf8Error),
/// Deserialization error (structure of json did not match expected structure)
- Json(::serde_json::Error),
+ #[error("failed to interpret `cargo metadata`'s json: {0}")]
+ Json(#[from] ::serde_json::Error),
/// The output did not contain any json
+ #[error("could not find any json in the output of `cargo metadata`")]
NoJson,
}
-
-impl From<io::Error> for Error {
- fn from(v: io::Error) -> Self {
- Error::Io(v)
- }
-}
-
-impl From<Utf8Error> for Error {
- fn from(v: Utf8Error) -> Self {
- Error::Utf8(v)
- }
-}
-
-impl From<FromUtf8Error> for Error {
- fn from(v: FromUtf8Error) -> Self {
- Error::ErrUtf8(v)
- }
-}
-
-impl From<::serde_json::Error> for Error {
- fn from(v: ::serde_json::Error) -> Self {
- Error::Json(v)
- }
-}
-
-impl fmt::Display for Error {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self {
- Error::CargoMetadata { stderr } => {
- write!(
- f,
- "`cargo metadata` exited with an error: {}",
- stderr.trim_end()
- )
- }
- Error::Io(err) => write!(f, "failed to start `cargo metadata`: {}", err),
- Error::Utf8(err) => write!(f, "cannot convert the stdout of `cargo metadata`: {}", err),
- Error::ErrUtf8(err) => {
- write!(f, "cannot convert the stderr of `cargo metadata`: {}", err)
- }
- Error::Json(err) => write!(f, "failed to interpret `cargo metadata`'s json: {}", err),
- Error::NoJson => write!(
- f,
- "could not find any json in the output of `cargo metadata`"
- ),
- }
- }
-}
-
-impl ::std::error::Error for Error {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- match self {
- Error::CargoMetadata { .. } => None,
- Error::Io(err) => Some(err),
- Error::Utf8(err) => Some(err),
- Error::ErrUtf8(err) => Some(err),
- Error::Json(err) => Some(err),
- Error::NoJson => None,
- }
- }
-}
diff --git a/vendor/cargo_metadata/src/lib.rs b/vendor/cargo_metadata/src/lib.rs
index a250aa176..27c72da0d 100644
--- a/vendor/cargo_metadata/src/lib.rs
+++ b/vendor/cargo_metadata/src/lib.rs
@@ -83,9 +83,11 @@ use camino::Utf8PathBuf;
use derive_builder::Builder;
use std::collections::HashMap;
use std::env;
+use std::ffi::OsString;
use std::fmt;
+use std::hash::Hash;
use std::path::PathBuf;
-use std::process::Command;
+use std::process::{Command, Stdio};
use std::str::from_utf8;
pub use camino;
@@ -154,10 +156,22 @@ pub struct Metadata {
}
impl Metadata {
- /// Get the root package of this metadata instance.
+ /// Get the workspace's root package of this metadata instance.
pub fn root_package(&self) -> Option<&Package> {
- let root = self.resolve.as_ref()?.root.as_ref()?;
- self.packages.iter().find(|pkg| &pkg.id == root)
+ match &self.resolve {
+ Some(resolve) => {
+ // if dependencies are resolved, use Cargo's answer
+ let root = resolve.root.as_ref()?;
+ self.packages.iter().find(|pkg| &pkg.id == root)
+ }
+ None => {
+ // if dependencies aren't resolved, check for a root package manually
+ let root_manifest_path = self.workspace_root.join("Cargo.toml");
+ self.packages
+ .iter()
+ .find(|pkg| pkg.manifest_path == root_manifest_path)
+ }
+ }
}
/// Get the workspace packages.
@@ -374,9 +388,12 @@ impl Package {
/// Full path to the readme file if one is present in the manifest
pub fn readme(&self) -> Option<Utf8PathBuf> {
- self.readme
- .as_ref()
- .map(|file| self.manifest_path.join(file))
+ self.readme.as_ref().map(|file| {
+ self.manifest_path
+ .parent()
+ .unwrap_or(&self.manifest_path)
+ .join(file)
+ })
}
}
@@ -409,7 +426,7 @@ impl std::fmt::Display for Source {
pub struct Target {
/// Name as given in the `Cargo.toml` or generated from the file name
pub name: String,
- /// Kind of target ("bin", "example", "test", "bench", "lib")
+ /// Kind of target ("bin", "example", "test", "bench", "lib", "custom-build")
pub kind: Vec<String>,
/// Almost the same as `kind`, except when an example is a library instead of an executable.
/// In that case `crate_types` contains things like `rlib` and `dylib` while `kind` is `example`
@@ -450,9 +467,47 @@ pub struct Target {
pub doc: bool,
}
-#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
+impl Target {
+ fn is_kind(&self, name: &str) -> bool {
+ self.kind.iter().any(|kind| kind == name)
+ }
+
+ /// Return true if this target is of kind "lib".
+ pub fn is_lib(&self) -> bool {
+ self.is_kind("lib")
+ }
+
+ /// Return true if this target is of kind "bin".
+ pub fn is_bin(&self) -> bool {
+ self.is_kind("bin")
+ }
+
+ /// Return true if this target is of kind "example".
+ pub fn is_example(&self) -> bool {
+ self.is_kind("example")
+ }
+
+ /// Return true if this target is of kind "test".
+ pub fn is_test(&self) -> bool {
+ self.is_kind("test")
+ }
+
+ /// Return true if this target is of kind "bench".
+ pub fn is_bench(&self) -> bool {
+ self.is_kind("bench")
+ }
+
+ /// Return true if this target is of kind "custom-build".
+ pub fn is_custom_build(&self) -> bool {
+ self.is_kind("custom-build")
+ }
+}
+
+/// The Rust edition
+///
+/// As of writing this comment rust editions 2024, 2027 and 2030 are not actually a thing yet but are parsed nonetheless for future proofing.
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
-/// The rust edition
pub enum Edition {
/// Edition 2015
#[serde(rename = "2015")]
@@ -463,6 +518,36 @@ pub enum Edition {
/// Edition 2021
#[serde(rename = "2021")]
E2021,
+ #[doc(hidden)]
+ #[serde(rename = "2024")]
+ _E2024,
+ #[doc(hidden)]
+ #[serde(rename = "2027")]
+ _E2027,
+ #[doc(hidden)]
+ #[serde(rename = "2030")]
+ _E2030,
+}
+
+impl Edition {
+ /// Return the string representation of the edition
+ pub fn as_str(&self) -> &'static str {
+ use Edition::*;
+ match self {
+ E2015 => "2015",
+ E2018 => "2018",
+ E2021 => "2021",
+ _E2024 => "2024",
+ _E2027 => "2027",
+ _E2030 => "2030",
+ }
+ }
+}
+
+impl fmt::Display for Edition {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.write_str(self.as_str())
+ }
}
impl Default for Edition {
@@ -497,7 +582,7 @@ pub struct MetadataCommand {
manifest_path: Option<PathBuf>,
/// Current directory of the `cargo metadata` process.
current_dir: Option<PathBuf>,
- /// Output information only about the root package and don't fetch dependencies.
+ /// Output information only about workspace members and don't fetch dependencies.
no_deps: bool,
/// Collections of `CargoOpt::SomeFeatures(..)`
features: Vec<String>,
@@ -508,6 +593,11 @@ pub struct MetadataCommand {
/// Arbitrary command line flags to pass to `cargo`. These will be added
/// to the end of the command line invocation.
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>,
+ /// Show stderr
+ verbose: bool,
}
impl MetadataCommand {
@@ -533,7 +623,7 @@ impl MetadataCommand {
self.current_dir = Some(path.into());
self
}
- /// Output information only about the root package and don't fetch dependencies.
+ /// Output information only about workspace members and don't fetch dependencies.
pub fn no_deps(&mut self) -> &mut MetadataCommand {
self.no_deps = true;
self
@@ -603,6 +693,38 @@ impl MetadataCommand {
self
}
+ /// Arbitrary environment variables to set when running `cargo`. These will be merged into
+ /// the calling environment, overriding any which clash.
+ ///
+ /// Some examples of when you may want to use this:
+ /// 1. Setting cargo config values without needing a .cargo/config.toml file, e.g. to set
+ /// `CARGO_NET_GIT_FETCH_WITH_CLI=true`
+ /// 2. To specify a custom path to RUSTC if your rust toolchain components aren't laid out in
+ /// the way cargo expects by default.
+ ///
+ /// ```no_run
+ /// # use cargo_metadata::{CargoOpt, MetadataCommand};
+ /// MetadataCommand::new()
+ /// .env("CARGO_NET_GIT_FETCH_WITH_CLI", "true")
+ /// .env("RUSTC", "/path/to/rustc")
+ /// // ...
+ /// # ;
+ /// ```
+ pub fn env<K: Into<OsString>, V: Into<OsString>>(
+ &mut self,
+ key: K,
+ val: V,
+ ) -> &mut MetadataCommand {
+ self.env.insert(key.into(), val.into());
+ self
+ }
+
+ /// Set whether to show stderr
+ pub fn verbose(&mut self, verbose: bool) -> &mut MetadataCommand {
+ self.verbose = verbose;
+ self
+ }
+
/// Builds a command for `cargo metadata`. This is the first
/// part of the work of `exec`.
pub fn cargo_command(&self) -> Command {
@@ -637,6 +759,8 @@ impl MetadataCommand {
}
cmd.args(&self.other_options);
+ cmd.envs(&self.env);
+
cmd
}
@@ -649,7 +773,11 @@ impl MetadataCommand {
/// Runs configured `cargo metadata` and returns parsed `Metadata`.
pub fn exec(&self) -> Result<Metadata> {
- let output = self.cargo_command().output()?;
+ let mut command = self.cargo_command();
+ if self.verbose {
+ command.stderr(Stdio::inherit());
+ }
+ let output = command.output()?;
if !output.status.success() {
return Err(Error::CargoMetadata {
stderr: String::from_utf8(output.stderr)?,
diff --git a/vendor/cargo_metadata/src/messages.rs b/vendor/cargo_metadata/src/messages.rs
index 0d086d3c3..ea2abd250 100644
--- a/vendor/cargo_metadata/src/messages.rs
+++ b/vendor/cargo_metadata/src/messages.rs
@@ -34,6 +34,9 @@ pub struct ArtifactProfile {
pub struct Artifact {
/// The package this artifact belongs to
pub package_id: PackageId,
+ /// Path to the `Cargo.toml` file
+ #[serde(default)]
+ pub manifest_path: Utf8PathBuf,
/// The target this artifact was compiled for
pub target: Target,
/// The profile this artifact was compiled with
diff --git a/vendor/cargo_metadata/tests/test_samples.rs b/vendor/cargo_metadata/tests/test_samples.rs
index 27a02f58f..3c747c595 100644
--- a/vendor/cargo_metadata/tests/test_samples.rs
+++ b/vendor/cargo_metadata/tests/test_samples.rs
@@ -344,6 +344,7 @@ fn all_the_fields() {
assert_eq!(all.categories, vec!["command-line-utilities"]);
assert_eq!(all.keywords, vec!["cli"]);
assert_eq!(all.readme, Some(Utf8PathBuf::from("README.md")));
+ assert!(all.readme().unwrap().ends_with("tests/all/README.md"));
assert_eq!(
all.repository,
Some("https://github.com/oli-obk/cargo_metadata/".to_string())
@@ -532,9 +533,9 @@ fn current_dir() {
fn parse_stream_is_robust() {
// Proc macros can print stuff to stdout, which naturally breaks JSON messages.
// Let's check that we don't die horribly in this case, and report an error.
- let json_output = r##"{"reason":"compiler-artifact","package_id":"chatty 0.1.0 (path+file:///chatty-macro/chatty)","target":{"kind":["proc-macro"],"crate_types":["proc-macro"],"name":"chatty","src_path":"/chatty-macro/chatty/src/lib.rs","edition":"2018","doctest":true},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":[],"filenames":["/chatty-macro/target/debug/deps/libchatty-f2adcff24cdf3bb2.so"],"executable":null,"fresh":false}
+ let json_output = r##"{"reason":"compiler-artifact","package_id":"chatty 0.1.0 (path+file:///chatty-macro/chatty)","manifest_path":"chatty-macro/Cargo.toml","target":{"kind":["proc-macro"],"crate_types":["proc-macro"],"name":"chatty","src_path":"/chatty-macro/chatty/src/lib.rs","edition":"2018","doctest":true},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":[],"filenames":["/chatty-macro/target/debug/deps/libchatty-f2adcff24cdf3bb2.so"],"executable":null,"fresh":false}
Evil proc macro was here!
-{"reason":"compiler-artifact","package_id":"chatty-macro 0.1.0 (path+file:///chatty-macro)","target":{"kind":["lib"],"crate_types":["lib"],"name":"chatty-macro","src_path":"/chatty-macro/src/lib.rs","edition":"2018","doctest":true},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":[],"filenames":["/chatty-macro/target/debug/libchatty_macro.rlib","/chatty-macro/target/debug/deps/libchatty_macro-cb5956ed52a11fb6.rmeta"],"executable":null,"fresh":false}
+{"reason":"compiler-artifact","package_id":"chatty-macro 0.1.0 (path+file:///chatty-macro)","manifest_path":"chatty-macro/Cargo.toml","target":{"kind":["lib"],"crate_types":["lib"],"name":"chatty-macro","src_path":"/chatty-macro/src/lib.rs","edition":"2018","doctest":true},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":[],"filenames":["/chatty-macro/target/debug/libchatty_macro.rlib","/chatty-macro/target/debug/deps/libchatty_macro-cb5956ed52a11fb6.rmeta"],"executable":null,"fresh":false}
"##;
let mut n_messages = 0;
let mut text = String::new();
@@ -622,3 +623,25 @@ fn depkind_to_string() {
assert_eq!(DependencyKind::Build.to_string(), "build");
assert_eq!(DependencyKind::Unknown.to_string(), "Unknown");
}
+
+#[test]
+fn basic_workspace_root_package_exists() {
+ // First try with dependencies
+ let meta = MetadataCommand::new()
+ .manifest_path("tests/basic_workspace/Cargo.toml")
+ .exec()
+ .unwrap();
+ assert_eq!(meta.root_package().unwrap().name, "ex_bin");
+ // Now with no_deps, it should still work exactly the same
+ let meta = MetadataCommand::new()
+ .manifest_path("tests/basic_workspace/Cargo.toml")
+ .no_deps()
+ .exec()
+ .unwrap();
+ assert_eq!(
+ meta.root_package()
+ .expect("workspace root still exists when no_deps used")
+ .name,
+ "ex_bin"
+ );
+}