From c1d901df2d24f0a2954e1eccf47deb54daff2b08 Mon Sep 17 00:00:00 2001 From: Eric Miotto Date: Wed, 9 Jul 2025 15:08:13 -0700 Subject: [PATCH] [Runtimes] handle incremental builds that have non nested swiftmodules Before #82571, we would generate a binary swiftmodule file at `/.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 --- Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake | 8 +++++++- Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake | 8 +++++++- .../Supplemental/cmake/modules/EmitSwiftInterface.cmake | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake b/Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake index a5332ccb5074c..b8d75ed487909 100644 --- a/Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake +++ b/Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake @@ -18,7 +18,13 @@ function(emit_swift_interface target) if(NOT module_name) set(module_name ${target}) endif() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + # Account for an existing swiftmodule file + # generated with the previous logic + if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule" + AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation") + file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + endif() target_compile_options(${target} PRIVATE "$<$:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftmodule>") if(SwiftCore_VARIANT_MODULE_TRIPLE) diff --git a/Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake b/Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake index c915793ca8769..b52560448df68 100644 --- a/Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake +++ b/Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake @@ -18,7 +18,13 @@ function(emit_swift_interface target) if(NOT module_name) set(module_name ${target}) endif() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + # Account for an existing swiftmodule file + # generated with the previous logic + if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule" + AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation") + file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + endif() target_compile_options(${target} PRIVATE "$<$:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftOverlay_MODULE_TRIPLE}.swiftmodule>") if(SwiftOverlay_VARIANT_MODULE_TRIPLE) diff --git a/Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake b/Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake index 9d56da0816b64..8a3540dd55e07 100644 --- a/Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake +++ b/Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake @@ -18,7 +18,13 @@ function(emit_swift_interface target) if(NOT module_name) set(module_name ${target}) endif() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + # Account for an existing swiftmodule file + # generated with the previous logic + if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule" + AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation") + file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + endif() target_compile_options(${target} PRIVATE "$<$:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${${PROJECT_NAME}_MODULE_TRIPLE}.swiftmodule>") if(${PROJECT_NAME}_VARIANT_MODULE_TRIPLE)