Skip to content

Repository redefinition using skylark rules are ok but should error out. #3908

Closed as not planned

Description

@damienmg

Update by @laszlocsomor: Damien no longer works on Bazel, but this bug is still not fixed with Bazel 0.21.


With latest bazel (0.6.1):

Recreation of the repo:

$ cat >test.bzl <<'EOF'
def _impl(ctx):
  print("Bleh")

my_repo = repository_rule(_impl)
EOF
$ cat >WORKSPACE <<'EOF'
local_repository(name = 'local_repo', path = 'local_repo')
load('//:test.bzl', 'my_repo')
local_repository(name = 'local_repo', path = 'local_repo')
EOF
$ touch BUILD
$ mkdir local_repo
$ touch local_repo/WORKSPACE
$ echo "filegroup(name = 'test', srcs = [], visibility = ['//visibility:public'])" >local_repo/BUILD

This creates an error as expected:

$ bazel clean --expunge
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
$ bazel fetch //...
..............
ERROR: /private/tmp/bug/WORKSPACE:3:1: Cannot redefine repository after any load statement in the WORKSPACE file (for repository 'local_repo')
ERROR: Error evaluating WORKSPACE file
ERROR: error loading package 'external': Package 'external' contains errors
ERROR: error loading package 'external': Package 'external' contains errors
Building: no action running

Now let's use a skylark repository:

$ cat >WORKSPACE <<'EOF'
local_repository(name = 'local_repo', path = 'local_repo')
load('//:test.bzl', 'my_repo')
my_repo(name = 'local_repo')
EOF

Bazel accept it no issue:

$ bazel clean --expunge
INFO: Starting clean (this may take a while). Consider using --expunge_async if the clean takes more than several minutes.
$ bazel fetch //...
...
$ bazel query //external:local_repo --output=label_kind
my_repo rule //external:local_repo

Activity

  1. added
    P3
    on Oct 16, 2017
  2. damienmg commented on Oct 16, 2017

    @damienmg
    ContributorAuthor

    Note that I found the bug while looking at external repo code:

    is throwing the error but Skylark repositories call directly createAndAddRepositoryRule which does not have that check.

  3. self-assigned this
    on Oct 16, 2017
  4. added a commit that references this issue on Dec 8, 2017
    766ba8a
  5. added 4 commits that reference this issue on Dec 8, 2017
    32613e1
    35376bf
    404b9c9
    ee3e55d
  6. added
    area-Windows
    untriaged
    on Jan 9, 2019
  7. 7 remaining items

  8. added
    P2
    and removed
    untriaged
    on Jan 17, 2019
  9. added
    team-OSS
    on Jun 15, 2020
  10. removed
    team-OSS
    on Nov 29, 2021
  11. added
    stale
    on Feb 17, 2023
  12. sgowroji commented on Feb 17, 2023

    @sgowroji
    Member

    Hi there! We're doing a clean up of old issues and will be closing this one. Please reopen (or ping me to reopen) if you’d like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2staleteam-ExternalDepstype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions