1

I've got two repositories, Client and Library.

Inside of Client's WORKSPACE file Client imports Library as a http_archive with the name "foo".

Inside of Client, I want to use Library macros that reference targets inside Library. My problem is that the Library macros don't know that were imported as "foo", so when the macro is expanded the targets are not found.

razeh
  • 2,725
  • 1
  • 20
  • 27
  • Did you consider importing Library as Library and then have the macros reference Library in both places? Canonical naming is where bazel is trying to go to – Ittai Aug 10 '18 at 20:46
  • Could you be more specific? If the macro refers to @Library/foo:bar, I see how that would work in Client, but inside of Library it doesn't know what @Library is. – razeh Aug 10 '18 at 21:04

1 Answers1

1

library/WORKSPACE:
workspace(name = "library") library/some.bzl:

def my_macro():
  native.java_library(name = "my_macro_lib",
    deps = ["@library//:my_macro_lib_dependnecy"]
  )

library/BUILD.bazel:

java_library(name = "my_macro_lib_dependnecy",
  ...
)

client/WORKSPACE:

workspace(name = "client")
http_archive(
             name = "library",
             urls = [...],
             strip_prefix = ...,
             sha256 = ...,
)

Because both workspaces use the same name for library workspace (name = "library") and because the macro refers to the workspace name in its dependencies (@library//:my_macro_lib_dependnecy) this works. Note this works but has some quirks which will be resolved in 0.17.0

Ittai
  • 5,625
  • 14
  • 60
  • 97