Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"tags" attribute should be usable with "select" #2971

Closed
philwo opened this issue May 8, 2017 · 9 comments
Closed

"tags" attribute should be usable with "select" #2971

philwo opened this issue May 8, 2017 · 9 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request

Comments

@philwo
Copy link
Member

philwo commented May 8, 2017

Reported by @gorset in #2669 (comment):

I tried falling back to exclusive using something like:
tags = select({":darwin": ["exclusive"], "//conditions:default": ["block-network"]}),
but this is unfortunately not supported:
attribute "tags" is not configurable.

Do we want the "tags" attribute to be configurable via "select"? If not, why not? (Would be good to document this decision here.)

Ping @ahumesky who replied on related #1904 earlier.

@ahumesky
Copy link
Contributor

ahumesky commented May 8, 2017

I don't know much past what I posted on #1904, perhaps @gregestren can comment?

@gregestren
Copy link
Contributor

gregestren commented May 8, 2017

"tags" is nonconfigurable for practical reasons, not principled ones. In short, multiple places in Bazel's codebase expect to know the value of "tags" before the build's configuration is known. This means they can't get their answer from a select. We can conceivably refactor that code away and make tags selectable. But that would be a mini-project for whoever wants to take up the effort.

I'm glad to review anyone's proposed cleanup, but I'm not prioritizing this work myself.

Examples:


return NonconfigurableAttributeMapper.of(rule).get(CONSTRAINTS_ATTR, Type.STRING_LIST)

if (TargetUtils.isTestRule(rule) && !TargetUtils.hasManualTag(rule)) {

I'd expect the cleanup to be relatively straightforward but not entirely trivial.

@dslomov dslomov added category: extensibility > configurability type: feature request P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed type: feature request labels May 16, 2017
@gregestren gregestren added team-Configurability platforms, toolchains, cquery, select(), config transitions and removed category: extensibility > configurability labels Dec 4, 2018
@gregestren
Copy link
Contributor

As mentioned on #7911 (comment), the challenge to make this viable is to figure out how to make

List<String> tagsAttribute =
NonconfigurableAttributeMapper.of(testSuite).get("tags", Type.STRING_LIST);

work without a NonconfigurableAttributeMapper.

This code unconditionally iterates over all values of tags. So we can't exempt "known safe" values like exclusive and make then select-friendly unless we know how to either exempt them here too or lift the general NonconfigurableAttributeMapper limitation.

@gregestren
Copy link
Contributor

gregestren commented May 15, 2020

Closing for the below reasons:

This can't be practically prioritized without a focused effort by a community contributor. This requires vetting how much logical complexity has to be considered due to the dependencies described in previous comments and evaluating the feature's benefit vs. the new complexity's maintenance cost.

It's also possible (maybe even preferable?) to explore alternative approaches that reduce the need to use tags in the first place, vs. other better-fitting attributes.

So basically, it's a design effort. And one that needs to evaluate the specific needs for this flag vs. alternatives, which varies from case to case. It's still a good design question but let's only keep this open when/if someone wants to own that.

bootstraponline pushed a commit to Flank/mirror-goog-studio-main that referenced this issue Sep 26, 2022
For our integration tests, we're using one iml_test rule for all
platforms (Windows, Linux, and macOS). However, the "block-network" tag
prevents Android Studio from starting up on macOS due to how sandboxing
is implemented, so we need to disable it there. Unfortunately, Bazel
doesn't allow for using "select" for tags (see
bazelbuild/bazel#2971), so we instead generate
per-platform rules. The rules are bundled into a test_suite for easier
use.

Bug: 242358149
Test: this will be tested by the other changes in this topic
Change-Id: I7669e4de2b8b7673177d4d368d00b147abde73e6
@tpudlik
Copy link
Contributor

tpudlik commented Nov 21, 2023

On Pigweed we ran into the exact same use case: we want to use "block-network", but that only works on Linux, and there's no way to tell Bazel to only enable "block-network" when running on Linux. As far as I can tell this means you can't benefit from network sandboxing at all (even while building on Linux) if you want your project to build on both Linux and MacOS. That's a bummer: it's a great feature!

It's also possible (maybe even preferable?) to explore alternative approaches that reduce the need to use tags in the first place, vs. other better-fitting attributes.

I agree with this sentiment. But it seems like there's a more fundamental problem here than tags being the wrong attribute. Bazel expects to extract some execution info about tests (linked by you above, in #2971 (comment)) before the target configuration is known. The real issue is whether extracting this information can be deferred until after the target configuration is determined. Moving the information from tags to another attribute will not help, since then that attribute would not be selectable. (Maybe addressing this is the "mini-project" you referred to in your first comment.)

@gregestren
Copy link
Contributor

On quick glance I didn't see anything obvious that required execution info that early (most consumes of getExecutionInfo look like they're in analysis? all?) Maybe we can defer those classes of tags?

The only other concern I'd have is if CI expects to know the execution info tags. Google's CI cares about knowing execution machine requirements with nothing more informed than a bazel query. We could always check with them on this point.

@philwo
Copy link
Member Author

philwo commented Nov 22, 2023

we want to use "block-network", but that only works on Linux

I implemented support for block-network in the macOS sandbox more than 6 years ago - does it no longer work?

See:

if (!allowNetwork) {
out.println("(deny network*)");
out.println("(allow network-inbound (local ip \"localhost:*\"))");
out.println("(allow network* (remote ip \"localhost:*\"))");
out.println("(allow network* (remote unix-socket))");
}

@tpudlik
Copy link
Contributor

tpudlik commented Nov 22, 2023

It does not appear to work for us: see https://issues.pigweed.dev/issues/312452379. (Should have linked to it in the original comment, sorry!)

@pcjanzen
Copy link
Contributor

One useful-but-slightly-gross hack:
Write a repository rule that detects the host OS (or reads some environment variable) and then writes a .bzl function that returns either ["block-network"] or [], and then call that function from your BUILD file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants