From 45b3387c50cb9516eb8ff6b88e537f0d97cd8404 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 22 May 2024 12:01:16 -0700 Subject: [PATCH] Tests/RunCMake/Swift: Enable more cases with Ninja Multi-Config Also factor out testing that's common across Xcode and Ninja.* generators. - Ninja expected output files were extended to accept directories named after the configuration in paths. - Tests that previously ran with Ninja were allowed to run with Ninja Multi-Config. - Swift/RunCMakeTest.cmake: - Checks for conditions where little or no testing could be done were moved to the top of the file, with return()s to limit nesting of the remainder of the code ("Early bailouts"). - CMP0157 tests, which were being performed for all generators, were factored out into a block at the top of the file. - RunCMake_TEST_OPTIONS is set initially for all multi-config generators and list(APPEND)'ed-to in each block() where it was previously set() and unset(). --- .../Swift/CMP0157-OLD-build-stdout.txt | 2 +- .../Swift/CompileCommands-check.cmake | 4 +- .../Swift/ForceResponseFile-check-stdout.txt | 4 +- Tests/RunCMake/Swift/ForceResponseFile.cmake | 4 +- .../Swift/IncrementalSwift-second-stderr.txt | 2 +- .../Swift/IncrementalSwift-second-stdout.txt | 2 +- Tests/RunCMake/Swift/RunCMakeTest.cmake | 220 +++++++++--------- 7 files changed, 120 insertions(+), 118 deletions(-) diff --git a/Tests/RunCMake/Swift/CMP0157-OLD-build-stdout.txt b/Tests/RunCMake/Swift/CMP0157-OLD-build-stdout.txt index d593b929fd..4fb69be5e2 100644 --- a/Tests/RunCMake/Swift/CMP0157-OLD-build-stdout.txt +++ b/Tests/RunCMake/Swift/CMP0157-OLD-build-stdout.txt @@ -1 +1 @@ -swiftc(.exe)? .* -output-file-map CMakeFiles(/|\\)greetings_default.dir(//|\\\\)output-file-map.json .* +swiftc(.exe)? .* -output-file-map CMakeFiles(/|\\)greetings_default.dir(/|\\)(Debug)?(/|\\)output-file-map.json .* diff --git a/Tests/RunCMake/Swift/CompileCommands-check.cmake b/Tests/RunCMake/Swift/CompileCommands-check.cmake index 645074500c..e33a027063 100644 --- a/Tests/RunCMake/Swift/CompileCommands-check.cmake +++ b/Tests/RunCMake/Swift/CompileCommands-check.cmake @@ -11,13 +11,13 @@ set(expected_compile_commands "directory": ".*(/Tests/RunCMake/Swift/CompileCommands-build|\\\\Tests\\\\RunCMake\\\\Swift\\\\CompileCommands-build)", "command": ".*swiftc .* (\\")?.*(/Tests/RunCMake/Swift/E.swift|\\\\Tests\\\\RunCMake\\\\Swift\\\\E.swift)(\\")? (\\")?.*(/Tests/RunCMake/Swift/L.swift|\\\\Tests\\\\RunCMake\\\\Swift\\\\L.swift)(\\")?", "file": ".*(/Tests/RunCMake/Swift/E.swift|\\\\Tests\\\\RunCMake\\\\Swift\\\\E.swift)", - "output": "CMakeFiles/CompileCommandLib.dir/E.swift.o|CMakeFiles\\\\CompileCommandLib.dir\\\\E.swift.obj" + "output": "CMakeFiles/CompileCommandLib.dir/(Debug(/|\\))?E.swift.o|CMakeFiles\\\\CompileCommandLib.dir\\\\E.swift.obj" }, { "directory": ".*(/Tests/RunCMake/Swift/CompileCommands-build|\\\\Tests\\\\RunCMake\\\\Swift\\\\CompileCommands-build)", "command": ".*swiftc .* (\\")?.*(/Tests/RunCMake/Swift/E.swift|\\\\Tests\\\\RunCMake\\\\Swift\\\\E.swift)(\\")? (\\")?.*(/Tests/RunCMake/Swift/L.swift|\\\\Tests\\\\RunCMake\\\\Swift\\\\L.swift)(\\")?", "file": ".*/Tests/RunCMake/Swift/L.swift", - "output": "CMakeFiles/CompileCommandLib.dir/L.swift.o|CMakeFiles\\\\CompileCommandLib.dir\\\\L.swift.obj" + "output": "CMakeFiles/CompileCommandLib.dir/(Debug(/|\\))?L.swift.o|CMakeFiles\\\\CompileCommandLib.dir\\\\L.swift.obj" } ]$]==] ) diff --git a/Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt b/Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt index ec396d7398..adea1f1646 100644 --- a/Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt +++ b/Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt @@ -1,2 +1,2 @@ -swiftc(.exe)? -j [0-9]+ -num-threads [0-9]+ -c @CMakeFiles(/|\\)L.dir(/|\\)L.o(bj)?.swift.rsp -.*swiftc(.exe)? -emit-library -static -o (libL.a|L.lib) @CMakeFiles(/|\\)L.rsp +swiftc(.exe)? -j [0-9]+ -num-threads [0-9]+ -c @CMakeFiles(/|\\)L.dir(/|\\)(Debug(/|\\))?L.o(bj)?.swift.rsp +.*swiftc(.exe)? -emit-library -static -o (Debug(/|\\))?(libL.a|L.lib) @CMakeFiles(/|\\)L.(Debug\.)?rsp diff --git a/Tests/RunCMake/Swift/ForceResponseFile.cmake b/Tests/RunCMake/Swift/ForceResponseFile.cmake index 7fd46365a9..880ff72c2a 100644 --- a/Tests/RunCMake/Swift/ForceResponseFile.cmake +++ b/Tests/RunCMake/Swift/ForceResponseFile.cmake @@ -2,8 +2,8 @@ if(POLICY CMP0157) cmake_policy(SET CMP0157 NEW) endif() -if(NOT CMAKE_GENERATOR STREQUAL "Ninja") - message(SEND_ERROR "this test must use Ninja generator, found ${CMAKE_GENERATOR} ") +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(SEND_ERROR "this test must use a Ninja generator, found ${CMAKE_GENERATOR} ") endif() set(CMAKE_NINJA_FORCE_RESPONSE_FILE TRUE) diff --git a/Tests/RunCMake/Swift/IncrementalSwift-second-stderr.txt b/Tests/RunCMake/Swift/IncrementalSwift-second-stderr.txt index 3650fe52c8..0131378b49 100644 --- a/Tests/RunCMake/Swift/IncrementalSwift-second-stderr.txt +++ b/Tests/RunCMake/Swift/IncrementalSwift-second-stderr.txt @@ -1 +1 @@ -ninja explain: A.swiftmodule is dirty +ninja explain: (Debug(/|\\))?A.swiftmodule is dirty diff --git a/Tests/RunCMake/Swift/IncrementalSwift-second-stdout.txt b/Tests/RunCMake/Swift/IncrementalSwift-second-stdout.txt index ccd8aeebd8..7bc8c75c02 100644 --- a/Tests/RunCMake/Swift/IncrementalSwift-second-stdout.txt +++ b/Tests/RunCMake/Swift/IncrementalSwift-second-stdout.txt @@ -1,3 +1,3 @@ .*Building Swift Module 'A' with 1 source .*Building Swift Module 'B' with 1 source -FAILED: B.swiftmodule CMakeFiles(/|\\)B.dir(/|\\)b.swift.o(bj)? +FAILED: (Debug(/|\\))?B.swiftmodule CMakeFiles(/|\\)B.dir(/|\\)(Debug(/|\\))?b.swift.o(bj)? diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake index e8a1daba8e..39f754cc62 100644 --- a/Tests/RunCMake/Swift/RunCMakeTest.cmake +++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake @@ -1,122 +1,124 @@ include(RunCMake) -if(RunCMake_GENERATOR STREQUAL Xcode) - if(XCODE_VERSION VERSION_LESS 6.1) - run_cmake(XcodeTooOld) - elseif(CMake_TEST_Swift) - run_cmake(CMP0157-NEW) - run_cmake(CMP0157-OLD) - run_cmake(CMP0157-WARN) +# Early bailouts. +if(RunCMake_GENERATOR STREQUAL "Xcode" AND XCODE_VERSION VERSION_LESS 6.1) + run_cmake(XcodeTooOld) + return() +elseif(NOT CMake_TEST_Swift) + return() +elseif(NOT RunCMake_GENERATOR MATCHES "^Ninja|^Xcode$") + run_cmake(NotSupported) + return() +endif() + +if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS "-DCMAKE_CONFIGURATION_TYPES=Debug\\;Release") +endif() + +block() + run_cmake(CMP0157-NEW) + run_cmake(CMP0157-WARN) + + if(RunCMake_GENERATOR MATCHES "Ninja.*") + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0157-OLD-build) endif() -elseif(RunCMake_GENERATOR STREQUAL Ninja) - if(CMake_TEST_Swift) + + run_cmake(CMP0157-OLD) + + if(RunCMake_GENERATOR MATCHES "Ninja.*") + set(RunCMake_TEST_NO_CLEAN 1) + # -n: dry-run to avoid actually compiling, -v: verbose to capture executed command + run_cmake_command(CMP0157-OLD-build ${CMAKE_COMMAND} --build . -- -n -v) + endif() +endblock() + +if(RunCMake_GENERATOR MATCHES "Ninja") + run_cmake(SwiftSimple) + + block() if (CMAKE_SYSTEM_NAME MATCHES "Windows") run_cmake_with_options(Win32ExecutableDisallowed) else() run_cmake_with_options(Win32ExecutableIgnored) - set(RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Darwin) + list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_SYSTEM_NAME=Darwin) run_cmake(SwiftMultiArch) - unset(RunCMake_TEST_OPTIONS) endif() + endblock() - # Test that a second build with no changes does nothing. - block() - run_cmake(NoWorkToDo) + # Test that a second build with no changes does nothing. + block() + run_cmake(NoWorkToDo) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/NoWorkToDo-build) + set(RunCMake_TEST_OUTPUT_MERGE 1) + run_cmake_command(NoWorkToDo-build ${CMAKE_COMMAND} --build .) + run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain) + file(WRITE ${RunCMake_TEST_BINARY_DIR}/hello.swift "//No-op change\n") + run_cmake_command(NoWorkToDo-norelink ${CMAKE_COMMAND} --build . -- -d explain) + run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain) + endblock() + + # Test that intermediate static libraries are rebuilt when the public + # interface of their dependency changes + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/IncrementalSwift-build) + # Since files are modified during test, the files are created in the cmake + # file into the build directory + run_cmake(IncrementalSwift) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(IncrementalSwift-first ${CMAKE_COMMAND} --build .) + + # Modify public interface of libA requiring rebuild of libB + file(WRITE ${RunCMake_TEST_BINARY_DIR}/a.swift + "public func callA() -> Float { return 32.0 }\n") + + # Note: We still expect this to fail, but instead of failure at link time, + # it should fail while re-compiling libB because the function changed + run_cmake_command(IncrementalSwift-second ${CMAKE_COMMAND} --build . -- -d explain) + endblock() + + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CompileCommands-build) + run_cmake(CompileCommands) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(CompileCommands-check ${CMAKE_COMMAND} --build .) + endblock() + + block() + # Try enabling Swift with a static-library try-compile + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/StaticLibTryCompile-build) + list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY) + run_cmake(EnableSwift) + endblock() + + block() + # Try enabling Swift with an executable try-compile + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExecutableTryCompile-build) + list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_TRY_COMPILE_TARGET_TYPE=EXECUTABLE) + run_cmake(EnableSwift) + endblock() + + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ForceResponseFile-build) + run_cmake(ForceResponseFile) + set(RunCMake_TEST_NO_CLEAN 1) + # -v: verbose to capture executed commands -n: dry-run to avoid actually compiling + run_cmake_command(ForceResponseFile-check ${CMAKE_COMMAND} --build . -- -vn) + endblock() + + block() + if(CMAKE_SYSTEM_NAME MATCHES Windows) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ImportLibraryFlags-build) + run_cmake(ImportLibraryFlags) set(RunCMake_TEST_NO_CLEAN 1) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/NoWorkToDo-build) - set(RunCMake_TEST_OUTPUT_MERGE 1) - run_cmake_command(NoWorkToDo-build ${CMAKE_COMMAND} --build .) - run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain) - file(WRITE ${RunCMake_TEST_BINARY_DIR}/hello.swift "//No-op change\n") - run_cmake_command(NoWorkToDo-norelink ${CMAKE_COMMAND} --build . -- -d explain) - run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain) - endblock() + run_cmake_command(ImportLibraryFlags-check ${CMAKE_COMMAND} --build . -- -n -v) + endif() + endblock() - # Test that intermediate static libraries are rebuilt when the public - # interface of their dependency changes - block() - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/IncrementalSwift-build) - # Since files are modified during test, the files are created in the cmake - # file into the build directory - run_cmake(IncrementalSwift) - set(RunCMake_TEST_NO_CLEAN 1) - run_cmake_command(IncrementalSwift-first ${CMAKE_COMMAND} --build .) - - # Modify public interface of libA requiring rebuild of libB - file(WRITE ${RunCMake_TEST_BINARY_DIR}/a.swift - "public func callA() -> Float { return 32.0 }\n") - - # Note: We still expect this to fail, but instead of failure at link time, - # it should fail while re-compiling libB because the function changed - run_cmake_command(IncrementalSwift-second ${CMAKE_COMMAND} --build . -- -d explain) - endblock() - - block() - run_cmake(CMP0157-NEW) - run_cmake(CMP0157-WARN) - - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0157-OLD-build) - run_cmake(CMP0157-OLD) - set(RunCMake_TEST_NO_CLEAN 1) - # -n: dry-run to avoid actually compiling, -v: verbose to capture executed command - run_cmake_command(CMP0157-OLD-build ${CMAKE_COMMAND} --build . -- -n -v) - endblock() - - block() - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CompileCommands-build) - run_cmake(CompileCommands) - set(RunCMake_TEST_NO_CLEAN 1) - run_cmake_command(CompileCommands-check ${CMAKE_COMMAND} --build .) - endblock() - - block() - # Try enabling Swift with a static-library try-compile - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/StaticLibTryCompile-build) - set(RunCMake_TEST_OPTIONS -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY) - run_cmake(EnableSwift) - endblock() - - block() - # Try enabling Swift with an executable try-compile - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExecutableTryCompile-build) - set(RunCMake_TEST_OPTIONS -DCMAKE_TRY_COMPILE_TARGET_TYPE=EXECUTABLE) - run_cmake(EnableSwift) - endblock() - - block() - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ForceResponseFile-build) - run_cmake(ForceResponseFile) - set(RunCMake_TEST_NO_CLEAN 1) - # -v: verbose to capture executed commands -n: dry-run to avoid actually compiling - run_cmake_command(ForceResponseFile-check ${CMAKE_COMMAND} --build . -- -vn) - endblock() - - block() - if(CMAKE_SYSTEM_NAME MATCHES Windows) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ImportLibraryFlags-build) - run_cmake(ImportLibraryFlags) - set(RunCMake_TEST_NO_CLEAN 1) - run_cmake_command(ImportLibraryFlags-check ${CMAKE_COMMAND} --build . -- -n -v) - endif() - endblock() - - block() - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SwiftLibraryModuleCommand-build) - run_cmake(SwiftLibraryModuleCommand) - set(RunCMake_TEST_NO_CLEAN 1) - run_cmake_command(SwiftLibraryModuleCommand-check ${CMAKE_COMMAND} --build . -- -n -v) - endblock() - endif() -elseif(RunCMake_GENERATOR STREQUAL "Ninja Multi-Config") - if(CMake_TEST_Swift) - set(RunCMake_TEST_OPTIONS "-DCMAKE_CONFIGURATION_TYPES=Debug\\;Release") - run_cmake(SwiftSimple) - - run_cmake(CMP0157-NEW) - run_cmake(CMP0157-OLD) - run_cmake(CMP0157-WARN) - unset(RunCMake_TEST_OPTIONS) - endif() -else() - run_cmake(NotSupported) + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SwiftLibraryModuleCommand-build) + run_cmake(SwiftLibraryModuleCommand) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(SwiftLibraryModuleCommand-check ${CMAKE_COMMAND} --build . -- -n -v) + endblock() endif()