Skip to content

Commit 598f2eb

Browse files
authored
Allow the CodeQL CLI path to be set from an environment variable (#3118)
1 parent e15f153 commit 598f2eb

5 files changed

Lines changed: 8 additions & 43 deletions

File tree

extensions/ql-vscode/src/config.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@ export interface DistributionConfig {
119119
ownerName?: string;
120120
repositoryName?: string;
121121
onDidChangeConfiguration?: Event<void>;
122-
123-
/**
124-
* This forces an update of the distribution, even if the settings haven't changed.
125-
*
126-
* This should only be used when the distribution has been updated outside of the extension
127-
* and only in tests. It should not be called in production code.
128-
*/
129-
forceUpdateConfiguration(): void;
130122
}
131123

132124
// Query server configuration
@@ -265,7 +257,10 @@ export class DistributionConfigListener
265257
implements DistributionConfig
266258
{
267259
public get customCodeQlPath(): string | undefined {
268-
return CUSTOM_CODEQL_PATH_SETTING.getValue() || undefined;
260+
const testCliPath =
261+
isIntegrationTestMode() &&
262+
process.env.VSCODE_CODEQL_TESTING_CODEQL_CLI_TEST_PATH;
263+
return CUSTOM_CODEQL_PATH_SETTING.getValue() || testCliPath || undefined;
269264
}
270265

271266
public get includePrerelease(): boolean {
@@ -283,10 +278,6 @@ export class DistributionConfigListener
283278
);
284279
}
285280

286-
public forceUpdateConfiguration() {
287-
this._onDidChangeConfiguration.fire(undefined);
288-
}
289-
290281
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
291282
this.handleDidChangeConfigurationForRelevantSettings(
292283
DISTRIBUTION_CHANGE_SETTINGS,

extensions/ql-vscode/test/vscode-tests/activated-extension/jest-runner-vscode.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const config = {
2222
extensionTestsEnv: {
2323
...baseConfig.extensionTestsEnv,
2424
INTEGRATION_TEST_MODE: "true",
25+
VSCODE_CODEQL_TESTING_CODEQL_CLI_TEST_PATH: process.env.CLI_PATH,
2526
},
2627
retries: 3,
2728
};

extensions/ql-vscode/test/vscode-tests/cli-integration/jest-runner-vscode.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const config = {
3535
extensionTestsEnv: {
3636
...baseConfig.extensionTestsEnv,
3737
INTEGRATION_TEST_MODE: "true",
38+
VSCODE_CODEQL_TESTING_CODEQL_CLI_TEST_PATH: process.env.CLI_PATH,
3839
},
3940
retries: 3,
4041
};

extensions/ql-vscode/test/vscode-tests/cli-integration/jest.setup.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "../jest.activated-extension.setup";
88
import { createWriteStream, existsSync, mkdirpSync } from "fs-extra";
99
import { dirname } from "path";
10-
import { DB_URL, dbLoc, getActivatedExtension } from "../global.helper";
10+
import { DB_URL, dbLoc } from "../global.helper";
1111
import fetch from "node-fetch";
1212

1313
beforeAll(async () => {
@@ -31,21 +31,6 @@ beforeAll(async () => {
3131
}
3232

3333
await beforeAllAction();
34-
35-
// Activate the extension
36-
const extension = await getActivatedExtension();
37-
38-
if (process.env.CLI_VERSION && process.env.CLI_VERSION !== "nightly") {
39-
const cliVersion = await extension.cliServer.getVersion();
40-
41-
if (cliVersion.compare(process.env.CLI_VERSION) !== 0) {
42-
// It seems like the CUSTOM_CODEQL_PATH_SETTING.updateValue() call in
43-
// `beforeAllAction` doesn't fire the event that the config has changed.
44-
// `forceUpdateConfiguration` will fire the event manually.
45-
// This is a hacky workaround.
46-
extension.distributionManager.config.forceUpdateConfiguration();
47-
}
48-
}
4934
});
5035

5136
beforeEach(async () => {

extensions/ql-vscode/test/vscode-tests/jest.activated-extension.setup.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { CUSTOM_CODEQL_PATH_SETTING } from "../../src/config";
2-
import { ConfigurationTarget, env } from "vscode";
1+
import { env } from "vscode";
32
import { beforeEachAction as testConfigBeforeEachAction } from "./test-config";
43
import * as tmp from "tmp";
54
import { realpathSync } from "fs-extra";
@@ -19,13 +18,6 @@ if (process.env.CI) {
1918
let removeStorage: tmp.DirResult["removeCallback"] | undefined;
2019

2120
export async function beforeAllAction() {
22-
// Set the CLI version here before activation to ensure we don't accidentally try to download a cli
23-
await testConfigBeforeEachAction();
24-
await CUSTOM_CODEQL_PATH_SETTING.updateValue(
25-
process.env.CLI_PATH,
26-
ConfigurationTarget.Workspace,
27-
);
28-
2921
// Create the temp directory to be used as extension local storage.
3022
const dir = tmp.dirSync();
3123
let storagePath = realpathSync(dir.name);
@@ -46,11 +38,6 @@ export async function beforeEachAction() {
4638
jest.spyOn(env, "openExternal").mockResolvedValue(false);
4739

4840
await testConfigBeforeEachAction();
49-
50-
await CUSTOM_CODEQL_PATH_SETTING.updateValue(
51-
process.env.CLI_PATH,
52-
ConfigurationTarget.Workspace,
53-
);
5441
}
5542

5643
export async function afterAllAction() {

0 commit comments

Comments
 (0)