Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde::Serialize;
use tracing::debug;

use crate::core::compiler::{CompileKind, RustcTargetData};
use crate::core::dependency::DepKind;
use crate::core::dependency::{ArtifactKind, DepKind};
use crate::core::resolver::features::ForceAllTargets;
use crate::core::resolver::{HasDevUnits, Resolve};
use crate::core::{
Expand Down Expand Up @@ -167,6 +167,14 @@ impl Package {
pub fn proc_macro(&self) -> bool {
self.targets().iter().any(|target| target.proc_macro())
}
// TODO fix this. For now, just wanted it to return a plausible value. Must figure out why .kinds() returns a Vec.
/// Gets crate-type in { .., artifact = <crate-type> } of this package
pub fn artifact_kind(&self) -> Option<&ArtifactKind> {
let found = self.dependencies().iter().find_map(|dep| dep.artifact());

// TODO for now just returns the first ArtifactKind in the Vec<ArtifactKind>
found?.kinds().iter().next()
}
/// Gets the package's minimum Rust version.
pub fn rust_version(&self) -> Option<&RustVersion> {
self.manifest().rust_version()
Expand Down
13 changes: 11 additions & 2 deletions src/cargo/ops/tree/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,21 @@ impl<'a> fmt::Display for Display<'a> {
} else {
""
};
// TODO this is probably NOT the right way to get the ArtifactKind
//
let artifact_suffix =
if let Some(artifact_kind) = package.artifact_kind() {
format!(" ({})", artifact_kind.crate_type())
} else {
"".to_string()
};
write!(
fmt,
"{} v{}{}",
"{} v{}{}{}",
package.name(),
package.version(),
proc_macro_suffix
proc_macro_suffix,
artifact_suffix,
)?;

let source_id = package.package_id().source_id();
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ fn dependencies_of_dependencies_work_in_artifacts() {
.with_stdout_data(str![[r#"
foo v0.0.0 ([ROOT]/foo)
[build-dependencies]
└── bar v0.5.0 ([ROOT]/foo/bar)
└── bar v0.5.0 (bin) ([ROOT]/foo/bar)
└── baz v1.0.0

"#]])
Expand Down Expand Up @@ -1572,7 +1572,7 @@ fn artifact_dep_target_specified() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stdout_data(str![[r#"
foo v0.0.0 ([ROOT]/foo)
└── bindep v0.0.0 ([ROOT]/foo/bindep)
└── bindep v0.0.0 (bin) ([ROOT]/foo/bindep)

"#]])
.with_status(0)
Expand Down Expand Up @@ -1651,7 +1651,7 @@ fn dep_of_artifact_dep_same_target_specified() {
.with_stdout_data(
r#"...
foo v0.1.0 ([ROOT]/foo)
└── bar v0.1.0 ([ROOT]/foo/bar)
└── bar v0.1.0 (bin) ([ROOT]/foo/bar)
└── baz v0.1.0 ([ROOT]/foo/baz)
"#,
)
Expand Down