@@ -38,7 +38,6 @@ export class TestingDebugConfigurationFactory {
38
38
fifoPipePath : string ,
39
39
testKind : TestKind ,
40
40
testList : string [ ] ,
41
- buildStartTime : Date ,
42
41
expandEnvVariables = false
43
42
) : Promise < vscode . DebugConfiguration | null > {
44
43
return new TestingDebugConfigurationFactory (
@@ -47,7 +46,6 @@ export class TestingDebugConfigurationFactory {
47
46
testKind ,
48
47
TestLibrary . swiftTesting ,
49
48
testList ,
50
- buildStartTime ,
51
49
expandEnvVariables
52
50
) . build ( ) ;
53
51
}
@@ -64,7 +62,6 @@ export class TestingDebugConfigurationFactory {
64
62
testKind ,
65
63
TestLibrary . xctest ,
66
64
testList ,
67
- null ,
68
65
expandEnvVariables
69
66
) . build ( ) ;
70
67
}
@@ -80,7 +77,6 @@ export class TestingDebugConfigurationFactory {
80
77
testKind ,
81
78
testLibrary ,
82
79
[ ] ,
83
- null ,
84
80
true
85
81
) . testExecutableOutputPath ( ) ;
86
82
}
@@ -91,7 +87,6 @@ export class TestingDebugConfigurationFactory {
91
87
private testKind : TestKind ,
92
88
private testLibrary : TestLibrary ,
93
89
private testList : string [ ] ,
94
- private buildStartTime : Date | null ,
95
90
private expandEnvVariables = false
96
91
) { }
97
92
@@ -454,23 +449,33 @@ export class TestingDebugConfigurationFactory {
454
449
) ;
455
450
}
456
451
452
+ private buildDescriptionPath ( ) : string {
453
+ return path . join ( this . buildDirectory , this . artifactFolderForTestKind , "description.json" ) ;
454
+ }
455
+
457
456
private async isUnifiedTestingBinary ( ) : Promise < boolean > {
458
457
// Toolchains that contain https://github.com/swiftlang/swift-package-manager/commit/844bd137070dcd18d0f46dd95885ef7907ea0697
459
458
// no longer produce a .swift-testing binary, instead we want to use `unifiedTestingOutputPath`.
460
459
// In order to determine if we're working with a unified binary we need to check if the .swift-testing
461
- // binary _doesn't_ exist, and if it does exist we need to check that it wasn't built by an old toolchain
462
- // and is still in the .build directory. We do this by checking its mtime and seeing if it is after
463
- // the `buildStartTime`.
460
+ // binary was produced by the latest build. If it was then we are not using a unified binary.
464
461
465
462
// TODO: When Swift 6 is released and enough time has passed that we're sure no one is building the .swift-testing
466
- // binary anymore this fs.stat workaround can be removed and `swiftTestingPath` can be returned. The
467
- // `buildStartTime` argument can be removed and the build config generation can be made synchronous again.
463
+ // binary anymore this workaround can be removed and `swiftTestingPath` can be returned, and the build config
464
+ // generation can be made synchronous again.
468
465
469
466
try {
470
- const stat = await fs . stat ( this . swiftTestingOutputPath ( ) ) ;
471
- return ! this . buildStartTime || stat . mtime . getTime ( ) < this . buildStartTime . getTime ( ) ;
467
+ const buildDescriptionStr = await fs . readFile ( this . buildDescriptionPath ( ) , "utf-8" ) ;
468
+ const buildDescription = JSON . parse ( buildDescriptionStr ) ;
469
+ const testProducts = buildDescription . builtTestProducts as { binaryPath : string } [ ] ;
470
+ if ( ! testProducts ) {
471
+ return false ;
472
+ }
473
+ const testBinaryPaths = testProducts . map ( ( { binaryPath } ) => binaryPath ) ;
474
+ const swiftTestingBinaryRealPath = await fs . realpath ( this . swiftTestingOutputPath ( ) ) ;
475
+ return ! testBinaryPaths . includes ( swiftTestingBinaryRealPath ) ;
472
476
} catch {
473
- // If the .swift-testing binary doesn't exist then swift-testing tests are in the unified binary.
477
+ // If the .swift-testing binary wasn't produced by the latest build then we assume the
478
+ // swift-testing tests are in the unified binary.
474
479
return true ;
475
480
}
476
481
}
0 commit comments