在bazel中,我经常看到以下代码:
srcs = [
"foo/bar.c",
] + select({
"@org_tensorflow//tensorflow:linux_x86_64": [
"foo/baz.c",
],
"//conditions:default": [],
})
但是如何像这样有条件地附加dict
?
subs = {
"#undef HWLOC_VERSION_MAJOR": "#define HWLOC_VERSION_MAJOR 2",
}
答案 0 :(得分:0)
那完全是不直观的,但是我设法通过以下方式做到这一点:
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,
})
ThaI从Python中学到了**
的魔力。