Skip to content

Commit a2a96c5

Browse files
9999yearslf-
authored andcommitted
//A/B/C is a valid name for //A/B/C:C
> Prefer using the short name when referring to an eponymous target (`//x` instead of `//x:x`). If > you are in the same package, prefer the local reference (`:x` instead of `//x`). See: https://bazel.build/build/style-guide#target-naming This syntax is supported on the command-line, but not in BUCK files. Unfortunately, the only(?) Starlark formatter (buildifier: https://github.com/bazelbuild/buildtools) automatically abbreviates targets on the assumption that this syntax is valid, which causes errors when using Buck2: ... 4: Error coercing "//src/Foo" 5: Invalid absolute target pattern `//src/Foo` is not allowed 6: Expected a `:`, a trailing `/...` or the literal `...`. We can adjust the parsing rules to allow this syntax in more places.
1 parent e074607 commit a2a96c5

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

app/buck2_core/src/pattern/pattern.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<T: PatternType> ParsedPattern<T> {
353353
cell_alias_resolver,
354354
TargetParsingOptions {
355355
relative,
356-
infer_target: false,
356+
infer_target: true,
357357
strip_package_trailing_slash: false,
358358
},
359359
pattern,
@@ -1603,21 +1603,19 @@ mod tests {
16031603
CellRelativePath::unchecked_new("package").to_owned(),
16041604
);
16051605

1606-
assert_matches!(
1606+
assert_eq!(
1607+
mk_target("root", "package/path", "path"),
16071608
ParsedPattern::<TargetPatternExtra>::parse_not_relaxed(
16081609
"path",
16091610
TargetParsingRel::AllowRelative(
1610-
&CellPathWithAllowedRelativeDir::backwards_relative_not_supported(package.clone()),
1611+
&CellPathWithAllowedRelativeDir::backwards_relative_not_supported(
1612+
package.clone()
1613+
),
16111614
Some(&NoAliases),
16121615
),
16131616
&resolver(),
16141617
&alias_resolver(),
1615-
),
1616-
Err(e) => {
1617-
assert!(
1618-
format!("{e:?}").contains(&format!("{}", TargetPatternParseError::UnexpectedFormat))
1619-
);
1620-
}
1618+
)?
16211619
);
16221620

16231621
assert_eq!(
@@ -1785,7 +1783,7 @@ mod tests {
17851783
),
17861784
Err(e) => {
17871785
assert!(
1788-
format!("{e:?}").contains(&format!("{}", TargetPatternParseError::UnexpectedFormat))
1786+
format!("{e:?}").contains(&format!("{}", TargetPatternParseError::AbsoluteRequired))
17891787
);
17901788
}
17911789
);

0 commit comments

Comments
 (0)