Skip to content

Commit 34b67e4

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 72df3e3 commit 34b67e4

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
@@ -369,7 +369,7 @@ impl<T: PatternType> ParsedPattern<T> {
369369
cell_alias_resolver,
370370
TargetParsingOptions {
371371
relative,
372-
infer_target: false,
372+
infer_target: true,
373373
strip_package_trailing_slash: false,
374374
},
375375
pattern,
@@ -1609,21 +1609,19 @@ mod tests {
16091609
CellRelativePath::unchecked_new("package").to_owned(),
16101610
);
16111611

1612-
assert_matches!(
1612+
assert_eq!(
1613+
mk_target("root", "package/path", "path"),
16131614
ParsedPattern::<TargetPatternExtra>::parse_not_relaxed(
16141615
"path",
16151616
TargetParsingRel::AllowRelative(
1616-
&CellPathWithAllowedRelativeDir::backwards_relative_not_supported(package.clone()),
1617+
&CellPathWithAllowedRelativeDir::backwards_relative_not_supported(
1618+
package.clone()
1619+
),
16171620
Some(&NoAliases),
16181621
),
16191622
&resolver(),
16201623
&alias_resolver(),
1621-
),
1622-
Err(e) => {
1623-
assert!(
1624-
format!("{e:?}").contains(&format!("{}", TargetPatternParseError::UnexpectedFormat))
1625-
);
1626-
}
1624+
)?
16271625
);
16281626

16291627
assert_eq!(
@@ -1791,7 +1789,7 @@ mod tests {
17911789
),
17921790
Err(e) => {
17931791
assert!(
1794-
format!("{e:?}").contains(&format!("{}", TargetPatternParseError::UnexpectedFormat))
1792+
format!("{e:?}").contains(&format!("{}", TargetPatternParseError::AbsoluteRequired))
17951793
);
17961794
}
17971795
);

0 commit comments

Comments
 (0)