Skip to content

Commit 97a560f

Browse files
Remove CI checks in production (#1578)
1 parent b108540 commit 97a560f

File tree

8 files changed

+48
-22
lines changed

8 files changed

+48
-22
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,11 +1656,11 @@
16561656
"scripts": {
16571657
"vscode:prepublish": "npm run bundle",
16581658
"bundle": "del-cli ./dist && npm run bundle-extension && npm run bundle-documentation-webview",
1659-
"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",
1659+
"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",
16601660
"bundle-documentation-webview": "npm run compile-documentation-webview -- --minify",
16611661
"compile": "del-cli ./dist/ && tsc --build",
16621662
"watch": "npm run compile -- --watch",
1663-
"compile-documentation-webview": "del-cli ./assets/documentation-webview && esbuild ./src/documentation/webview/webview.ts --bundle --outfile=assets/documentation-webview/index.js --format=cjs --sourcemap",
1663+
"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",
16641664
"watch-documentation-webview": "npm run compile-documentation-webview -- --watch",
16651665
"lint": "eslint ./ --ext ts && tsc --noEmit",
16661666
"update-swift-docc-render": "tsx ./scripts/update_swift_docc_render.ts",

src/debugger/buildConfig.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { Version } from "../utilities/version";
2626
import { TestLibrary } from "../TestExplorer/TestRunner";
2727
import { TestKind, isDebugging, isRelease } from "../TestExplorer/TestKind";
2828
import { buildOptions } from "../tasks/SwiftTaskProvider";
29-
import { CI_DISABLE_ASLR } from "./lldb";
29+
import { updateLaunchConfigForCI } from "./lldb";
3030

3131
export class BuildConfigurationFactory {
3232
public static buildAll(
@@ -697,7 +697,7 @@ export class TestingConfigurationFactory {
697697
async function getBaseConfig(ctx: FolderContext, expandEnvVariables: boolean) {
698698
const { folder, nameSuffix } = getFolderAndNameSuffix(ctx, expandEnvVariables);
699699
const packageName = await ctx.swiftPackage.name;
700-
return {
700+
return updateLaunchConfigForCI({
701701
type: SWIFT_LAUNCH_CONFIG_TYPE,
702702
request: "launch",
703703
sourceLanguages: ["swift"],
@@ -706,8 +706,7 @@ async function getBaseConfig(ctx: FolderContext, expandEnvVariables: boolean) {
706706
args: [],
707707
preLaunchTask: `swift: Build All${nameSuffix}`,
708708
terminal: "console",
709-
...CI_DISABLE_ASLR,
710-
};
709+
});
711710
}
712711

713712
export function getFolderAndNameSuffix(

src/debugger/debugAdapterFactory.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { registerLoggingDebugAdapterTracker } from "./logTracker";
2020
import { SwiftToolchain } from "../toolchain/toolchain";
2121
import { SwiftOutputChannel } from "../ui/SwiftOutputChannel";
2222
import { fileExists } from "../utilities/filesystem";
23-
import { CI_DISABLE_ASLR, getLLDBLibPath } from "./lldb";
23+
import { updateLaunchConfigForCI, getLLDBLibPath } from "./lldb";
2424
import { getErrorDescription, swiftRuntimeEnv } from "../utilities/utilities";
2525
import configuration from "../configuration";
2626

@@ -171,10 +171,7 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
171171
launchConfig.debugAdapterExecutable = lldbDapPath;
172172
}
173173

174-
return {
175-
...launchConfig,
176-
...CI_DISABLE_ASLR,
177-
};
174+
return updateLaunchConfigForCI(launchConfig);
178175
}
179176

180177
private async promptToInstallCodeLLDB(): Promise<boolean> {

src/debugger/lldb.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,31 @@
1515
// Based on code taken from CodeLLDB https://github.com/vadimcn/vscode-lldb/
1616
// LICENSED with MIT License
1717

18+
import * as vscode from "vscode";
1819
import * as path from "path";
1920
import * as fs from "fs/promises";
20-
import { execFile } from "../utilities/utilities";
21+
import { execFile, IS_RUNNING_IN_CI } from "../utilities/utilities";
2122
import { Result } from "../utilities/result";
2223
import { SwiftToolchain } from "../toolchain/toolchain";
2324

24-
export const CI_DISABLE_ASLR =
25-
// DisableASLR when running in Docker CI https://stackoverflow.com/a/78471987
26-
process.env["CI"]
27-
? {
28-
disableASLR: false,
29-
initCommands: ["settings set target.disable-aslr false"],
30-
}
31-
: {};
25+
/**
26+
* Updates the provided debug configuration to be compatible with running in CI.
27+
*
28+
* Will be optimized out of production builds.
29+
*/
30+
export function updateLaunchConfigForCI(
31+
config: vscode.DebugConfiguration
32+
): vscode.DebugConfiguration {
33+
if (!IS_RUNNING_IN_CI) {
34+
return config;
35+
}
36+
37+
const result = structuredClone(config);
38+
// Tell LLDB not to disable ASLR when running in Docker CI https://stackoverflow.com/a/78471987
39+
result.disableASLR = false;
40+
result.initCommands = ["settings set target.disable-aslr false"];
41+
return result;
42+
}
3243

3344
/**
3445
* Get the path to the LLDB library.

src/ui/SwiftOutputChannel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import * as vscode from "vscode";
1616
import configuration from "../configuration";
17+
import { IS_RUNNING_IN_CI } from "../utilities/utilities";
1718

1819
export class SwiftOutputChannel implements vscode.OutputChannel {
1920
private channel: vscode.OutputChannel;
@@ -76,7 +77,7 @@ export class SwiftOutputChannel implements vscode.OutputChannel {
7677
}
7778

7879
logDiagnostic(message: string, label?: string) {
79-
if (!configuration.diagnostics && process.env["CI"] !== "1") {
80+
if (!configuration.diagnostics && !IS_RUNNING_IN_CI) {
8081
return;
8182
}
8283
const fullMessage = label !== undefined ? `${label}: ${message}` : message;

src/utilities/utilities.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ import configuration from "../configuration";
2020
import { FolderContext } from "../FolderContext";
2121
import { SwiftToolchain } from "../toolchain/toolchain";
2222

23+
/**
24+
* Whether or not this is a production build.
25+
*
26+
* Code that checks for this will be removed completely when the extension is packaged into
27+
* a VSIX.
28+
*/
29+
export const IS_PRODUCTION_BUILD = process.env.NODE_ENV === "production";
30+
31+
/**
32+
* Whether or not the code is being run in CI.
33+
*
34+
* Code that checks for this will be removed completely when the extension is packaged into
35+
* a VSIX.
36+
*/
37+
export const IS_RUNNING_IN_CI = process.env.CI === "1";
38+
2339
/**
2440
* Get required environment variable for Swift product
2541
*

test/integration-tests/debugger/lldb.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getLLDBLibPath } from "../../../src/debugger/lldb";
1717
import { WorkspaceContext } from "../../../src/WorkspaceContext";
1818
import { activateExtensionForTest } from "../utilities/testutilities";
1919
import { Version } from "../../../src/utilities/version";
20+
import { IS_RUNNING_IN_CI } from "../../../src/utilities/utilities";
2021

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

test/unit-tests/debugger/debugAdapterFactory.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ suite("LLDBDebugConfigurationProvider Tests", () => {
152152
update: mockFn(),
153153
});
154154
mockWorkspace.getConfiguration.returns(instance(mockLldbConfiguration));
155+
mockLLDB.updateLaunchConfigForCI.returnsArg(0);
155156
mockLLDB.getLLDBLibPath.resolves(Result.makeSuccess("/path/to/liblldb.dyLib"));
156157
mockDebuggerConfig.setupCodeLLDB = "prompt";
157158
mockDebugAdapter.getLaunchConfigType.returns(LaunchConfigType.CODE_LLDB);

0 commit comments

Comments
 (0)