Skip to content

Commit 9556d46

Browse files
Wilfredmeta-codesync[bot]
authored andcommitted
Improve display names of proc-macro crates
Summary: Proc macro targets tend to have names like `fbsource//third-party/rust/vendor/derive_more-impl:_2.1.0` which wasn't previously handled in our display logic. Add support for names with underscores and add a test. Reviewed By: anps77, diliop Differential Revision: D95063510 fbshipit-source-id: 0f594a7f89f0f71a915640acd5b7257fa3688bf7
1 parent 67217c4 commit 9556d46

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

integrations/rust-project/src/target.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,13 @@ impl TargetInfo {
154154
}
155155

156156
pub(crate) fn display_name(&self) -> String {
157-
if self.name.chars().all(|c| c.is_ascii_digit() || c == '.') {
158-
// For target of the form foo:1.2.3, the buck name is 1.2.3 but
159-
// that's not useful for a display name.
157+
if self
158+
.name
159+
.chars()
160+
.all(|c| c.is_ascii_digit() || c == '.' || c == '_')
161+
{
162+
// For targets of the form foo:1.2.3 or foo:_1.2.3, the buck
163+
// name (1.2.3 or _1.2.3 respectively) isn't useful as a display name.
160164
self.crate_name()
161165
} else {
162166
self.name
@@ -323,6 +327,32 @@ mod tests {
323327
assert_eq!(info.display_name(), "foo");
324328
}
325329

330+
#[test]
331+
fn test_display_name_version_with_underscore() {
332+
let info = TargetInfo {
333+
name: "_1.2.3".to_owned(),
334+
label: "//third-party/foo:_1.2.3".to_owned(),
335+
kind: Kind::Library,
336+
edition: None,
337+
srcs: vec![],
338+
mapped_srcs: FxHashMap::default(),
339+
crate_name: Some("foo".to_owned()),
340+
crate_dynamic: None,
341+
crate_root: PathBuf::default(),
342+
deps: vec![],
343+
test_deps: vec![],
344+
named_deps: FxHashMap::default(),
345+
proc_macro: None,
346+
features: vec![],
347+
env: FxHashMap::default(),
348+
source_folder: PathBuf::from("/tmp"),
349+
project_relative_buildfile: PathBuf::from("third-party/BUCK"),
350+
in_workspace: false,
351+
rustc_flags: vec![],
352+
};
353+
assert_eq!(info.display_name(), "foo");
354+
}
355+
326356
#[test]
327357
fn test_display_name_strips_unittest_suffix() {
328358
let info = TargetInfo {

0 commit comments

Comments
 (0)