In bazel I often see following code:
srcs = [
"foo/bar.c",
] + select({
"@org_tensorflow//tensorflow:linux_x86_64": [
"foo/baz.c",
],
"//conditions:default": [],
})
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,
})
I learned that **
magic from Python.