Bazel to CMake: Refactor _convert_target()
* Don't add full package name to local deps
* Handles local deps and IREE deps including the full package name within the same conversion block
* Drop local deps ending on `_gen` or `Gen`
Closes https://github.com/google/iree/pull/622
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/iree/pull/622 from iml130:bazel-to-cmake-2 06f207eecff645af076bd359eec114dfe8adb029
PiperOrigin-RevId: 292386664
diff --git a/build_tools/scripts/bazel_to_cmake.py b/build_tools/scripts/bazel_to_cmake.py
index 79ff0d7..f548c7b 100755
--- a/build_tools/scripts/bazel_to_cmake.py
+++ b/build_tools/scripts/bazel_to_cmake.py
@@ -203,30 +203,22 @@
return ""
def _convert_target(self, target):
- if target.startswith(":"):
- # Bazel package-relative `:logging` -> CMake absolute `iree::base::logging`
- package = os.path.dirname(self.converter.rel_build_file_path)
- package = package.replace(os.path.sep, "::")
- if package.endswith(target):
- target = package # Omit target if it matches the package name
- else:
- target = package + ":" + target
- if target.endswith("_gen"):
- # Files created by gentbl have to be included as source and header files
- # and not as a dependency. Adding these targets to the dependencies list,
- # results in linkage failures if the library including the gentbl dep is
- # marked as ALWAYSLINK.
- # TODO: Some targets not to be included end to "Gen", but others like
- # LLVMTableGen still need to be included.
- return ""
- elif not target.startswith("//iree"):
+ if target.startswith(":") and target.endswith(("_gen", "Gen")):
+ # Files created by gentbl have to be included as source and header files
+ # and not as a dependency. Adding these targets to the dependencies list,
+ # results in linkage failures if the library including the gentbl dep is
+ # marked as ALWAYSLINK.
+ # This drops deps in the local namespace ending with '_gen' and 'Gen'
+ target = ""
+ elif not target.startswith(("//iree", ":")):
# External target, call helper method for special case handling.
target = bazel_to_cmake_targets.convert_external_target(target)
else:
+ # 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/base::api
+ target = target.replace(":", "::") # iree/base::api or ::api
target = target.replace("/", "::") # iree::base::api
return target