15
15
import * as os from "os" ;
16
16
import * as path from "path" ;
17
17
import * as vscode from "vscode" ;
18
- import * as fs from "fs/promises" ;
19
18
import configuration from "../configuration" ;
20
19
import { FolderContext } from "../FolderContext" ;
21
20
import { BuildFlags } from "../toolchain/BuildFlags" ;
@@ -104,13 +103,13 @@ export class BuildConfigurationFactory {
104
103
* and `xcTestConfig` functions to create
105
104
*/
106
105
export class TestingConfigurationFactory {
107
- public static async swiftTestingConfig (
106
+ public static swiftTestingConfig (
108
107
ctx : FolderContext ,
109
108
fifoPipePath : string ,
110
109
testKind : TestKind ,
111
110
testList : string [ ] ,
112
111
expandEnvVariables = false
113
- ) : Promise < vscode . DebugConfiguration | null > {
112
+ ) : vscode . DebugConfiguration | null {
114
113
return new TestingConfigurationFactory (
115
114
ctx ,
116
115
fifoPipePath ,
@@ -121,12 +120,12 @@ export class TestingConfigurationFactory {
121
120
) . build ( ) ;
122
121
}
123
122
124
- public static async xcTestConfig (
123
+ public static xcTestConfig (
125
124
ctx : FolderContext ,
126
125
testKind : TestKind ,
127
126
testList : string [ ] ,
128
127
expandEnvVariables = false
129
- ) : Promise < vscode . DebugConfiguration | null > {
128
+ ) : vscode . DebugConfiguration | null {
130
129
return new TestingConfigurationFactory (
131
130
ctx ,
132
131
"" ,
@@ -137,11 +136,11 @@ export class TestingConfigurationFactory {
137
136
) . build ( ) ;
138
137
}
139
138
140
- public static async testExecutableOutputPath (
139
+ public static testExecutableOutputPath (
141
140
ctx : FolderContext ,
142
141
testKind : TestKind ,
143
142
testLibrary : TestLibrary
144
- ) : Promise < string > {
143
+ ) : string {
145
144
return new TestingConfigurationFactory (
146
145
ctx ,
147
146
"" ,
@@ -169,7 +168,7 @@ export class TestingConfigurationFactory {
169
168
* - Test Kind (coverage, debugging)
170
169
* - Test Library (XCTest, swift-testing)
171
170
*/
172
- private async build ( ) : Promise < vscode . DebugConfiguration | null > {
171
+ private build ( ) : vscode . DebugConfiguration | null {
173
172
if ( ! this . hasTestTarget ) {
174
173
return null ;
175
174
}
@@ -185,7 +184,7 @@ export class TestingConfigurationFactory {
185
184
}
186
185
187
186
/* eslint-disable no-case-declarations */
188
- private async buildWindowsConfig ( ) : Promise < vscode . DebugConfiguration | null > {
187
+ private buildWindowsConfig ( ) : vscode . DebugConfiguration | null {
189
188
if ( isDebugging ( this . testKind ) ) {
190
189
const testEnv = {
191
190
...swiftRuntimeEnv ( ) ,
@@ -201,8 +200,8 @@ export class TestingConfigurationFactory {
201
200
202
201
return {
203
202
...this . baseConfig ,
204
- program : await this . testExecutableOutputPath ( ) ,
205
- args : await this . debuggingTestExecutableArgs ( ) ,
203
+ program : this . testExecutableOutputPath ( ) ,
204
+ args : this . debuggingTestExecutableArgs ( ) ,
206
205
env : testEnv ,
207
206
} ;
208
207
} else {
@@ -211,23 +210,23 @@ export class TestingConfigurationFactory {
211
210
}
212
211
213
212
/* eslint-disable no-case-declarations */
214
- private async buildLinuxConfig ( ) : Promise < vscode . DebugConfiguration | null > {
213
+ private buildLinuxConfig ( ) : vscode . DebugConfiguration | null {
215
214
if ( isDebugging ( this . testKind ) && this . testLibrary === TestLibrary . xctest ) {
216
215
return {
217
216
...this . baseConfig ,
218
- program : await this . testExecutableOutputPath ( ) ,
219
- args : await this . debuggingTestExecutableArgs ( ) ,
217
+ program : this . testExecutableOutputPath ( ) ,
218
+ args : this . debuggingTestExecutableArgs ( ) ,
220
219
env : {
221
220
...swiftRuntimeEnv ( ) ,
222
221
...configuration . folder ( this . ctx . workspaceFolder ) . testEnvironmentVariables ,
223
222
} ,
224
223
} ;
225
224
} else {
226
- return await this . buildDarwinConfig ( ) ;
225
+ return this . buildDarwinConfig ( ) ;
227
226
}
228
227
}
229
228
230
- private async buildDarwinConfig ( ) : Promise < vscode . DebugConfiguration | null > {
229
+ private buildDarwinConfig ( ) : vscode . DebugConfiguration | null {
231
230
switch ( this . testLibrary ) {
232
231
case TestLibrary . swiftTesting :
233
232
switch ( this . testKind ) {
@@ -272,8 +271,8 @@ export class TestingConfigurationFactory {
272
271
273
272
const result = {
274
273
...this . baseConfig ,
275
- program : await this . testExecutableOutputPath ( ) ,
276
- args : await this . debuggingTestExecutableArgs ( ) ,
274
+ program : this . testExecutableOutputPath ( ) ,
275
+ args : this . debuggingTestExecutableArgs ( ) ,
277
276
env : {
278
277
...this . testEnv ,
279
278
...this . sanitizerRuntimeEnvironment ,
@@ -519,45 +518,6 @@ export class TestingConfigurationFactory {
519
518
) ;
520
519
}
521
520
522
- private swiftTestingOutputPath ( ) : string {
523
- return path . join (
524
- this . buildDirectory ,
525
- this . artifactFolderForTestKind ,
526
- `${ this . ctx . swiftPackage . name } PackageTests.swift-testing`
527
- ) ;
528
- }
529
-
530
- private buildDescriptionPath ( ) : string {
531
- return path . join ( this . buildDirectory , this . artifactFolderForTestKind , "description.json" ) ;
532
- }
533
-
534
- private async isUnifiedTestingBinary ( ) : Promise < boolean > {
535
- // Toolchains that contain https://github.com/swiftlang/swift-package-manager/commit/844bd137070dcd18d0f46dd95885ef7907ea0697
536
- // no longer produce a .swift-testing binary, instead we want to use `unifiedTestingOutputPath`.
537
- // In order to determine if we're working with a unified binary we need to check if the .swift-testing
538
- // binary was produced by the latest build. If it was then we are not using a unified binary.
539
-
540
- // TODO: When Swift 6 is released and enough time has passed that we're sure no one is building the .swift-testing
541
- // binary anymore this workaround can be removed and `swiftTestingPath` can be returned, and the build config
542
- // generation can be made synchronous again.
543
-
544
- try {
545
- const buildDescriptionStr = await fs . readFile ( this . buildDescriptionPath ( ) , "utf-8" ) ;
546
- const buildDescription = JSON . parse ( buildDescriptionStr ) ;
547
- const testProducts = buildDescription . builtTestProducts as { binaryPath : string } [ ] ;
548
- if ( ! testProducts ) {
549
- return false ;
550
- }
551
- const testBinaryPaths = testProducts . map ( ( { binaryPath } ) => binaryPath ) ;
552
- const swiftTestingBinaryRealPath = await fs . realpath ( this . swiftTestingOutputPath ( ) ) ;
553
- return ! testBinaryPaths . includes ( swiftTestingBinaryRealPath ) ;
554
- } catch {
555
- // If the .swift-testing binary wasn't produced by the latest build then we assume the
556
- // swift-testing tests are in the unified binary.
557
- return true ;
558
- }
559
- }
560
-
561
521
private unifiedTestingOutputPath ( ) : string {
562
522
// The unified binary that contains both swift-testing and XCTests
563
523
// is named the same as the old style .xctest binary. The swiftpm-testing-helper
@@ -574,24 +534,19 @@ export class TestingConfigurationFactory {
574
534
}
575
535
}
576
536
577
- private async testExecutableOutputPath ( ) : Promise < string > {
537
+ private testExecutableOutputPath ( ) : string {
578
538
switch ( this . testLibrary ) {
579
539
case TestLibrary . swiftTesting :
580
- return ( await this . isUnifiedTestingBinary ( ) )
581
- ? this . unifiedTestingOutputPath ( )
582
- : this . swiftTestingOutputPath ( ) ;
540
+ return this . unifiedTestingOutputPath ( ) ;
583
541
case TestLibrary . xctest :
584
542
return this . xcTestOutputPath ( ) ;
585
543
}
586
544
}
587
545
588
- private async debuggingTestExecutableArgs ( ) : Promise < string [ ] > {
546
+ private debuggingTestExecutableArgs ( ) : string [ ] {
589
547
switch ( this . testLibrary ) {
590
548
case TestLibrary . swiftTesting : {
591
- const isUnifiedBinary = await this . isUnifiedTestingBinary ( ) ;
592
- const swiftTestingArgs = isUnifiedBinary
593
- ? [ "--testing-library" , "swift-testing" ]
594
- : [ ] ;
549
+ const swiftTestingArgs = [ "--testing-library" , "swift-testing" ] ;
595
550
596
551
return this . addBuildOptionsToArgs (
597
552
this . addTestsToArgs ( this . addSwiftTestingFlagsArgs ( swiftTestingArgs ) )
0 commit comments