@@ -236,11 +236,11 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
236
236
throw TestError . xcodeNotInstalled
237
237
}
238
238
239
- let buildParameters = try swiftCommandState. buildParametersForTest ( options: self . options, library: . xctest)
239
+ let ( productsBuildParameters , _ ) = try swiftCommandState. buildParametersForTest ( options: self . options, library: . xctest)
240
240
241
241
// Remove test output from prior runs and validate priors.
242
- if self . options. enableExperimentalTestOutput && buildParameters . triple. supportsTestSummary {
243
- _ = try ? localFileSystem. removeFileTree ( buildParameters . testOutputPath)
242
+ if self . options. enableExperimentalTestOutput && productsBuildParameters . triple. supportsTestSummary {
243
+ _ = try ? localFileSystem. removeFileTree ( productsBuildParameters . testOutputPath)
244
244
}
245
245
246
246
let testProducts = try buildTestsIfNeeded ( swiftCommandState: swiftCommandState, library: . xctest)
@@ -249,7 +249,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
249
249
try await runTestProducts (
250
250
testProducts,
251
251
additionalArguments: xctestArgs,
252
- buildParameters : buildParameters ,
252
+ productsBuildParameters : productsBuildParameters ,
253
253
swiftCommandState: swiftCommandState,
254
254
library: . xctest
255
255
)
@@ -276,7 +276,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
276
276
// Clean out the code coverage directory that may contain stale
277
277
// profraw files from a previous run of the code coverage tool.
278
278
if self . options. enableCodeCoverage {
279
- try swiftCommandState. fileSystem. removeFileTree ( buildParameters . codeCovPath)
279
+ try swiftCommandState. fileSystem. removeFileTree ( productsBuildParameters . codeCovPath)
280
280
}
281
281
282
282
// Run the tests using the parallel runner.
@@ -286,7 +286,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
286
286
toolchain: toolchain,
287
287
numJobs: options. numberOfWorkers ?? ProcessInfo . processInfo. activeProcessorCount,
288
288
buildOptions: globalOptions. build,
289
- buildParameters : buildParameters ,
289
+ productsBuildParameters : productsBuildParameters ,
290
290
shouldOutputSuccess: swiftCommandState. logLevel <= . info,
291
291
observabilityScope: swiftCommandState. observabilityScope
292
292
)
@@ -305,7 +305,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
305
305
}
306
306
307
307
if self . options. enableExperimentalTestOutput, !runner. ranSuccessfully {
308
- try Self . handleTestOutput ( buildParameters : buildParameters , packagePath: testProducts [ 0 ] . packagePath)
308
+ try Self . handleTestOutput ( productsBuildParameters : productsBuildParameters , packagePath: testProducts [ 0 ] . packagePath)
309
309
}
310
310
}
311
311
}
@@ -366,13 +366,13 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
366
366
// MARK: - swift-testing
367
367
368
368
private func swiftTestingRun( _ swiftCommandState: SwiftCommandState ) async throws {
369
- let buildParameters = try swiftCommandState. buildParametersForTest ( options: self . options, library: . swiftTesting)
369
+ let ( productsBuildParameters , _ ) = try swiftCommandState. buildParametersForTest ( options: self . options, library: . swiftTesting)
370
370
let testProducts = try buildTestsIfNeeded ( swiftCommandState: swiftCommandState, library: . swiftTesting)
371
371
let additionalArguments = Array ( CommandLine . arguments. dropFirst ( ) )
372
372
try await runTestProducts (
373
373
testProducts,
374
374
additionalArguments: additionalArguments,
375
- buildParameters : buildParameters ,
375
+ productsBuildParameters : productsBuildParameters ,
376
376
swiftCommandState: swiftCommandState,
377
377
library: . swiftTesting
378
378
)
@@ -408,20 +408,20 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
408
408
private func runTestProducts(
409
409
_ testProducts: [ BuiltTestProduct ] ,
410
410
additionalArguments: [ String ] ,
411
- buildParameters : BuildParameters ,
411
+ productsBuildParameters : BuildParameters ,
412
412
swiftCommandState: SwiftCommandState ,
413
413
library: BuildParameters . Testing . Library
414
414
) async throws {
415
415
// Clean out the code coverage directory that may contain stale
416
416
// profraw files from a previous run of the code coverage tool.
417
417
if self . options. enableCodeCoverage {
418
- try swiftCommandState. fileSystem. removeFileTree ( buildParameters . codeCovPath)
418
+ try swiftCommandState. fileSystem. removeFileTree ( productsBuildParameters . codeCovPath)
419
419
}
420
420
421
421
let toolchain = try swiftCommandState. getTargetToolchain ( )
422
422
let testEnv = try TestingSupport . constructTestEnvironment (
423
423
toolchain: toolchain,
424
- buildParameters : buildParameters ,
424
+ destinationBuildParameters : productsBuildParameters ,
425
425
sanitizers: globalOptions. build. sanitizers,
426
426
library: library
427
427
)
@@ -451,17 +451,17 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
451
451
}
452
452
453
453
if self . options. enableExperimentalTestOutput, !ranSuccessfully {
454
- try Self . handleTestOutput ( buildParameters : buildParameters , packagePath: testProducts [ 0 ] . packagePath)
454
+ try Self . handleTestOutput ( productsBuildParameters : productsBuildParameters , packagePath: testProducts [ 0 ] . packagePath)
455
455
}
456
456
}
457
457
458
- private static func handleTestOutput( buildParameters : BuildParameters , packagePath: AbsolutePath ) throws {
459
- guard localFileSystem. exists ( buildParameters . testOutputPath) else {
458
+ private static func handleTestOutput( productsBuildParameters : BuildParameters , packagePath: AbsolutePath ) throws {
459
+ guard localFileSystem. exists ( productsBuildParameters . testOutputPath) else {
460
460
print ( " No existing test output found. " )
461
461
return
462
462
}
463
463
464
- let lines = try String ( contentsOfFile: buildParameters . testOutputPath. pathString) . components ( separatedBy: " \n " )
464
+ let lines = try String ( contentsOfFile: productsBuildParameters . testOutputPath. pathString) . components ( separatedBy: " \n " )
465
465
let events = try lines. map { try JSONDecoder ( ) . decode ( TestEventRecord . self, from: $0) }
466
466
467
467
let caseEvents = events. compactMap { $0. caseEvent }
@@ -505,10 +505,10 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
505
505
// Merge all the profraw files to produce a single profdata file.
506
506
try mergeCodeCovRawDataFiles ( swiftCommandState: swiftCommandState, library: library)
507
507
508
- let buildParameters = try swiftCommandState. buildParametersForTest ( options: self . options, library: library)
508
+ let ( productsBuildParameters , _ ) = try swiftCommandState. buildParametersForTest ( options: self . options, library: library)
509
509
for product in testProducts {
510
510
// Export the codecov data as JSON.
511
- let jsonPath = buildParameters . codeCovAsJSONPath ( packageName: rootManifest. displayName)
511
+ let jsonPath = productsBuildParameters . codeCovAsJSONPath ( packageName: rootManifest. displayName)
512
512
try exportCodeCovAsJSON ( to: jsonPath, testBinary: product. binaryPath, swiftCommandState: swiftCommandState, library: library)
513
513
}
514
514
}
@@ -519,18 +519,18 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
519
519
let llvmProf = try swiftCommandState. getTargetToolchain ( ) . getLLVMProf ( )
520
520
521
521
// Get the profraw files.
522
- let buildParameters = try swiftCommandState. buildParametersForTest ( options: self . options, library: library)
523
- let codeCovFiles = try swiftCommandState. fileSystem. getDirectoryContents ( buildParameters . codeCovPath)
522
+ let ( productsBuildParameters , _ ) = try swiftCommandState. buildParametersForTest ( options: self . options, library: library)
523
+ let codeCovFiles = try swiftCommandState. fileSystem. getDirectoryContents ( productsBuildParameters . codeCovPath)
524
524
525
525
// Construct arguments for invoking the llvm-prof tool.
526
526
var args = [ llvmProf. pathString, " merge " , " -sparse " ]
527
527
for file in codeCovFiles {
528
- let filePath = buildParameters . codeCovPath. appending ( component: file)
528
+ let filePath = productsBuildParameters . codeCovPath. appending ( component: file)
529
529
if filePath. extension == " profraw " {
530
530
args. append ( filePath. pathString)
531
531
}
532
532
}
533
- args += [ " -o " , buildParameters . codeCovDataFile. pathString]
533
+ args += [ " -o " , productsBuildParameters . codeCovDataFile. pathString]
534
534
535
535
try TSCBasic . Process. checkNonZeroExit ( arguments: args)
536
536
}
@@ -544,11 +544,11 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
544
544
) throws {
545
545
// Export using the llvm-cov tool.
546
546
let llvmCov = try swiftCommandState. getTargetToolchain ( ) . getLLVMCov ( )
547
- let buildParameters = try swiftCommandState. buildParametersForTest ( options: self . options, library: library)
547
+ let ( productsBuildParameters , _ ) = try swiftCommandState. buildParametersForTest ( options: self . options, library: library)
548
548
let args = [
549
549
llvmCov. pathString,
550
550
" export " ,
551
- " -instr-profile= \( buildParameters . codeCovDataFile) " ,
551
+ " -instr-profile= \( productsBuildParameters . codeCovDataFile) " ,
552
552
testBinary. pathString
553
553
]
554
554
let result = try TSCBasic . Process. popen ( arguments: args)
@@ -567,10 +567,11 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
567
567
swiftCommandState: SwiftCommandState ,
568
568
library: BuildParameters . Testing . Library
569
569
) throws -> [ BuiltTestProduct ] {
570
- let buildParameters = try swiftCommandState. buildParametersForTest ( options: self . options, library: library)
570
+ let ( productsBuildParameters , toolsBuildParameters ) = try swiftCommandState. buildParametersForTest ( options: self . options, library: library)
571
571
return try Commands . buildTestsIfNeeded (
572
572
swiftCommandState: swiftCommandState,
573
- buildParameters: buildParameters,
573
+ productsBuildParameters: productsBuildParameters,
574
+ toolsBuildParameters: toolsBuildParameters,
574
575
testProduct: self . options. sharedOptions. testProduct
575
576
)
576
577
}
@@ -620,8 +621,8 @@ extension SwiftTestCommand {
620
621
guard let rootManifest = rootManifests. values. first else {
621
622
throw StringError ( " invalid manifests at \( root. packages) " )
622
623
}
623
- let buildParameters = try swiftCommandState. buildParametersForTest ( enableCodeCoverage: true , library: . xctest)
624
- print ( buildParameters . codeCovAsJSONPath ( packageName: rootManifest. displayName) )
624
+ let ( productsBuildParameters , _ ) = try swiftCommandState. buildParametersForTest ( enableCodeCoverage: true , library: . xctest)
625
+ print ( productsBuildParameters . codeCovAsJSONPath ( packageName: rootManifest. displayName) )
625
626
}
626
627
}
627
628
@@ -632,7 +633,7 @@ extension SwiftTestCommand {
632
633
633
634
func run( _ swiftCommandState: SwiftCommandState ) throws {
634
635
try SwiftTestCommand . handleTestOutput (
635
- buildParameters : try swiftCommandState. productsBuildParameters,
636
+ productsBuildParameters : try swiftCommandState. productsBuildParameters,
636
637
packagePath: localFileSystem. currentWorkingDirectory ?? . root // by definition runs in the current working directory
637
638
)
638
639
}
@@ -660,12 +661,16 @@ extension SwiftTestCommand {
660
661
// MARK: - XCTest
661
662
662
663
private func xctestRun( _ swiftCommandState: SwiftCommandState ) throws {
663
- let buildParameters = try swiftCommandState. buildParametersForTest (
664
+ let ( productsBuildParameters , toolsBuildParameters ) = try swiftCommandState. buildParametersForTest (
664
665
enableCodeCoverage: false ,
665
666
shouldSkipBuilding: sharedOptions. shouldSkipBuilding,
666
667
library: . xctest
667
668
)
668
- let testProducts = try buildTestsIfNeeded ( swiftCommandState: swiftCommandState, buildParameters: buildParameters)
669
+ let testProducts = try buildTestsIfNeeded (
670
+ swiftCommandState: swiftCommandState,
671
+ productsBuildParameters: productsBuildParameters,
672
+ toolsBuildParameters: toolsBuildParameters
673
+ )
669
674
let testSuites = try TestingSupport . getTestSuites (
670
675
in: testProducts,
671
676
swiftCommandState: swiftCommandState,
@@ -684,20 +689,21 @@ extension SwiftTestCommand {
684
689
// MARK: - swift-testing
685
690
686
691
private func swiftTestingRun( _ swiftCommandState: SwiftCommandState ) throws {
687
- let buildParameters = try swiftCommandState. buildParametersForTest (
692
+ let ( productsBuildParameters , toolsBuildParameters ) = try swiftCommandState. buildParametersForTest (
688
693
enableCodeCoverage: false ,
689
694
shouldSkipBuilding: sharedOptions. shouldSkipBuilding,
690
695
library: . swiftTesting
691
696
)
692
697
let testProducts = try buildTestsIfNeeded (
693
698
swiftCommandState: swiftCommandState,
694
- buildParameters: buildParameters
699
+ productsBuildParameters: productsBuildParameters,
700
+ toolsBuildParameters: toolsBuildParameters
695
701
)
696
702
697
703
let toolchain = try swiftCommandState. getTargetToolchain ( )
698
704
let testEnv = try TestingSupport . constructTestEnvironment (
699
705
toolchain: toolchain,
700
- buildParameters : buildParameters ,
706
+ destinationBuildParameters : productsBuildParameters ,
701
707
sanitizers: globalOptions. build. sanitizers,
702
708
library: . swiftTesting
703
709
)
@@ -737,11 +743,13 @@ extension SwiftTestCommand {
737
743
738
744
private func buildTestsIfNeeded(
739
745
swiftCommandState: SwiftCommandState ,
740
- buildParameters: BuildParameters
746
+ productsBuildParameters: BuildParameters ,
747
+ toolsBuildParameters: BuildParameters
741
748
) throws -> [ BuiltTestProduct ] {
742
749
return try Commands . buildTestsIfNeeded (
743
750
swiftCommandState: swiftCommandState,
744
- buildParameters: buildParameters,
751
+ productsBuildParameters: productsBuildParameters,
752
+ toolsBuildParameters: toolsBuildParameters,
745
753
testProduct: self . sharedOptions. testProduct
746
754
)
747
755
}
@@ -934,7 +942,7 @@ final class ParallelTestRunner {
934
942
private let toolchain : UserToolchain
935
943
936
944
private let buildOptions : BuildOptions
937
- private let buildParameters : BuildParameters
945
+ private let productsBuildParameters : BuildParameters
938
946
939
947
/// Number of tests to execute in parallel.
940
948
private let numJobs : Int
@@ -951,7 +959,7 @@ final class ParallelTestRunner {
951
959
toolchain: UserToolchain ,
952
960
numJobs: Int ,
953
961
buildOptions: BuildOptions ,
954
- buildParameters : BuildParameters ,
962
+ productsBuildParameters : BuildParameters ,
955
963
shouldOutputSuccess: Bool ,
956
964
observabilityScope: ObservabilityScope
957
965
) {
@@ -978,7 +986,7 @@ final class ParallelTestRunner {
978
986
}
979
987
980
988
self . buildOptions = buildOptions
981
- self . buildParameters = buildParameters
989
+ self . productsBuildParameters = productsBuildParameters
982
990
983
991
assert ( numJobs > 0 , " num jobs should be > 0 " )
984
992
}
@@ -1008,7 +1016,7 @@ final class ParallelTestRunner {
1008
1016
1009
1017
let testEnv = try TestingSupport . constructTestEnvironment (
1010
1018
toolchain: self . toolchain,
1011
- buildParameters : self . buildParameters ,
1019
+ destinationBuildParameters : self . productsBuildParameters ,
1012
1020
sanitizers: self . buildOptions. sanitizers,
1013
1021
library: . xctest // swift-testing does not use ParallelTestRunner
1014
1022
)
@@ -1076,7 +1084,7 @@ final class ParallelTestRunner {
1076
1084
1077
1085
// Print test results.
1078
1086
for test in processedTests. get ( ) {
1079
- if ( !test. success || shouldOutputSuccess) && !buildParameters . testingParameters. experimentalTestOutput {
1087
+ if ( !test. success || shouldOutputSuccess) && !productsBuildParameters . testingParameters. experimentalTestOutput {
1080
1088
// command's result output goes on stdout
1081
1089
// ie "swift test" should output to stdout
1082
1090
print ( test. output)
@@ -1295,7 +1303,7 @@ extension SwiftCommandState {
1295
1303
func buildParametersForTest(
1296
1304
options: TestCommandOptions ,
1297
1305
library: BuildParameters . Testing . Library
1298
- ) throws -> BuildParameters {
1306
+ ) throws -> ( productsBuildParameters : BuildParameters , toolsBuildParameters : BuildParameters ) {
1299
1307
var result = try self . buildParametersForTest (
1300
1308
enableCodeCoverage: options. enableCodeCoverage,
1301
1309
enableTestability: options. enableTestableImports,
@@ -1304,7 +1312,8 @@ extension SwiftCommandState {
1304
1312
library: library
1305
1313
)
1306
1314
if try options. testLibraryOptions. enableSwiftTestingLibrarySupport ( swiftCommandState: self ) {
1307
- result. flags. swiftCompilerFlags += [ " -DSWIFT_PM_SUPPORTS_SWIFT_TESTING " ]
1315
+ result. productsBuildParameters. flags. swiftCompilerFlags += [ " -DSWIFT_PM_SUPPORTS_SWIFT_TESTING " ]
1316
+ result. toolsBuildParameters. flags. swiftCompilerFlags += [ " -DSWIFT_PM_SUPPORTS_SWIFT_TESTING " ]
1308
1317
}
1309
1318
return result
1310
1319
}
@@ -1364,10 +1373,14 @@ private extension Basics.Diagnostic {
1364
1373
/// - Returns: The paths to the build test products.
1365
1374
private func buildTestsIfNeeded(
1366
1375
swiftCommandState: SwiftCommandState ,
1367
- buildParameters: BuildParameters ,
1376
+ productsBuildParameters: BuildParameters ,
1377
+ toolsBuildParameters: BuildParameters ,
1368
1378
testProduct: String ?
1369
1379
) throws -> [ BuiltTestProduct ] {
1370
- let buildSystem = try swiftCommandState. createBuildSystem ( productsBuildParameters: buildParameters)
1380
+ let buildSystem = try swiftCommandState. createBuildSystem (
1381
+ productsBuildParameters: productsBuildParameters,
1382
+ toolsBuildParameters: toolsBuildParameters
1383
+ )
1371
1384
1372
1385
let subset = testProduct. map ( BuildSubset . product) ?? . allIncludingTests
1373
1386
try buildSystem. build ( subset: subset)
0 commit comments