Skip to content

Commit 65fbb6b

Browse files
author
Dave Bartolomeo
committed
Fix PR feedback
1 parent 1d27598 commit 65fbb6b

File tree

5 files changed

+78
-61
lines changed

5 files changed

+78
-61
lines changed

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,16 +1420,28 @@ export class CodeQLCliServer implements Disposable {
14201420
);
14211421
}
14221422

1423+
/**
1424+
* Compile a CodeQL pack and bundle it into a single file.
1425+
*
1426+
* @param sourcePackDir The directory of the input CodeQL pack.
1427+
* @param workspaceFolders The workspace folders to search for additional packs.
1428+
* @param outputBundleFile The path to the output bundle file.
1429+
* @param outputPackDir The directory to contain the unbundled output pack.
1430+
* @param moreOptions Additional options to be passed to `codeql pack bundle`.
1431+
*/
14231432
async packBundle(
1424-
dir: string,
1433+
sourcePackDir: string,
14251434
workspaceFolders: string[],
1426-
outputPath: string,
1435+
outputBundleFile: string,
1436+
outputPackDir: string,
14271437
moreOptions: string[],
14281438
): Promise<void> {
14291439
const args = [
14301440
"-o",
1431-
outputPath,
1432-
dir,
1441+
outputBundleFile,
1442+
sourcePackDir,
1443+
"--pack-path",
1444+
outputPackDir,
14331445
...moreOptions,
14341446
...this.getAdditionalPacksArg(workspaceFolders),
14351447
];
@@ -1492,7 +1504,7 @@ export class CodeQLCliServer implements Disposable {
14921504
return (await this.getVersionAndFeatures()).features;
14931505
}
14941506

1495-
public async getVersionAndFeatures(): Promise<VersionAndFeatures> {
1507+
private async getVersionAndFeatures(): Promise<VersionAndFeatures> {
14961508
if (!this._versionAndFeatures) {
14971509
try {
14981510
const newVersionAndFeatures = await this.refreshVersion();

extensions/ql-vscode/src/variant-analysis/run-remote-query.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ async function generateQueryPack(
7979
? await askForLanguage(cliServer) // open popup to ask for language if not already hardcoded
8080
: await findLanguage(cliServer, Uri.file(queryFile));
8181
if (!language) {
82-
throw new UserCancellationException("Could not determine language.");
82+
throw new UserCancellationException("Could not determine language");
8383
}
8484

8585
let queryPackDir: string;
86-
let precompilationOpts: string[];
8786
let needsInstall: boolean;
8887
if (mustSynthesizePack) {
8988
// This section applies whether or not the CLI supports MRVA pack creation directly.
@@ -136,8 +135,7 @@ async function generateQueryPack(
136135
await cliServer.clearCache();
137136
}
138137

139-
// Clear the CLI cache so that the most recent qlpack lock file is used.
140-
await cliServer.clearCache();
138+
let precompilationOpts: string[];
141139
if (cliSupportsMrvaPackCreate) {
142140
precompilationOpts = [
143141
"--mrva",
@@ -151,11 +149,11 @@ async function generateQueryPack(
151149
if (await cliServer.cliConstraints.usesGlobalCompilationCache()) {
152150
precompilationOpts = ["--qlx"];
153151
} else {
154-
const ccache = join(originalPackRoot, ".cache");
152+
const cache = join(originalPackRoot, ".cache");
155153
precompilationOpts = [
156154
"--qlx",
157155
"--no-default-compilation-cache",
158-
`--compilation-cache=${ccache}`,
156+
`--compilation-cache=${cache}`,
159157
];
160158
}
161159

@@ -168,11 +166,13 @@ async function generateQueryPack(
168166
void extLogger.log(
169167
`Compiling and bundling query pack from ${queryPackDir} to ${bundlePath}. (This may take a while.)`,
170168
);
171-
await cliServer.packBundle(queryPackDir, workspaceFolders, bundlePath, [
172-
"--pack-path",
169+
await cliServer.packBundle(
170+
queryPackDir,
171+
workspaceFolders,
172+
bundlePath,
173173
tmpDir.compiledPackDir,
174-
...precompilationOpts,
175-
]);
174+
precompilationOpts,
175+
);
176176
const base64Pack = (await readFile(bundlePath)).toString("base64");
177177
return {
178178
base64Pack,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { expect } from "@jest/globals";
2+
import type { ExpectationResult } from "expect";
3+
import type { QueryPackFS } from "../vscode-tests/utils/bundled-pack-helpers";
4+
import { EOL } from "os";
5+
6+
/**
7+
* Custom Jest matcher to check if a file exists in a query pack.
8+
*/
9+
function toExistInPack(
10+
this: jest.MatcherContext,
11+
actual: unknown,
12+
packFS: QueryPackFS,
13+
): ExpectationResult {
14+
if (typeof actual !== "string") {
15+
throw new TypeError(
16+
`Expected actual value to be a string. Found ${typeof actual}`,
17+
);
18+
}
19+
20+
const pass = packFS.fileExists(actual);
21+
if (pass) {
22+
return {
23+
pass: true,
24+
message: () => `expected ${actual} not to exist in pack`,
25+
};
26+
} else {
27+
const files = packFS.allFiles();
28+
const filesString = files.length > 0 ? files.join(EOL) : "<none>";
29+
return {
30+
pass: false,
31+
message: () =>
32+
`expected ${actual} to exist in pack.\nThe following files were found in the pack:\n${filesString}`,
33+
};
34+
}
35+
}
36+
37+
expect.extend({ toExistInPack });
38+
39+
declare module "expect" {
40+
interface Matchers<R> {
41+
toExistInCodeQLPack(packFS: QueryPackFS): R;
42+
}
43+
}

extensions/ql-vscode/test/vscode-tests/cli-integration/variant-analysis/variant-analysis-manager.test.ts

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,11 @@ import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
2020
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
2121
import { mockedQuickPickItem } from "../../utils/mocking.helpers";
2222
import { QueryLanguage } from "../../../../src/common/query-language";
23-
import type { QueryPackFS } from "../../utils/bundled-pack-helpers";
2423
import { readBundledPack } from "../../utils/bundled-pack-helpers";
2524
import { load } from "js-yaml";
2625
import type { ExtensionPackMetadata } from "../../../../src/model-editor/extension-pack-metadata";
2726
import type { QlPackLockFile } from "../../../../src/packaging/qlpack-lock-file";
2827
import { expect } from "@jest/globals";
29-
import type { ExpectationResult } from "expect";
30-
31-
/**
32-
* Custom Jest matcher to check if a file exists in a query pack.
33-
*/
34-
function toExistInPack(
35-
this: jest.MatcherContext,
36-
actual: unknown,
37-
packFS: QueryPackFS,
38-
): ExpectationResult {
39-
if (typeof actual !== "string") {
40-
throw new TypeError("Expected actual value to be a string.");
41-
}
42-
43-
const pass = packFS.fileExists(actual);
44-
const files = packFS.allFiles();
45-
const filesString = files.length > 0 ? files.join("\n") : "<none>";
46-
if (pass) {
47-
return {
48-
pass: true,
49-
message: () => `expected ${actual} not to exist in pack`,
50-
};
51-
} else {
52-
return {
53-
pass: false,
54-
message: () =>
55-
`expected ${actual} to exist in pack.\nThe following files were found in the pack:\n${filesString}`,
56-
};
57-
}
58-
}
59-
60-
expect.extend({ toExistInPack });
61-
62-
declare module "expect" {
63-
interface Matchers<R> {
64-
toExistInPack(packFS: QueryPackFS): R;
65-
}
66-
}
6728

6829
describe("Variant Analysis Manager", () => {
6930
let cli: CodeQLCliServer;
@@ -371,14 +332,14 @@ describe("Variant Analysis Manager", () => {
371332

372333
const packFS = await readBundledPack(request.query.pack);
373334
filesThatExist.forEach((file) => {
374-
expect(file).toExistInPack(packFS);
335+
expect(file).toExistInCodeQLPack(packFS);
375336
});
376337

377338
qlxFilesThatExist.forEach((file) => {
378-
expect(file).toExistInPack(packFS);
339+
expect(file).toExistInCodeQLPack(packFS);
379340
});
380341
filesThatDoNotExist.forEach((file) => {
381-
expect(file).not.toExistInPack(packFS);
342+
expect(file).not.toExistInCodeQLPack(packFS);
382343
});
383344

384345
expect(

extensions/ql-vscode/test/vscode-tests/cli.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { dirname } from "path";
12
import { workspace } from "vscode";
23

34
/**
@@ -6,10 +7,10 @@ import { workspace } from "vscode";
67
*/
78
function hasCodeQL() {
89
const folders = workspace.workspaceFolders;
9-
return !!folders?.some(
10-
(folder) =>
11-
folder.uri.path.endsWith("/codeql") || folder.uri.path.endsWith("/ql"),
12-
);
10+
return !!folders?.some((folder) => {
11+
const name = dirname(folder.uri.fsPath);
12+
return name === "codeql" || name === "ql";
13+
});
1314
}
1415

1516
// describeWithCodeQL will be equal to describe if the CodeQL libraries are

0 commit comments

Comments
 (0)