buildtools icon indicating copy to clipboard operation
buildtools copied to clipboard

Buildozer needs a conditional operator

Open manuelF opened this issue 7 years ago • 2 comments

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.

manuelF avatar Aug 21 '17 09:08 manuelF

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.

srawlins avatar Aug 30 '17 16:08 srawlins

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.

aiuto avatar Aug 03 '21 17:08 aiuto