[Bazel] Change external_zlib attribute to string

When using `llvm_zlib_external` rule with `external_zlib` attribute set to a
label referring to the main repository, like `@//third_party/zlib`, it will be
replaced with `//third_party/zlib` after template substitution. This will then
attempt to find `//third_party/zlib` within the local repository
`@llvm_zlib//third_party/zlib`, which does not exist, rather than the intended
reference back to the main repository. The issue appears to be that the
conversion of `Label` type to string with
`str(repository_ctx.attr.external_zlib)`, which is causing the main repository
qualifier to be lost.

This diff fixes the issue by changing the `external_zlib` attribute to
`attr.string` type rather than `attr.label`.

In future a more elegant solution may be possible that preserves use of the
`Label` type, depending on resolution of the issue
https://github.com/bazelbuild/bazel/issues/13731.

Ported from Github PR https://github.com/google/llvm-bazel/pull/236.

Reviewed By: GMNGeoffrey

Differential Revision: https://reviews.llvm.org/D106606
This commit is contained in:
Michael McLoughlin 2021-07-22 16:01:49 -07:00 committed by Geoffrey Martin-Noble
parent cf8a1f6208
commit b4f8a000f6
1 changed files with 2 additions and 2 deletions

View File

@ -24,7 +24,7 @@ def _llvm_zlib_external_impl(repository_ctx):
"BUILD",
repository_ctx.attr._external_build_template,
substitutions = {
"@external_zlib_repo//:zlib_rule": str(repository_ctx.attr.external_zlib),
"@external_zlib_repo//:zlib_rule": repository_ctx.attr.external_zlib,
},
executable = False,
)
@ -36,7 +36,7 @@ llvm_zlib_external = repository_rule(
default = Label("//deps_impl:zlib_external.BUILD"),
allow_single_file = True,
),
"external_zlib": attr.label(
"external_zlib": attr.string(
doc = "The dependency that should be used for the external zlib library.",
mandatory = True,
),