Add support for gazelle handling relative imports (#271)
This commit is contained in:
parent
2ec2e6d715
commit
836f1b2f56
|
@ -49,5 +49,5 @@ gazelle_binary(
|
|||
|
||||
gazelle(
|
||||
name = "gazelle",
|
||||
gazelle = "//gazelle:gazelle-skylib",
|
||||
gazelle = ":gazelle-skylib",
|
||||
)
|
||||
|
|
|
@ -152,23 +152,34 @@ func (*bzlLibraryLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo
|
|||
|
||||
deps := make([]string, 0, len(imports))
|
||||
for _, imp := range imports {
|
||||
if strings.HasPrefix(imp, "@") || !c.IndexLibraries {
|
||||
impLabel, err := label.Parse(imp)
|
||||
if err != nil {
|
||||
log.Printf("%s: import of %q is invalid: %v", from.String(), imp, err)
|
||||
continue
|
||||
}
|
||||
|
||||
// the index only contains absolute labels, not relative
|
||||
impLabel = impLabel.Abs(from.Repo, from.Pkg)
|
||||
|
||||
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 {
|
||||
res := resolve.ImportSpec{
|
||||
Lang: languageName,
|
||||
Imp: imp,
|
||||
Imp: impLabel.String(),
|
||||
}
|
||||
matches := ix.FindRulesByImport(res, languageName)
|
||||
|
||||
if len(matches) == 0 {
|
||||
log.Printf("%s: %q was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp)
|
||||
log.Printf("%s: %q (%s) was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp, impLabel.String())
|
||||
}
|
||||
|
||||
for _, m := range matches {
|
||||
deps = append(deps, m.Label.String())
|
||||
depLabel := m.Label
|
||||
depLabel = depLabel.Rel(from.Repo, from.Pkg)
|
||||
deps = append(deps, depLabel.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,5 +10,5 @@ bzl_library(
|
|||
name = "foo",
|
||||
srcs = ["foo.bzl"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//:bar"],
|
||||
deps = [":bar"],
|
||||
)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
|
||||
|
||||
bzl_library(
|
||||
name = "bar",
|
||||
srcs = ["bar.bzl"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "foo",
|
||||
srcs = ["foo.bzl"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":bar"],
|
||||
)
|
|
@ -0,0 +1,6 @@
|
|||
"""
|
||||
Doc string
|
||||
"""
|
||||
|
||||
def func():
|
||||
pass
|
|
@ -0,0 +1,7 @@
|
|||
"""
|
||||
Doc string
|
||||
"""
|
||||
|
||||
load(":bar.bzl", "func")
|
||||
|
||||
func()
|
|
@ -0,0 +1,14 @@
|
|||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
|
||||
|
||||
bzl_library(
|
||||
name = "bar",
|
||||
srcs = ["bar.bzl"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "foo",
|
||||
srcs = ["foo.bzl"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":bar"],
|
||||
)
|
|
@ -0,0 +1,6 @@
|
|||
"""
|
||||
Doc string
|
||||
"""
|
||||
|
||||
def func():
|
||||
pass
|
|
@ -0,0 +1,7 @@
|
|||
"""
|
||||
Doc string
|
||||
"""
|
||||
|
||||
load(":bar.bzl", "func")
|
||||
|
||||
func()
|
|
@ -0,0 +1,14 @@
|
|||
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
|
||||
|
||||
bzl_library(
|
||||
name = "bar",
|
||||
srcs = ["bar.bzl"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
name = "foo",
|
||||
srcs = ["foo.bzl"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":bar"],
|
||||
)
|
|
@ -0,0 +1 @@
|
|||
workspace(name = "com_example")
|
|
@ -0,0 +1,6 @@
|
|||
"""
|
||||
Doc string
|
||||
"""
|
||||
|
||||
def func():
|
||||
pass
|
|
@ -0,0 +1,7 @@
|
|||
"""
|
||||
Doc string
|
||||
"""
|
||||
|
||||
load("//:bar.bzl", "func")
|
||||
|
||||
func()
|
Loading…
Reference in New Issue