Skip to content

Commit c1d901d

Browse files
committed
[Runtimes] handle incremental builds that have non nested swiftmodules
Before #82571, we would generate a binary swiftmodule file at `<build folder>/<module>.swiftmodule`, while now in the same location we generate a directory. Trying an incremental run on top of a build folder generated with the old logic will fail during configuration with an error similar to ``` CMake Error at .../Supplemental/cmake/modules/EmitSwiftInterface.cmake:21 (file): file failed to create directory: .../StringProcessing-build/_RegexParser/_RegexParser.swiftmodule because: File exists ``` To reduce churn in CI and at desk, delete such remnant from the previous logic. Addresses rdar://155466197
1 parent 2edec10 commit c1d901d

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ function(emit_swift_interface target)
1818
if(NOT module_name)
1919
set(module_name ${target})
2020
endif()
21-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
21+
# Account for an existing swiftmodule file
22+
# generated with the previous logic
23+
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule"
24+
AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
25+
message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation")
26+
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
27+
endif()
2228
target_compile_options(${target} PRIVATE
2329
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftmodule>")
2430
if(SwiftCore_VARIANT_MODULE_TRIPLE)

Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ function(emit_swift_interface target)
1818
if(NOT module_name)
1919
set(module_name ${target})
2020
endif()
21-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
21+
# Account for an existing swiftmodule file
22+
# generated with the previous logic
23+
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule"
24+
AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
25+
message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation")
26+
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
27+
endif()
2228
target_compile_options(${target} PRIVATE
2329
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftOverlay_MODULE_TRIPLE}.swiftmodule>")
2430
if(SwiftOverlay_VARIANT_MODULE_TRIPLE)

Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ function(emit_swift_interface target)
1818
if(NOT module_name)
1919
set(module_name ${target})
2020
endif()
21-
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
21+
# Account for an existing swiftmodule file
22+
# generated with the previous logic
23+
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule"
24+
AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
25+
message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation")
26+
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule")
27+
endif()
2228
target_compile_options(${target} PRIVATE
2329
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${${PROJECT_NAME}_MODULE_TRIPLE}.swiftmodule>")
2430
if(${PROJECT_NAME}_VARIANT_MODULE_TRIPLE)

0 commit comments

Comments
 (0)