buildtools
buildtools copied to clipboard
Buildozer needs a conditional operator
Say I need to set testing_only to 1 for all java testing libraries. These libraries are identified by having a //java/junit dependency
buildozer \
'set testing_only 1' \
$(find -L ~/my_project -name BUILD | sed"s/\/BUILD/:%java_library/" )
I can't identify here any of these testing libraries. It would be great for me if I could add some condition using a 'where' keyword:
buildozer \
'set testing_only 1' \
'where ("//java/junit" in deps and testing_only != 1)'
$(find -L ~/my_project -name BUILD | sed"s/\/BUILD/:%java_library/" )
The semantics of where is basically to match the entire build rule and, if it doesn't match the condition, then skip it from the atomic mutation.
Multiple 'where' operators would be either 'and'-ed or a parse error.
This would make a ton of refactors much easier instead of doing constant git manipulations to have better specificity especially for BUILD files with many tests.
For now this can done with bazel query and xargs, but I agree it would be very helpful to have this where
functionality. Very powerful.
I think the most powerful would be a combination of the conditional and the find, so that it would be possible to write a single buildozer script that would work on both *ix and windows. That is, do not rely on xargs or find or sed.