Skip to content

Commit 510a0c9

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 79d8571 commit 510a0c9

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

app/buck2_core/src/pattern/pattern.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<T: PatternType> ParsedPattern<T> {
302302
cell_alias_resolver,
303303
TargetParsingOptions {
304304
relative,
305-
infer_target: false,
305+
infer_target: true,
306306
strip_package_trailing_slash: false,
307307
},
308308
pattern,
@@ -1511,7 +1511,8 @@ mod tests {
15111511
CellRelativePath::unchecked_new("package").to_owned(),
15121512
);
15131513

1514-
assert_matches!(
1514+
assert_eq!(
1515+
mk_target("root", "package/path", "path"),
15151516
ParsedPattern::<TargetPatternExtra>::parse_not_relaxed(
15161517
"path",
15171518
TargetParsingRel::AllowRelative(
@@ -1520,12 +1521,7 @@ mod tests {
15201521
),
15211522
&resolver(),
15221523
&alias_resolver(),
1523-
),
1524-
Err(e) => {
1525-
assert!(
1526-
format!("{:?}", e).contains(&format!("{}", TargetPatternParseError::UnexpectedFormat))
1527-
);
1528-
}
1524+
)?
15291525
);
15301526

15311527
assert_eq!(
@@ -1693,7 +1689,7 @@ mod tests {
16931689
),
16941690
Err(e) => {
16951691
assert!(
1696-
format!("{:?}", e).contains(&format!("{}", TargetPatternParseError::UnexpectedFormat))
1692+
format!("{:?}", e).contains(&format!("{}", TargetPatternParseError::AbsoluteRequired))
16971693
);
16981694
}
16991695
);

0 commit comments

Comments
 (0)