Skip to content

Commit 0d8df9a

Browse files
authored
Merge pull request #2065 from github/aeisenberg/run-with-all-data-extensions
Add ability to run query with data extensions
2 parents e3d8dbc + 790a152 commit 0d8df9a

13 files changed

Lines changed: 201 additions & 13 deletions

File tree

.vscode/settings.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,29 @@
4242
"LANG": "en-US",
4343
"TZ": "UTC"
4444
},
45+
46+
// These options are used by the `jestrunner.debug` command.
47+
// They are not used by the `jestrunner.run` command.
48+
// After clicking "debug" over a test, continually invoke the
49+
// "Debug: Attach to Node Process" command until you see a
50+
// process named "Code Helper (Plugin)". Then click "attach".
51+
// This will attach the debugger to the test process.
4552
"jestrunner.debugOptions": {
4653
// Uncomment to debug integration tests
47-
// "attachSimplePort": 9223,
54+
"attachSimplePort": 9223,
4855
"env": {
4956
"LANG": "en-US",
5057
"TZ": "UTC",
5158

5259
// Uncomment to set a custom path to a CodeQL checkout.
53-
// "TEST_CODEQL_PATH": "../codeql",
60+
// "TEST_CODEQL_PATH": "/absolute/path/to/checkout/of/codeql",
5461

5562
// Uncomment to set a custom path to a CodeQL CLI executable.
5663
// This is the CodeQL version that will be used in the tests.
57-
// "CLI_PATH": "/path/to/customg/codeql",
64+
// "CLI_PATH": "/absolute/path/to/custom/codeql",
5865

5966
// Uncomment to debug integration tests
60-
// "VSCODE_WAIT_FOR_DEBUGGER": "true",
67+
"VSCODE_WAIT_FOR_DEBUGGER": "true",
6168
}
6269
},
6370
"terminal.integrated.env.linux": {

extensions/ql-vscode/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@
224224
"default": true,
225225
"description": "Enable the 'Quick Evaluation' CodeLens."
226226
},
227+
"codeQL.runningQueries.useExtensionPacks": {
228+
"type": "string",
229+
"default": "none",
230+
"enum": [
231+
"none",
232+
"all"
233+
],
234+
"enumDescriptions": [
235+
"Do not use extension packs.",
236+
"Use all extension packs found in the workspace."
237+
],
238+
"description": "Choose whether or not to run queries using extension packs. Requires CodeQL CLI v2.12.3 or later."
239+
},
227240
"codeQL.resultsDisplay.pageSize": {
228241
"type": "integer",
229242
"default": 200,

extensions/ql-vscode/src/cli.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,24 +1163,32 @@ export class CodeQLCliServer implements Disposable {
11631163

11641164
/**
11651165
* Gets information about available qlpacks
1166-
* @param additionalPacks A list of directories to search for qlpacks before searching in `searchPath`.
1167-
* @param searchPath A list of directories to search for packs not found in `additionalPacks`. If undefined,
1168-
* the default CLI search path is used.
1166+
* @param additionalPacks A list of directories to search for qlpacks.
1167+
* @param extensionPacksOnly Whether to only search for extension packs. If true, only extension packs will
1168+
* be returned. If false, all packs will be returned.
11691169
* @returns A dictionary mapping qlpack name to the directory it comes from
11701170
*/
1171-
resolveQlpacks(
1171+
async resolveQlpacks(
11721172
additionalPacks: string[],
1173-
searchPath?: string[],
1173+
extensionPacksOnly = false,
11741174
): Promise<QlpacksInfo> {
11751175
const args = this.getAdditionalPacksArg(additionalPacks);
1176-
if (searchPath?.length) {
1177-
args.push("--search-path", join(...searchPath));
1176+
if (extensionPacksOnly) {
1177+
if (!(await this.cliConstraints.supportsQlpacksKind())) {
1178+
void this.logger.log(
1179+
"Warning: Running with extension packs is only supported by CodeQL CLI v2.12.3 or later.",
1180+
);
1181+
return {};
1182+
}
1183+
args.push("--kind", "extension", "--no-recursive");
11781184
}
11791185

11801186
return this.runJsonCodeQlCliCommand<QlpacksInfo>(
11811187
["resolve", "qlpacks"],
11821188
args,
1183-
"Resolving qlpack information",
1189+
`Resolving qlpack information${
1190+
extensionPacksOnly ? " (extension packs only)" : ""
1191+
}`,
11841192
);
11851193
}
11861194

@@ -1380,6 +1388,17 @@ export class CodeQLCliServer implements Disposable {
13801388
private getAdditionalPacksArg(paths: string[]): string[] {
13811389
return paths.length ? ["--additional-packs", paths.join(delimiter)] : [];
13821390
}
1391+
1392+
public async useExtensionPacks(): Promise<boolean> {
1393+
return (
1394+
this.cliConfig.useExtensionPacks &&
1395+
(await this.cliConstraints.supportsQlpacksKind())
1396+
);
1397+
}
1398+
1399+
public async setUseExtensionPacks(useExtensionPacks: boolean) {
1400+
await this.cliConfig.setUseExtensionPacks(useExtensionPacks);
1401+
}
13831402
}
13841403

13851404
/**
@@ -1668,6 +1687,11 @@ export class CliVersionConstraint {
16681687
*/
16691688
public static CLI_VERSION_WITH_WORKSPACE_RFERENCES = new SemVer("2.11.3");
16701689

1690+
/**
1691+
* CLI version that supports the `--kind` option for the `resolve qlpacks` command.
1692+
*/
1693+
public static CLI_VERSION_WITH_QLPACKS_KIND = new SemVer("2.12.3");
1694+
16711695
constructor(private readonly cli: CodeQLCliServer) {
16721696
/**/
16731697
}
@@ -1725,4 +1749,10 @@ export class CliVersionConstraint {
17251749
CliVersionConstraint.CLI_VERSION_WITH_WORKSPACE_RFERENCES,
17261750
);
17271751
}
1752+
1753+
async supportsQlpacksKind() {
1754+
return this.isVersionAtLeast(
1755+
CliVersionConstraint.CLI_VERSION_WITH_QLPACKS_KIND,
1756+
);
1757+
}
17281758
}

extensions/ql-vscode/src/config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ const DEBUG_SETTING = new Setting("debug", RUNNING_QUERIES_SETTING);
137137
const MAX_PATHS = new Setting("maxPaths", RUNNING_QUERIES_SETTING);
138138
const RUNNING_TESTS_SETTING = new Setting("runningTests", ROOT_SETTING);
139139
const RESULTS_DISPLAY_SETTING = new Setting("resultsDisplay", ROOT_SETTING);
140+
const USE_EXTENSION_PACKS = new Setting(
141+
"useExtensionPacks",
142+
RUNNING_QUERIES_SETTING,
143+
);
140144

141145
export const ADDITIONAL_TEST_ARGUMENTS_SETTING = new Setting(
142146
"additionalTestArguments",
@@ -196,14 +200,17 @@ const CLI_SETTINGS = [
196200
NUMBER_OF_TEST_THREADS_SETTING,
197201
NUMBER_OF_THREADS_SETTING,
198202
MAX_PATHS,
203+
USE_EXTENSION_PACKS,
199204
];
200205

201206
export interface CliConfig {
202207
additionalTestArguments: string[];
203208
numberTestThreads: number;
204209
numberThreads: number;
205210
maxPaths: number;
211+
useExtensionPacks: boolean;
206212
onDidChangeConfiguration?: Event<void>;
213+
setUseExtensionPacks: (useExtensionPacks: boolean) => Promise<void>;
207214
}
208215

209216
export abstract class ConfigListener extends DisposableObject {
@@ -400,6 +407,19 @@ export class CliConfigListener extends ConfigListener implements CliConfig {
400407
return MAX_PATHS.getValue<number>();
401408
}
402409

410+
public get useExtensionPacks(): boolean {
411+
// currently, we are restricting the values of this setting to 'all' or 'none'.
412+
return USE_EXTENSION_PACKS.getValue() === "all";
413+
}
414+
415+
// Exposed for testing only
416+
public async setUseExtensionPacks(newUseExtensionPacks: boolean) {
417+
await USE_EXTENSION_PACKS.updateValue(
418+
newUseExtensionPacks ? "all" : "none",
419+
ConfigurationTarget.Global,
420+
);
421+
}
422+
403423
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
404424
this.handleDidChangeConfigurationForRelevantSettings(CLI_SETTINGS, e);
405425
}

extensions/ql-vscode/src/pure/new-messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export interface RunQueryParams {
126126
singletonExternalInputs: Record<string, string>;
127127
dilPath?: string;
128128
logPath?: string;
129+
extensionPacks?: string[];
129130
}
130131

131132
export interface RunQueryResult {

extensions/ql-vscode/src/query-server/run-queries.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export async function compileAndRunQueryAgainstDatabase(
7070
: { query: {} };
7171

7272
const diskWorkspaceFolders = getOnDiskWorkspaceFolders();
73+
const extensionPacks = (await qs.cliServer.useExtensionPacks())
74+
? Object.keys(await qs.cliServer.resolveQlpacks(diskWorkspaceFolders, true))
75+
: undefined;
76+
7377
const db = dbItem.databaseUri.fsPath;
7478
const logPath = queryInfo ? query.evalLogPath : undefined;
7579
const queryToRun: messages.RunQueryParams = {
@@ -82,6 +86,7 @@ export async function compileAndRunQueryAgainstDatabase(
8286
dilPath: query.dilPath,
8387
logPath,
8488
target,
89+
extensionPacks,
8590
};
8691
await query.createTimestampFile();
8792
let result: messages.RunQueryResult | undefined;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extensions:
2+
- data:
3+
- [2]
4+
- [3]
5+
- [4]
6+
addsTo:
7+
extensible: testExtensible
8+
pack: semmle/has-extension
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: semmle/targets-extension
2+
library: true
3+
version: 0.0.0
4+
extensionTargets:
5+
semmle/has-extension: '*'
6+
7+
dataExtensions:
8+
- ext/*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
- data:
3+
- [1]
4+
5+
addsTo:
6+
extensible: testExtensible
7+
pack: semmle/has-extension
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: semmle/has-extension
2+
version: 0.0.0
3+
dependencies:
4+
codeql/javascript-all: '*'
5+
dataExtensions:
6+
- ext/*

0 commit comments

Comments
 (0)