Skip to content

Commit 42e43ed

Browse files
authored
[cmake] Unify usage of create_symlink/copy across the build files. (swiftlang#72202)
In several places, there was the same or similar code to either do a symlink or use copy/copy_if_different/copy_directory in Windows systems. The checks were also slightly different in some cases. There is a `SWIFT_COPY_OR_SYMLINK` that can be controlled as a CMake option, and uses `CMAKE_HOST_UNIX` as default. Change all cases that I can find to use that value. Also create a parallel value `SWIFT_COPY_OR_SYMLINK_DIR` to apply to directories. There is still a couple of cases that are specific to macOS SourceKit framework which I have left as-is, since symlinks is probably the only right thing to do there. There's a case for Windows specifically that uses symlinks (in https://github.com/apple/swift/blob/523f80769487b0fea30880ca98c42470f740ff02/cmake/modules/SwiftConfigureSDK.cmake#L502) which I have not modified as well.
1 parent d3ed4a4 commit 42e43ed

File tree

5 files changed

+13
-31
lines changed

5 files changed

+13
-31
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,11 @@ How swift-C++ bridging code is compiled:
360360
]=] DEFAULT)
361361

362362
option(SWIFT_USE_SYMLINKS "Use symlinks instead of copying binaries" ${CMAKE_HOST_UNIX})
363-
set(SWIFT_COPY_OR_SYMLINK "copy")
363+
set(SWIFT_COPY_OR_SYMLINK "copy_if_different")
364+
set(SWIFT_COPY_OR_SYMLINK_DIR "copy_directory")
364365
if(SWIFT_USE_SYMLINKS)
365366
set(SWIFT_COPY_OR_SYMLINK "create_symlink")
367+
set(SWIFT_COPY_OR_SYMLINK_DIR "create_symlink")
366368
endif()
367369

368370
# The following only works with the Ninja generator in CMake >= 3.0.

cmake/modules/SwiftUtils.cmake

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,10 @@ function(swift_create_post_build_symlink target)
171171
""
172172
${ARGN})
173173

174-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
175-
if(CS_IS_DIRECTORY)
176-
set(cmake_symlink_option "copy_directory")
177-
else()
178-
set(cmake_symlink_option "copy_if_different")
179-
endif()
174+
if(CS_IS_DIRECTORY)
175+
set(cmake_symlink_option "${SWIFT_COPY_OR_SYMLINK_DIR}")
180176
else()
181-
set(cmake_symlink_option "create_symlink")
177+
set(cmake_symlink_option "${SWIFT_COPY_OR_SYMLINK}")
182178
endif()
183179

184180
add_custom_command(TARGET "${target}" POST_BUILD

lib/Migrator/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,13 @@ set(outputs)
2323
foreach(input ${datafiles})
2424
set(source "${CMAKE_CURRENT_SOURCE_DIR}/${input}")
2525
set(dest "${output_dir}/${input}")
26-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
27-
set(CMAKE_SYMLINK_COMMAND copy)
28-
else()
29-
set(CMAKE_SYMLINK_COMMAND create_symlink)
30-
endif()
3126

3227
add_custom_command(OUTPUT
3328
"${output_dir}/${input}"
3429
DEPENDS
3530
"${CMAKE_CURRENT_SOURCE_DIR}/${input}"
3631
COMMAND
37-
"${CMAKE_COMMAND}" "-E" "${CMAKE_SYMLINK_COMMAND}" "${source}" "${dest}")
32+
"${CMAKE_COMMAND}" "-E" "${SWIFT_COPY_OR_SYMLINK}" "${source}" "${dest}")
3833
list(APPEND outputs "${output_dir}/${input}")
3934
endforeach()
4035
list(APPEND outputs "${output_dir}")

stdlib/public/SwiftShims/swift/shims/CMakeLists.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,11 @@ else()
129129
set(clang_headers_location "${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION_MAJOR}")
130130
endif()
131131

132-
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
133-
set(cmake_symlink_option "copy_directory")
134-
else()
135-
set(cmake_symlink_option "create_symlink")
136-
endif()
137-
138132
add_custom_command_target(unused_var
139133
COMMAND
140134
"${CMAKE_COMMAND}" "-E" "make_directory" "${SWIFTLIB_DIR}"
141135
COMMAND
142-
"${CMAKE_COMMAND}" "-E" "${cmake_symlink_option}"
136+
"${CMAKE_COMMAND}" "-E" "${SWIFT_COPY_OR_SYMLINK_DIR}"
143137
"${clang_headers_location}"
144138
"${SWIFTLIB_DIR}/clang"
145139

@@ -154,7 +148,7 @@ if(SWIFT_BUILD_STATIC_STDLIB)
154148
COMMAND
155149
"${CMAKE_COMMAND}" "-E" "make_directory" "${SWIFTSTATICLIB_DIR}"
156150
COMMAND
157-
"${CMAKE_COMMAND}" "-E" "${cmake_symlink_option}"
151+
"${CMAKE_COMMAND}" "-E" "${SWIFT_COPY_OR_SYMLINK_DIR}"
158152
"${clang_headers_location}"
159153
"${SWIFTSTATICLIB_DIR}/clang"
160154

@@ -193,10 +187,10 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
193187
COMMAND
194188
"${CMAKE_COMMAND}" "-E" "make_directory" "${outdir}"
195189
COMMAND
196-
"${CMAKE_COMMAND}" "-E" ${cmake_symlink_option}
190+
"${CMAKE_COMMAND}" "-E" ${SWIFT_COPY_OR_SYMLINK_DIR}
197191
${output_dir} "${outdir}/shims"
198192
COMMAND
199-
"${CMAKE_COMMAND}" "-E" "${cmake_symlink_option}"
193+
"${CMAKE_COMMAND}" "-E" "${SWIFT_COPY_OR_SYMLINK_DIR}"
200194
"${clang_headers_location}"
201195
"${outdir}/clang"
202196

@@ -212,7 +206,7 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
212206
COMMAND
213207
"${CMAKE_COMMAND}" "-E" "make_directory" "${outdir}"
214208
COMMAND
215-
"${CMAKE_COMMAND}" "-E" ${cmake_symlink_option}
209+
"${CMAKE_COMMAND}" "-E" ${SWIFT_COPY_OR_SYMLINK_DIR}
216210
"${output_dir}/../module.modulemap" "${outdir}/module.modulemap"
217211

218212
CUSTOM_TARGET_NAME ${modulemap_target_name}

utils/api_checker/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ set(SWIFTLIB_DIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift")
1616
set(dest "${SWIFTLIB_DIR}/${framework}")
1717
set(source "${CMAKE_CURRENT_SOURCE_DIR}/${framework}")
1818

19-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
20-
set(CMAKE_SYMLINK_COMMAND copy)
21-
else()
22-
set(CMAKE_SYMLINK_COMMAND create_symlink)
23-
endif()
2419
add_custom_command(OUTPUT "${dest}"
2520
DEPENDS "${source}"
26-
COMMAND "${CMAKE_COMMAND}" "-E" "${CMAKE_SYMLINK_COMMAND}" "${source}" "${dest}"
21+
COMMAND "${CMAKE_COMMAND}" "-E" "${SWIFT_COPY_OR_SYMLINK}" "${source}" "${dest}"
2722
COMMENT "Symlinking ABI checker baseline data to ${dest}")
2823
add_custom_target("symlink_abi_checker_data" ALL
2924
DEPENDS "${dest}"

0 commit comments

Comments
 (0)