Skip to content

selects.bzl: Add config_setting_group for config_setting AND/OR-chaining#89

Merged
c-parsons merged 8 commits intobazelbuild:masterfrom
gregestren:master
Jun 5, 2019
Merged

selects.bzl: Add config_setting_group for config_setting AND/OR-chaining#89
c-parsons merged 8 commits intobazelbuild:masterfrom
gregestren:master

Conversation

@gregestren
Copy link
Copy Markdown
Contributor

Implements https://github.com/bazelbuild/proposals/blob/master/designs/2018-11-09-config-setting-chaining.md.

I started adding tests, but I don't think the current testing infrastructure is powerful enough for this feature. @c-parsons suggests using the upcoming improved In-Build Starlark Testing as an inaugural user. That feature's destined for the next Bazel release. Progress trackable at bazelbuild/bazel#6237.

So now I'm just seeding the review. Should merging be hard-blocked on the above considerations?

@gregestren
Copy link
Copy Markdown
Contributor Author

CC'ing @serynth who reviewed the proposal.

@allevato
Copy link
Copy Markdown
Member

allevato commented Jan 2, 2019

Given that this function covers functionality in Bazel that I'm not intimately familiar with and @c-parsons has already discussed parts of the design with you (and because he's the owner of Skylib now), I prefer to defer to him on the review.

@allevato allevato requested review from c-parsons and removed request for allevato January 2, 2019 23:08
@gregestren
Copy link
Copy Markdown
Contributor Author

and because he's the owner of Skylib now

Oh, my bad. Hello new owner!

@gregestren
Copy link
Copy Markdown
Contributor Author

@c-parsons - given the state of bazelbuild/bazel#6237, do you think I can start integrating this with that now?

@c-parsons
Copy link
Copy Markdown
Collaborator

If by "integrating this with that" you mean: testing your Pull Request using the analysis-testing framework proposed in that issue?

If so, yes! Please do!
There are analysis tests using this framework which exist in the repository now today. See https://github.com/bazelbuild/bazel-skylib/blob/master/tests/unittest_tests.bzl for some examples (in truth, they are testing the analysis-test framework itself, but these are good canonical examples to get you started)

@steeve
Copy link
Copy Markdown

steeve commented May 24, 2019

Is there something preventing this to be merged ? Thanks!

@gregestren
Copy link
Copy Markdown
Contributor Author

See the previous two comments. @c-parsons was writing some Starlark testing infrastructure that this change needed to get proper testing. That wasn't ready at first but now it is. So that's what I need to integrate.

I want to tackle this in O(weeks) but it's not something I'll practically be able to have done tomorrow.

@steeve
Copy link
Copy Markdown

steeve commented May 24, 2019

No worries, I'm running off the patch from the PR. Thanks for the clarification!

@gregestren gregestren requested a review from laurentlb as a code owner May 28, 2019 22:04
@gregestren
Copy link
Copy Markdown
Contributor Author

Update: I'm revisiting this PR.

@c-parsons - I added a bunch of tests. It was fun using the new analysis-aware infrastructure. I would have liked to hide each test behind a single call, but that doesn't seem possible. It would also be nice to have test suite support.

I have two commented out tests which require checking that a macro fail()s. Is there any way to test that?

Otherwise, PTAL.

@steeve
Copy link
Copy Markdown

steeve commented May 29, 2019

@gregestren FYI, i've had some issues when ANDing with config_setting that had constraint_values where bazel would fail. It seems it had to do with the alias.

@gregestren
Copy link
Copy Markdown
Contributor Author

gregestren commented May 29, 2019 via email

@steeve
Copy link
Copy Markdown

steeve commented Jun 5, 2019

I seems it has to do with AND'ing on a platform and a config_setting:

    native.config_setting(
        name = "something",
        define_values = {
            "something": "1",
        },
        visibility = ["//visibility:public"],
    )
    selects.config_setting_group(
        name = "mymegarule",
        match_all = [
            "@io_bazel_rules_go//go/toolchain:android_arm64",
            ":something",
        ],
    )

It fails with:

//:mymegarule is not a valid configuration key for //XXXX

@steeve
Copy link
Copy Markdown

steeve commented Jun 5, 2019

Oddly enough, if I invert the match_all, then it works

    selects.config_setting_group(
        name = "mymegarule",
        match_all = [
            ":something",
            "@io_bazel_rules_go//go/toolchain:android_arm64",
        ],
    )

@steeve
Copy link
Copy Markdown

steeve commented Jun 5, 2019

All tests on bazel 0.25.3, for the record

Copy link
Copy Markdown
Collaborator

@c-parsons c-parsons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c-parsons - I added a bunch of tests. It was fun using the new analysis-aware infrastructure. I would have liked to hide each test behind a single call, but that doesn't seem possible. It would also be nice to have test suite support.

I'm glad to hear it!

What are you looking for in test suite support? It looks like you somewhat do this by having all targets created under
Is it that you'd like to be able to test specifically your whole "suite" given a single target?
If so, I'll give it some thought :) Thanks for the feedback!

I have two commented out tests which require checking that a macro fail()s. Is there any way to test that?

If there's a failure during loading phase, unfortunately not. We can test rules failing (see https://docs.bazel.build/versions/master/skylark/testing.html#failure-testing). analysistest is mostly designed for rule implementation tests; macro tests are a whole other ballgame.

Comment thread lib/selects.bzl Outdated
_config_setting_and_group(name, match_all)

def _check_duplicates(settings):
""" Fails if any entry in settings appears more than once.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Any reason we can't just have this be a single line? (And remove the extra space at the beginning of string?

(same for other docstrings of private functions in this file)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread lib/selects.bzl Outdated

The core idea is to create a sequential chain of alias targets where each is
select-resolved as follows: If alias n matches config_setting n, the chain
is true so it resolves to config_setting n. Else it resolves to alias n+1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Else it" -> "Else it"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@gregestren
Copy link
Copy Markdown
Contributor Author

Oddly enough, if I invert the match_all, then it works

    selects.config_setting_group(
        name = "mymegarule",
        match_all = [
            ":something",
            "@io_bazel_rules_go//go/toolchain:android_arm64",
        ],
    )

So it's a TODO to be able to put constraint_value directly in select() (or by extension in config_setting_group). See bazelbuild/bazel#4167 (comment). So that's a valid error: all entries in config_setting_group have to be config_setting.

You can fix that in the interim by putting your constraint_value in a config_setting:

config_setting(
    name = "android_arm64",
    constraint_values = ["@io_bazel_rules_go//go/toolchain:android_arm64"]
)

As for inverting the order, an AND fails fast if the first condition already fails. :)

@gregestren
Copy link
Copy Markdown
Contributor Author

What are you looking for in test suite support? It looks like you somewhat do this by having all targets created under
Is it that you'd like to be able to test specifically your whole "suite" given a single target?
If so, I'll give it some thought :) Thanks for the feedback!

Yes, exactly. I just see a huge explosion of the number of tests at the top level so I imagine at some point of scale that could be a problem. No major issue as things stand now though.

Comment thread lib/selects.bzl
name_off = name + "_stamp_binary_off_check"
native.config_setting(
name = name_on,
values = {"stamp": True},
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try to manually create such a rule, Bazel complains

expected value of type 'string' for dict value element, but got True (bool)

so it seems like this is not valid. Is it possible this function is not being exercised?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. That's a bug and I didn't add coverage for //conditions:default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants