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

experimental_remap_main_repo and register_execution_platforms issue #7773

Closed
ittaiz opened this issue Mar 20, 2019 · 18 comments
Closed

experimental_remap_main_repo and register_execution_platforms issue #7773

ittaiz opened this issue Mar 20, 2019 · 18 comments
Assignees
Labels
P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@ittaiz
Copy link
Member

ittaiz commented Mar 20, 2019

Description of the problem / feature request:

build breaks when using --experimental_remap_main_repo=true and register_execution_platforms refers to current workspace in fully qualified manner.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

https://github.com/ittaiz/bazel_remap_platforms_issue

Error:

➜  bazel_remap_platforms_issue git:(master) bazel build //...                 
INFO: Invocation ID: b8f78378-5b97-42bc-a982-ae9aa9c23824
ERROR: While resolving toolchains for target //code:foo: Unable to find an execution platform for target platform @bazel_tools//platforms:target_platform from available execution platforms []
ERROR: Analysis of target '//code:foo' failed; build aborted: Unable to find an execution platform for target platform @bazel_tools//platforms:target_platform from available execution platforms []
INFO: Elapsed time: 0.188s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 3 targets configured)

You can also check the remap_off_passes and no_qualify_in_ws_passes branches which show the build passes when remap is off or when you don't qualify the execution platform in the WORKSPACE.

What operating system are you running Bazel on?

OS X

What's the output of bazel info release?

0.23.1
I also tried to verify that 2398d85 doesn't solve the issue. It wasn't easy since it was rollbacked, I can't seem to build bazel HEAD locally and I had a really hard time finding a bazel nightly release.
I ended up downloading the mac binary from this build https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/862#36abbed3-6d50-4137-a779-4a6c989bc557 as I think it should contain the above change.
In any case the build still fails there.
Also happens with 0.24.0rc7

Have you found anything relevant by searching the web?

#7654 sounds related, which is why I tried the above commit, but we have a bit of a different error.

Also I'll share that in our internal workspace we did see ERROR: While resolving toolchains for target //some-target: no matching toolchains found for types @io_bazel_rules_scala//scala:toolchain_type but when I worked on the repro and worked on a minimized example I actually got the error from above.
Also the two workarounds above also workaround it for our internal cases.

@iirina iirina added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Mar 21, 2019
@dslomov dslomov added type: bug P1 I'll work on this now. (Assignee required) and removed untriaged labels Mar 21, 2019
@ittaiz
Copy link
Member Author

ittaiz commented Mar 26, 2019

@iirina any update?

@katre
Copy link
Member

katre commented Mar 26, 2019

@dkelmer and I were just discussing this (and #7654) and realized the problem and how to fix it.

Here is a brief explanation of how the code works currently:

  1. The register_toolchains and register_execution_platforms functions merely save their arguments, as strings, into the Package.Builder instance for //external.
  2. RegisteredToolchainsFunction and RegisteredExecutionPlatformsFunction then call into TargetPatternUtil.expandTargetPatterns to get a list of Labels.
  3. Those Labels are then used directly.

This was fine before repository remapping existed. Now, however, we need to move the target pattern expansion into the workspace functions and out of the skyfunctions.

So, to fix these issues:

  1. Change Package.registeredToolchains and Package.registeredExecutionPlatform (and the associated Builder methods) to take Label instead of String
  2. Add target pattern expansion into register_toolchains and register_execution_platforms (including error handling). This needs to use the current repository map, based on the currently loaded repository.
  3. Remove target pattern expansion from RegisteredToolchainsFunction and RegisteredExecutionPlatformsFunction.

Of these, the hard part is adding target pattern expansion to the workspace functions, since that requires access to TargetPatternUtil or something similar, which needs a SkyFunction.Environment to be available. Note that the Environment in the BuiltinFunction.invoke signature is a syntax.Environment, not a SkyFunction.Environment.

@ittaiz
Copy link
Member Author

ittaiz commented Mar 27, 2019

Thanks @katre and @dkelmer!
Priority and complexity wise is there a chance this will get in the 0.25 rc next week? (I assume chances are slim but am keeping my hopes up).

@dkelmer
Copy link
Contributor

dkelmer commented Mar 27, 2019

Priority wise: definitely. Complexity wise: I'm doing my best

@ittaiz
Copy link
Member Author

ittaiz commented Apr 30, 2019

@dkelmer will this make 0.26rc?

bazel-io pushed a commit that referenced this issue Apr 30, 2019
… unrelated Bazel FR (#7773) more cumbersome to implement.

RELNOTES: None
PiperOrigin-RevId: 246007951
bazel-io pushed a commit that referenced this issue May 1, 2019
Platform and toolchain resolution rely on the target pattern parsing code to turn target pattern strings into Labels. Since most of the target pattern parsing codepaths turn target patterns that originated from the command line, they don't need to pass along the repository renaming map. But instances that affect platform and toolchain target patterns, we need to pass the map.

This allows us to turn on the --incompatible_remap_main_repo flag on by default in Bazel.

Closes #7902.
Fixes #7755, #7773, #7654.

RELNOTES: None
PiperOrigin-RevId: 246199440
bazel-io pushed a commit that referenced this issue May 3, 2019
*** Reason for rollback ***

Breaks bazel-skylib

See #8227 for details.

*** Original change description ***

Make target pattern parsing repository-renaming aware.

Platform and toolchain resolution rely on the target pattern parsing code to turn target pattern strings into Labels. Since most of the target pattern parsing codepaths turn target patterns that originated from the command line, they don't need to pass along the repository renaming map. But instances that affect platform and toolchain target patterns, we need to pass the map.

This allows us to turn on the --incompatible_remap_main_repo flag on by default in Bazel.

Closes #7902.
Fixes #7755, #7773, #7654.

RELNOTES: None
PiperOrigin-RevId: 246546091
@ittaiz
Copy link
Member Author

ittaiz commented Jun 11, 2019

@dkelmer any update? We're nearing three months on it. I have a workaround but I'm not sure when it will break

@katre
Copy link
Member

katre commented Jun 11, 2019

Unfortunately @dkelmer is no longer working on Bazel. I'm going to try and figure out who can take over this work.

@katre katre assigned dslomov and unassigned dkelmer Jun 11, 2019
@katre
Copy link
Member

katre commented Jun 11, 2019

Re-assigning to @dslomov to find a new owner.

@laurentlb
Copy link
Contributor

Klaus, can you take a look at what needs to be done here (and how much work it is)?

@aehlig
Copy link
Contributor

aehlig commented Jun 19, 2019

Hi @katre,

@dkelmer and I were just discussing this (and #7654) and realized the problem and how to fix it.

Here is a brief explanation of how the code works currently: [...]
This was fine before repository remapping existed.

thanks for the detailed description of how things work at the moment. However, I have a question on your conclusion.

Now, however, we need to move the target pattern expansion into the workspace functions and out of the skyfunctions.

Why is it necessary, to move the pattern expansion out of the skyfunctions? Wouldn't it be an alternative to perform the repository mapping (with the current map based on the currently loaded repository) at the level of target patterns? As far as I can see, pattern expansion is pretty orthogonal to repository remapping, as we do not do any form of expansion in the repository part of a pattern.

In this way, we would also get rid of the problem...

Of these, the hard part is adding target pattern expansion to the workspace functions, since that requires access to TargetPatternUtil or something similar, which needs a SkyFunction.Environment to be available. Note that the Environment in the BuiltinFunction.invoke signature is a syntax.Environment, not a SkyFunction.Environment.

...of getting a full skyframe access (through a SkyFunction.Environment) with the side effect of reading BUILD files as part of the WORKSPACE semantics, disallowing the currently possible forward-referencing toolchain declarations, etc.

Am I missing something, or is this a way forward worth investigating further?

@katre
Copy link
Member

katre commented Jun 19, 2019

Wouldn't it be an alternative to perform the repository mapping (with the current map based on the currently loaded repository) at the level of target patterns? As far as I can see, pattern expansion is pretty orthogonal to repository remapping, as we do not do any form of expansion in the repository part of a pattern.

Hmm, I think this would work. You're entirely correct that target patterns can't change the repository, only the "local" package and targets selected.

I believe @Dannark was working on something similar: she had several changes which added the concept of repo mapping to target pattern evaluation (771cb7a, which was rolled back in dac2135). I don't think this was ever finished and rolled forward again, but may prove a basis for starting.

@ittaiz
Copy link
Member Author

ittaiz commented Jun 26, 2019

@aehlig can you explain what will be the implications of disallowing the currently possible forward-referencing toolchain declarations, etc.? I'm not sure I fully understand

@aehlig
Copy link
Contributor

aehlig commented Jul 1, 2019

@aehlig can you explain what will be the implications of disallowing the currently possible forward-referencing toolchain declarations, etc.? I'm not sure I fully understand

Well, my proposal is to not disallow it. What it's all about is the following. Currently, you can have a WORKSPACE file like the following.

register_execution_platforms("@foo//platforms/...")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
  name = "foo",
  ...
)

This works, because we do not need to expand the pattern in the registration of an execution platform at time of registration. And with the proposal to do the renaming of repositories at the level of pattern strings this continues to work; however, if we followed the proposal of immediately expanding and keeping the labels instead, the example would stop working.

@aehlig
Copy link
Contributor

aehlig commented Jul 2, 2019

My proposed fix for that issue is the following sequence of commits.

@katre @ittaiz can you have a look if this is a reasonable implementation or whether I missed something? Thanks.

@ittaiz
Copy link
Member Author

ittaiz commented Jul 5, 2019

I skimmed it but I don’t feel I have enough understanding of that area to weigh in.

@katre
Copy link
Member

katre commented Jul 8, 2019 via email

bazel-io pushed a commit that referenced this issue Jul 9, 2019
*** Reason for rollback ***

Breaks Skylib tests: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1082#95e91cd3-c796-408b-83ab-9991efcf1292
Culprit finder: https://buildkite.com/bazel/culprit-finder/builds/183#985aa488-33c9-4dcc-8561-a96c6e1fb4ed

*** Original change description ***

register_{toolchains, execution_platforms}: honor renaming

When handling the registration of toolchains or execution platforms,
take the applicable renaming into account. This, in particular, includes
the renaming from the name of the main workspace to the canonical '@'.

Fixes #7773.

Change-Id: I22fe84e337ad6d33df2a9263e6671e2e0d0a284d
PiperOrigin-RevId: 257214983
@aehlig
Copy link
Contributor

aehlig commented Jul 10, 2019

Reopening, as the change was rolled back. It seems, the renaming is missing in the toolchain_type attribute of the toolchain rule (which is in BUILD files, so in a later phase).

@aehlig aehlig reopened this Jul 10, 2019
irengrig pushed a commit to irengrig/bazel that referenced this issue Jul 15, 2019
When handling the registration of toolchains or execution platforms,
take the applicable renaming into account. This, in particular, includes
the renaming from the name of the main workspace to the canonical '@'.

Fixes bazelbuild#7773.

Change-Id: I22fe84e337ad6d33df2a9263e6671e2e0d0a284d
PiperOrigin-RevId: 257176466
irengrig pushed a commit to irengrig/bazel that referenced this issue Jul 15, 2019
*** Reason for rollback ***

Breaks Skylib tests: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/1082#95e91cd3-c796-408b-83ab-9991efcf1292
Culprit finder: https://buildkite.com/bazel/culprit-finder/builds/183#985aa488-33c9-4dcc-8561-a96c6e1fb4ed

*** Original change description ***

register_{toolchains, execution_platforms}: honor renaming

When handling the registration of toolchains or execution platforms,
take the applicable renaming into account. This, in particular, includes
the renaming from the name of the main workspace to the canonical '@'.

Fixes bazelbuild#7773.

Change-Id: I22fe84e337ad6d33df2a9263e6671e2e0d0a284d
PiperOrigin-RevId: 257214983
bazel-io pushed a commit that referenced this issue Jul 18, 2019
*** Reason for rollback ***

Breaks bazel-skylib

See bazelbuild/bazel-skylib#173

*** Original change description ***

register_{toolchains, execution_platforms}: honor renaming

When handling the registration of toolchains or execution platforms,
take the applicable renaming into account. This, in particular, includes
the renaming from the name of the main workspace to the canonical '@'.

Fixes #7773.

This is a roll-forward of 40e2d7f
with fixing the needed additional renamings for tool chains, as to
not break skylib.

RELNOTES: None.
PiperOrigin-RevId: 258776285
@aehlig
Copy link
Contributor

aehlig commented Jul 19, 2019

Unfortunately, the commit was rolled back again, due to bazelbuild/bazel-skylib#173 which I, unfortunately, cannot reproduce locally.

@aehlig aehlig reopened this Jul 19, 2019
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
…g unrelated Bazel FR (bazelbuild/bazel#7773) more cumbersome to implement.

    RELNOTES: None
    PiperOrigin-RevId: 246007951
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 I'll work on this now. (Assignee required) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

8 participants