Skip to content

Commit 2c12337

Browse files
authored
Allow disabling SwiftPM sandboxing (#1386)
* Allow disabling SwiftPM sandboxing 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 - Add new `swift.disableSandbox` setting - Disable sandboxing for tasks and commands run by the extension - Disable hardware acceleration since ci.swift.org will run on x64 - Fix failing xcode watcher unit test - Increase some timeouts as build times seem slower on these nodes - Skip any LSP dependent tests for 6.0 or earlier. The LSP will only allow disabling sandboxing in 6.1+ - Disable debugging tests since need shareport permission * Fix review comment * Disable test for Windows
1 parent 2c43d6f commit 2c12337

32 files changed

+312
-98
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ default.profraw
1212
assets/documentation-webview
1313
assets/test/**/Package.resolved
1414
assets/swift-docc-render
15+
ud

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ node_modules/
1818
/coverage/
1919
/dist/
2020
/snippets/
21+
22+
# macOS CI
23+
/ud/

.vscode-test.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,36 @@ const path = require("path");
1818
const isCIBuild = process.env["CI"] === "1";
1919
const isFastTestRun = process.env["FAST_TEST_RUN"] === "1";
2020

21+
const dataDir = process.env["VSCODE_DATA_DIR"];
22+
2123
// "env" in launch.json doesn't seem to work with vscode-test
2224
const isDebugRun = !(process.env["_"] ?? "").endsWith("node_modules/.bin/vscode-test");
2325

2426
// so tests don't timeout when a breakpoint is hit
2527
const timeout = isDebugRun ? Number.MAX_SAFE_INTEGER : 3000;
2628

29+
const launchArgs = [
30+
"--disable-updates",
31+
"--disable-crash-reporter",
32+
"--disable-workspace-trust",
33+
"--disable-telemetry",
34+
];
35+
if (dataDir) {
36+
launchArgs.push("--user-data-dir", dataDir);
37+
}
38+
// GPU hardware acceleration not working on Darwin for intel
39+
if (process.platform === "darwin" && process.arch === "x64") {
40+
launchArgs.push("--disable-gpu");
41+
}
42+
2743
module.exports = defineConfig({
2844
tests: [
2945
{
3046
label: "integrationTests",
3147
files: ["dist/test/common.js", "dist/test/integration-tests/**/*.test.js"],
3248
version: process.env["VSCODE_VERSION"] ?? "stable",
3349
workspaceFolder: "./assets/test",
34-
launchArgs: [
35-
"--disable-updates",
36-
"--disable-crash-reporter",
37-
"--disable-workspace-trust",
38-
"--disable-telemetry",
39-
],
50+
launchArgs,
4051
mocha: {
4152
ui: "tdd",
4253
color: true,
@@ -59,13 +70,7 @@ module.exports = defineConfig({
5970
label: "unitTests",
6071
files: ["dist/test/common.js", "dist/test/unit-tests/**/*.test.js"],
6172
version: process.env["VSCODE_VERSION"] ?? "stable",
62-
launchArgs: [
63-
"--disable-extensions",
64-
"--disable-updates",
65-
"--disable-crash-reporter",
66-
"--disable-workspace-trust",
67-
"--disable-telemetry",
68-
],
73+
launchArgs: launchArgs.concat("--disable-extensions"),
6974
mocha: {
7075
ui: "tdd",
7176
color: true,

assets/test/.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"command": "command_plugin",
3636
"args": ["--foo"],
3737
"cwd": "command-plugin",
38+
"disableSandbox": true,
3839
"problemMatcher": [
3940
"$swiftc"
4041
],

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,12 @@
719719
"swift.swiftSDK": {
720720
"type": "string",
721721
"default": "",
722-
"markdownDescription": "The [Swift SDK](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md) to compile against (`--swift-sdk` parameter).",
722+
"markdownDescription": "The [Swift SDK](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0387-cross-compilation-destinations.md) to compile against (`--swift-sdk` parameter)."
723+
},
724+
"swift.disableSandox": {
725+
"type": "boolean",
726+
"default": false,
727+
"markdownDescription": "Disable sandboxing when running SwiftPM commands. In most cases you should keep the sandbox enabled and leave this setting set to `false`",
723728
"order": 4
724729
},
725730
"swift.diagnostics": {

src/commands/dependencies/unedit.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ async function uneditFolderDependency(
4444
) {
4545
try {
4646
const uneditOperation = new SwiftExecOperation(
47-
["package", "unedit", ...args, identifier],
47+
ctx.toolchain.buildFlags.withAdditionalFlags([
48+
"package",
49+
"unedit",
50+
...args,
51+
identifier,
52+
]),
4853
folder,
4954
`Finish editing ${identifier}`,
5055
{ showStatusItem: true, checkAlreadyRunning: false, log: "Unedit" },

src/commands/dependencies/useLocal.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ export async function useLocalDependency(
5050
folder = folders[0];
5151
}
5252
const task = createSwiftTask(
53-
["package", "edit", "--path", folder.fsPath, identifier],
53+
ctx.toolchain.buildFlags.withAdditionalFlags([
54+
"package",
55+
"edit",
56+
"--path",
57+
folder.fsPath,
58+
identifier,
59+
]),
5460
"Edit Package Dependency",
5561
{
5662
scope: currentFolder.workspaceFolder,

src/commands/resetPackage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export async function resetPackage(ctx: WorkspaceContext) {
3535
*/
3636
export async function folderResetPackage(folderContext: FolderContext) {
3737
const task = createSwiftTask(
38-
["package", "reset"],
38+
folderContext.workspaceContext.toolchain.buildFlags.withAdditionalFlags([
39+
"package",
40+
"reset",
41+
]),
3942
"Reset Package Dependencies",
4043
{
4144
cwd: folderContext.folder,

src/configuration.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export interface DebuggerConfiguration {
5252
readonly debugAdapter: DebugAdapters;
5353
/** Return path to debug adapter */
5454
readonly customDebugAdapterPath: string;
55+
/** Whether or not to disable setting up the debugger */
56+
readonly disable: boolean;
5557
}
5658

5759
/** workspace folder configuration */
@@ -212,6 +214,11 @@ const configuration = {
212214
get customDebugAdapterPath(): string {
213215
return vscode.workspace.getConfiguration("swift.debugger").get<string>("path", "");
214216
},
217+
get disable(): boolean {
218+
return vscode.workspace
219+
.getConfiguration("swift.debugger")
220+
.get<boolean>("disable", false);
221+
},
215222
};
216223
},
217224
/** Files and directories to exclude from the code coverage. */
@@ -375,6 +382,10 @@ const configuration = {
375382
.getConfiguration("swift")
376383
.get<boolean>("enableTerminalEnvironment", true);
377384
},
385+
/** Whether or not to disable SwiftPM sandboxing */
386+
get disableSandbox(): boolean {
387+
return vscode.workspace.getConfiguration("swift").get<boolean>("disableSandbox", false);
388+
},
378389
};
379390

380391
export default configuration;

src/debugger/buildConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ export class TestingConfigurationFactory {
535535
}
536536

537537
const swiftTestingArgs = [
538-
...args,
538+
...this.ctx.workspaceContext.toolchain.buildFlags.withAdditionalFlags(args),
539539
"--enable-swift-testing",
540540
"--event-stream-version",
541541
"0",

0 commit comments

Comments
 (0)