Skip to content

Commit aada351

Browse files
authored
Move QL pack file path to the QlPackDetails (#3269)
1 parent e612764 commit aada351

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ export interface QlPackDetails {
88
// The path to the QL pack that is used for triggering a variant analysis.
99
// If there is no query pack, this is the same as the directory of the query files.
1010
qlPackRootPath: string;
11+
12+
// The path to the QL pack file (a qlpack.yml or codeql-pack.yml) or undefined if
13+
// it doesn't exist.
14+
qlPackFilePath: string | undefined;
1115
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ async function generateQueryPack(
7373
workspaceFolders,
7474
);
7575

76-
const mustSynthesizePack =
77-
(await getQlPackFilePath(originalPackRoot)) === undefined;
76+
const mustSynthesizePack = qlPackDetails.qlPackFilePath === undefined;
7877
const cliSupportsMrvaPackCreate =
7978
await cliServer.cliConstraints.supportsMrvaPackCreate();
8079

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ import { handleRequestError } from "./custom-errors";
9090
import { createMultiSelectionCommand } from "../common/vscode/selection-commands";
9191
import { askForLanguage } from "../codeql-cli/query-language";
9292
import type { QlPackDetails } from "./ql-pack-details";
93-
import { findPackRoot } from "../common/ql";
93+
import { findPackRoot, getQlPackFilePath } from "../common/ql";
9494

9595
const maxRetryCount = 3;
9696

@@ -269,12 +269,15 @@ export class VariantAnalysisManager
269269
return;
270270
}
271271

272+
const qlPackFilePath = await getQlPackFilePath(packDir);
273+
272274
// Build up details to pass to the functions that run the variant analysis.
273275
// For now, only include the first problem query until we have support
274276
// for multiple queries.
275277
const qlPackDetails: QlPackDetails = {
276278
queryFile: problemQueries[0],
277279
qlPackRootPath: packDir,
280+
qlPackFilePath,
278281
};
279282

280283
await this.runVariantAnalysis(
@@ -311,9 +314,11 @@ export class VariantAnalysisManager
311314
private async runVariantAnalysisCommand(uri: Uri): Promise<void> {
312315
// Build up details to pass to the functions that run the variant analysis.
313316
const qlPackRootPath = await findPackRoot(uri.fsPath);
317+
const qlPackFilePath = await getQlPackFilePath(qlPackRootPath);
314318
const qlPackDetails: QlPackDetails = {
315319
queryFile: uri.fsPath,
316320
qlPackRootPath,
321+
qlPackFilePath,
317322
};
318323

319324
return withProgress(

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ describe("Variant Analysis Manager", () => {
102102

103103
it("should run a variant analysis that is part of a qlpack", async () => {
104104
const filePath = getFileOrDir("data-remote-qlpack/in-pack.ql");
105+
const qlPackRootPath = getFileOrDir("data-remote-qlpack");
106+
const qlPackFilePath = getFileOrDir("data-remote-qlpack/qlpack.yml");
105107
const qlPackDetails: QlPackDetails = {
106108
queryFile: filePath,
107-
qlPackRootPath: join(baseDir, "data-remote-qlpack"),
109+
qlPackRootPath,
110+
qlPackFilePath,
108111
};
109112

110113
await variantAnalysisManager.runVariantAnalysis(
@@ -127,9 +130,11 @@ describe("Variant Analysis Manager", () => {
127130

128131
it("should run a remote query that is not part of a qlpack", async () => {
129132
const filePath = getFileOrDir("data-remote-no-qlpack/in-pack.ql");
133+
const qlPackRootPath = getFileOrDir("data-remote-no-qlpack");
130134
const qlPackDetails: QlPackDetails = {
131135
queryFile: filePath,
132-
qlPackRootPath: join(baseDir, "data-remote-no-qlpack"),
136+
qlPackRootPath,
137+
qlPackFilePath: undefined,
133138
};
134139

135140
await variantAnalysisManager.runVariantAnalysis(
@@ -154,9 +159,14 @@ describe("Variant Analysis Manager", () => {
154159
const filePath = getFileOrDir(
155160
"data-remote-qlpack-nested/subfolder/in-pack.ql",
156161
);
162+
const qlPackRootPath = getFileOrDir("data-remote-qlpack-nested");
163+
const qlPackFilePath = getFileOrDir(
164+
"data-remote-qlpack-nested/codeql-pack.yml",
165+
);
157166
const qlPackDetails: QlPackDetails = {
158167
queryFile: filePath,
159-
qlPackRootPath: join(baseDir, "data-remote-qlpack-nested"),
168+
qlPackRootPath,
169+
qlPackFilePath,
160170
};
161171

162172
await variantAnalysisManager.runVariantAnalysis(
@@ -179,9 +189,11 @@ describe("Variant Analysis Manager", () => {
179189

180190
it("should cancel a run before uploading", async () => {
181191
const filePath = getFileOrDir("data-remote-no-qlpack/in-pack.ql");
192+
const qlPackRootPath = getFileOrDir("data-remote-no-qlpack");
182193
const qlPackDetails: QlPackDetails = {
183194
queryFile: filePath,
184-
qlPackRootPath: join(baseDir, "data-remote-no-qlpack"),
195+
qlPackRootPath,
196+
qlPackFilePath: undefined,
185197
};
186198

187199
const promise = variantAnalysisManager.runVariantAnalysis(
@@ -223,6 +235,7 @@ describe("Variant Analysis Manager", () => {
223235
await doVariantAnalysisTest({
224236
queryPath: "data-remote-qlpack/in-pack.ql",
225237
qlPackRootPath: "data-remote-qlpack",
238+
qlPackFilePath: "data-remote-qlpack/qlpack.yml",
226239
expectedPackName: "github/remote-query-pack",
227240
filesThatExist: ["in-pack.ql", "lib.qll"],
228241
filesThatDoNotExist: [],
@@ -234,6 +247,7 @@ describe("Variant Analysis Manager", () => {
234247
await doVariantAnalysisTest({
235248
queryPath: "data-remote-no-qlpack/in-pack.ql",
236249
qlPackRootPath: "data-remote-no-qlpack",
250+
qlPackFilePath: undefined,
237251
expectedPackName: "codeql-remote/query",
238252
filesThatExist: ["in-pack.ql"],
239253
filesThatDoNotExist: ["lib.qll", "not-in-pack.ql"],
@@ -245,6 +259,7 @@ describe("Variant Analysis Manager", () => {
245259
await doVariantAnalysisTest({
246260
queryPath: "data-remote-qlpack-nested/subfolder/in-pack.ql",
247261
qlPackRootPath: "data-remote-qlpack-nested",
262+
qlPackFilePath: "data-remote-qlpack-nested/codeql-pack.yml",
248263
expectedPackName: "github/remote-query-pack",
249264
filesThatExist: ["subfolder/in-pack.ql", "otherfolder/lib.qll"],
250265
filesThatDoNotExist: ["subfolder/not-in-pack.ql"],
@@ -263,6 +278,7 @@ describe("Variant Analysis Manager", () => {
263278
await doVariantAnalysisTest({
264279
queryPath: "data-remote-qlpack-nested/subfolder/in-pack.ql",
265280
qlPackRootPath: "data-remote-qlpack-nested",
281+
qlPackFilePath: "data-remote-qlpack-nested/codeql-pack.yml",
266282
expectedPackName: "github/remote-query-pack",
267283
filesThatExist: [
268284
"subfolder/in-pack.ql",
@@ -309,9 +325,11 @@ describe("Variant Analysis Manager", () => {
309325

310326
const qlPackRootPath = join(process.env.TEST_CODEQL_PATH, "java/ql/src");
311327
const queryPath = join(qlPackRootPath, queryToRun);
328+
const qlPackFilePath = join(qlPackRootPath, "qlpack.yml");
312329
await doVariantAnalysisTest({
313330
queryPath,
314331
qlPackRootPath,
332+
qlPackFilePath,
315333
expectedPackName: "codeql/java-queries",
316334
filesThatExist: [queryToRun, ...extraQueries],
317335
filesThatDoNotExist: [],
@@ -325,6 +343,7 @@ describe("Variant Analysis Manager", () => {
325343
async function doVariantAnalysisTest({
326344
queryPath,
327345
qlPackRootPath,
346+
qlPackFilePath,
328347
expectedPackName,
329348
filesThatExist,
330349
qlxFilesThatExist,
@@ -337,6 +356,7 @@ describe("Variant Analysis Manager", () => {
337356
}: {
338357
queryPath: string;
339358
qlPackRootPath: string;
359+
qlPackFilePath: string | undefined;
340360
expectedPackName: string;
341361
filesThatExist: string[];
342362
qlxFilesThatExist: string[];
@@ -348,6 +368,7 @@ describe("Variant Analysis Manager", () => {
348368
const qlPackDetails: QlPackDetails = {
349369
queryFile: filePath,
350370
qlPackRootPath: getFileOrDir(qlPackRootPath),
371+
qlPackFilePath: qlPackFilePath && getFileOrDir(qlPackFilePath),
351372
};
352373

353374
await variantAnalysisManager.runVariantAnalysis(

0 commit comments

Comments
 (0)