Skip to content

Commit 67e2ff3

Browse files
authored
Move QL pack root path to the QlPackDetails (#3267)
1 parent 9285b02 commit 67e2ff3

4 files changed

Lines changed: 38 additions & 17 deletions

File tree

extensions/ql-vscode/src/variant-analysis/ql-pack-details.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
*/
55
export interface QlPackDetails {
66
queryFile: string;
7+
8+
// The path to the QL pack that is used for triggering a variant analysis.
9+
// If there is no query pack, this is the same as the directory of the query files.
10+
qlPackRootPath: string;
711
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function generateQueryPack(
6565
): Promise<GeneratedQueryPack> {
6666
const queryFile = qlPackDetails.queryFile;
6767

68-
const originalPackRoot = await findPackRoot(queryFile);
68+
const originalPackRoot = qlPackDetails.qlPackRootPath;
6969
const packRelativePath = relative(originalPackRoot, queryFile);
7070
const workspaceFolders = getOnDiskWorkspaceFolders();
7171
const extensionPacks = await getExtensionPacksToInject(
@@ -262,7 +262,7 @@ async function copyExistingQueryPack(
262262
await fixPackFile(queryPackDir, packRelativePath);
263263
}
264264

265-
async function findPackRoot(queryFile: string): Promise<string> {
265+
export async function findPackRoot(queryFile: string): Promise<string> {
266266
// recursively find the directory containing qlpack.yml or codeql-pack.yml
267267
let dir = dirname(queryFile);
268268
while (!(await getQlPackFilePath(dir))) {

extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ import type {
4242
LoadResultsOptions,
4343
VariantAnalysisResultsManager,
4444
} from "./variant-analysis-results-manager";
45-
import { getQueryName, prepareRemoteQueryRun } from "./run-remote-query";
45+
import {
46+
findPackRoot,
47+
getQueryName,
48+
prepareRemoteQueryRun,
49+
} from "./run-remote-query";
4650
import {
4751
mapVariantAnalysis,
4852
mapVariantAnalysisRepositoryTask,
@@ -273,6 +277,7 @@ export class VariantAnalysisManager
273277
// for multiple queries.
274278
const qlPackDetails: QlPackDetails = {
275279
queryFile: problemQueries[0],
280+
qlPackRootPath: packDir,
276281
};
277282

278283
await this.runVariantAnalysis(
@@ -308,8 +313,10 @@ export class VariantAnalysisManager
308313

309314
private async runVariantAnalysisCommand(uri: Uri): Promise<void> {
310315
// Build up details to pass to the functions that run the variant analysis.
316+
const qlPackRootPath = await findPackRoot(uri.fsPath);
311317
const qlPackDetails: QlPackDetails = {
312318
queryFile: uri.fsPath,
319+
qlPackRootPath,
313320
};
314321

315322
return withProgress(

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ describe("Variant Analysis Manager", () => {
101101
});
102102

103103
it("should run a variant analysis that is part of a qlpack", async () => {
104-
const filePath = getFile("data-remote-qlpack/in-pack.ql");
104+
const filePath = getFileOrDir("data-remote-qlpack/in-pack.ql");
105105
const qlPackDetails: QlPackDetails = {
106106
queryFile: filePath,
107+
qlPackRootPath: join(baseDir, "data-remote-qlpack"),
107108
};
108109

109110
await variantAnalysisManager.runVariantAnalysis(
@@ -125,9 +126,10 @@ describe("Variant Analysis Manager", () => {
125126
});
126127

127128
it("should run a remote query that is not part of a qlpack", async () => {
128-
const filePath = getFile("data-remote-no-qlpack/in-pack.ql");
129+
const filePath = getFileOrDir("data-remote-no-qlpack/in-pack.ql");
129130
const qlPackDetails: QlPackDetails = {
130131
queryFile: filePath,
132+
qlPackRootPath: join(baseDir, "data-remote-no-qlpack"),
131133
};
132134

133135
await variantAnalysisManager.runVariantAnalysis(
@@ -149,11 +151,12 @@ describe("Variant Analysis Manager", () => {
149151
});
150152

151153
it("should run a remote query that is nested inside a qlpack", async () => {
152-
const filePath = getFile(
154+
const filePath = getFileOrDir(
153155
"data-remote-qlpack-nested/subfolder/in-pack.ql",
154156
);
155157
const qlPackDetails: QlPackDetails = {
156158
queryFile: filePath,
159+
qlPackRootPath: join(baseDir, "data-remote-qlpack-nested"),
157160
};
158161

159162
await variantAnalysisManager.runVariantAnalysis(
@@ -175,9 +178,10 @@ describe("Variant Analysis Manager", () => {
175178
});
176179

177180
it("should cancel a run before uploading", async () => {
178-
const filePath = getFile("data-remote-no-qlpack/in-pack.ql");
181+
const filePath = getFileOrDir("data-remote-no-qlpack/in-pack.ql");
179182
const qlPackDetails: QlPackDetails = {
180183
queryFile: filePath,
184+
qlPackRootPath: join(baseDir, "data-remote-no-qlpack"),
181185
};
182186

183187
const promise = variantAnalysisManager.runVariantAnalysis(
@@ -218,6 +222,7 @@ describe("Variant Analysis Manager", () => {
218222
it("should run a remote query that is part of a qlpack", async () => {
219223
await doVariantAnalysisTest({
220224
queryPath: "data-remote-qlpack/in-pack.ql",
225+
qlPackRootPath: "data-remote-qlpack",
221226
expectedPackName: "github/remote-query-pack",
222227
filesThatExist: ["in-pack.ql", "lib.qll"],
223228
filesThatDoNotExist: [],
@@ -228,6 +233,7 @@ describe("Variant Analysis Manager", () => {
228233
it("should run a remote query that is not part of a qlpack", async () => {
229234
await doVariantAnalysisTest({
230235
queryPath: "data-remote-no-qlpack/in-pack.ql",
236+
qlPackRootPath: "data-remote-no-qlpack",
231237
expectedPackName: "codeql-remote/query",
232238
filesThatExist: ["in-pack.ql"],
233239
filesThatDoNotExist: ["lib.qll", "not-in-pack.ql"],
@@ -238,6 +244,7 @@ describe("Variant Analysis Manager", () => {
238244
it("should run a remote query that is nested inside a qlpack", async () => {
239245
await doVariantAnalysisTest({
240246
queryPath: "data-remote-qlpack-nested/subfolder/in-pack.ql",
247+
qlPackRootPath: "data-remote-qlpack-nested",
241248
expectedPackName: "github/remote-query-pack",
242249
filesThatExist: ["subfolder/in-pack.ql", "otherfolder/lib.qll"],
243250
filesThatDoNotExist: ["subfolder/not-in-pack.ql"],
@@ -255,6 +262,7 @@ describe("Variant Analysis Manager", () => {
255262
await cli.setUseExtensionPacks(true);
256263
await doVariantAnalysisTest({
257264
queryPath: "data-remote-qlpack-nested/subfolder/in-pack.ql",
265+
qlPackRootPath: "data-remote-qlpack-nested",
258266
expectedPackName: "github/remote-query-pack",
259267
filesThatExist: [
260268
"subfolder/in-pack.ql",
@@ -299,12 +307,11 @@ describe("Variant Analysis Manager", () => {
299307
? ["Telemetry/ExtractorInformation.ql"]
300308
: [];
301309

310+
const qlPackRootPath = join(process.env.TEST_CODEQL_PATH, "java/ql/src");
311+
const queryPath = join(qlPackRootPath, queryToRun);
302312
await doVariantAnalysisTest({
303-
queryPath: join(
304-
process.env.TEST_CODEQL_PATH,
305-
"java/ql/src",
306-
queryToRun,
307-
),
313+
queryPath,
314+
qlPackRootPath,
308315
expectedPackName: "codeql/java-queries",
309316
filesThatExist: [queryToRun, ...extraQueries],
310317
filesThatDoNotExist: [],
@@ -317,6 +324,7 @@ describe("Variant Analysis Manager", () => {
317324

318325
async function doVariantAnalysisTest({
319326
queryPath,
327+
qlPackRootPath,
320328
expectedPackName,
321329
filesThatExist,
322330
qlxFilesThatExist,
@@ -328,16 +336,18 @@ describe("Variant Analysis Manager", () => {
328336
checkVersion = true,
329337
}: {
330338
queryPath: string;
339+
qlPackRootPath: string;
331340
expectedPackName: string;
332341
filesThatExist: string[];
333342
qlxFilesThatExist: string[];
334343
filesThatDoNotExist: string[];
335344
dependenciesToCheck?: string[];
336345
checkVersion?: boolean;
337346
}) {
338-
const filePath = getFile(queryPath);
347+
const filePath = getFileOrDir(queryPath);
339348
const qlPackDetails: QlPackDetails = {
340349
queryFile: filePath,
350+
qlPackRootPath: getFileOrDir(qlPackRootPath),
341351
};
342352

343353
await variantAnalysisManager.runVariantAnalysis(
@@ -416,11 +426,11 @@ describe("Variant Analysis Manager", () => {
416426
);
417427
}
418428

419-
function getFile(file: string): string {
420-
if (isAbsolute(file)) {
421-
return file;
429+
function getFileOrDir(path: string): string {
430+
if (isAbsolute(path)) {
431+
return path;
422432
} else {
423-
return join(baseDir, file);
433+
return join(baseDir, path);
424434
}
425435
}
426436
});

0 commit comments

Comments
 (0)