Skip to content

Commit e891169

Browse files
Edoardo Pirovanohmakholm
authored andcommitted
MRVA: Use QLX to precompile queries
Co-authored-by: Henning Makholm <hmakholm@github.com>
1 parent 98284d9 commit e891169

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

extensions/ql-vscode/src/cli.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,16 +944,14 @@ export class CodeQLCliServer implements Disposable {
944944
return this.runJsonCodeQlCliCommand(['pack', 'install'], args, 'Installing pack dependencies');
945945
}
946946

947-
async packBundle(dir: string, workspaceFolders: string[], outputPath: string, precompile = true): Promise<void> {
947+
async packBundle(dir: string, workspaceFolders: string[], outputPath: string, moreOptions: string[]): Promise<void> {
948948
const args = [
949949
'-o',
950950
outputPath,
951951
dir,
952+
...moreOptions,
952953
...this.getAdditionalPacksArg(workspaceFolders)
953954
];
954-
if (!precompile && await this.cliConstraints.supportsNoPrecompile()) {
955-
args.push('--no-precompile');
956-
}
957955

958956
return this.runJsonCodeQlCliCommand(['pack', 'bundle'], args, 'Bundling pack');
959957
}
@@ -1288,6 +1286,13 @@ export class CliVersionConstraint {
12881286
*/
12891287
public static CLI_VERSION_REMOTE_QUERIES = new SemVer('2.6.3');
12901288

1289+
/**
1290+
* CLI version where building QLX packs for remote queries is supported.
1291+
* (The options were _accepted_ by a few earlier versions, but only from
1292+
* 2.11.3 will it actually use the existing compilation cache correctly).
1293+
*/
1294+
public static CLI_VERSION_QLX_REMOTE = new SemVer('2.11.3');
1295+
12911296
/**
12921297
* CLI version where the `resolve ml-models` subcommand was introduced.
12931298
*/
@@ -1383,6 +1388,10 @@ export class CliVersionConstraint {
13831388
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES);
13841389
}
13851390

1391+
async supportsQlxRemote() {
1392+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_QLX_REMOTE);
1393+
}
1394+
13861395
async supportsResolveMlModels() {
13871396
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_ML_MODELS);
13881397
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,21 @@ async function generateQueryPack(cliServer: cli.CodeQLCliServer, queryFile: stri
130130
// Clear the cliServer cache so that the previous qlpack text is purged from the CLI.
131131
await cliServer.clearCache();
132132

133+
let precompilationOpts: string[] = [];
134+
if (await cliServer.cliConstraints.supportsQlxRemote()) {
135+
const ccache = path.join(originalPackRoot, '.cache');
136+
precompilationOpts = ['--qlx',
137+
'--no-default-compilation-cache',
138+
`--compilation-cache=${ccache}`];
139+
} else if (await cliServer.cliConstraints.supportsNoPrecompile()) {
140+
precompilationOpts = ['--no-precompile'];
141+
}
142+
133143
const bundlePath = await getPackedBundlePath(queryPackDir);
134144
void logger.log(`Compiling and bundling query pack from ${queryPackDir} to ${bundlePath}. (This may take a while.)`);
135145
await cliServer.packInstall(queryPackDir);
136146
const workspaceFolders = getOnDiskWorkspaceFolders();
137-
await cliServer.packBundle(queryPackDir, workspaceFolders, bundlePath, false);
147+
await cliServer.packBundle(queryPackDir, workspaceFolders, bundlePath, precompilationOpts);
138148
const base64Pack = (await fs.readFile(bundlePath)).toString('base64');
139149
return {
140150
base64Pack,

0 commit comments

Comments
 (0)