Skip to content

Commit

Permalink
Fix bug in TargetsMap that ignores non-root buck target patterns
Browse files Browse the repository at this point in the history
Summary:
Add support for non-root buck target patterns that are currently shadowed by root buck target pattern matcher. Thanks Acesine for finding this bug.

~~DISCLAIMER: this is my 2nd rust diff so there's a good chance implementation is suboptimal, any/all guidance appreciated! ~~

Reviewed By: pcerl017

Differential Revision: D53147078

fbshipit-source-id: 2f67616cdc94bb5813b72046b27cc0f5c28d7082
  • Loading branch information
ndmitchell authored and facebook-github-bot committed Jan 29, 2024
1 parent d941944 commit 2d74711
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion btd/src/buck/target_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ impl<T> TargetMap<T> {
.or_default()
.push(value);
} else if let Some(prefix) = key.as_str().strip_suffix("...") {
// if it is foo// we need to keep the slash, if foo//bar/ we need to remove it
let prefix = match prefix.strip_suffix('/') {
Some(x) if !x.ends_with('/') => x,
_ => prefix,
};
self.recursive_pattern
.update(&Package::new(prefix), move |old| {
let mut res = old.unwrap_or_default();
Expand Down Expand Up @@ -97,11 +102,12 @@ mod test {
t.insert(&TargetLabel::new("foo//bar:quz"), 100);
t.insert_pattern(&TargetPattern::new("foo//bar:"), 3);
t.insert_pattern(&TargetPattern::new("foo//..."), 4);
t.insert_pattern(&TargetPattern::new("foo//bar/..."), 5);
assert_eq!(
t.get(&TargetLabel::new("foo//bar:baz"))
.copied()
.collect::<Vec<_>>(),
vec![1, 2, 3, 4]
vec![1, 2, 3, 4, 5]
);
assert_eq!(
t.get(&TargetLabel::new("foo//moo:boo"))
Expand Down

0 comments on commit 2d74711

Please sign in to comment.