best way to negate a filter?

926 views
Skip to first unread message

Jeff Hodges

unread,
Feb 23, 2018, 1:22:13 PM2/23/18
to bazel-discuss
Hey, just wanted to double check that this is the best way to negate a filter. There's no obvious example using that kind of language in the examples.

I want "all of the container_image targets that don't have the noci tag on them", so I did:

    bazel query 'kind(container_image, //...) - attr(tags, noci, kind(container_image, //...))'

Is there a more succinct way to do this?

I know I could have made the second half only `attr(tags, noci, //...)` but I didn't want to end up doing more work accidentally (if the attr and kind queries are cached differently) and I didn't want to cause a large except if the `noci` tag is used in a lot of other contexts (I know, for instance, that rules_webtesting uses it on some test target wrappers).

Thanks much!

Brian Silverman

unread,
Feb 23, 2018, 9:35:10 PM2/23/18
to Jeff Hodges, bazel-discuss
One small tweak is to avoid duplicating the kind(container_image, //...) part, both for maintainability and possible performance improvements:
'let all_container_images = kind(container_image, //...) in $all_container_images - attr(tags, noci, $all_container_images)'

Other than that though, I don't have any ideas on really making it any more succinct. I migrated away from some similar queries to --build_tag_filters/--test_tag_filters when --build_tag_filters was introduced; if those apply to your use case, the syntax and performance are a lot better.

Also, attr takes a regex, so that's going to exclude tags with noci as a substring. Might consider "(\[|, )(noci)(\]|, )" instead. Similar considerations apply to kind too.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CANV%3DTHiFGNCTWtDD4DNcEQovoYZyJ%2BwVzS5w74STtTViG%3DOfYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Hodges

unread,
Feb 25, 2018, 2:25:41 PM2/25/18
to Brian Silverman, bazel-discuss
wagh, I did not know about the attr regex thing. Thanks!

Unfortunately, I can't find "--build_tag_filters" on bazel query. It doesn't seem to exist. This is with bazel 0.10.

I don't see anything similar on the bazel command proper, either. I've also not found any similarly named command line args either.

Do you know what the deal is here?

On Fri, Feb 23, 2018 at 6:35 PM Brian Silverman <bsilve...@gmail.com> wrote:
One small tweak is to avoid duplicating the kind(container_image, //...) part, both for maintainability and possible performance improvements:
'let all_container_images = kind(container_image, //...) in $all_container_images - attr(tags, noci, $all_container_images)'

Other than that though, I don't have any ideas on really making it any more succinct. I migrated away from some similar queries to --build_tag_filters/--test_tag_filters when --build_tag_filters was introduced; if those apply to your use case, the syntax and performance are a lot better.

Also, attr takes a regex, so that's going to exclude tags with noci as a substring. Might consider "(\[|, )(noci)(\]|, )" instead. Similar considerations apply to kind too.

On Fri, Feb 23, 2018 at 1:21 PM, 'Jeff Hodges' via bazel-discuss <bazel-...@googlegroups.com> wrote:
Hey, just wanted to double check that this is the best way to negate a filter. There's no obvious example using that kind of language in the examples.

I want "all of the container_image targets that don't have the noci tag on them", so I did:

    bazel query 'kind(container_image, //...) - attr(tags, noci, kind(container_image, //...))'

Is there a more succinct way to do this?

I know I could have made the second half only `attr(tags, noci, //...)` but I didn't want to end up doing more work accidentally (if the attr and kind queries are cached differently) and I didn't want to cause a large except if the `noci` tag is used in a lot of other contexts (I know, for instance, that rules_webtesting uses it on some test target wrappers).

Thanks much!

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Brian Silverman

unread,
Feb 25, 2018, 3:57:41 PM2/25/18
to Jeff Hodges, bazel-discuss
--build_tag_filters/--test_tag_filters are options for `bazel build`/`bazel test`. They don't help if you actually need the list of targets for something, but if you're actually trying to build/test some set of targets then they're helpful (that's what I was thinking with that "if it applies in your use case" stuff, although in hindsight it's pretty subtle...).

For example, if you're currently doing this:

bazel build $(bazel query 'kind(container_image, //...) - attr(tags, noci, kind(container_image, //...))')

Then this does the same thing:

bazel build $(bazel query 'kind(container_image, //...)') --build_tag_filters=-noci

--test_tag_filters has been around for a long time. --build_tag_filters is more recent, but 0.10 should be fine. I notice that the online documentation throws them under "Miscellaneous options, not otherwise categorized.", which might mean they won't show up in some formats of documentation. Seems worth filing a bug if you notice them missing from someplace they would make sense.

On Sun, Feb 25, 2018 at 2:25 PM, Jeff Hodges <je...@somethingsimilar.com> wrote:
wagh, I did not know about the attr regex thing. Thanks!

Unfortunately, I can't find "--build_tag_filters" on bazel query. It doesn't seem to exist. This is with bazel 0.10.

I don't see anything similar on the bazel command proper, either. I've also not found any similarly named command line args either.

Do you know what the deal is here?
On Fri, Feb 23, 2018 at 6:35 PM Brian Silverman <bsilve...@gmail.com> wrote:
One small tweak is to avoid duplicating the kind(container_image, //...) part, both for maintainability and possible performance improvements:
'let all_container_images = kind(container_image, //...) in $all_container_images - attr(tags, noci, $all_container_images)'

Other than that though, I don't have any ideas on really making it any more succinct. I migrated away from some similar queries to --build_tag_filters/--test_tag_filters when --build_tag_filters was introduced; if those apply to your use case, the syntax and performance are a lot better.

Also, attr takes a regex, so that's going to exclude tags with noci as a substring. Might consider "(\[|, )(noci)(\]|, )" instead. Similar considerations apply to kind too.

On Fri, Feb 23, 2018 at 1:21 PM, 'Jeff Hodges' via bazel-discuss <bazel-discuss@googlegroups.com> wrote:
Hey, just wanted to double check that this is the best way to negate a filter. There's no obvious example using that kind of language in the examples.

I want "all of the container_image targets that don't have the noci tag on them", so I did:

    bazel query 'kind(container_image, //...) - attr(tags, noci, kind(container_image, //...))'

Is there a more succinct way to do this?

I know I could have made the second half only `attr(tags, noci, //...)` but I didn't want to end up doing more work accidentally (if the attr and kind queries are cached differently) and I didn't want to cause a large except if the `noci` tag is used in a lot of other contexts (I know, for instance, that rules_webtesting uses it on some test target wrappers).

Thanks much!

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.

Jeff Hodges

unread,
Feb 26, 2018, 4:19:14 PM2/26/18
to Brian Silverman, bazel-discuss
Ah, too bad that this isn't available on `bazel query`. I was trying to avoid both query inefficiencies and textual redundancy at the same time.

On Sun, Feb 25, 2018 at 12:57 PM Brian Silverman <bsilve...@gmail.com> wrote:
--build_tag_filters/--test_tag_filters are options for `bazel build`/`bazel test`. They don't help if you actually need the list of targets for something, but if you're actually trying to build/test some set of targets then they're helpful (that's what I was thinking with that "if it applies in your use case" stuff, although in hindsight it's pretty subtle...).

For example, if you're currently doing this:

bazel build $(bazel query 'kind(container_image, //...) - attr(tags, noci, kind(container_image, //...))')

Then this does the same thing:

bazel build $(bazel query 'kind(container_image, //...)') --build_tag_filters=-noci

--test_tag_filters has been around for a long time. --build_tag_filters is more recent, but 0.10 should be fine. I notice that the online documentation throws them under "Miscellaneous options, not otherwise categorized.", which might mean they won't show up in some formats of documentation. Seems worth filing a bug if you notice them missing from someplace they would make sense.
On Sun, Feb 25, 2018 at 2:25 PM, Jeff Hodges <je...@somethingsimilar.com> wrote:
wagh, I did not know about the attr regex thing. Thanks!

Unfortunately, I can't find "--build_tag_filters" on bazel query. It doesn't seem to exist. This is with bazel 0.10.

I don't see anything similar on the bazel command proper, either. I've also not found any similarly named command line args either.

Do you know what the deal is here?
On Fri, Feb 23, 2018 at 6:35 PM Brian Silverman <bsilve...@gmail.com> wrote:
One small tweak is to avoid duplicating the kind(container_image, //...) part, both for maintainability and possible performance improvements:
'let all_container_images = kind(container_image, //...) in $all_container_images - attr(tags, noci, $all_container_images)'

Other than that though, I don't have any ideas on really making it any more succinct. I migrated away from some similar queries to --build_tag_filters/--test_tag_filters when --build_tag_filters was introduced; if those apply to your use case, the syntax and performance are a lot better.

Also, attr takes a regex, so that's going to exclude tags with noci as a substring. Might consider "(\[|, )(noci)(\]|, )" instead. Similar considerations apply to kind too.

On Fri, Feb 23, 2018 at 1:21 PM, 'Jeff Hodges' via bazel-discuss <bazel-...@googlegroups.com> wrote:
Hey, just wanted to double check that this is the best way to negate a filter. There's no obvious example using that kind of language in the examples.

I want "all of the container_image targets that don't have the noci tag on them", so I did:

    bazel query 'kind(container_image, //...) - attr(tags, noci, kind(container_image, //...))'

Is there a more succinct way to do this?

I know I could have made the second half only `attr(tags, noci, //...)` but I didn't want to end up doing more work accidentally (if the attr and kind queries are cached differently) and I didn't want to cause a large except if the `noci` tag is used in a lot of other contexts (I know, for instance, that rules_webtesting uses it on some test target wrappers).

Thanks much!

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages