Skip to content

Commit 26dc6ea

Browse files
committed
Pass build arguments to some swiftExec calls
These particular commands (or subcommands) take the same build arguments as we pass to "build", "run", and "test" commands. To get our tests to run in a sandbox, we need to disable sandboxing because you cannot create a new sandbox when you're already running under a sandbox
1 parent 90251e3 commit 26dc6ea

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

src/SwiftPackage.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from "./utilities/utilities";
2424
import { SwiftToolchain } from "./toolchain/toolchain";
2525
import { BuildFlags } from "./toolchain/BuildFlags";
26+
import configuration from "./configuration";
2627

2728
/** Swift Package Manager contents */
2829
export interface PackageContents {
@@ -215,9 +216,15 @@ export class SwiftPackage implements PackageContents {
215216
toolchain: SwiftToolchain
216217
): Promise<SwiftPackageState> {
217218
try {
218-
let { stdout } = await execSwift(["package", "describe", "--type", "json"], toolchain, {
219-
cwd: folder.fsPath,
220-
});
219+
let { stdout } = await execSwift(
220+
["package"]
221+
.concat(configuration.buildArguments)
222+
.concat(["describe", "--type", "json"]),
223+
toolchain,
224+
{
225+
cwd: folder.fsPath,
226+
}
227+
);
221228
// remove lines from `swift package describe` until we find a "{"
222229
while (!stdout.startsWith("{")) {
223230
const firstNewLine = stdout.indexOf("\n");
@@ -257,9 +264,13 @@ export class SwiftPackage implements PackageContents {
257264
toolchain: SwiftToolchain
258265
): Promise<PackagePlugin[]> {
259266
try {
260-
const { stdout } = await execSwift(["package", "plugin", "--list"], toolchain, {
261-
cwd: folder.fsPath,
262-
});
267+
const { stdout } = await execSwift(
268+
["package"].concat(configuration.buildArguments).concat(["plugin", "--list"]),
269+
toolchain,
270+
{
271+
cwd: folder.fsPath,
272+
}
273+
);
263274
const plugins: PackagePlugin[] = [];
264275
const lines = stdout.split("\n").map(item => item.trim());
265276
for (const line of lines) {

src/commands.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ export async function createNewProject(toolchain: SwiftToolchain | undefined): P
198198
},
199199
async () => {
200200
await execSwift(
201-
["package", "init", "--type", projectType, "--name", projectName],
201+
["package"]
202+
.concat(configuration.buildArguments)
203+
.concat(["init", "--type", projectType, "--name", projectName]),
202204
toolchain,
203205
{
204206
cwd: projectUri.fsPath,

src/toolchain/toolchain.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,10 @@ export class SwiftToolchain {
678678
private static async getSwiftTargetInfo(): Promise<SwiftTargetInfo> {
679679
try {
680680
try {
681-
const { stdout } = await execSwift(["-print-target-info"], "default");
681+
const { stdout } = await execSwift(
682+
["-print-target-info"].concat(configuration.buildArguments),
683+
"default"
684+
);
682685
const targetInfo = JSON.parse(stdout.trimEnd()) as SwiftTargetInfo;
683686
if (targetInfo.compilerVersion) {
684687
return targetInfo;

test/suite/tasks/SwiftTaskProvider.test.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ suite("SwiftTaskProvider Test Suite", () => {
5151

5252
test("Exit code on success", async () => {
5353
const task = createSwiftTask(
54-
["--help"],
55-
"help",
54+
["build", "--show-bin-path"],
55+
"show bin path",
5656
{ cwd: workspaceFolder.uri, scope: vscode.TaskScope.Workspace },
5757
toolchain
5858
);
@@ -84,7 +84,12 @@ suite("SwiftTaskProvider Test Suite", () => {
8484
new vscode.CancellationTokenSource().token
8585
);
8686
const task = tasks.find(t => t.name === "Build All (defaultPackage)");
87-
assert.equal(task?.detail, "swift build --build-tests -Xswiftc -diagnostic-style=llvm");
87+
assert.equal(
88+
task?.detail?.startsWith(
89+
"swift build --build-tests -Xswiftc -diagnostic-style=llvm"
90+
),
91+
true
92+
);
8893
});
8994

9095
test("includes product debug task", async () => {
@@ -94,8 +99,10 @@ suite("SwiftTaskProvider Test Suite", () => {
9499
);
95100
const task = tasks.find(t => t.name === "Build Debug PackageExe (defaultPackage)");
96101
assert.equal(
97-
task?.detail,
98-
"swift build --product PackageExe -Xswiftc -diagnostic-style=llvm"
102+
task?.detail?.startsWith(
103+
"swift build --product PackageExe -Xswiftc -diagnostic-style=llvm"
104+
),
105+
true
99106
);
100107
});
101108

@@ -106,8 +113,10 @@ suite("SwiftTaskProvider Test Suite", () => {
106113
);
107114
const task = tasks.find(t => t.name === "Build Release PackageExe (defaultPackage)");
108115
assert.equal(
109-
task?.detail,
110-
"swift build -c release --product PackageExe -Xswiftc -diagnostic-style=llvm"
116+
task?.detail?.startsWith(
117+
"swift build -c release --product PackageExe -Xswiftc -diagnostic-style=llvm"
118+
),
119+
true
111120
);
112121
});
113122
});

0 commit comments

Comments
 (0)