Skip to content

Commit d4e166a

Browse files
committed
Drop support for Swift 5.8
Clean up several legacy conditions for Swift 5.8 and drop support.
1 parent afc3471 commit d4e166a

File tree

9 files changed

+8
-130
lines changed

9 files changed

+8
-130
lines changed

src/TestExplorer/TestExplorer.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,8 @@ export class TestExplorer {
343343
return;
344344
}
345345

346-
// get list of tests from `swift test --list-tests`
347-
let listTestArguments: string[];
348-
if (toolchain.swiftVersion.isGreaterThanOrEqual(new Version(5, 8, 0))) {
349-
listTestArguments = ["test", "list", "--skip-build"];
350-
} else {
351-
listTestArguments = ["test", "--list-tests", "--skip-build"];
352-
}
346+
// get list of tests from `swift test list --skip-build`
347+
let listTestArguments: string[] = ["test", "list", "--skip-build"];
353348
listTestArguments = [...listTestArguments, ...testBuildOptions];
354349
const listTestsOperation = new SwiftExecOperation(
355350
listTestArguments,

src/commands/createNewProject.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { SwiftProjectTemplate, SwiftToolchain } from "../toolchain/toolchain";
1919
import { showToolchainError } from "../ui/ToolchainSelection";
2020
import { withDelayedProgress } from "../ui/withDelayedProgress";
2121
import { execSwift } from "../utilities/utilities";
22-
import { Version } from "../utilities/version";
2322

2423
/**
2524
* Prompts the user to input project details and then executes `swift package init`
@@ -34,16 +33,6 @@ export async function createNewProject(toolchain: SwiftToolchain | undefined): P
3433
return;
3534
}
3635

37-
// The context key `swift.createNewProjectAvailable` only works if the extension has been
38-
// activated. As such, we also have to allow this command to run when no workspace is
39-
// active. Show an error to the user if the command is unavailable.
40-
if (!toolchain.swiftVersion.isGreaterThanOrEqual(new Version(5, 8, 0))) {
41-
void vscode.window.showErrorMessage(
42-
"Creating a new swift project is only available starting in swift version 5.8.0."
43-
);
44-
return;
45-
}
46-
4736
// Prompt the user for the type of project they would like to create
4837
const availableProjectTemplates = await toolchain.getProjectTemplates();
4938
const selectedProjectTemplate = await vscode.window.showQuickPick<

src/contextKeys.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ export function createContextKeys(): ContextKeys {
113113

114114
return {
115115
updateKeysBasedOnActiveVersion(toolchainVersion: Version) {
116-
this.createNewProjectAvailable = toolchainVersion.isGreaterThanOrEqual(
117-
new Version(5, 8, 0)
118-
);
116+
this.createNewProjectAvailable = true;
119117
this.switchPlatformAvailable =
120118
process.platform === "darwin"
121119
? toolchainVersion.isGreaterThanOrEqual(new Version(6, 1, 0))

src/debugger/buildConfig.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
import * as fs from "fs/promises";
15-
import * as os from "os";
1615
import * as path from "path";
1716
import * as vscode from "vscode";
1817

@@ -79,10 +78,6 @@ export class BuildConfigurationFactory {
7978

8079
/** flag for enabling test discovery */
8180
private testDiscoveryFlag(ctx: FolderContext): string[] {
82-
// Test discovery is only available in SwiftPM 5.1 and later.
83-
if (ctx.swiftVersion.isLessThan(new Version(5, 1, 0))) {
84-
return [];
85-
}
8681
// Test discovery is always enabled on Darwin.
8782
if (process.platform !== "darwin") {
8883
const hasLinuxMain = ctx.linuxMain.exists;
@@ -427,17 +422,6 @@ export class TestingConfigurationFactory {
427422
},
428423
};
429424
default:
430-
const swiftVersion = this.ctx.toolchain.swiftVersion;
431-
if (
432-
swiftVersion.isLessThan(new Version(5, 7, 0)) &&
433-
swiftVersion.isGreaterThanOrEqual(new Version(5, 6, 0)) &&
434-
process.platform === "darwin"
435-
) {
436-
// if debugging on macOS with Swift 5.6 we need to create a custom launch
437-
// configuration so we can set the system architecture
438-
return await this.createDarwin56TestConfiguration();
439-
}
440-
441425
let xcTestArgs = [
442426
"test",
443427
...(this.testKind === TestKind.coverage
@@ -477,60 +461,6 @@ export class TestingConfigurationFactory {
477461
}
478462
/* eslint-enable no-case-declarations */
479463

480-
/**
481-
* Return custom Darwin test configuration that works with Swift 5.6
482-
**/
483-
private async createDarwin56TestConfiguration(): Promise<vscode.DebugConfiguration | null> {
484-
if ((await this.ctx.swiftPackage.getTargets(TargetType.test)).length === 0) {
485-
return null;
486-
}
487-
488-
let testFilterArg: string;
489-
const testList = this.testList.join(",");
490-
if (testList.length > 0) {
491-
testFilterArg = `-XCTest ${testList}`;
492-
} else {
493-
testFilterArg = "";
494-
}
495-
496-
const { folder, nameSuffix } = getFolderAndNameSuffix(this.ctx, true);
497-
// On macOS, find the path to xctest
498-
// and point it at the .xctest bundle from the configured build directory.
499-
const xctestPath = this.ctx.toolchain.xcTestPath;
500-
if (xctestPath === undefined) {
501-
return null;
502-
}
503-
let arch: string;
504-
switch (os.arch()) {
505-
case "x64":
506-
arch = "x86_64";
507-
break;
508-
case "arm64":
509-
arch = "arm64e";
510-
break;
511-
default:
512-
return null;
513-
}
514-
const sanitizer = this.ctx.toolchain.sanitizer(configuration.sanitizer);
515-
const envCommands = Object.entries({
516-
...swiftRuntimeEnv(),
517-
...configuration.folder(this.ctx.workspaceFolder).testEnvironmentVariables,
518-
...sanitizer?.runtimeEnvironment,
519-
}).map(([key, value]) => `settings set target.env-vars ${key}="${value}"`);
520-
521-
return {
522-
type: SWIFT_LAUNCH_CONFIG_TYPE,
523-
request: "custom",
524-
name: `Test ${await this.ctx.swiftPackage.name}`,
525-
targetCreateCommands: [`file -a ${arch} ${xctestPath}/xctest`],
526-
processCreateCommands: [
527-
...envCommands,
528-
`process launch -w ${folder} -- ${testFilterArg} ${this.xcTestOutputPath()}`,
529-
],
530-
preLaunchTask: `swift: Build All${nameSuffix}`,
531-
};
532-
}
533-
534464
private addSwiftTestingFlagsArgs(args: string[]): string[] {
535465
if (!this.swiftTestingArguments) {
536466
throw new Error(

src/sourcekit-lsp/LanguageClientManager.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import { SourceKitLogMessageNotification, SourceKitLogMessageParams } from "./ex
4040
import { DidChangeActiveDocumentNotification } from "./extensions/DidChangeActiveDocumentRequest";
4141
import { PollIndexRequest, WorkspaceSynchronizeRequest } from "./extensions/PollIndexRequest";
4242
import { activateGetReferenceDocument } from "./getReferenceDocument";
43-
import { activateLegacyInlayHints } from "./inlayHints";
4443
import { activatePeekDocuments } from "./peekDocuments";
4544

4645
interface LanguageClientManageOptions {
@@ -165,21 +164,6 @@ export class LanguageClientManager implements vscode.Disposable {
165164

166165
this.subscriptions.push(onChangeConfig);
167166

168-
// Swift versions prior to 5.6 don't support file changes, so need to restart
169-
// lSP server when a file is either created or deleted
170-
if (this.swiftVersion.isLessThan(new Version(5, 6, 0))) {
171-
folderContext.workspaceContext.logger.debug("LSP: Adding new/delete file handlers");
172-
// restart LSP server on creation of a new file
173-
const onDidCreateFileDisposable = vscode.workspace.onDidCreateFiles(() => {
174-
void this.restart();
175-
});
176-
// restart LSP server on deletion of a file
177-
const onDidDeleteFileDisposable = vscode.workspace.onDidDeleteFiles(() => {
178-
void this.restart();
179-
});
180-
this.subscriptions.push(onDidCreateFileDisposable, onDidDeleteFileDisposable);
181-
}
182-
183167
this.waitingOnRestartCount = 0;
184168
this.documentSymbolWatcher = undefined;
185169
this.cancellationToken = new vscode.CancellationTokenSource();
@@ -526,10 +510,6 @@ export class LanguageClientManager implements vscode.Disposable {
526510
// if sourcekit-lsp crashes during normal operation.
527511
errorHandler.enable();
528512

529-
if (this.swiftVersion.isLessThan(new Version(5, 7, 0))) {
530-
this.legacyInlayHints = activateLegacyInlayHints(client);
531-
}
532-
533513
this.peekDocuments = activatePeekDocuments(client);
534514
this.getReferenceDocument = activateGetReferenceDocument(client);
535515
this.subscriptions.push(this.getReferenceDocument);

src/toolchain/BuildFlags.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import * as path from "path";
1616
import configuration from "../configuration";
1717
import { SwiftLogger } from "../logging/SwiftLogger";
1818
import { execSwift } from "../utilities/utilities";
19-
import { Version } from "../utilities/version";
2019
import { DarwinCompatibleTarget, SwiftToolchain, getDarwinTargetTriple } from "./toolchain";
2120

2221
/** Target info */
@@ -111,11 +110,7 @@ export class BuildFlags {
111110
*/
112111
buildPathFlags(): string[] {
113112
if (configuration.buildPath && configuration.buildPath.length > 0) {
114-
if (this.toolchain.swiftVersion.isLessThan(new Version(5, 8, 0))) {
115-
return ["--build-path", configuration.buildPath];
116-
} else {
117-
return ["--scratch-path", configuration.buildPath];
118-
}
113+
return ["--scratch-path", configuration.buildPath];
119114
} else {
120115
return [];
121116
}

src/toolchain/toolchain.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,6 @@ export class SwiftToolchain {
307307
* @returns a {@link SwiftProjectTemplate} for each discovered project type
308308
*/
309309
public async getProjectTemplates(): Promise<SwiftProjectTemplate[]> {
310-
// Only swift versions >=5.8.0 are supported
311-
if (this.swiftVersion.isLessThan(new Version(5, 8, 0))) {
312-
return [];
313-
}
314310
// Parse the output from `swift package init --help`
315311
const { stdout } = await execSwift(["package", "init", "--help"], "default");
316312
const lines = stdout.split(/\r?\n/g);

test/integration-tests/WorkspaceContext.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,6 @@ tag("medium").suite("WorkspaceContext Test Suite", () => {
199199
});
200200

201201
tag("small").test("get project templates", async () => {
202-
// This is only supported in swift versions >=5.8.0
203-
const swiftVersion = workspaceContext.globalToolchain.swiftVersion;
204-
if (swiftVersion.isLessThan(new Version(5, 8, 0))) {
205-
assert.deepEqual(await workspaceContext.globalToolchain.getProjectTemplates(), []);
206-
return;
207-
}
208202
// The output of `swift package init --help` will probably change at some point.
209203
// Just make sure that the most complex portions of the output are parsed correctly.
210204
const projectTemplates = await workspaceContext.globalToolchain.getProjectTemplates();
@@ -218,6 +212,7 @@ tag("medium").suite("WorkspaceContext Test Suite", () => {
218212
"A package with an executable that uses Swift Argument Parser. Use this template if you plan to have a rich set of command-line arguments.",
219213
});
220214
// build-tool-plugin is only available in swift versions >=5.9.0
215+
const swiftVersion = workspaceContext.globalToolchain.swiftVersion;
221216
if (swiftVersion.isLessThan(new Version(5, 9, 0))) {
222217
return;
223218
}

test/unit-tests/toolchain/BuildFlags.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ suite("BuildFlags Test Suite", () => {
191191
]);
192192
});
193193

194-
test("configuration provided, before swift 5.8", () => {
195-
mockedToolchain.swiftVersion = new Version(5, 7, 0);
194+
test("configuration provided", () => {
195+
mockedToolchain.swiftVersion = new Version(5, 9, 0);
196196
buildPathConfig.setValue("/some/other/full/test/path");
197197
expect(buildFlags.buildPathFlags()).to.deep.equal([
198-
"--build-path",
198+
"--scratch-path",
199199
"/some/other/full/test/path",
200200
]);
201201
});

0 commit comments

Comments
 (0)