Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Windows paths provided to CMake contain forward slashes only #807

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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