bazel-gazelle icon indicating copy to clipboard operation
bazel-gazelle copied to clipboard

Calling buildozer to modify build files in go_repository

Open linzhp opened this issue 2 years ago • 3 comments

Currently, to modify the generated BUILD files in go_repository, people would have to create a patch, which is hard to review and maintain. We can potentially add a buildozer_args to go_repository, so if it is set, go_repository will call buildozer to modify the build files, like "add tags no-remote //:go-sqlite3".

We can potentially introduce a breaking change to address #1064 by applying the patches before calling Gazelle, and only allow to modify build files using the buildozer_args.

linzhp avatar Apr 05 '22 15:04 linzhp

My main concern is that to run buildozer as part of go_repository we would need to vendor all of its code and compile it with go, similar to what we do for other go_repository_tools. I also assume running buildozer would be much slower than applying patches, but that concern is minor.

We can potentially introduce a breaking change to address https://github.com/bazelbuild/bazel-gazelle/issues/1064 by applying the patches before calling Gazelle, and only allow to modify build files using the buildozer_args.

I do not think we should do this. Requiring everyone to convert their patches to buildozer_args would be quite the pain. It also makes us entirely dependent on the buildozer command's functionality for modifying BUILD files, and we can never 100% guarantee that it covers every case.

With these points in mind, I think it would be fine to introduce this as an optional feature, but we should not enforce this requirement on consumers.

blico avatar Apr 05 '22 15:04 blico

We can download the released binary for buildozer to avoid the compiling issue.

linzhp avatar Apr 05 '22 16:04 linzhp

It wouldn't need to actually run buildozer as a separate binary. gazelle is already linking in buildtools for formatting BUILD files; it can link against and call the code necessary for processing buildozer directives directly.

adam-azarchs avatar May 25 '22 00:05 adam-azarchs