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

Visibility attributes in sub-workspace for top-level workspace targets breaks bazel build //... #10341

Closed
minorhacks opened this issue Dec 1, 2019 · 3 comments
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@minorhacks
Copy link

Description of the problem / feature request:

Given a workspace top_level_workspace and a sub-workspace third_party_lib:

If a visibility declaration to a target is added to third_party_lib to grant visibility to targets in top_level_workspace, bazel build //... in top_level_workspace will fail; only bazel build @top_level_workspace//... works.

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

Minimal repro workspace: visibility_bug_minimal_repro.zip

In the following workspace:

WORKSPACE

workspace(name = "top_level_workspace")

local_repository(
    name = "third_party_lib",
    path = "third_party_lib",
)

//foo/BUILD.bazel

filegroup(
    name = "some_app",
    srcs = [
        "local_file.txt",
        "@third_party_lib//:third_party_target",
    ],
)

//third_party_lib/BUILD.bazel

filegroup(
    name = "third_party_target",
    srcs = ["target.txt"],
    visibility = [
        "@top_level_workspace//foo:__pkg__",
    ],
)
  • bazel build @top_level_workspace//foo/... succeeds

  • bazel build //foo/... fails:

    ERROR: /home/bminor/dev/bazel_workspace_bug/foo/BUILD.bazel:1:1: in filegroup rule //foo:some_app: target '@third_party_lib//:third_party_target' is not visible from target '//foo:some_app'. Check the visibility declaration of the former target if you think the dependency is legitimate
    ERROR: Analysis of target '//foo:some_app' failed; build aborted: Analysis of target '//foo:some_app' failed; build aborted
    

Since the current working directory is in @top_level_workspace, I would expect that these two commands are equivalent; shouldn't //foo/... resolve to this workspace unambiguously? It's definitely inconvenient to lose the ability to do bazel build //... due to this.

What operating system are you running Bazel on?

Fedora Workstation 31

What's the output of bazel info release?

release 1.2.1

Have you found anything relevant by searching the web?

No, but this issue is a bit ambiguous to search for. Please feel free to dupe if this is already known.

@laszlocsomor
Copy link
Contributor

laszlocsomor commented Dec 2, 2019

Thanks for reporting.

This is a consequence of Bazel treating @// and @top_level_workspace// differently.
The --incompatible_remap_main_repo flag merges the two and solves this issue.

I cannot tell though when --incompatible_remap_main_repo will be enabled.

/cc @aehlig

@laszlocsomor laszlocsomor added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug untriaged labels Dec 2, 2019
@laszlocsomor
Copy link
Contributor

FYI, we plan to release Bazel 2.0.0 this month and to enable --incompatible_remap_main_repo by default.

@laurentlb
Copy link
Contributor

Sounds like the issue is now fixed.

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

3 participants