Skip to content

Commit f681d3f

Browse files
committed
Add swift.packageArguments setting
Adds a new setting to provide arguments to swift commands that can resolve packages. This applies to `swift package resolve`, `swift package update`, `swift build` and `swift test`. This lets users set package resolution specific flags that should be used whenever resolution is performed, such as `--replace-scm-with-registry`. Issue: #1340
1 parent 95a6e43 commit f681d3f

File tree

7 files changed

+36
-5
lines changed

7 files changed

+36
-5
lines changed

Diff for: package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,15 @@
271271
"items": {
272272
"type": "string"
273273
},
274-
"markdownDescription": "Additional arguments to pass to `swift` commands such as `swift build`, `swift package`, `swift test`, etc... Keys and values should be provided as individual entries in the list. If you have created a copy of the build task in `tasks.json` then these build arguments will not be propagated to that task."
274+
"markdownDescription": "Additional arguments to pass to `swift build` and `swift test`. Keys and values should be provided as individual entries in the list. If you have created a copy of the build task in `tasks.json` then these build arguments will not be propagated to that task."
275+
},
276+
"swift.packageArguments": {
277+
"type": "array",
278+
"default": [],
279+
"items": {
280+
"type": "string"
281+
},
282+
"markdownDescription": "Additional arguments to pass to swift commands that do package resolution, such as `swift package resolve`, `swift package update`, `swift build` and `swift test`. Keys and values should be provided as individual entries in the list. If you have created a copy of the build task in `tasks.json` then these build arguments will not be propagated to that task."
275283
},
276284
"swift.additionalTestArguments": {
277285
"type": "array",
@@ -1439,4 +1447,4 @@
14391447
"vscode-languageclient": "^9.0.1",
14401448
"xml2js": "^0.6.2"
14411449
}
1442-
}
1450+
}

Diff for: src/commands/dependencies/resolve.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { FolderContext } from "../../FolderContext";
1717
import { createSwiftTask, SwiftTaskProvider } from "../../tasks/SwiftTaskProvider";
1818
import { WorkspaceContext } from "../../WorkspaceContext";
1919
import { executeTaskWithUI, updateAfterError } from "../utilities";
20+
import configuration from "../../configuration";
2021

2122
/**
2223
* Executes a {@link vscode.Task task} to resolve this package's dependencies.
@@ -39,7 +40,7 @@ export async function resolveFolderDependencies(
3940
checkAlreadyRunning?: boolean
4041
) {
4142
const task = createSwiftTask(
42-
["package", "resolve"],
43+
["package", "resolve", ...configuration.packageArguments],
4344
SwiftTaskProvider.resolvePackageName,
4445
{
4546
cwd: folderContext.folder,

Diff for: src/commands/dependencies/update.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { FolderContext } from "../../FolderContext";
1717
import { WorkspaceContext } from "../../WorkspaceContext";
1818
import { createSwiftTask, SwiftTaskProvider } from "../../tasks/SwiftTaskProvider";
1919
import { executeTaskWithUI, updateAfterError } from "./../utilities";
20+
import configuration from "../../configuration";
2021

2122
/**
2223
* Executes a {@link vscode.Task task} to update this package's dependencies.
@@ -36,7 +37,7 @@ export async function updateDependencies(ctx: WorkspaceContext) {
3637
*/
3738
export async function updateFolderDependencies(folderContext: FolderContext) {
3839
const task = createSwiftTask(
39-
["package", "update"],
40+
["package", "update", ...configuration.packageArguments],
4041
SwiftTaskProvider.updatePackageName,
4142
{
4243
cwd: folderContext.folder,

Diff for: src/commands/resetPackage.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { FolderContext } from "../FolderContext";
1717
import { createSwiftTask, SwiftTaskProvider } from "../tasks/SwiftTaskProvider";
1818
import { WorkspaceContext } from "../WorkspaceContext";
1919
import { executeTaskWithUI } from "./utilities";
20+
import configuration from "../configuration";
2021

2122
/**
2223
* Executes a {@link vscode.Task task} to reset the complete cache/build directory.
@@ -53,7 +54,7 @@ export async function folderResetPackage(folderContext: FolderContext) {
5354
return false;
5455
}
5556
const resolveTask = createSwiftTask(
56-
["package", "resolve"],
57+
["package", "resolve", ...configuration.packageArguments],
5758
SwiftTaskProvider.resolvePackageName,
5859
{
5960
cwd: folderContext.folder,

Diff for: src/configuration.ts

+4
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ const configuration = {
239239
get buildArguments(): string[] {
240240
return vscode.workspace.getConfiguration("swift").get<string[]>("buildArguments", []);
241241
},
242+
/** swift package arguments */
243+
get packageArguments(): string[] {
244+
return vscode.workspace.getConfiguration("swift").get<string[]>("packageArguments", []);
245+
},
242246
/** thread/address sanitizer */
243247
get sanitizer(): string {
244248
return vscode.workspace.getConfiguration("swift").get<string>("sanitizer", "off");

Diff for: src/tasks/SwiftTaskProvider.ts

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export function buildOptions(toolchain: SwiftToolchain, debug = true): string[]
8989
args.push(...sanitizer.buildFlags);
9090
}
9191
args.push(...configuration.buildArguments);
92+
// build can also trigger package resolution
93+
args.push(...configuration.packageArguments);
9294
return args;
9395
}
9496

Diff for: test/integration-tests/WorkspaceContext.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ suite("WorkspaceContext Test Suite", () => {
9696

9797
suiteTeardown(async () => {
9898
await swiftConfig.update("buildArguments", undefined);
99+
await swiftConfig.update("packageArguments", undefined);
99100
await swiftConfig.update("path", undefined);
100101
await swiftConfig.update("diagnosticsStyle", undefined);
101102
});
@@ -163,6 +164,19 @@ suite("WorkspaceContext Test Suite", () => {
163164
await swiftConfig.update("buildArguments", []);
164165
});
165166

167+
test("Package Arguments Settings", async () => {
168+
const folder = workspaceContext.folders.find(
169+
f => f.folder.fsPath === packageFolder.fsPath
170+
);
171+
assert(folder);
172+
await swiftConfig.update("diagnosticsStyle", undefined);
173+
await swiftConfig.update("packageArguments", ["--replace-scm-with-registry"]);
174+
const buildAllTask = createBuildAllTask(folder);
175+
const execution = buildAllTask.execution as SwiftExecution;
176+
assertContainsArg(execution, "--replace-scm-with-registry");
177+
await swiftConfig.update("packageArguments", []);
178+
});
179+
166180
test("Swift Path", async () => {
167181
/* Temporarily disabled (need swift path to update immediately for this to work)
168182
const folder = workspaceContext.folders.find(

0 commit comments

Comments
 (0)