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

Fix toolchains and repo remapping #7755

Closed
dkelmer opened this issue Mar 18, 2019 · 10 comments
Closed

Fix toolchains and repo remapping #7755

dkelmer opened this issue Mar 18, 2019 · 10 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) stale Issues or PRs that are stale (no activity for 30 days) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@dkelmer
Copy link
Contributor

dkelmer commented Mar 18, 2019

2398d85 broke bazelbuild/skydoc which already passes --incompatible_remap_main_repo (which gates the behavior that was changed in the PR)

To reproduce:

  1. checkout bazel at 2398d85
  2. build bazel
  3. check out https://github.com/bazelbuild/bazel-skylib
  4. devbazel test //tests:shell_tests_test_1 --incompatible_remap_main_repo

The error is:

ERROR: Analysis of target '//tests:shell_tests_test_1' failed; build aborted: no matching toolchains found for types //toolchains/unittest:toolchain_type

I assume this error is due to not passing the map in all locations that would require it, but I can't find more locations that refer to the toolchain by label

@dkelmer
Copy link
Contributor Author

dkelmer commented Mar 18, 2019

/cc @katre

@dkelmer dkelmer self-assigned this Mar 18, 2019
@dkelmer
Copy link
Contributor Author

dkelmer commented Mar 18, 2019

Something that is probably related to the problem: the toolchain type is defined here and is then imported in all BUILD/bzl files where it's used. Repository renaming does not (and should not) apply to strings. But then when that string is passed to various attributes in toolchain processing, the string should be converted to a label and remapped then.

@iirina iirina added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Mar 19, 2019
@katre
Copy link
Member

katre commented Mar 19, 2019

Some investigation:

This fails:

$ bazel-dev test //tests:shell_tests_test_1 --incompatible_remap_main_repo

This works:

$ bazel-dev test @bazel_skylib//tests:shell_tests_test_1 --incompatible_remap_main_repo

Why? Because, when Bazel loads //tests, the toolchain type is //toolchains/unittest:toolchain_type (the repository @bazel_skylib is being remapped back to @). When Bazel loads @bazel_skylib//tests, the toolchain type is left alone as @bazel_skylib//toolchains/unittest:toolchain_type.

Trying both forms of this does work with bazelbuild/rules_rust. So next step is to figure out what rules_rust is doing differently with the toolchain type.

@katre
Copy link
Member

katre commented Mar 19, 2019

I think I see the difference: rules_rust defines the toolchains in a separate (local) external repository, so the toolchain types there are also fully-qualified labels, not local labels. Trying that change now.

@katre
Copy link
Member

katre commented Mar 19, 2019

Okay, looking at rules_rust was a red herring. Actual diagnosis is from debugging:

Here is the flow:

  • The rule is defined as _shell_array_literal_test
  • The WORKSPACE registers toolchains as @bazel_skylib//toolchains/unittest:bash_toolchain.
    • This is not a label, it is a target pattern
  • In RegisteredToolchainsFunction these target patterns are expended via TargetPatternUtil.expandTargetPatterns
    • TargetPatternUtil calls into TargetPatternFunction
    • I have no idea what TargetPatternFunction is doing
    • When the labels are returned to RegisteredToolchainsFunction they have not been remapped and are still of the form @bazel_skylib//toolchains/unittest:bash_toolchain instead of the expected //toolchains/unittest:bash_toolchain

@dslomov dslomov added P1 I'll work on this now. (Assignee required) type: bug and removed untriaged labels Mar 21, 2019
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
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@jonathan-enf
Copy link

The fix was rolled back, and this still seems broken in bazel 4.1.0. This bug should be re-opened.

@katre
Copy link
Member

katre commented Sep 4, 2021

Re-opening this but reducing the priority to reflect that no one is actively working on this.

@katre katre reopened this Sep 4, 2021
@katre katre added P2 We'll consider working on this in future. (Assignee optional) and removed P1 I'll work on this now. (Assignee required) labels Sep 4, 2021
@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label May 24, 2023
@fmeum
Copy link
Collaborator

fmeum commented May 24, 2023

@katre Pretty sure this has been fixed as otherwise toolchains wouldn't work with Bzlmod.

@katre
Copy link
Member

katre commented May 24, 2023

You are correct.

@katre katre closed this as completed May 24, 2023
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) stale Issues or PRs that are stale (no activity for 30 days) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

7 participants