Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1656,11 +1656,11 @@
"scripts": {
"vscode:prepublish": "npm run bundle",
"bundle": "del-cli ./dist && npm run bundle-extension && npm run bundle-documentation-webview",
"bundle-extension": "del-cli ./dist && esbuild ./src/extension.ts --bundle --outfile=dist/src/extension.js --external:vscode --format=cjs --platform=node --target=node18 --minify --sourcemap",
"bundle-extension": "del-cli ./dist && esbuild ./src/extension.ts --bundle --outfile=dist/src/extension.js --external:vscode --define:process.env.NODE_ENV=\\\"production\\\" --define:process.env.CI=\\\"\\\" --format=cjs --platform=node --target=node18 --minify --sourcemap",
"bundle-documentation-webview": "npm run compile-documentation-webview -- --minify",
"compile": "del-cli ./dist/ && tsc --build",
"watch": "npm run compile -- --watch",
"compile-documentation-webview": "del-cli ./assets/documentation-webview && esbuild ./src/documentation/webview/webview.ts --bundle --outfile=assets/documentation-webview/index.js --format=cjs --sourcemap",
"compile-documentation-webview": "del-cli ./assets/documentation-webview && esbuild ./src/documentation/webview/webview.ts --bundle --outfile=assets/documentation-webview/index.js --define:process.env.NODE_ENV=\\\"production\\\" --define:process.env.CI=\\\"\\\" --format=cjs --sourcemap",
"watch-documentation-webview": "npm run compile-documentation-webview -- --watch",
"lint": "eslint ./ --ext ts && tsc --noEmit",
"update-swift-docc-render": "tsx ./scripts/update_swift_docc_render.ts",
Expand Down
7 changes: 3 additions & 4 deletions src/debugger/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Version } from "../utilities/version";
import { TestLibrary } from "../TestExplorer/TestRunner";
import { TestKind, isDebugging, isRelease } from "../TestExplorer/TestKind";
import { buildOptions } from "../tasks/SwiftTaskProvider";
import { CI_DISABLE_ASLR } from "./lldb";
import { updateLaunchConfigForCI } from "./lldb";

export class BuildConfigurationFactory {
public static buildAll(
Expand Down Expand Up @@ -697,7 +697,7 @@ export class TestingConfigurationFactory {
async function getBaseConfig(ctx: FolderContext, expandEnvVariables: boolean) {
const { folder, nameSuffix } = getFolderAndNameSuffix(ctx, expandEnvVariables);
const packageName = await ctx.swiftPackage.name;
return {
return updateLaunchConfigForCI({
type: SWIFT_LAUNCH_CONFIG_TYPE,
request: "launch",
sourceLanguages: ["swift"],
Expand All @@ -706,8 +706,7 @@ async function getBaseConfig(ctx: FolderContext, expandEnvVariables: boolean) {
args: [],
preLaunchTask: `swift: Build All${nameSuffix}`,
terminal: "console",
...CI_DISABLE_ASLR,
};
});
}

export function getFolderAndNameSuffix(
Expand Down
7 changes: 2 additions & 5 deletions src/debugger/debugAdapterFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { registerLoggingDebugAdapterTracker } from "./logTracker";
import { SwiftToolchain } from "../toolchain/toolchain";
import { SwiftOutputChannel } from "../ui/SwiftOutputChannel";
import { fileExists } from "../utilities/filesystem";
import { CI_DISABLE_ASLR, getLLDBLibPath } from "./lldb";
import { updateLaunchConfigForCI, getLLDBLibPath } from "./lldb";
import { getErrorDescription, swiftRuntimeEnv } from "../utilities/utilities";
import configuration from "../configuration";

Expand Down Expand Up @@ -171,10 +171,7 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
launchConfig.debugAdapterExecutable = lldbDapPath;
}

return {
...launchConfig,
...CI_DISABLE_ASLR,
};
return updateLaunchConfigForCI(launchConfig);
}

private async promptToInstallCodeLLDB(): Promise<boolean> {
Expand Down
29 changes: 20 additions & 9 deletions src/debugger/lldb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,31 @@
// Based on code taken from CodeLLDB https://github.com/vadimcn/vscode-lldb/
// LICENSED with MIT License

import * as vscode from "vscode";
import * as path from "path";
import * as fs from "fs/promises";
import { execFile } from "../utilities/utilities";
import { execFile, IS_RUNNING_IN_CI } from "../utilities/utilities";
import { Result } from "../utilities/result";
import { SwiftToolchain } from "../toolchain/toolchain";

export const CI_DISABLE_ASLR =
// DisableASLR when running in Docker CI https://stackoverflow.com/a/78471987
process.env["CI"]
? {
disableASLR: false,
initCommands: ["settings set target.disable-aslr false"],
}
: {};
/**
* Updates the provided debug configuration to be compatible with running in CI.
*
* Will be optimized out of production builds.
*/
export function updateLaunchConfigForCI(
config: vscode.DebugConfiguration
): vscode.DebugConfiguration {
if (!IS_RUNNING_IN_CI) {
return config;
}

const result = structuredClone(config);
// Tell LLDB not to disable ASLR when running in Docker CI https://stackoverflow.com/a/78471987
result.disableASLR = false;
result.initCommands = ["settings set target.disable-aslr false"];
return result;
}

/**
* Get the path to the LLDB library.
Expand Down
3 changes: 2 additions & 1 deletion src/ui/SwiftOutputChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import * as vscode from "vscode";
import configuration from "../configuration";
import { IS_RUNNING_IN_CI } from "../utilities/utilities";

export class SwiftOutputChannel implements vscode.OutputChannel {
private channel: vscode.OutputChannel;
Expand Down Expand Up @@ -76,7 +77,7 @@ export class SwiftOutputChannel implements vscode.OutputChannel {
}

logDiagnostic(message: string, label?: string) {
if (!configuration.diagnostics && process.env["CI"] !== "1") {
if (!configuration.diagnostics && !IS_RUNNING_IN_CI) {
return;
}
const fullMessage = label !== undefined ? `${label}: ${message}` : message;
Expand Down
16 changes: 16 additions & 0 deletions src/utilities/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ import configuration from "../configuration";
import { FolderContext } from "../FolderContext";
import { SwiftToolchain } from "../toolchain/toolchain";

/**
* Whether or not this is a production build.
*
* Code that checks for this will be removed completely when the extension is packaged into
* a VSIX.
*/
export const IS_PRODUCTION_BUILD = process.env.NODE_ENV === "production";

/**
* Whether or not the code is being run in CI.
*
* Code that checks for this will be removed completely when the extension is packaged into
* a VSIX.
*/
export const IS_RUNNING_IN_CI = process.env.CI === "1";

/**
* Get required environment variable for Swift product
*
Expand Down
3 changes: 2 additions & 1 deletion test/integration-tests/debugger/lldb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getLLDBLibPath } from "../../../src/debugger/lldb";
import { WorkspaceContext } from "../../../src/WorkspaceContext";
import { activateExtensionForTest } from "../utilities/testutilities";
import { Version } from "../../../src/utilities/version";
import { IS_RUNNING_IN_CI } from "../../../src/utilities/utilities";

suite("lldb contract test suite", () => {
let workspaceContext: WorkspaceContext;
Expand All @@ -25,7 +26,7 @@ suite("lldb contract test suite", () => {
async setup(ctx) {
// lldb.exe on Windows is not launching correctly, but only in Docker.
if (
process.env["CI"] &&
IS_RUNNING_IN_CI &&
process.platform === "win32" &&
ctx.globalToolchainSwiftVersion.isGreaterThanOrEqual(new Version(6, 0, 0)) &&
ctx.globalToolchainSwiftVersion.isLessThan(new Version(6, 0, 2))
Expand Down
Loading