Skip to content

Commit

Permalink
Move QL pack file path to the QlPackDetails (#3269)
Browse files Browse the repository at this point in the history
  • Loading branch information
charisk authored Jan 23, 2024
1 parent e612764 commit aada351
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions extensions/ql-vscode/src/variant-analysis/ql-pack-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export interface QlPackDetails {
// The path to the QL pack that is used for triggering a variant analysis.
// If there is no query pack, this is the same as the directory of the query files.
qlPackRootPath: string;

// The path to the QL pack file (a qlpack.yml or codeql-pack.yml) or undefined if
// it doesn't exist.
qlPackFilePath: string | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ async function generateQueryPack(
workspaceFolders,
);

const mustSynthesizePack =
(await getQlPackFilePath(originalPackRoot)) === undefined;
const mustSynthesizePack = qlPackDetails.qlPackFilePath === undefined;
const cliSupportsMrvaPackCreate =
await cliServer.cliConstraints.supportsMrvaPackCreate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import { handleRequestError } from "./custom-errors";
import { createMultiSelectionCommand } from "../common/vscode/selection-commands";
import { askForLanguage } from "../codeql-cli/query-language";
import type { QlPackDetails } from "./ql-pack-details";
import { findPackRoot } from "../common/ql";
import { findPackRoot, getQlPackFilePath } from "../common/ql";

const maxRetryCount = 3;

Expand Down Expand Up @@ -269,12 +269,15 @@ export class VariantAnalysisManager
return;
}

const qlPackFilePath = await getQlPackFilePath(packDir);

// Build up details to pass to the functions that run the variant analysis.
// For now, only include the first problem query until we have support
// for multiple queries.
const qlPackDetails: QlPackDetails = {
queryFile: problemQueries[0],
qlPackRootPath: packDir,
qlPackFilePath,
};

await this.runVariantAnalysis(
Expand Down Expand Up @@ -311,9 +314,11 @@ export class VariantAnalysisManager
private async runVariantAnalysisCommand(uri: Uri): Promise<void> {
// Build up details to pass to the functions that run the variant analysis.
const qlPackRootPath = await findPackRoot(uri.fsPath);
const qlPackFilePath = await getQlPackFilePath(qlPackRootPath);
const qlPackDetails: QlPackDetails = {
queryFile: uri.fsPath,
qlPackRootPath,
qlPackFilePath,
};

return withProgress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ describe("Variant Analysis Manager", () => {

it("should run a variant analysis that is part of a qlpack", async () => {
const filePath = getFileOrDir("data-remote-qlpack/in-pack.ql");
const qlPackRootPath = getFileOrDir("data-remote-qlpack");
const qlPackFilePath = getFileOrDir("data-remote-qlpack/qlpack.yml");
const qlPackDetails: QlPackDetails = {
queryFile: filePath,
qlPackRootPath: join(baseDir, "data-remote-qlpack"),
qlPackRootPath,
qlPackFilePath,
};

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

it("should run a remote query that is not part of a qlpack", async () => {
const filePath = getFileOrDir("data-remote-no-qlpack/in-pack.ql");
const qlPackRootPath = getFileOrDir("data-remote-no-qlpack");
const qlPackDetails: QlPackDetails = {
queryFile: filePath,
qlPackRootPath: join(baseDir, "data-remote-no-qlpack"),
qlPackRootPath,
qlPackFilePath: undefined,
};

await variantAnalysisManager.runVariantAnalysis(
Expand All @@ -154,9 +159,14 @@ describe("Variant Analysis Manager", () => {
const filePath = getFileOrDir(
"data-remote-qlpack-nested/subfolder/in-pack.ql",
);
const qlPackRootPath = getFileOrDir("data-remote-qlpack-nested");
const qlPackFilePath = getFileOrDir(
"data-remote-qlpack-nested/codeql-pack.yml",
);
const qlPackDetails: QlPackDetails = {
queryFile: filePath,
qlPackRootPath: join(baseDir, "data-remote-qlpack-nested"),
qlPackRootPath,
qlPackFilePath,
};

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

it("should cancel a run before uploading", async () => {
const filePath = getFileOrDir("data-remote-no-qlpack/in-pack.ql");
const qlPackRootPath = getFileOrDir("data-remote-no-qlpack");
const qlPackDetails: QlPackDetails = {
queryFile: filePath,
qlPackRootPath: join(baseDir, "data-remote-no-qlpack"),
qlPackRootPath,
qlPackFilePath: undefined,
};

const promise = variantAnalysisManager.runVariantAnalysis(
Expand Down Expand Up @@ -223,6 +235,7 @@ describe("Variant Analysis Manager", () => {
await doVariantAnalysisTest({
queryPath: "data-remote-qlpack/in-pack.ql",
qlPackRootPath: "data-remote-qlpack",
qlPackFilePath: "data-remote-qlpack/qlpack.yml",
expectedPackName: "github/remote-query-pack",
filesThatExist: ["in-pack.ql", "lib.qll"],
filesThatDoNotExist: [],
Expand All @@ -234,6 +247,7 @@ describe("Variant Analysis Manager", () => {
await doVariantAnalysisTest({
queryPath: "data-remote-no-qlpack/in-pack.ql",
qlPackRootPath: "data-remote-no-qlpack",
qlPackFilePath: undefined,
expectedPackName: "codeql-remote/query",
filesThatExist: ["in-pack.ql"],
filesThatDoNotExist: ["lib.qll", "not-in-pack.ql"],
Expand All @@ -245,6 +259,7 @@ describe("Variant Analysis Manager", () => {
await doVariantAnalysisTest({
queryPath: "data-remote-qlpack-nested/subfolder/in-pack.ql",
qlPackRootPath: "data-remote-qlpack-nested",
qlPackFilePath: "data-remote-qlpack-nested/codeql-pack.yml",
expectedPackName: "github/remote-query-pack",
filesThatExist: ["subfolder/in-pack.ql", "otherfolder/lib.qll"],
filesThatDoNotExist: ["subfolder/not-in-pack.ql"],
Expand All @@ -263,6 +278,7 @@ describe("Variant Analysis Manager", () => {
await doVariantAnalysisTest({
queryPath: "data-remote-qlpack-nested/subfolder/in-pack.ql",
qlPackRootPath: "data-remote-qlpack-nested",
qlPackFilePath: "data-remote-qlpack-nested/codeql-pack.yml",
expectedPackName: "github/remote-query-pack",
filesThatExist: [
"subfolder/in-pack.ql",
Expand Down Expand Up @@ -309,9 +325,11 @@ describe("Variant Analysis Manager", () => {

const qlPackRootPath = join(process.env.TEST_CODEQL_PATH, "java/ql/src");
const queryPath = join(qlPackRootPath, queryToRun);
const qlPackFilePath = join(qlPackRootPath, "qlpack.yml");
await doVariantAnalysisTest({
queryPath,
qlPackRootPath,
qlPackFilePath,
expectedPackName: "codeql/java-queries",
filesThatExist: [queryToRun, ...extraQueries],
filesThatDoNotExist: [],
Expand All @@ -325,6 +343,7 @@ describe("Variant Analysis Manager", () => {
async function doVariantAnalysisTest({
queryPath,
qlPackRootPath,
qlPackFilePath,
expectedPackName,
filesThatExist,
qlxFilesThatExist,
Expand All @@ -337,6 +356,7 @@ describe("Variant Analysis Manager", () => {
}: {
queryPath: string;
qlPackRootPath: string;
qlPackFilePath: string | undefined;
expectedPackName: string;
filesThatExist: string[];
qlxFilesThatExist: string[];
Expand All @@ -348,6 +368,7 @@ describe("Variant Analysis Manager", () => {
const qlPackDetails: QlPackDetails = {
queryFile: filePath,
qlPackRootPath: getFileOrDir(qlPackRootPath),
qlPackFilePath: qlPackFilePath && getFileOrDir(qlPackFilePath),
};

await variantAnalysisManager.runVariantAnalysis(
Expand Down

0 comments on commit aada351

Please sign in to comment.