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

cquery produces non-actionable warning related to toolchains #11993

Closed
konste opened this issue Aug 21, 2020 · 26 comments
Closed

cquery produces non-actionable warning related to toolchains #11993

konste opened this issue Aug 21, 2020 · 26 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request

Comments

@konste
Copy link

konste commented Aug 21, 2020

Description of the problem / feature request:

IF

  1. there is a target Foo which depends on some toolchain;
  2. --incompatible_override_toolchain_transition is in effect;
    3 command is bazel cquery deps(Foo) THEN WARNING: Targets were missing from graph` is generated.

The small repro with Python toolchain is published here
We get exactly the same problem with C++ toolchain as well.

What operating system are you running Bazel on?

Windows, Linux, OSX.

What's the output of bazel info release?

3.4.1

@katre
Copy link
Member

katre commented Aug 31, 2020

This means that something referred to that target, but it hadn't actually been analyzed as part of the build (in this case, '//:tab_python_runtime_pairis discovered as thetoolchainattribute of//:tab_python_toolchain, but since toolchain` is a no-dependency label, there was no call to actually analyze it).

What is your preference? Do not show the message? Make it clearer what is happening?

@katre
Copy link
Member

katre commented Aug 31, 2020

Adding @juliexxia as a cquery expert while we determine the right course of action.

@konste
Copy link
Author

konste commented Aug 31, 2020

Frankly I still don't quite understand what causes the warning. And the fact that the warning shows up only when --incompatible_override_toolchain_transition is in effect makes it even more confusing.
In this case warning does not look actionable, like - what we supposed to fix to make the warning go away?

@katre
Copy link
Member

katre commented Aug 31, 2020

Looks like, without --incompatible_override_toolchain_transition, cquery sees the expected dependency on the toolchain //:tab_python_runtime_pair (in the host configuration), which in turn depends on @python_linux//:tab_python_runtime (also in the host configuration).

With --incompatible_override_toolchain_transition, the toolchain is still //:tab_python_runtime_pair, but in the target configuration, and there is no dependency to @python_linux, because //:tab_python_runtime_pair isn't being fully analyzed.

If I try to build //:main, I get an error:

ERROR: /usr/local/google/home/jcater/repos/cquery_targets_missing_repro/BUILD.bazel:16:10: Couldn't build runfiles for //:main: //:main: missing input file 'external/python_linux/python', owner: '@python_linux//:python'

This may be due to me having to complete the BUILD files for linux (your repro only has Windows paths). Based on the Windows config, I assumed that the correct URL for linux would be https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz, is this correct?

@konste
Copy link
Author

konste commented Aug 31, 2020

It is not the correct path and I don't see the correct one there. Need 30 min to make Linux compatible repro.

@katre
Copy link
Member

katre commented Aug 31, 2020

Thanks!

@juliexxia
Copy link
Contributor

juliexxia commented Aug 31, 2020

re: this specific warning in the query environment.

It's difficult to be totally sure without running the full repro, but the error is coming from here:

eventHandler.handle(Event.warn("Targets were missing from graph: " + missingTargets));
which seems to indicate that there's a mismatch between what targets the query engine expects to be in the graph and what targets are actually there (which we already knew).

We ran into a similar issue a while back with mysteriously not-there garden variety (not-toolchain) nodes in the cquery graph which may be related?

"query-requested node '%s' was unavailable in the query environment graph. If you"

Basically, I think that while trying to get all dependencies of a particular target in the graph, if any calculated dependency does not fall into any cases in this if/else, this warning will print. Not totally sure without a repro though.

@konste
Copy link
Author

konste commented Aug 31, 2020

Repro updated.
Command to run is bazel cquery "deps(main)"
I just added almost empty folder named pseudo_python and pointed new_local_repository to it. We don't need to execute any actual Python to see the repro.

@katre
Copy link
Member

katre commented Aug 31, 2020

Thanks!

Okay, I see the same behavior: with the flag, //:tab_python_runtime_pair is in the target config (as expected), and there's no dependency on @python_linux. Without the flag, //:tab_python_runtime_pair is in the host config (also as expected), and there is a dependency on @python_linux. That's unexpected, and I'll debug a bit to try and see why.

One question I had: why are you using the flag --incompatible_override_toolchain_transition? No toolchains have actually migrated yet, and it's only intended for compatibility testing, not for users. It's possible that part of this failure is because the python rules aren't ready for this yet.

@konste
Copy link
Author

konste commented Aug 31, 2020

We are not using --incompatible_override_toolchain_transition directly, but we are using --all_incompatible_changes end except for that warning everything else works just fine.

@konste
Copy link
Author

konste commented Aug 31, 2020

I am not saying this warning is a blocker by any means, more like an indication of the possible bug which better be discovered early than later.

@katre
Copy link
Member

katre commented Aug 31, 2020

It's definitely surprising, I'm going to keep investigating.

@katre
Copy link
Member

katre commented Sep 2, 2020

Okay, added some test code to PostAnalysisQueryEnvironment to dig into skyframe and report configured targets with the same label but which aren't the same, and here we are:

WARNING: Targets were missing from graph: [ConfiguredTargetKey{label=//:tab_python_runtime_pair, config=BuildConfigurationValue.Key[285b04bb4645367b5ec24e973f3b8f58c7ba97955812264d6468841139055aed]}]
WARNING: Found similar configured target keys: [ConfiguredTargetKeyWithToolchainContext{label=//:tab_python_runtime_pair, config=BuildConfigurationValue.Key[285b04bb4645367b5ec24e973f3b8f58c7ba97955812264d6468841139055aed], toolchainContextKey=ToolchainContextKey{configurationKey=BuildConfigurationValue.Key[285b04bb4645367b5ec24e973f3b8f58c7ba97955812264d6468841139055aed], requiredToolchainTypeLabels=[@bazel_tools//tools/python:toolchain_type, @bazel_tools//tools/cpp:toolchain_type], execConstraintLabels=[], shouldSanityCheckConfiguration=false}}]

So, the issue is that, when toolchain transitions are in use, toolchains actually have ConfiguredTargetKeyWithToolchainContext (with an added toolchain context key), not a ConfiguredTargetKey (without). Unfortunately, the cquery infrastructure doesn't use the right key types, so it's not found.

Coincidentally, @juliexxia was working on this just yesterday, so it should be fixed soon.

Thanks, @konste, for bringing this to my attention.

@katre katre removed the untriaged label Sep 3, 2020
Yannic pushed a commit to Yannic/bazel that referenced this issue Oct 5, 2020
Toolchain deps were not being caught by implicit deps filtering because there's no way to tell them apart from regular deps. Thus, we add (back) logic to do it during ruleContext building. This was caught by a user in unknown commit when they fixed our test for us. The test fix in included in this CL. Fixing the test triggered the bug.

Fixes bazelbuild#11993

PiperOrigin-RevId: 333367049
@konste
Copy link
Author

konste commented Oct 22, 2020

As far as I understand the fix is released with the version 3.7.0. Is that right?
I ask because we have switched to 3.7.0 and I still see this issue repro, although on a smaller scale than before.
If it is indeed supposed to be fixed in 3.7.0. then I will work on a repro.

@katre
Copy link
Member

katre commented Oct 22, 2020

31b0453 is in 3.7.0. If you're still seeing strange results, and if it's not a problem to come up with a repro, please do and we'll take a look some more.

@konste
Copy link
Author

konste commented Oct 23, 2020

I have tried my original repro here and it still reproduces on both Windows and Linux. Try the command bazel cquery "deps(main)".

@konste
Copy link
Author

konste commented Oct 30, 2020

@katre This issue needs to be re-activated. Hopefully, it requires just a little amendment to your existing fix and it would not take much of your time.

@konste
Copy link
Author

konste commented Nov 11, 2020

@katre could we please get some traction on this issue so the fix can make it to 4.0? It produces confusing WARNING for our users which we cannot suppress and we get support tickets for that.

@katre
Copy link
Member

katre commented Nov 12, 2020

I'm sorry this has been sitting for so long. I have been snowed under by other projects and this has slipped through.

Unfortunately, since the cut for 4.0 is happening shortly and I am busy with BazelCon activities, I don't know if I'll be able to debug this further and identify a fix before the cut.

@katre katre reopened this Nov 12, 2020
@konste
Copy link
Author

konste commented Nov 12, 2020

@katre Thank you for getting back to me! I realized that meeting 4.0 cut time is tough and retract my ask for it. Still, it would be great to have this issue fixed this year. We try to stay at the edge and upgrade to every monthly Bazel release, often including RCs when they contain the fixes we need, so missing 4.0 cut off is not that important as we hopefully can get the fix only about a month later.

katre added a commit to katre/bazel that referenced this issue Nov 24, 2020
- Fix looking up a target from the walkable graph.
  - This prevents ConfiguredTargetValueAccessor from needing to look into
    ConfiguredTargetAccessor.
  - And removes duplicated code.
- Move CTVA into the correct package.

Part of bazelbuild#11993.
katre added a commit to katre/bazel that referenced this issue Nov 24, 2020
Uses a default value for non-alias and non-rule CTs.

This alloows removing many instanceof/cast checks when getting config
conditions.

Part of the work on bazelbuild#11993.
katre added a commit to katre/bazel that referenced this issue Nov 24, 2020
katre added a commit to katre/bazel that referenced this issue Nov 24, 2020
This will allow us to keep the configured target key between lookup
rounds.

Fixes bazelbuild#11993.
@katre
Copy link
Member

katre commented Nov 24, 2020

Okay, I have a clean-looking fix, but it requires a decent bit of cleanup. I'll send out the stages for review over the next week or so (given the break for US holidays this week).

katre added a commit to katre/bazel that referenced this issue Nov 24, 2020
Uses a default value for non-alias and non-rule CTs.

This alloows removing many instanceof/cast checks when getting config
conditions.

Part of the work on bazelbuild#11993.
katre added a commit to katre/bazel that referenced this issue Nov 24, 2020
bazel-io pushed a commit that referenced this issue Nov 24, 2020
Uses a default value for non-alias and non-rule CTs.

This alloows removing many instanceof/cast checks when getting config
conditions.

Part of the work on #11993.

Closes #12550.

PiperOrigin-RevId: 344126290
bazel-io pushed a commit that referenced this issue Nov 24, 2020
Part of work on #11993.

Closes #12551.

PiperOrigin-RevId: 344131151
bazel-io pushed a commit that referenced this issue Nov 25, 2020
- Fix looking up a target from the walkable graph.
  - This prevents ConfiguredTargetValueAccessor from needing to look into
    ConfiguredTargetAccessor.
  - And removes duplicated code.
- Move CTVA into the correct package.

Part of #11993.

Closes #12549.

PiperOrigin-RevId: 344151199
katre added a commit to katre/bazel that referenced this issue Nov 25, 2020
This will allow us to keep the configured target key between lookup
rounds.

Fixes bazelbuild#11993.
@konste
Copy link
Author

konste commented Nov 25, 2020

Super! Thanks @katre for a kind of unexpected ton of work! But as far as I understand this fix prevents much more serious problems in the future than the cosmetic issue I initially reported.
Which version of Bazel shall we expect to see the fix in?

@katre
Copy link
Member

katre commented Nov 25, 2020

Bazel 4.1 would be the release to contain this. I'm not sure it's something we can cherrypick into 4.0, unfortunately.

bazel-io pushed a commit that referenced this issue Nov 25, 2020
philwo pushed a commit that referenced this issue Mar 15, 2021
Part of work on #11993.

Closes #12551.

PiperOrigin-RevId: 344131151
philwo pushed a commit that referenced this issue Mar 15, 2021
- Fix looking up a target from the walkable graph.
  - This prevents ConfiguredTargetValueAccessor from needing to look into
    ConfiguredTargetAccessor.
  - And removes duplicated code.
- Move CTVA into the correct package.

Part of #11993.

Closes #12549.

PiperOrigin-RevId: 344151199
philwo pushed a commit that referenced this issue Mar 15, 2021
Uses a default value for non-alias and non-rule CTs.

This alloows removing many instanceof/cast checks when getting config
conditions.

Part of the work on #11993.

Closes #12550.

PiperOrigin-RevId: 344126290
philwo pushed a commit that referenced this issue Mar 15, 2021
This will allow us to keep the configured target key between lookup rounds.

Fixes #11993.

Closes #12547.

PiperOrigin-RevId: 344299744
philwo pushed a commit that referenced this issue Mar 15, 2021
philwo pushed a commit that referenced this issue Mar 15, 2021
Part of work on #11993.

Closes #12551.

PiperOrigin-RevId: 344131151
philwo pushed a commit that referenced this issue Mar 15, 2021
- Fix looking up a target from the walkable graph.
  - This prevents ConfiguredTargetValueAccessor from needing to look into
    ConfiguredTargetAccessor.
  - And removes duplicated code.
- Move CTVA into the correct package.

Part of #11993.

Closes #12549.

PiperOrigin-RevId: 344151199
philwo pushed a commit that referenced this issue Mar 15, 2021
Uses a default value for non-alias and non-rule CTs.

This alloows removing many instanceof/cast checks when getting config
conditions.

Part of the work on #11993.

Closes #12550.

PiperOrigin-RevId: 344126290
philwo pushed a commit that referenced this issue Mar 15, 2021
This will allow us to keep the configured target key between lookup rounds.

Fixes #11993.

Closes #12547.

PiperOrigin-RevId: 344299744
philwo pushed a commit that referenced this issue Mar 15, 2021
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    Toolchain deps were not being caught by implicit deps filtering because there's no way to tell them apart from regular deps. Thus, we add (back) logic to do it during ruleContext building. This was caught by a user in unknown commit when they fixed our test for us. The test fix in included in this CL. Fixing the test triggered the bug.

    Fixes bazelbuild/bazel#11993

    PiperOrigin-RevId: 333367049
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants