Gazelle now handles imports from `@bazel_tools` (#273)
`@bazel_tools` is tricky since it is effectively a part of the standard library that can not have a `bzl_library` attached to it. As a simple fix for this, `bzl_library` can have a srcs dependency on it so that it includes the transitive closure of all of its dependencies. `@bazel_tools` imports are rewritten into the `srcs` attribute since they are `exports_files`ed from the @bazel_tools. Co-authored-by: c-parsons <cparsons@google.com>
This commit is contained in:
parent
a81c2c0efe
commit
b2ffc94b17
|
@ -161,11 +161,23 @@ func (*bzlLibraryLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo
|
|||
// the index only contains absolute labels, not relative
|
||||
impLabel = impLabel.Abs(from.Repo, from.Pkg)
|
||||
|
||||
if impLabel.Repo == "bazel_tools" {
|
||||
// The @bazel_tools repo is tricky because it is a part of the "shipped
|
||||
// with bazel" core library for interacting with the outside world.
|
||||
// This means that it can not depend on skylib. Fortunately there is a
|
||||
// fairly simple workaround for this, which is that you can add those
|
||||
// bzl files as `deps` entries.
|
||||
deps = append(deps, imp)
|
||||
continue
|
||||
}
|
||||
|
||||
if impLabel.Repo != "" || !c.IndexLibraries {
|
||||
// This is a dependency that is external to the current repo, or indexing
|
||||
// is disabled so take a guess at what hte target name should be.
|
||||
deps = append(deps, strings.TrimSuffix(imp, fileType))
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
res := resolve.ImportSpec{
|
||||
Lang: languageName,
|
||||
Imp: impLabel.String(),
|
||||
|
@ -182,7 +194,6 @@ func (*bzlLibraryLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo
|
|||
deps = append(deps, depLabel.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(deps)
|
||||
if len(deps) > 0 {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# Some comment to be preserved
|
||||
|
||||
filegroup(
|
||||
name = "allfiles",
|
||||
srcs = glob(["**"]),
|
||||
)
|
|
@ -0,0 +1,15 @@
|
|||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
|
||||
|
||||
# Some comment to be preserved
|
||||
|
||||
filegroup(
|
||||
name = "allfiles",
|
||||
srcs = glob(["**"]),
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "foo",
|
||||
srcs = ["foo.bzl"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["@bazel_tools//tools/build_defs/repo:http.bzl"],
|
||||
)
|
|
@ -0,0 +1,10 @@
|
|||
"""
|
||||
Doc string
|
||||
"""
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
def wrapped_http_archive(**kwargs):
|
||||
http_archive(
|
||||
**kwargs
|
||||
)
|
Loading…
Reference in New Issue