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().
This commit is contained in:
Dave Abrahams
2024-05-22 12:01:16 -07:00
parent 50252733c4
commit 45b3387c50
7 changed files with 120 additions and 118 deletions

View File

@@ -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 .*

View File

@@ -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"
}
]$]==]
)

View File

@@ -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

View File

@@ -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)

View File

@@ -1 +1 @@
ninja explain: A.swiftmodule is dirty
ninja explain: (Debug(/|\\))?A.swiftmodule is dirty

View File

@@ -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)?

View File

@@ -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()