Files
vscode-codeql/extensions/ql-vscode/src/codeql-cli/cli-version.ts
Nick Rolfe a069ae45fb Allow compatible CLIs to generate summary symbols file
This should be much faster than generating it in the extension.
2024-07-12 10:18:56 +00:00

57 lines
1.4 KiB
TypeScript

import type { SemVer } from "semver";
import { parse } from "semver";
import { runJsonCodeQlCliCommand } from "./cli-command";
import type { Logger } from "../common/logging";
import { getErrorMessage } from "../common/helpers-pure";
interface VersionResult {
version: string;
features: CliFeatures | undefined;
}
export interface CliFeatures {
featuresInVersionResult?: boolean;
mrvaPackCreate?: boolean;
generateSummarySymbolMap?: boolean;
}
export interface VersionAndFeatures {
version: SemVer;
features: CliFeatures;
}
/**
* Get the version of a CodeQL CLI.
*/
export async function getCodeQlCliVersion(
codeQlPath: string,
logger: Logger,
): Promise<VersionAndFeatures | undefined> {
try {
const output: VersionResult = await runJsonCodeQlCliCommand<VersionResult>(
codeQlPath,
["version"],
["--format=json"],
"Checking CodeQL version",
logger,
);
const version = parse(output.version.trim()) || undefined;
if (version === undefined) {
return undefined;
}
return {
version,
features: output.features ?? {},
};
} catch (e) {
// Failed to run the version command. This might happen if the cli version is _really_ old, or it is corrupted.
// Either way, we can't determine compatibility.
void logger.log(
`Failed to run 'codeql version'. Reason: ${getErrorMessage(e)}`,
);
return undefined;
}
}