@@ -91,9 +91,8 @@ extension BuildParameters {
91
91
case . auto:
92
92
if configuration == . debug {
93
93
addIndexStoreArguments = true
94
- } else if enableTestDiscovery && target. type == . test {
95
- // Test discovery requires an index store for the test targets
96
- // to discover the tests
94
+ } else if target. type == . test {
95
+ // Test discovery requires an index store for the test target to discover the tests
97
96
addIndexStoreArguments = true
98
97
} else {
99
98
addIndexStoreArguments = false
@@ -963,15 +962,10 @@ public final class SwiftTargetBuildDescription {
963
962
964
963
/// Testing arguments according to the build configuration.
965
964
private var testingArguments : [ String ] {
966
- switch buildParameters. configuration {
967
- case . debug:
965
+ if buildParameters. enableTestability {
968
966
return [ " -enable-testing " ]
969
- case . release:
970
- if self . buildParameters. enableTestDiscovery {
971
- return [ " -enable-testing " ]
972
- } else {
973
- return [ ]
974
- }
967
+ } else {
968
+ return [ ]
975
969
}
976
970
}
977
971
@@ -1100,10 +1094,11 @@ public final class ProductBuildDescription {
1100
1094
// No arguments for static libraries.
1101
1095
return [ ]
1102
1096
case . test:
1103
- // Test products are bundle on macOS, executable on linux.
1104
- if buildParameters. triple. isDarwin ( ) {
1097
+ // Test products are bundle when using objectiveC, executable when using test manifests.
1098
+ switch buildParameters. testDiscoveryStrategy {
1099
+ case . objectiveC:
1105
1100
args += [ " -Xlinker " , " -bundle " ]
1106
- } else {
1101
+ case . manifest :
1107
1102
args += [ " -emit-executable " ]
1108
1103
}
1109
1104
case . library( . dynamic) :
@@ -1224,16 +1219,11 @@ public final class ProductBuildDescription {
1224
1219
public class BuildPlan {
1225
1220
1226
1221
public enum Error : Swift . Error , CustomStringConvertible , Equatable {
1227
- /// The linux main file is missing.
1228
- case missingLinuxMain
1229
-
1230
1222
/// There is no buildable target in the graph.
1231
1223
case noBuildableTarget
1232
1224
1233
1225
public var description : String {
1234
1226
switch self {
1235
- case . missingLinuxMain:
1236
- return " missing LinuxMain.swift file in the Tests directory "
1237
1227
case . noBuildableTarget:
1238
1228
return " the package does not contain a buildable target "
1239
1229
}
@@ -1273,64 +1263,60 @@ public class BuildPlan {
1273
1263
/// Diagnostics Engine for emitting diagnostics.
1274
1264
let diagnostics : DiagnosticsEngine
1275
1265
1276
- private static func planLinuxMain (
1266
+ private static func makeTestManifestTargets (
1277
1267
_ buildParameters: BuildParameters ,
1278
1268
_ graph: PackageGraph
1279
- ) throws -> [ ( ResolvedProduct , SwiftTargetBuildDescription ) ] {
1280
- guard !buildParameters . triple . isDarwin ( ) else {
1281
- return [ ]
1269
+ ) throws -> [ ( product : ResolvedProduct , targetBuildDescription : SwiftTargetBuildDescription ) ] {
1270
+ guard case . manifest ( let generate ) = buildParameters . testDiscoveryStrategy else {
1271
+ preconditionFailure ( " makeTestManifestTargets should not be used for build plan with useTestManifest set to false " )
1282
1272
}
1283
1273
1284
1274
var result : [ ( ResolvedProduct , SwiftTargetBuildDescription ) ] = [ ]
1285
-
1286
1275
for testProduct in graph. allProducts where testProduct. type == . test {
1287
- // Create the target description from the linux main if test discovery is off.
1288
- if !buildParameters. enableTestDiscovery {
1289
- guard let linuxMainTarget = testProduct. linuxMainTarget else {
1290
- throw Error . missingLinuxMain
1291
- }
1292
-
1276
+ // if test manifest exists, prefer that over test detection,
1277
+ // this is designed as an escape hatch when test discovery is not appropriate
1278
+ // and for backwards compatibility for projects that have existing test manifests (LinuxMain.swift)
1279
+ if let testManifestTarget = testProduct. testManifestTarget, !generate {
1293
1280
let desc = try SwiftTargetBuildDescription (
1294
- target: linuxMainTarget ,
1281
+ target: testManifestTarget ,
1295
1282
buildParameters: buildParameters,
1296
1283
isTestTarget: true
1297
1284
)
1298
1285
1299
1286
result. append ( ( testProduct, desc) )
1300
- continue
1301
- }
1302
-
1303
- // We'll generate sources containing the test names as part of the build process.
1304
- let derivedTestListDir = buildParameters. buildPath. appending ( components: " \( testProduct. name) Testlist.derived " )
1305
- let mainFile = derivedTestListDir. appending ( component: " main.swift " )
1306
-
1307
- var paths : [ AbsolutePath ] = [ ]
1308
- paths. append ( mainFile)
1309
- for testTarget in testProduct. targets {
1310
- let path = derivedTestListDir. appending ( components: testTarget. name + " .swift " )
1311
- paths. append ( path)
1312
- }
1287
+ } else {
1288
+ // We'll generate sources containing the test names as part of the build process.
1289
+ let derivedTestListDir = buildParameters. buildPath. appending ( components: " \( testProduct. name) .derived " )
1290
+ let mainFile = derivedTestListDir. appending ( component: " main.swift " )
1291
+
1292
+ var paths : [ AbsolutePath ] = [ ]
1293
+ paths. append ( mainFile)
1294
+ for testTarget in testProduct. targets {
1295
+ let path = derivedTestListDir. appending ( components: testTarget. name + " .swift " )
1296
+ paths. append ( path)
1297
+ }
1313
1298
1314
- let src = Sources ( paths: paths, root: derivedTestListDir)
1299
+ let src = Sources ( paths: paths, root: derivedTestListDir)
1315
1300
1316
- let swiftTarget = SwiftTarget (
1317
- testDiscoverySrc: src,
1318
- name: testProduct. name,
1319
- dependencies: testProduct. underlyingProduct. targets. map { . target( $0, conditions: [ ] ) }
1320
- )
1321
- let linuxMainTarget = ResolvedTarget (
1322
- target: swiftTarget,
1323
- dependencies: testProduct. targets. map { . target( $0, conditions: [ ] ) }
1324
- )
1301
+ let swiftTarget = SwiftTarget (
1302
+ testDiscoverySrc: src,
1303
+ name: testProduct. name,
1304
+ dependencies: testProduct. underlyingProduct. targets. map { . target( $0, conditions: [ ] ) }
1305
+ )
1306
+ let testManifestTarget = ResolvedTarget (
1307
+ target: swiftTarget,
1308
+ dependencies: testProduct. targets. map { . target( $0, conditions: [ ] ) }
1309
+ )
1325
1310
1326
- let target = try SwiftTargetBuildDescription (
1327
- target: linuxMainTarget ,
1328
- buildParameters: buildParameters,
1329
- isTestTarget: true ,
1330
- testDiscoveryTarget: true
1331
- )
1311
+ let target = try SwiftTargetBuildDescription (
1312
+ target: testManifestTarget ,
1313
+ buildParameters: buildParameters,
1314
+ isTestTarget: true ,
1315
+ testDiscoveryTarget: true
1316
+ )
1332
1317
1333
- result. append ( ( testProduct, target) )
1318
+ result. append ( ( testProduct, target) )
1319
+ }
1334
1320
}
1335
1321
return result
1336
1322
}
@@ -1389,11 +1375,13 @@ public class BuildPlan {
1389
1375
throw Diagnostics . fatalError
1390
1376
}
1391
1377
1392
- // Plan the linux main target.
1393
- let results = try Self . planLinuxMain ( buildParameters, graph)
1394
- for result in results {
1395
- targetMap [ result. 1 . target] = . swift( result. 1 )
1396
- linuxMainMap [ result. 0 ] = result. 1 . target
1378
+ // Plan the test manifest target.
1379
+ if case . manifest = buildParameters. testDiscoveryStrategy {
1380
+ let testManifestTargets = try Self . makeTestManifestTargets ( buildParameters, graph)
1381
+ for item in testManifestTargets {
1382
+ targetMap [ item. targetBuildDescription. target] = . swift( item. targetBuildDescription)
1383
+ testManifestTargetsMap [ item. product] = item. targetBuildDescription. target
1384
+ }
1397
1385
}
1398
1386
1399
1387
var productMap : [ ResolvedProduct : ProductBuildDescription ] = [ : ]
@@ -1413,7 +1401,7 @@ public class BuildPlan {
1413
1401
try plan ( )
1414
1402
}
1415
1403
1416
- private var linuxMainMap : [ ResolvedProduct : ResolvedTarget ] = [ : ]
1404
+ private var testManifestTargetsMap : [ ResolvedProduct : ResolvedTarget ] = [ : ]
1417
1405
1418
1406
static func validateDeploymentVersionOfProductDependency(
1419
1407
_ product: ResolvedProduct ,
@@ -1603,9 +1591,10 @@ public class BuildPlan {
1603
1591
}
1604
1592
}
1605
1593
1606
- if !buildParameters. triple. isDarwin ( ) {
1607
- if product. type == . test {
1608
- linuxMainMap [ product] . map { staticTargets. append ( $0) }
1594
+ // add test manifest targets
1595
+ if case . manifest = buildParameters. testDiscoveryStrategy {
1596
+ if product. type == . test, let testManifestTarget = testManifestTargetsMap [ product] {
1597
+ staticTargets. append ( testManifestTarget)
1609
1598
}
1610
1599
}
1611
1600
0 commit comments