@@ -140,8 +140,8 @@ let package = Package(
140140 " TestingMacros " ,
141141 ] ,
142142 exclude: [ " CMakeLists.txt " , " Testing.swiftcrossimport " ] ,
143- cxxSettings: . packageSettings,
144- swiftSettings: . packageSettings + . enableLibraryEvolution( ) + . moduleABIName( " Testing " ) ,
143+ cxxSettings: . packageSettings( ) ,
144+ swiftSettings: . packageSettings( ) + . enableLibraryEvolution( ) + . moduleABIName( " Testing " ) ,
145145 linkerSettings: [
146146 . linkedLibrary( " execinfo " , . when( platforms: [ . custom( " freebsd " ) , . openbsd] ) ) ,
147147 . linkedLibrary( " _TestingInterop " ) ,
@@ -159,7 +159,7 @@ let package = Package(
159159 " _Testing_WinSDK " ,
160160 " MemorySafeTestingTests " ,
161161 ] ,
162- swiftSettings: . packageSettings,
162+ swiftSettings: . packageSettings( isTestTarget : true ) ,
163163 linkerSettings: [
164164 . linkedLibrary( " util " , . when( platforms: [ . openbsd] ) )
165165 ]
@@ -176,7 +176,7 @@ let package = Package(
176176 " Testing " ,
177177 ] ,
178178 path: " Tests/_MemorySafeTestingTests " ,
179- swiftSettings: . packageSettings + [ . strictMemorySafety( ) ]
179+ swiftSettings: . packageSettings( isTestTarget : true ) + [ . strictMemorySafety( ) ]
180180 ) ,
181181
182182 . macro(
@@ -190,7 +190,7 @@ let package = Package(
190190 . product( name: " SwiftCompilerPlugin " , package : " swift-syntax " ) ,
191191 ] ,
192192 exclude: [ " CMakeLists.txt " ] ,
193- swiftSettings: . packageSettings + [
193+ swiftSettings: . packageSettings( ) + [
194194 // The only target which needs the ability to import this macro
195195 // implementation target's module is its unit test target. Users of the
196196 // macros this target implements use them via their declarations in the
@@ -206,14 +206,14 @@ let package = Package(
206206 . target(
207207 name: " _TestingInternals " ,
208208 exclude: [ " CMakeLists.txt " ] ,
209- cxxSettings: . packageSettings
209+ cxxSettings: . packageSettings( )
210210 ) ,
211211 . target(
212212 name: " _TestDiscovery " ,
213213 dependencies: [ " _TestingInternals " , ] ,
214214 exclude: [ " CMakeLists.txt " ] ,
215- cxxSettings: . packageSettings,
216- swiftSettings: . packageSettings + . enableLibraryEvolution( ) + . moduleABIName( " _TestDiscovery " )
215+ cxxSettings: . packageSettings( ) ,
216+ swiftSettings: . packageSettings( ) + . enableLibraryEvolution( ) + . moduleABIName( " _TestDiscovery " )
217217 ) ,
218218 . target(
219219 // Build _TestingInterop for debugging/testing purposes only. It is
@@ -222,8 +222,8 @@ let package = Package(
222222 dependencies: [ " _TestingInternals " , ] ,
223223 path: " Sources/_TestingInterop " ,
224224 exclude: [ " CMakeLists.txt " ] ,
225- cxxSettings: . packageSettings,
226- swiftSettings: . packageSettings + . moduleABIName( " _TestingInterop " )
225+ cxxSettings: . packageSettings( ) ,
226+ swiftSettings: . packageSettings( ) + . moduleABIName( " _TestingInterop " )
227227 ) ,
228228
229229 // Cross-import overlays (not supported by Swift Package Manager)
@@ -235,7 +235,7 @@ let package = Package(
235235 ] ,
236236 path: " Sources/Overlays/_Testing_AppKit " ,
237237 exclude: [ " CMakeLists.txt " ] ,
238- swiftSettings: . packageSettings + . enableLibraryEvolution( ) + . moduleABIName( " Testing " )
238+ swiftSettings: . packageSettings( ) + . enableLibraryEvolution( ) + . moduleABIName( " Testing " )
239239 ) ,
240240 . target(
241241 name: " _Testing_CoreGraphics " ,
@@ -244,7 +244,7 @@ let package = Package(
244244 ] ,
245245 path: " Sources/Overlays/_Testing_CoreGraphics " ,
246246 exclude: [ " CMakeLists.txt " ] ,
247- swiftSettings: . packageSettings + . enableLibraryEvolution( ) + . moduleABIName( " _Testing_CoreGraphics " )
247+ swiftSettings: . packageSettings( ) + . enableLibraryEvolution( ) + . moduleABIName( " _Testing_CoreGraphics " )
248248 ) ,
249249 . target(
250250 name: " _Testing_CoreImage " ,
@@ -254,7 +254,7 @@ let package = Package(
254254 ] ,
255255 path: " Sources/Overlays/_Testing_CoreImage " ,
256256 exclude: [ " CMakeLists.txt " ] ,
257- swiftSettings: . packageSettings + . enableLibraryEvolution( ) + . moduleABIName( " _Testing_CoreImage " )
257+ swiftSettings: . packageSettings( ) + . enableLibraryEvolution( ) + . moduleABIName( " _Testing_CoreImage " )
258258 ) ,
259259 . target(
260260 name: " _Testing_Foundation " ,
@@ -267,7 +267,7 @@ let package = Package(
267267 // The Foundation module only has Library Evolution enabled on Apple
268268 // platforms, and since this target's module publicly imports Foundation,
269269 // it can only enable Library Evolution itself on those platforms.
270- swiftSettings: . packageSettings + . enableLibraryEvolution( . whenApple( ) ) + . moduleABIName( " _Testing_Foundation " )
270+ swiftSettings: . packageSettings( ) + . enableLibraryEvolution( . whenApple( ) ) + . moduleABIName( " _Testing_Foundation " )
271271 ) ,
272272 . target(
273273 name: " _Testing_UIKit " ,
@@ -278,7 +278,7 @@ let package = Package(
278278 ] ,
279279 path: " Sources/Overlays/_Testing_UIKit " ,
280280 exclude: [ " CMakeLists.txt " ] ,
281- swiftSettings: . packageSettings + . enableLibraryEvolution( ) + . moduleABIName( " _Testing_UIKit " )
281+ swiftSettings: . packageSettings( ) + . enableLibraryEvolution( ) + . moduleABIName( " _Testing_UIKit " )
282282 ) ,
283283 . target(
284284 name: " _Testing_WinSDK " ,
@@ -287,7 +287,7 @@ let package = Package(
287287 ] ,
288288 path: " Sources/Overlays/_Testing_WinSDK " ,
289289 exclude: [ " CMakeLists.txt " ] ,
290- swiftSettings: . packageSettings + . enableLibraryEvolution( ) + . moduleABIName( " _Testing_WinSDK " )
290+ swiftSettings: . packageSettings( ) + . enableLibraryEvolution( ) + . moduleABIName( " _Testing_WinSDK " )
291291 ) ,
292292
293293 // Utility targets: These are utilities intended for use when developing
@@ -297,7 +297,7 @@ let package = Package(
297297 dependencies: [
298298 " Testing " ,
299299 ] ,
300- swiftSettings: . packageSettings
300+ swiftSettings: . packageSettings( )
301301 ) ,
302302 ] ,
303303
@@ -313,7 +313,7 @@ package.targets.append(contentsOf: [
313313 " Testing " ,
314314 " TestingMacros " ,
315315 ] ,
316- swiftSettings: . packageSettings
316+ swiftSettings: . packageSettings( isTestTarget : true )
317317 )
318318] )
319319#endif
@@ -362,7 +362,7 @@ extension BuildSettingCondition {
362362extension Array where Element == PackageDescription . SwiftSetting {
363363 /// Settings intended to be applied to every Swift target in this package.
364364 /// Analogous to project-level build settings in an Xcode project.
365- static var packageSettings : Self {
365+ static func packageSettings( isTestTarget : Bool = false ) -> Self {
366366 var result = availabilityMacroSettings
367367
368368 // treatWarning(..., as: .warning) cannot be used in packages which are
@@ -376,6 +376,14 @@ extension Array where Element == PackageDescription.SwiftSetting {
376376 result. append ( . enableExperimentalFeature( " Embedded " ) )
377377 }
378378
379+ // Define a compiler condition so we can discover at macro expansion time if
380+ // we're accidentally expanding our own macros in Swift Testing.
381+ if !isTestTarget {
382+ result += [
383+ . define( " SWT_BUILDING_SWIFT_TESTING_CONTENT " ) ,
384+ ]
385+ }
386+
379387 result += [
380388 . enableUpcomingFeature( " ExistentialAny " ) ,
381389
@@ -474,9 +482,17 @@ extension Array where Element == PackageDescription.SwiftSetting {
474482extension Array where Element == PackageDescription . CXXSetting {
475483 /// Settings intended to be applied to every C++ target in this package.
476484 /// Analogous to project-level build settings in an Xcode project.
477- static var packageSettings : Self {
485+ static func packageSettings( isTestTarget : Bool = false ) -> Self {
478486 var result = Self ( )
479487
488+ // Define a compiler condition so we can discover at macro expansion time if
489+ // we're accidentally expanding our own macros in Swift Testing.
490+ if !isTestTarget {
491+ result += [
492+ . define( " SWT_BUILDING_SWIFT_TESTING_CONTENT " ) ,
493+ ]
494+ }
495+
480496 result += [
481497 . define( " SWT_NO_EXIT_TESTS " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
482498 . define( " SWT_NO_PROCESS_SPAWNING " , . whenEmbedded( or: . when( platforms: [ . iOS, . watchOS, . tvOS, . visionOS, . wasi, . android] ) ) ) ,
0 commit comments