Skip to content

Commit

Permalink
Ensure Windows paths used by CMake contain forward slashes only (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheaff1 authored Nov 22, 2021
1 parent 7baefc1 commit 7205619
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion foreign_cc/private/cmake_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
12 changes: 6 additions & 6 deletions test/cmake_text_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>",
"CMAKE_CXX_LINK_EXECUTABLE": "$${EXT_BUILD_ROOT//\\\\//}$$/ws/cxx_linker_executable <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>",
"CMAKE_C_COMPILER": "/some-cc-value",
"CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN": "cc-toolchain",
"CMAKE_C_FLAGS_INIT": "-cc-flag -gcc_toolchain cc-toolchain",
Expand Down

0 comments on commit 7205619

Please sign in to comment.