Bazel to CMake: Some tweaks to make it work upstream
There's not a lot of point in having separate target-mapping dicts if they're a direct mapping and it causes some issues because it introduces extra reliance on prefix matches to partition between the dicts. We could have multiple dict vars and merge them, but that just seemed more complicated.
Bare "//" prefix matching causes issues for our migration tooling because it's pretty hard to detect that that's the repo root in general.
Tested:
Ran upstream and on git in strict mode and confirmed no diffs in CMakeLists.txt files and no new errors.
Depends on https://github.com/google/iree/pull/777
PiperOrigin-RevId: 295813382
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake.py b/build_tools/bazel_to_cmake/bazel_to_cmake.py
index 6977ad8..17d058b 100755
--- a/build_tools/bazel_to_cmake/bazel_to_cmake.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake.py
@@ -38,7 +38,7 @@
repo_root = None
EDIT_BLOCKING_PATTERN = re.compile(
- "bazel[\s_]*to[\s_]*cmake[\s_]*:?[\s_]*do[\s_]*not[\s_]*edit",
+ r"bazel[\s_]*to[\s_]*cmake[\s_]*:?[\s_]*do[\s_]*not[\s_]*edit",
flags=re.IGNORECASE)
@@ -128,7 +128,7 @@
if translate_tool:
# Bazel `//iree/base` -> CMake `iree::base`
# Bazel `//iree/base:api` -> CMake `iree::base::api`
- translate_tool = translate_tool.replace("//", "") # iree/base:api
+ translate_tool = translate_tool.replace("//iree", "iree") # iree/base:api
translate_tool = translate_tool.replace(":", "_") # iree/base::api
translate_tool = translate_tool.replace("/", "_") # iree::base::api
return " TRANSLATE_TOOL\n %s\n" % (translate_tool)
@@ -187,7 +187,7 @@
# -> CMake `${IREE_ROOT_DIR}/iree/dir/td_file.td
# Bazel `//iree/dir/IR:td_file.td`
# -> CMake `${IREE_ROOT_DIR}/iree/dir/IR/td_file.td
- td_file = td_file.replace("//", "${IREE_ROOT_DIR}/")
+ td_file = td_file.replace("//iree", "${IREE_ROOT_DIR}/iree")
td_file = td_file.replace(":", "/")
return " TD_FILE\n \"%s\"\n" % (td_file)
@@ -216,7 +216,7 @@
# Bazel `:api` -> CMake `::api`
# Bazel `//iree/base` -> CMake `iree::base`
# Bazel `//iree/base:api` -> CMake `iree::base::api`
- target = target.replace("//", "") # iree/base:api
+ target = target.replace("//iree", "iree") # iree/base:api
target = target.replace(":", "::") # iree/base::api or ::api
target = target.replace("/", "::") # iree::base::api
target = [target]