bazelbuild / buildtools

A bazel BUILD file formatter and editor
Apache License 2.0
994 stars 410 forks source link

[buildozer]: Support adding symbols instead of literal strings #1232

Open justhecuke opened 5 months ago

justhecuke commented 5 months ago

If I want to, for example, add a symbol with a value to a list, that is not possible right now.

buildozer 'add tags SOME_CONST' //pkg:target
-->
some_rule(
  name = "target",
  tags = ["SOME_CONST"],
  ...
)

What I want is the ability to do something such as:

buildozer --symbol 'add tags SOME_CONST' //pkg:target
-->
some_rule(
  name = "target",
  tags = [SOME_CONST],
  ...
)

and

buildozer --symbol 'set tags LIST_CONST' //pkg:target
-->
some_rule(
  name = "target",
  tags = LIST_CONST,
  ...
)

In this way, we can use buildozer better for larger refactors if we want to centralize control of a few key attributes without needing to create a mess of macros and rules.

stagnation commented 4 months ago

Nice idea! I have historically wanted all tags to be included as literals, to have a centralized location with documentation for what they all mean. And to reduce the risk of typos that are very hard to catch after the fact. At one point I tried to do a post-process sed to make them literals after the fact, I think that should work. I did not look into the tables configuration to temporarily define tags as not-strings either, though maybe that works.