diff --git a/internal/linker/link_node_modules.bzl b/internal/linker/link_node_modules.bzl index b0b58c739b..f91580effd 100644 --- a/internal/linker/link_node_modules.bzl +++ b/internal/linker/link_node_modules.bzl @@ -50,8 +50,22 @@ def _link_mapping(label, mappings, k, v): # Map values are of format [deprecated, link_path] iter_package_name = iter_key.split(":")[0] iter_source_path = iter_values - if package_name == iter_package_name and link_path != iter_source_path: - fail("conflicting mapping at '%s': '%s' and '%s' map to conflicting %s and %s" % (label, k, iter_key, link_path, iter_source_path)) + if package_name == iter_package_name: + # If we're linking to the output tree be tolerant of linking to different + # output trees since we can have "static" links that come from cfg="exec" binaries. + # In the future when we static link directly into runfiles without the linker + # we can remove this logic. + link_path_segments = link_path.split("/") + iter_source_path_segments = iter_source_path.split("/") + bin_links = link_path_segments[0] == "bazel-out" and iter_source_path_segments[0] == "bazel-out" and link_path_segments[2] == "bin" and iter_source_path_segments[2] == "bin" + if bin_links: + compare_link_path = "/".join(link_path_segments[3:]) + compare_iter_source_path = "/".join(iter_source_path_segments[3:]) + else: + compare_link_path = link_path + compare_iter_source_path = iter_source_path + if compare_link_path != compare_iter_source_path: + fail("conflicting mapping at '%s': '%s' and '%s' map to conflicting %s and %s" % (label, k, iter_key, compare_link_path, compare_iter_source_path)) return True