22## Environment ##
33#################
44
5- # MSYS2 bash usually handles Windows paths relatively well, but not when putting them in the PATH
6- string (REGEX REPLACE "^([a-zA-Z]):" "/\\ 1" LEAN_BIN "${CMAKE_BINARY_DIR} /bin" )
5+ # MSYS2 bash usually handles Windows paths relatively well, but not in all situations.
6+ # Thus, rewrite C:/foo/bar to /C/foo/bar on Windows.
7+ function (mangle_windows_path OUT PATH )
8+ if (WIN32 )
9+ string (REGEX REPLACE "^([a-zA-Z]):" "/\\ 1" RESULT "${PATH} " )
10+ # Replace with return(PROPAGATE) if we ever update to cmake 3.25+
11+ set ("${OUT} " "${RESULT} " PARENT_SCOPE)
12+ else ()
13+ # Replace with return(PROPAGATE) if we ever update to cmake 3.25+
14+ set ("${OUT} " "${PATH} " PARENT_SCOPE)
15+ endif ()
16+ endfunction ()
17+
18+ mangle_windows_path(MANGLED_BINARY_DIR "${CMAKE_BINARY_DIR} " )
19+ mangle_windows_path(MANGLED_SOURCE_DIR "${CMAKE_SOURCE_DIR} " )
20+ mangle_windows_path(MANGLED_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR} " )
21+
22+ set (LEAN_BIN "${MANGLED_BINARY_DIR} /bin" )
723
824set (TEST_VARS "${LEAN_TEST_VARS} " )
925
1026# Test scripts can use these to find other parts of the repo, e.g. "$TEST_DIR/measure.py"
1127string (APPEND TEST_VARS " STAGE='${STAGE} '" ) # Using this should not normally be necessary
12- string (APPEND TEST_VARS " SRC_DIR='${CMAKE_SOURCE_DIR } '" )
13- string (APPEND TEST_VARS " TEST_DIR='${CMAKE_CURRENT_SOURCE_DIR } '" )
14- string (APPEND TEST_VARS " BUILD_DIR='${CMAKE_BINARY_DIR } '" )
15- string (APPEND TEST_VARS " SCRIPT_DIR='${CMAKE_SOURCE_DIR } /../script'" )
28+ string (APPEND TEST_VARS " SRC_DIR='${MANGLED_SOURCE_DIR } '" )
29+ string (APPEND TEST_VARS " TEST_DIR='${MANGLED_CURRENT_SOURCE_DIR } '" )
30+ string (APPEND TEST_VARS " BUILD_DIR='${MANGLED_BINARY_DIR } '" )
31+ string (APPEND TEST_VARS " SCRIPT_DIR='${MANGLED_SOURCE_DIR } /../script'" )
1632
1733# Use the current stage's lean binary instead of whatever lake thinks we want
1834string (APPEND TEST_VARS " PATH='${LEAN_BIN} ':\" $PATH\" " )
@@ -117,7 +133,12 @@ function(add_test_pile DIR GLOB)
117133 cmake_path(RELATIVE_PATH FILE_ABS BASE_DIRECTORY "${DIR_ABS} " OUTPUT_VARIABLE FILE_NAME)
118134
119135 if (RUN_TEST_EXISTS AND NOT EXISTS "${FILE_ABS} .no_test" )
120- add_test (NAME "${FILE} " WORKING_DIRECTORY "${DIR_ABS} " COMMAND "${RUN_TEST} " "${FILE_NAME} " )
136+ add_test (
137+ NAME "${FILE} "
138+ WORKING_DIRECTORY "${DIR_ABS} "
139+ # On Windows, we can't call the file directly, hence we always use bash.
140+ COMMAND bash "${RUN_TEST} " "${FILE_NAME} "
141+ )
121142 endif ()
122143
123144 if (RUN_BENCH_EXISTS AND NOT EXISTS "${FILE_ABS} .no_bench" )
@@ -127,7 +148,8 @@ function(add_test_pile DIR GLOB)
127148 OUTPUT "${MEASUREMENTS_FILE} "
128149 WORKING_DIRECTORY "${DIR_ABS} "
129150 COMMAND "${CMAKE_COMMAND} " -E remove -f "${MEASUREMENTS_FILE} "
130- COMMAND "${RUN_BENCH} " "${FILE_NAME} "
151+ # On Windows, we can't call the file directly, hence we always use bash.
152+ COMMAND bash "${RUN_BENCH} " "${FILE_NAME} "
131153 )
132154 endif ()
133155 endforeach ()
@@ -152,7 +174,12 @@ function(add_test_dir DIR)
152174
153175 # Add as test
154176 if (RUN_TEST_EXISTS)
155- add_test (NAME "${DIR} " WORKING_DIRECTORY "${DIR_ABS} " COMMAND "${RUN_TEST} " )
177+ add_test (
178+ NAME "${DIR} "
179+ WORKING_DIRECTORY "${DIR_ABS} "
180+ # On Windows, we can't call the file directly, hence we always use bash.
181+ COMMAND bash "${RUN_TEST} "
182+ )
156183 endif ()
157184
158185 # Add as benchmark
@@ -164,7 +191,8 @@ function(add_test_dir DIR)
164191 OUTPUT "${MEASUREMENTS_FILE} "
165192 WORKING_DIRECTORY "${DIR_ABS} "
166193 COMMAND "${CMAKE_COMMAND} " -E remove -f "${MEASUREMENTS_FILE} "
167- COMMAND "${RUN_BENCH} "
194+ # On Windows, we can't call the file directly, hence we always use bash.
195+ COMMAND bash "${RUN_BENCH} "
168196 )
169197 endif ()
170198endfunction ()
0 commit comments