0

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?

4

1 回答 1

0

那是一个错误!//main:development 应该自动解析为@base//main:development。我已经为它提交了一个问题

作为一种(有点烦人的)解决方法,您可以在@child//main 中重新定义配置设置。

于 2016-06-17T18:55:25.423 回答