From 720561970473da340b70cda74895bc249ab24c3d Mon Sep 17 00:00:00 2001 From: jheaff1 <48310225+jheaff1@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:53:28 +0000 Subject: [PATCH] Ensure Windows paths used by CMake contain forward slashes only (#807) --- foreign_cc/private/cmake_script.bzl | 4 +++- test/cmake_text_tests.bzl | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/foreign_cc/private/cmake_script.bzl b/foreign_cc/private/cmake_script.bzl index 6f212455..9f811623 100644 --- a/foreign_cc/private/cmake_script.bzl +++ b/foreign_cc/private/cmake_script.bzl @@ -349,7 +349,9 @@ def _tail_if_starts_with(str, start): def _absolutize(workspace_name, text, force = False): if text.strip(" ").startswith("C:") or text.strip(" ").startswith("c:"): return text - return absolutize_path_in_str(workspace_name, "$$EXT_BUILD_ROOT$$/", text, force) + + # Use bash parameter substitution to replace backslashes with forward slashes as CMake fails if provided paths containing backslashes + return absolutize_path_in_str(workspace_name, "$${EXT_BUILD_ROOT//\\\\//}$$/", text, force) def _join_flags_list(workspace_name, flags): return " ".join([_absolutize(workspace_name, flag) for flag in flags]) diff --git a/test/cmake_text_tests.bzl b/test/cmake_text_tests.bzl index e7cb8d4f..4009b2da 100644 --- a/test/cmake_text_tests.bzl +++ b/test/cmake_text_tests.bzl @@ -12,12 +12,12 @@ def _absolutize_test(ctx): env = unittest.begin(ctx) cases = { - "-Lexternal/cmake/aaa": "-L$$EXT_BUILD_ROOT$$/external/cmake/aaa", + "-Lexternal/cmake/aaa": "-L$${EXT_BUILD_ROOT//\\\\//}$$/external/cmake/aaa", "/abs/a12": "/abs/a12", "abs/a12": "abs/a12", - "external/cmake/aaa": "$$EXT_BUILD_ROOT$$/external/cmake/aaa", - "name=ws/cmake/aaa": "name=$$EXT_BUILD_ROOT$$/ws/cmake/aaa", - "ws/cmake/aaa": "$$EXT_BUILD_ROOT$$/ws/cmake/aaa", + "external/cmake/aaa": "$${EXT_BUILD_ROOT//\\\\//}$$/external/cmake/aaa", + "name=ws/cmake/aaa": "name=$${EXT_BUILD_ROOT//\\\\//}$$/ws/cmake/aaa", + "ws/cmake/aaa": "$${EXT_BUILD_ROOT//\\\\//}$$/ws/cmake/aaa", } for case in cases: @@ -94,11 +94,11 @@ def _fill_crossfile_from_toolchain_test(ctx): expected = { "CMAKE_AR": "/cxx_linker_static", "CMAKE_ASM_FLAGS_INIT": "assemble", - "CMAKE_CXX_COMPILER": "$$EXT_BUILD_ROOT$$/external/cxx-value", + "CMAKE_CXX_COMPILER": "$${EXT_BUILD_ROOT//\\\\//}$$/external/cxx-value", "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN": "cxx-toolchain", # Quoted args are escaped when crossfile is written to a script in create_cmake_script "CMAKE_CXX_FLAGS_INIT": "--quoted=\"abc def\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain", - "CMAKE_CXX_LINK_EXECUTABLE": "$$EXT_BUILD_ROOT$$/ws/cxx_linker_executable -o ", + "CMAKE_CXX_LINK_EXECUTABLE": "$${EXT_BUILD_ROOT//\\\\//}$$/ws/cxx_linker_executable -o ", "CMAKE_C_COMPILER": "/some-cc-value", "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN": "cc-toolchain", "CMAKE_C_FLAGS_INIT": "-cc-flag -gcc_toolchain cc-toolchain",