在Bazel中定义字典时使用选择 [英] Using select when defining a dict in Bazel

查看:53
本文介绍了在Bazel中定义字典时使用选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bazel中,我经常看到以下代码:

In bazel I often see following code:

srcs = [
        "foo/bar.c",
    ] + select({
        "@org_tensorflow//tensorflow:linux_x86_64": [
            "foo/baz.c",
        ],
        "//conditions:default": [],
    })

但是如何像这样有条件地附加dict?

But how do I go with conditionally appending a dict like this?

subs = {
        "#undef HWLOC_VERSION_MAJOR": "#define HWLOC_VERSION_MAJOR 2",
}

推荐答案

那是完全不直观的,但是我设法通过以下方式做到这一点:

That was completely non-intuitive, but I managed to do this in following way:

common_subs = {"foo": "bar"}

linux_subs = {"baz": "boo"}

subs = select({
  "@org_tensorflow//tensorflow:linux_x86_64": dict(common_subs, **linux_subs),
  "//conditions:default": common_subs,
})

我从Python中学到了**魔术.

I learned that ** magic from Python.

这篇关于在Bazel中定义字典时使用选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆