When in package mode, the gazelle plugin is always overwriting existing buf_breaking_test rules instead of merging them.
In my case, I've set the size attribute on my rule but it gets removed on each invocation of gazelle.
There is a code path in generate.go to handle this case but the check is sensitive to the targets exactly matching the key in protoRuleMap.
The protoRuleMap is populated from a rule's name attribute, but the lookup is using another rule's targets attribute. The targets attribute is a set of labels so they are typically prepended with a colon (e.g. :protos vs protos). As a result, the targets never match a value in protoRuleMap and any existing buf_breaking_test rule is removed instead of merged.
Here's an example of my patch to work around this.
gazelle/buf/generate.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gazelle/buf/generate.go b/gazelle/buf/generate.go
index 7766961..0f8aed9 100644
--- a/gazelle/buf/generate.go
+++ b/gazelle/buf/generate.go
@@ -133,7 +133,7 @@ func shouldRemoveSingleTargetBufRule(
// Not generated by us
return false
}
- if len(targets) == 1 && protoRuleMap[targets[0]] != nil {
+ if len(targets) == 1 && protoRuleMap[strings.TrimPrefix(targets[0], ":")] != nil {
// Target is accurate so skip
return false
}
When in
package
mode, the gazelle plugin is always overwriting existingbuf_breaking_test
rules instead of merging them. In my case, I've set thesize
attribute on my rule but it gets removed on each invocation of gazelle.There is a code path in generate.go to handle this case but the check is sensitive to the
targets
exactly matching the key inprotoRuleMap
.The protoRuleMap is populated from a rule's
name
attribute, but the lookup is using another rule's targets attribute. Thetargets
attribute is a set of labels so they are typically prepended with a colon (e.g.:protos
vsprotos
). As a result, thetargets
never match a value inprotoRuleMap
and any existingbuf_breaking_test
rule is removed instead of merged.Here's an example of my patch to work around this.