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

Duplicate --config=foo produces a seemingly pointless warning #11592

Open
mehrdadn opened this issue Jun 15, 2020 · 7 comments
Open

Duplicate --config=foo produces a seemingly pointless warning #11592

mehrdadn opened this issue Jun 15, 2020 · 7 comments
Labels
help wanted Someone outside the Bazel team could own this P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions team-Documentation Documentation improvements that cannot be directly linked to other team labels type: documentation (cleanup)

Comments

@mehrdadn
Copy link

As of Bazel 3.2.0, if you have build --config=foo in multiple places (like .bazelrc and ~/.bazelrc), bazel build produces the following warning:

WARNING: The following configs were expanded more than once: [foo]. For repeatable flags, repeats are counted twice and may lead to unexpected behavior.

It's not clear under which scenario --config=foo may be "repeatable" or produce "unexpected behavior". To my understanding, such a thing cannot happen, and hence the warning seems like a bug. There does not appear to be any conflict in the requested flags. Could the warning be removed?

@ulfjack
Copy link
Contributor

ulfjack commented Jun 15, 2020

In most cases, it's safe to have the same flag multiple times. The only (?) case where flags can produce unexpected results if expanded multiple times are 'list' options, such as --copt. The bazel invocation bazel build --copt=-DFOO --copt=-DFOO is not the same as bazel build --copt=-DFOO. Bazel does not know what these flags mean and will not de-duplicate them. In this case, switching from once to twice means that you'll get cache misses on all caches (in-memory, local action cache, remote action cache). In general, this means you get separate cache silos depending on how often the flag is specified.

@mehrdadn
Copy link
Author

mehrdadn commented Jun 15, 2020

Right, that makes sense for --copt, but why --config? It seems trivial to just look for --config flags and deduplicate them? Why should it not do that?
Note that Bazel even understands that these are 'config' entries, and not arbitrary flags ("The following configs were expanded more than once: [foo]."), and it already deduplicates the warning messages too (it won't emit it 2 times if you have the flag 3 times). So it's very confusing as to why it's emitting the warning in the first place.

@ulfjack
Copy link
Contributor

ulfjack commented Jun 15, 2020

--config flags are expanded in-place, so it's not trivial to de-duplicate them, either. E.g.:

bazel build --config=foo --config=bar --config=foo

is not equivalent to:

bazel build --config=foo --config=bar

You also have to take into account that configs can include each other, like so:

build:foo --config=bar

@mehrdadn
Copy link
Author

Ahh... I actually don't really grok how that works to be honest. I've seen something about "in-place expansion" in the documentation too, but it still left me confused even though I've read it several times. Would you mind giving a concrete example to show how the end result might differ?

@ulfjack
Copy link
Contributor

ulfjack commented Jun 19, 2020

Sure:

.bazelrc:
build:foo --copt=-Dfoo=1
build:bar --copt=-Dfoo=0

$ bazel build --config=foo --config=bar --config=foo
is equivalent to:
$ bazel build --copt=-Dfoo=1 --copt=-Dfoo=0 --copt=-Dfoo=1

For the compiler, this ends up setting foo=1.

$ bazel build --config=foo --config=bar
is equivalent to:
$ bazel build --copt=-Dfoo=1 --copt=-Dfoo=0

For the compiler, this ends up setting foo=0.

FWIW, I think this warning could be made less noisy, e.g., by filtering out non-list flags. That said, you should be able to arrange your config sections so you don't see the warning (although sometimes it may be inconvenient to do so).

@mehrdadn
Copy link
Author

mehrdadn commented Jun 19, 2020

Oh wow I see. So --config= basically just forces a copy-paste of all the underlying command-line options? There's no intelligence to it at all?

Is this actually useful, or is it just an implementation quirk? Do people depend on duplication behavior like this for correctness?

@ulfjack
Copy link
Contributor

ulfjack commented Jun 19, 2020

The original implementation didn't inline in-place, but did something more complex that also involved de-duplicating the configs. Unfortunately, it was confusing people more than it was helping and there were numerous bug reports about it - that's why it was changed. Dumb is good.

@aiuto aiuto added team-Configurability platforms, toolchains, cquery, select(), config transitions type: documentation (cleanup) P3 We're not considering working on this, but happy to review a PR. (No assignee) labels Jun 22, 2020
@keertk keertk added the team-Documentation Documentation improvements that cannot be directly linked to other team labels label Jan 10, 2023
@keertk keertk added the help wanted Someone outside the Bazel team could own this label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Someone outside the Bazel team could own this P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions team-Documentation Documentation improvements that cannot be directly linked to other team labels type: documentation (cleanup)
Projects
None yet
Development

No branches or pull requests

4 participants