Skip to content

buildifier rewrite BUILD targets "@abc//:abc" incorrectly. #1354

@laramiel

Description

@laramiel

Our project uses the re2 library. Presently this is named "com_google_re2" in our workspace, but I'm trying to rename the repository to follow more common conventions.

This rename gives me a BUILD.bazel file with the following:

cc_library(
  name = ...
  deps = [
    ...
    "@re2//:re2"
   ]
)

After running buildifier on it the deps are rewritten to:

  deps = [
  ...
   "@re2",
  ...
  ]

This rewrite causes bazel build errors like:

ERROR: git/tensorstore/tensorstore/util/BUILD?l=694:23: no such package '@@re2//': The repository '@@re2' could not be resolved: '@@re2' is not a repository rule and referenced by '//tensorstore/util:unit'

I believe that this is incorrect; buildifier should leave this dep as-is since in @re2//:re2, the repository is re2, the package is the empty string, and the target is re2.

This behavior is tested in build/testdata/019.build.golden

// Second, it removes redundant target qualifiers, turning labels like
// "//third_party/m4:m4" into "//third_party/m4" as well as ones like
// "@foo//:foo" into "@foo".

} else if m[3] != "" && m[4] == "" && m[3] == m[5] { // e.g. @foo//:foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3We're not considering working on this, but happy to review a PR. (No assignee)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions