Skip to content

@ and @workspacename considered different repositories #3115

Closed

Description

@jayconrod

Description of the problem / feature request / question:

Bazel evaluates the same Skylark file multiple times if it is loaded with a local path and an absolute path. This creates problems for rules, since everything gets defined twice. It is particularly problematic for named providers, since the duplicate definitions are neither equivalent nor compatible.

We ran into this issue when trying to migrate rules_go to use named providers. We load our .bzl files with local labels in our own repository, but repositories that depend on ours load using absolute labels, which causes errors.

Bazel should not evaluate the same .bzl file in the same repository more than once.

If possible, provide a minimal example to reproduce the problem:

Create an empty workspace with these files.

# WORKSPACE
workspace(name = "scratch")
# BUILD
load("//:def.bzl", "a")
load("@scratch//:def.bzl", "a")
# def.bzl
print("def.bzl evaluated")
a = 10

Run bazel query //... to evaluate the files. The message is printed twice.

$ bazel query //...
____Loading package: 
WARNING: /usr/local/google/home/jayconrod/Code/scratch/def.bzl:1:1: def.bzl evaluated.
WARNING: /usr/local/google/home/jayconrod/.cache/bazel/_bazel_jayconrod/1df8d8ad4cb35ee83522d81953b4d69f/external/scratch/def.bzl:1:1: def.bzl evaluated.
____Empty results

Environment info

  • Operating System: Linux
  • Bazel version (output of bazel info release): 0.5.0

cc @ianthehat

Activity

  1. jwnimmer-tri commented on Nov 9, 2017

    @jwnimmer-tri
    Contributor

    This is acutely annoying for providers, since it both breaks things, and gives bad diagnostics ("does not have mandatory providers Foo" even though it has "Foo", just a different foo). If it is difficult to fix, it might be worth at least failing-fast in the meantime, even if only for providers.

  2. added
    P1
    on Nov 9, 2017
  3. removed their assignment
    on Dec 14, 2017
  4. ittaiz commented on May 16, 2018

    @ittaiz
    Member

    @laurentlb this P1 will celebrate anniversary soon.
    Is there an update here? I'm not hitting this exact issue but I think I have an adjacent problem (same target gets evaluated twice, once as external and once as internal)

  5. laurentlb commented on May 16, 2018

    @laurentlb
    Contributor

    Klaus, are you aware of this issue?
    I don't know exactly at which level we need to fix this (so assigning to both Jon and Klaus).

  6. brandjon commented on May 25, 2018

    @brandjon
    Member

    FYI if it's a local and absolute path within the same repo ("//" vs ":") it doesn't reproduce, so I believe it has to be a repository-specific issue.

  7. 54 remaining items

  8. sergiocampama commented on May 9, 2019

    @sergiocampama
    Contributor

    what about

    ? It is also a noop? Or was the experimental flag migrated to incompatible and never flipped?

  9. sergiocampama commented on May 9, 2019

    @sergiocampama
    Contributor
  10. katre commented on May 9, 2019

    @katre
    Collaborator

    The flag is now --incompatible_remap_main_repo: https://source.bazel.build/bazel/+/master:src/main/java/com/google/devtools/build/lib/packages/StarlarkSemanticsOptions.java;l=503?q=main_repo

    It was scheduled to be flipped but there was missing functionality, and it was not made default in 0.26.

    See the tracking issue: #7130.

  11. sergiocampama commented on May 9, 2019

    @sergiocampama
    Contributor

    Shouldn't this issue be open then until the incompatible flag is flipped?

  12. aehlig commented on Aug 23, 2019

    @aehlig
    Contributor

    Interestingly, the issue is not fully solved by (the current implementation of) --incompatible_remap_main_repo (#7130). Consider the following test cases

    The first test passes, whereas the second fails in the build with remapping; interestingly enough, that command passes if we build //:y instead of @foo//:y.

  13. aehlig commented on Dec 3, 2019

    @aehlig
    Contributor

    #7130 is flipped now.

  14. ittaiz commented on Jul 20, 2020

    @ittaiz
    Member

    @aehlig if there are test cases that are failing with the flag on, shouldn't they be fixed?

  15. katre commented on Jul 20, 2020

    @katre
    Collaborator

    @ittaiz Klaus is no longer working at Google or on Bazel. As far as I know there are open issues for a few related problems, if there are any more, can you file them separately?

  16. ittaiz commented on Jul 20, 2020

    @ittaiz
    Member

    Didn't know that. Will do, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions