Move query language to the QlPackDetails (#3270)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import type { QueryLanguage } from "../common/query-language";
|
||||
|
||||
/**
|
||||
* Details about the original QL pack that is used for triggering
|
||||
* a variant analysis.
|
||||
@@ -12,4 +14,6 @@ export interface QlPackDetails {
|
||||
// The path to the QL pack file (a qlpack.yml or codeql-pack.yml) or undefined if
|
||||
// it doesn't exist.
|
||||
qlPackFilePath: string | undefined;
|
||||
|
||||
language: QueryLanguage;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ import {
|
||||
QLPACK_FILENAMES,
|
||||
QLPACK_LOCK_FILENAMES,
|
||||
} from "../common/ql";
|
||||
import type { QueryLanguage } from "../common/query-language";
|
||||
import { tryGetQueryMetadata } from "../codeql-cli/query-metadata";
|
||||
import { askForLanguage, findLanguage } from "../codeql-cli/query-language";
|
||||
import type { QlPackFile } from "../packaging/qlpack-file";
|
||||
import { expandShortPaths } from "../common/short-paths";
|
||||
import type { QlPackDetails } from "./ql-pack-details";
|
||||
@@ -46,11 +44,6 @@ import type { QlPackDetails } from "./ql-pack-details";
|
||||
*/
|
||||
const QUERY_PACK_NAME = "codeql-remote/query";
|
||||
|
||||
interface GeneratedQueryPack {
|
||||
base64Pack: string;
|
||||
language: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Two possibilities:
|
||||
* 1. There is no qlpack.yml (or codeql-pack.yml) in this directory. Assume this is a lone query and generate a synthetic qlpack for it.
|
||||
@@ -62,7 +55,7 @@ async function generateQueryPack(
|
||||
cliServer: CodeQLCliServer,
|
||||
qlPackDetails: QlPackDetails,
|
||||
tmpDir: RemoteQueryTempDir,
|
||||
): Promise<GeneratedQueryPack> {
|
||||
): Promise<string> {
|
||||
const queryFile = qlPackDetails.queryFile;
|
||||
|
||||
const originalPackRoot = qlPackDetails.qlPackRootPath;
|
||||
@@ -77,13 +70,6 @@ async function generateQueryPack(
|
||||
const cliSupportsMrvaPackCreate =
|
||||
await cliServer.cliConstraints.supportsMrvaPackCreate();
|
||||
|
||||
const language: QueryLanguage | undefined = mustSynthesizePack
|
||||
? await askForLanguage(cliServer) // open popup to ask for language if not already hardcoded
|
||||
: await findLanguage(cliServer, Uri.file(queryFile));
|
||||
if (!language) {
|
||||
throw new UserCancellationException("Could not determine language");
|
||||
}
|
||||
|
||||
let queryPackDir: string;
|
||||
let needsInstall: boolean;
|
||||
if (mustSynthesizePack) {
|
||||
@@ -97,7 +83,7 @@ async function generateQueryPack(
|
||||
await createNewQueryPack(
|
||||
queryFile,
|
||||
queryPackDir,
|
||||
language,
|
||||
qlPackDetails.language,
|
||||
packRelativePath,
|
||||
);
|
||||
// Clear the cliServer cache so that the previous qlpack text is purged from the CLI.
|
||||
@@ -176,10 +162,7 @@ async function generateQueryPack(
|
||||
precompilationOpts,
|
||||
);
|
||||
const base64Pack = (await readFile(bundlePath)).toString("base64");
|
||||
return {
|
||||
base64Pack,
|
||||
language,
|
||||
};
|
||||
return base64Pack;
|
||||
}
|
||||
|
||||
async function createNewQueryPack(
|
||||
@@ -305,7 +288,6 @@ interface PreparedRemoteQuery {
|
||||
queryMetadata: QueryMetadata | undefined;
|
||||
controllerRepo: Repository;
|
||||
queryStartTime: number;
|
||||
language: string;
|
||||
}
|
||||
|
||||
export async function prepareRemoteQueryRun(
|
||||
@@ -351,16 +333,14 @@ export async function prepareRemoteQueryRun(
|
||||
|
||||
const tempDir = await createRemoteQueriesTempDirectory();
|
||||
|
||||
let pack: GeneratedQueryPack;
|
||||
let base64Pack: string;
|
||||
|
||||
try {
|
||||
pack = await generateQueryPack(cliServer, qlPackDetails, tempDir);
|
||||
base64Pack = await generateQueryPack(cliServer, qlPackDetails, tempDir);
|
||||
} finally {
|
||||
await tempDir.remoteQueryDir.cleanup();
|
||||
}
|
||||
|
||||
const { base64Pack, language } = pack;
|
||||
|
||||
if (token.isCancellationRequested) {
|
||||
throw new UserCancellationException("Cancelled");
|
||||
}
|
||||
@@ -384,7 +364,6 @@ export async function prepareRemoteQueryRun(
|
||||
queryMetadata,
|
||||
controllerRepo,
|
||||
queryStartTime,
|
||||
language,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
|
||||
import { RequestError } from "@octokit/request-error";
|
||||
import { handleRequestError } from "./custom-errors";
|
||||
import { createMultiSelectionCommand } from "../common/vscode/selection-commands";
|
||||
import { askForLanguage } from "../codeql-cli/query-language";
|
||||
import { askForLanguage, findLanguage } from "../codeql-cli/query-language";
|
||||
import type { QlPackDetails } from "./ql-pack-details";
|
||||
import { findPackRoot, getQlPackFilePath } from "../common/ql";
|
||||
|
||||
@@ -278,6 +278,7 @@ export class VariantAnalysisManager
|
||||
queryFile: problemQueries[0],
|
||||
qlPackRootPath: packDir,
|
||||
qlPackFilePath,
|
||||
language,
|
||||
};
|
||||
|
||||
await this.runVariantAnalysis(
|
||||
@@ -315,10 +316,21 @@ export class VariantAnalysisManager
|
||||
// Build up details to pass to the functions that run the variant analysis.
|
||||
const qlPackRootPath = await findPackRoot(uri.fsPath);
|
||||
const qlPackFilePath = await getQlPackFilePath(qlPackRootPath);
|
||||
|
||||
// Open popup to ask for language if not already hardcoded
|
||||
const language = qlPackFilePath
|
||||
? await findLanguage(this.cliServer, uri)
|
||||
: await askForLanguage(this.cliServer);
|
||||
|
||||
if (!language) {
|
||||
throw new UserCancellationException("Could not determine query language");
|
||||
}
|
||||
|
||||
const qlPackDetails: QlPackDetails = {
|
||||
queryFile: uri.fsPath,
|
||||
qlPackRootPath,
|
||||
qlPackFilePath,
|
||||
language,
|
||||
};
|
||||
|
||||
return withProgress(
|
||||
@@ -353,7 +365,6 @@ export class VariantAnalysisManager
|
||||
queryMetadata,
|
||||
controllerRepo,
|
||||
queryStartTime,
|
||||
language,
|
||||
} = await prepareRemoteQueryRun(
|
||||
this.cliServer,
|
||||
this.app.credentials,
|
||||
@@ -364,6 +375,7 @@ export class VariantAnalysisManager
|
||||
);
|
||||
|
||||
const queryName = getQueryName(queryMetadata, queryFile);
|
||||
const language = qlPackDetails.language;
|
||||
const variantAnalysisLanguage = parseVariantAnalysisQueryLanguage(language);
|
||||
if (variantAnalysisLanguage === undefined) {
|
||||
throw new UserCancellationException(
|
||||
|
||||
@@ -108,6 +108,7 @@ describe("Variant Analysis Manager", () => {
|
||||
queryFile: filePath,
|
||||
qlPackRootPath,
|
||||
qlPackFilePath,
|
||||
language: QueryLanguage.Javascript,
|
||||
};
|
||||
|
||||
await variantAnalysisManager.runVariantAnalysis(
|
||||
@@ -135,6 +136,7 @@ describe("Variant Analysis Manager", () => {
|
||||
queryFile: filePath,
|
||||
qlPackRootPath,
|
||||
qlPackFilePath: undefined,
|
||||
language: QueryLanguage.Javascript,
|
||||
};
|
||||
|
||||
await variantAnalysisManager.runVariantAnalysis(
|
||||
@@ -167,6 +169,7 @@ describe("Variant Analysis Manager", () => {
|
||||
queryFile: filePath,
|
||||
qlPackRootPath,
|
||||
qlPackFilePath,
|
||||
language: QueryLanguage.Javascript,
|
||||
};
|
||||
|
||||
await variantAnalysisManager.runVariantAnalysis(
|
||||
@@ -194,6 +197,7 @@ describe("Variant Analysis Manager", () => {
|
||||
queryFile: filePath,
|
||||
qlPackRootPath,
|
||||
qlPackFilePath: undefined,
|
||||
language: QueryLanguage.Javascript,
|
||||
};
|
||||
|
||||
const promise = variantAnalysisManager.runVariantAnalysis(
|
||||
@@ -369,6 +373,7 @@ describe("Variant Analysis Manager", () => {
|
||||
queryFile: filePath,
|
||||
qlPackRootPath: getFileOrDir(qlPackRootPath),
|
||||
qlPackFilePath: qlPackFilePath && getFileOrDir(qlPackFilePath),
|
||||
language: QueryLanguage.Javascript,
|
||||
};
|
||||
|
||||
await variantAnalysisManager.runVariantAnalysis(
|
||||
|
||||
@@ -86,6 +86,14 @@ describe("Variant Analysis Submission Integration", () => {
|
||||
it("shows the error message", async () => {
|
||||
await showQlDocument("query.ql");
|
||||
|
||||
// Select target language for your query
|
||||
quickPickSpy.mockResolvedValueOnce(
|
||||
mockedQuickPickItem({
|
||||
label: "JavaScript",
|
||||
language: "javascript",
|
||||
}),
|
||||
);
|
||||
|
||||
await commandManager.execute("codeQL.runVariantAnalysis");
|
||||
|
||||
expect(showErrorMessageSpy).toHaveBeenCalledWith(
|
||||
|
||||
Reference in New Issue
Block a user