Skip to content

Commit ebb4cc1

Browse files
authored
Remove @_implementationOnly imports guarded by 'SWT_BUILDING_WITH_CMAKE' (#554)
This removes the `SWT_BUILDING_WITH_CMAKE` compilation condition, and the `@_implementationOnly import _TestingInternals` declarations it guards. ### Motivation: When support for building via CMake was first added (in #387), many source files in the `Testing` target were modified to avoid using `private`- or `internal`-level imports of the `_TestingInternals` module and instead use the older `@_implementationOnly import` style when building via CMake. As a result, many files have: ```swift #if SWT_BUILDING_WITH_CMAKE @_implementationOnly import _TestingInternals #else private import _TestingInternals #endif ``` This has proven to be a maintenance problem for us, because as new files are added over time, it's not immediately obvious that they need to use this pattern for importing this module—leading to warnings when building with CMake such as the one fixed by #553. I wasn't aware of the reasoning behind the above change at the time, but I investigated it recently and here's what I concluded: Early on, the changes in #387 did _not_ enable Library Evolution (LE) for the `Testing` module, meaning it was still a non-resilient module. [SE-0409](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md) states that all dependencies of non-resilient modules must be loaded by clients, so it would make sense that under those conditions, the build of a client who imports `Testing` would fail because clients do not have visibility to the `_TestingInternals` module. However, in a later PR commit LE was enabled, but nobody realized that those `import` code changes were no longer necessary and could be reverted. I was able to reproduce this and confirm the theory: I added an example client target in the CMake build, then disabled LE in the `Testing` module, and attempted to build the client. It failed with the expected missing module error. Then, re-enabling LE and rebuilding everything, the error went away. Hopefully this is sufficient proof that reverting this is safe, but I'll check with the main contributor of that PR to check and see if there were any other issues before landing. But overall, the goal here is to simplify these imports to reduce maintenance burden and fully embrace SE-0409. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent f0730c4 commit ebb4cc1

31 files changed

+0
-123
lines changed

Sources/Testing/ABI/EntryPoints/EntryPoint.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
/// The common implementation of the entry point functions in this package.
1814
///

Sources/Testing/ABI/EntryPoints/SwiftPMEntryPoint.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
/// The exit code returned to Swift Package Manager by Swift Testing when no
1814
/// tests matched the inputs specified by the developer (or, for the case of

Sources/Testing/Events/Clock.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
@_spi(Experimental) @_spi(ForToolsIntegrationOnly)
1814
extension Test {

Sources/Testing/Events/TimeValue.swift

-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
// `internal` because `TimeValue.init(_ timespec:)` below is internal and
1212
// references a type (`timespec`) which comes from this import.
13-
#if SWT_BUILDING_WITH_CMAKE
14-
@_implementationOnly import _TestingInternals
15-
#else
1613
internal import _TestingInternals
17-
#endif
1814

1915
/// A container type representing a time value that is suitable for storage,
2016
/// conversion, encoding, and decoding.

Sources/Testing/ExitTests/ExitCondition.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
/// An enumeration describing possible conditions under which an exit test will
1814
/// succeed or fail.

Sources/Testing/ExitTests/ExitTest.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
#if !SWT_NO_EXIT_TESTS
1814
/// A type describing an exit test.

Sources/Testing/ExitTests/WaitFor.swift

-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
#if !SWT_NO_EXIT_TESTS
1212

13-
#if SWT_BUILDING_WITH_CMAKE
14-
@_implementationOnly import _TestingInternals
15-
#else
1613
internal import _TestingInternals
17-
#endif
1814

1915
#if SWT_TARGET_OS_APPLE || os(Linux)
2016
/// Block the calling thread, wait for the target process to exit, and return

Sources/Testing/SourceAttribution/Backtrace.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
/// A type representing a backtrace or stack trace.
1814
@_spi(ForToolsIntegrationOnly)

Sources/Testing/Support/Additions/CommandLineAdditions.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
extension CommandLine {
1814
/// The path to the current process' executable.

Sources/Testing/Support/CError.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
internal import _TestingInternals
15-
#endif
1612

1713
/// A type representing an error from a C function such as `fopen()`.
1814
///

Sources/Testing/Support/Environment.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
/// A type describing the environment of the current process.
1814
///

Sources/Testing/Support/FileHandle.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
internal import _TestingInternals
15-
#endif
1612

1713
#if !SWT_NO_FILE_IO
1814
/// A type representing a file handle.

Sources/Testing/Support/GetSymbol.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
internal import _TestingInternals
15-
#endif
1612

1713
#if !SWT_NO_DYNAMIC_LINKING
1814

Sources/Testing/Support/Locked.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
internal import _TestingInternals
15-
#endif
1612

1713
/// A type that wraps a value requiring access from a synchronous caller during
1814
/// concurrent execution.

Sources/Testing/Support/Versions.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
/// A human-readable string describing the current operating system's version.
1814
///

Sources/Testing/Test+Discovery.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
/// A protocol describing a type that contains tests.
1814
///

Sources/Testing/Traits/Tags/Tag.Color+Loading.swift

-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
#if SWT_BUILDING_WITH_CMAKE
12-
@_implementationOnly import _TestingInternals
13-
#else
1411
private import _TestingInternals
15-
#endif
1612

1713
#if !SWT_NO_FILE_IO
1814
#if os(macOS) || (os(iOS) && targetEnvironment(macCatalyst)) || os(Linux)

Tests/TestingTests/ABIEntryPointTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
#if canImport(Foundation) && !SWT_NO_ABI_ENTRY_POINT
1212
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1313

14-
#if SWT_BUILDING_WITH_CMAKE
15-
@_implementationOnly import _TestingInternals
16-
#else
1714
private import _TestingInternals
18-
#endif
1915

2016
@Suite("ABI entry point tests")
2117
struct ABIEntryPointTests {

Tests/TestingTests/ClockTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
1212

13-
#if SWT_BUILDING_WITH_CMAKE
14-
@_implementationOnly import _TestingInternals
15-
#else
1613
private import _TestingInternals
17-
#endif
1814

1915
@Suite("Clock API Tests")
2016
struct ClockTests {

Tests/TestingTests/DumpTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable @_spi(ForToolsIntegrationOnly) import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
// NOTE: The tests in this file are here to exercise Plan.dump(), but they are
1915
// not intended to actually test that the output is in a particular format since

Tests/TestingTests/EventTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
#if !SWT_NO_SNAPSHOT_TYPES
1212
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
13-
#if SWT_BUILDING_WITH_CMAKE
14-
@_implementationOnly import _TestingInternals
15-
#else
1613
private import _TestingInternals
17-
#endif
1814

1915
@Suite("Event Tests")
2016
struct EventTests {

Tests/TestingTests/ExitTestTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
#if !SWT_NO_EXIT_TESTS
1915
@Suite("Exit test tests") struct ExitTestTests {

Tests/TestingTests/IssueTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
#if canImport(XCTest)
1915
import XCTest

Tests/TestingTests/Support/CErrorTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
@Suite("CError Tests")
1915
struct CErrorTests {

Tests/TestingTests/Support/EnvironmentTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable @_spi(Experimental) import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
@Suite("Environment Tests", .serialized)
1915
struct EnvironmentTests {

Tests/TestingTests/Support/FileHandleTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
#if !SWT_NO_FILE_IO
1915
// NOTE: we don't run these tests on iOS (etc.) because processes on those

Tests/TestingTests/SwiftPMTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
private func configurationForEntryPoint(withArguments args: [String]) throws -> Configuration {
1915
let args = try parseCommandLineArguments(from: args)

Tests/TestingTests/Traits/TagListTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable @_spi(Experimental) @_spi(ForToolsIntegrationOnly) import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
@Suite("Tag/Tag List Tests", .tags(.traitRelated))
1915
struct TagListTests {

Tests/TestingTests/TypeInfoTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
@testable @_spi(ForToolsIntegrationOnly) import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
@Suite("TypeInfo Tests")
1915
struct TypeInfoTests {

Tests/TestingTests/VariadicGenericTests.swift

-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
//
1010

1111
import Testing
12-
#if SWT_BUILDING_WITH_CMAKE
13-
@_implementationOnly import _TestingInternals
14-
#else
1512
private import _TestingInternals
16-
#endif
1713

1814
@Test func variadicCStringArguments() async throws {
1915
#expect(swt_pointersNotEqual2("abc", "123"))

cmake/modules/shared/CompilerSettings.cmake

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ add_compile_options(
1616
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend ExistentialAny>"
1717
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend InternalImportsByDefault>")
1818

19-
# Definitions applied unconditionally to files of all languages, in all targets.
20-
add_compile_definitions("SWT_BUILDING_WITH_CMAKE")
21-
2219
# Platform-specific definitions.
2320
if(APPLE)
2421
add_compile_definitions("SWT_TARGET_OS_APPLE")

0 commit comments

Comments
 (0)