Closed EdSchouten closed 7 months ago
Something here seems to have broken imports for all our rules relying on imports
being populated from a couple of core deps
. Now despite "top-level" deps having for example; imports = ["lib", "vendor"]
the only thing showing up in the jsonnet command are the two duplicated .
arguments, like: -J . -J .
.
lib/kube-libsonnet/BUILD
:
jsonnet_library(
name = "kube",
srcs = ["kube.libsonnet"],
visibility = ["//visibility:public"],
deps = ["//:imports"], # this doesn't work anymore ...
imports = ["../"] # this had to be added now
)
With the explicit `imports = ["../"] in this library, it works.
The trickery I did in previous versions was a top-level //:imports
rule which was a dep of the other libs, see example:
jsonnet_library(
name = "imports",
imports = [
"./lib",
"./vendor",
],
)
jsonnet_library(
name = "k",
srcs = glob([
"vendor/github.com/jsonnet-libs/k8s-libsonnet/1.25/**/*.libsonnet",
"lib/k/**/*.libsonnet",
]) + ["lib/k.libsonnet"],
visibility = ["//visibility:public"],
deps = [
":imports",
":ksonnet-util",
],
)
Why? This was to make other jsonnet tools and bazel able to co-exist. Many of those tools, and editor configurations expect the import paths to be -J vendor -J lib
to have good mechanisms for both imports and overrides available.
The reason this construct no longer works is becasue jsonnet_library(name = "imports")
does not have any sources. Without sources, the rule isn't able to determine whether it should add include paths for the source directory or the output directory.
Instead of using that dummy jsonnet_library(name = "imports")
, why can't you add imports = []
to jsonnet_library(name = "k")
directly? If you want to reuse these import paths between various targets in that same package, keep in mind that you can always put those in a constant MY_IMPORTS = ["lib", "vendor"]
and use that constant within your BUILD
file.
Right now you see that jsonnet_to_json() and jsonnet_to_json_test() implicitly call jsonnet with "-J .". This means that if these rules are used in combination with libraries that are declared in the root module, everything works as expected. But as soon as libraries are used from other modules, importing them becomes more tedious.
The goal of this change is to ensure that if a Jsonnet project can be built within the root module, that module can also safely be used as a child module. We solve this by automatically adding the workspace root to the set of import paths for which one or more source files exist. Furthermore, by considering the root of every source file, we no longer need to use bin_dir and genfiles_dir.
Fixes: #44 Fixes: #86 Fixed: #139 Fixes: #154 Fixes: #178