In a workspace @base
, suppose I have a "macro" in main/macros.bzl such as:
def if_development(if_true, if_false = []):
return select({
"//main:development": if_true,
"//conditions:default": if_false
})
And in main/BUILD:
package(default_visibility = ["//visibility:public"])
config_setting(
name = "development",
values = { "define": "MODE=development" },
)
Now I want to be able to load this macro from a different workspace, @child
, e.g.:
load("@base//main:macros.bzl", "if_development")
Then it will fail because //main:development
is not resolved against the @base
workspace, it's resolved against the @child
workspace.
ERROR: /path/to/child/src/BUILD:3:1: no such package 'main': BUILD file not found on package path and referenced by '//src:bar'.
However, if I fully qualify it, as in:
def if_development(if_true, if_false = []):
return select({
"@base//main:development": if_true,
"//conditions:default": if_false
})
Then it will work in @child
, but fail when used inside the defining workspace, @base
, because apparently you can't refer to your own workspace using the @main
notation:
ERROR: /path/to/base/src/BUILD:3:1: no such package '@base//main': error loading package 'external': The repository named 'base' could not be resolved and referenced by '//src:bar'.
How can I refer to @base//main:development
in the macro in a way that will work inside and outside the defining workspace?