aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Yu <zachyu@google.com>2023-07-06 16:08:40 -0700
committerZach Yu <zachyu@google.com>2023-07-06 16:11:39 -0700
commita20c893266723576f22a54f467549f13c1dac7bd (patch)
treeb47ad14eb145c02a07c36abdc5a0c925d81431c6
parent9245432b069638cfc7c00f9cd2558e13ce054b20 (diff)
downloadbazel-a20c893266723576f22a54f467549f13c1dac7bd.tar.gz
Avoid depending on the bazel-out symlink.
The "bazel-out" symlink is not created until "bazel build" is run. Therefore it is not suitable for referring to e.g. include paths as cmake requires them to exist at config time. This change converts the paths to either relative to output_base or workspace. To use the output, cmake scripts need to substitute "${output_base}" and "${workspace}" variables. Change-Id: Ib1f48501ae9897631594060526ab5b44b6473aa1
-rw-r--r--utils/cmake.cquery.bzl19
1 files changed, 15 insertions, 4 deletions
diff --git a/utils/cmake.cquery.bzl b/utils/cmake.cquery.bzl
index a07b05ad..d41fc96c 100644
--- a/utils/cmake.cquery.bzl
+++ b/utils/cmake.cquery.bzl
@@ -19,7 +19,7 @@ def format(target):
"includes": "path1;path2;...",
"defines": "key1;key2=val;...",
}
- paths are all relative to workspace root.
+ paths are relative to either output base directory or workspace root.
"""
compilation_context = providers(target).get("CcInfo").compilation_context
@@ -30,7 +30,7 @@ def format(target):
# same as others.
includes = compilation_context.includes.to_list()
combined_includes = _uniq([
- i
+ normalize_execroot_path(i)
for i in quote_includes + system_includes + includes
if not i.startswith("bazel-out/")
])
@@ -40,8 +40,8 @@ def format(target):
defines = compilation_context.defines.to_list()
json_struct = {
- "archive": archive.path,
- "includes": ";".join(["bazel-out/../" + p for p in combined_includes]),
+ "archive": normalize_execroot_path(archive.path),
+ "includes": ";".join(combined_includes),
"defines": ";".join(defines),
}
@@ -50,3 +50,14 @@ def format(target):
def _uniq(hashables):
uniq = dict([(o, None) for o in hashables])
return uniq.keys()
+
+def normalize_execroot_path(path):
+ if path.startswith("../"):
+ # For paths to external repositories, use "<output-base>/external" instead.
+ return "${output_base}/external/" + path.removeprefix("../")
+ if path.startswith("bazel-out"):
+ # Prepend execroot to bazel-out
+ return "${output_base}/execroot/__main__/" + path
+
+ # Otherwise it's a workspace path
+ return "${workspace}/" + path