Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsupported version constraints #1788

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/ql-vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [UNRELEASED]

- Renamed command "CodeQL: Run Query" to "CodeQL: Run Query on Selected Dababase".
- Remove support for CodeQL CLI versions older than 2.7.6. [#1788](https://github.com/github/vscode-codeql/pull/1788)

## 1.7.7 - 13 December 2022

Expand Down
159 changes: 4 additions & 155 deletions extensions/ql-vscode/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,10 +1125,7 @@ export class CodeQLCliServer implements Disposable {
];
if (targetDbScheme) {
args.push("--target-dbscheme", targetDbScheme);
if (
allowDowngradesIfPossible &&
(await this.cliConstraints.supportsDowngrades())
) {
if (allowDowngradesIfPossible) {
args.push("--allow-downgrades");
}
}
Expand Down Expand Up @@ -1210,10 +1207,8 @@ export class CodeQLCliServer implements Disposable {
if (searchPath !== undefined) {
args.push("--search-path", join(...searchPath));
}
if (await this.cliConstraints.supportsAllowLibraryPacksInResolveQueries()) {
// All of our usage of `codeql resolve queries` needs to handle library packs.
args.push("--allow-library-packs");
}
// All of our usage of `codeql resolve queries` needs to handle library packs.
args.push("--allow-library-packs");
args.push(suite);
return this.runJsonCodeQlCliCommand<string[]>(
["resolve", "queries"],
Expand Down Expand Up @@ -1300,12 +1295,9 @@ export class CodeQLCliServer implements Disposable {
}

async generateDil(qloFile: string, outFile: string): Promise<void> {
const extraArgs = (await this.cliConstraints.supportsDecompileDil())
? ["--kind", "dil", "-o", outFile, qloFile]
: ["-o", outFile, qloFile];
await this.runCodeQlCliCommand(
["query", "decompile"],
extraArgs,
["--kind", "dil", "-o", outFile, qloFile],
"Generating DIL",
);
}
Expand Down Expand Up @@ -1583,85 +1575,20 @@ export function shouldDebugCliServer() {
}

export class CliVersionConstraint {
/**
* CLI version where --kind=DIL was introduced
*/
public static CLI_VERSION_WITH_DECOMPILE_KIND_DIL = new SemVer("2.3.0");

/**
* CLI version where languages are exposed during a `codeql resolve database` command.
*/
public static CLI_VERSION_WITH_LANGUAGE = new SemVer("2.4.1");

public static CLI_VERSION_WITH_NONDESTURCTIVE_UPGRADES = new SemVer("2.4.2");

/**
* CLI version where `codeql resolve upgrades` supports
* the `--allow-downgrades` flag
*/
public static CLI_VERSION_WITH_DOWNGRADES = new SemVer("2.4.4");

/**
* CLI version where the `codeql resolve qlref` command is available.
*/
public static CLI_VERSION_WITH_RESOLVE_QLREF = new SemVer("2.5.1");

/**
* CLI version where database registration was introduced
*/
public static CLI_VERSION_WITH_DB_REGISTRATION = new SemVer("2.4.1");

/**
* CLI version where the `--allow-library-packs` option to `codeql resolve queries` was
* introduced.
*/
public static CLI_VERSION_WITH_ALLOW_LIBRARY_PACKS_IN_RESOLVE_QUERIES =
new SemVer("2.6.1");

/**
* CLI version where the `database unbundle` subcommand was introduced.
*/
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer("2.6.0");

/**
* CLI version where the `--no-precompile` option for pack creation was introduced.
*/
public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer("2.7.1");

/**
* CLI version where remote queries (variant analysis) are supported.
*/
public static CLI_VERSION_REMOTE_QUERIES = new SemVer("2.6.3");

/**
* CLI version where building QLX packs for remote queries is supported.
* (The options were _accepted_ by a few earlier versions, but only from
* 2.11.3 will it actually use the existing compilation cache correctly).
*/
public static CLI_VERSION_QLX_REMOTE = new SemVer("2.11.3");

/**
* CLI version where the `resolve ml-models` subcommand was introduced.
*/
public static CLI_VERSION_WITH_RESOLVE_ML_MODELS = new SemVer("2.7.3");

/**
* CLI version where the `resolve ml-models` subcommand was enhanced to work with packaging.
*/
public static CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS = new SemVer(
"2.10.0",
);

/**
* CLI version where the `--old-eval-stats` option to the query server was introduced.
*/
public static CLI_VERSION_WITH_OLD_EVAL_STATS = new SemVer("2.7.4");

/**
* CLI version where packaging was introduced.
*/
public static CLI_VERSION_WITH_PACKAGING = new SemVer("2.6.0");

/**
* CLI version where the `--evaluator-log` and related options to the query server were introduced,
* on a per-query server basis.
Expand Down Expand Up @@ -1702,94 +1629,16 @@ export class CliVersionConstraint {
return (await this.cli.getVersion()).compare(v) >= 0;
}

public async supportsDecompileDil() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_DECOMPILE_KIND_DIL,
);
}

public async supportsLanguageName() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_LANGUAGE,
);
}

public async supportsNonDestructiveUpgrades() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_NONDESTURCTIVE_UPGRADES,
);
}

public async supportsDowngrades() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_DOWNGRADES,
);
}

public async supportsResolveQlref() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_QLREF,
);
}

public async supportsAllowLibraryPacksInResolveQueries() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_ALLOW_LIBRARY_PACKS_IN_RESOLVE_QUERIES,
);
}

async supportsDatabaseRegistration() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_DB_REGISTRATION,
);
}

async supportsDatabaseUnbundle() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE,
);
}

async supportsNoPrecompile() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_NO_PRECOMPILE,
);
}

async supportsRemoteQueries() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES,
);
}

async supportsQlxRemote() {
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_QLX_REMOTE);
}

async supportsResolveMlModels() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_ML_MODELS,
);
}

async supportsPreciseResolveMlModels() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS,
);
}

async supportsOldEvalStats() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_OLD_EVAL_STATS,
);
}

async supportsPackaging() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_PACKAGING,
);
}

async supportsStructuredEvalLog() {
return this.isVersionAtLeast(
CliVersionConstraint.CLI_VERSION_WITH_STRUCTURED_EVAL_LOG,
Expand Down
49 changes: 9 additions & 40 deletions extensions/ql-vscode/src/contextual/queryResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,12 @@ export async function resolveQueries(
qlpacks: QlPacksForLanguage,
keyType: KeyType,
): Promise<string[]> {
const cliCanHandleLibraryPack =
await cli.cliConstraints.supportsAllowLibraryPacksInResolveQueries();
const packsToSearch: string[] = [];
let blameCli: boolean;

if (cliCanHandleLibraryPack) {
// The CLI can handle both library packs and query packs, so search both packs in order.
packsToSearch.push(qlpacks.dbschemePack);
if (qlpacks.queryPack !== undefined) {
packsToSearch.push(qlpacks.queryPack);
}
// If we don't find the query, it's because it's not there, not because the CLI was unable to
// search the pack.
blameCli = false;
} else {
// Older CLIs can't handle `codeql resolve queries` with a suite that references a library pack.
if (qlpacks.dbschemePackIsLibraryPack) {
if (qlpacks.queryPack !== undefined) {
// Just search the query pack, because some older library/query releases still had the
// contextual queries in the query pack.
packsToSearch.push(qlpacks.queryPack);
}
// If we don't find it, it's because the CLI was unable to search the library pack that
// actually contains the query. Blame any failure on the CLI, not the packs.
blameCli = true;
} else {
// We have an old CLI, but the dbscheme pack is old enough that it's still a unified pack with
// both libraries and queries. Just search that pack.
packsToSearch.push(qlpacks.dbschemePack);
// Any CLI should be able to search the single query pack, so if we don't find it, it's
// because the language doesn't support it.
blameCli = false;
}
// The CLI can handle both library packs and query packs, so search both packs in order.
packsToSearch.push(qlpacks.dbschemePack);
if (qlpacks.queryPack !== undefined) {
packsToSearch.push(qlpacks.queryPack);
}

const queries = await resolveQueriesFromPacks(cli, packsToSearch, keyType);
Expand All @@ -115,15 +88,11 @@ export async function resolveQueries(
}

// No queries found. Determine the correct error message for the various scenarios.
const errorMessage = blameCli
? `Your current version of the CodeQL CLI, '${
(await cli.getVersion()).version
}', \
is unable to use contextual queries from recent versions of the standard CodeQL libraries. \
Please upgrade to the latest version of the CodeQL CLI.`
: `No ${nameOfKeyType(keyType)} queries (tagged "${tagOfKeyType(
keyType,
)}") could be found in the current library path. \
const errorMessage = `No ${nameOfKeyType(
keyType,
)} queries (tagged "${tagOfKeyType(
keyType,
)}") could be found in the current library path. \
Try upgrading the CodeQL libraries. If that doesn't work, then ${nameOfKeyType(
keyType,
)} queries are not yet available \
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/databaseFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ async function readAndUnzip(
step: 9,
message: `Unzipping into ${basename(unzipPath)}`,
});
if (cli && (await cli.cliConstraints.supportsDatabaseUnbundle())) {
if (cli) {
// Use the `database unbundle` command if the installed cli version supports it
await cli.databaseUnbundle(zipFile, unzipPath);
} else {
Expand Down
6 changes: 0 additions & 6 deletions extensions/ql-vscode/src/databases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,12 +990,6 @@ export class DatabaseManager extends DisposableObject {
}

private async getPrimaryLanguage(dbPath: string) {
if (!(await this.cli.cliConstraints.supportsLanguageName())) {
// return undefined so that we recalculate on restart until the cli is at a version that
// supports this feature. This recalculation is cheap since we avoid calling into the cli
// unless we know it can return the langauges property.
return undefined;
}
const dbInfo = await this.cli.resolveDatabase(dbPath);
return dbInfo.languages?.[0] || "";
}
Expand Down
29 changes: 4 additions & 25 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
zipArchiveScheme,
} from "./archive-filesystem-provider";
import QuickEvalCodeLensProvider from "./quickEvalCodeLensProvider";
import { CodeQLCliServer, CliVersionConstraint } from "./cli";
import { CodeQLCliServer } from "./cli";
import {
CliConfigListener,
DistributionConfigListener,
Expand Down Expand Up @@ -820,17 +820,9 @@ async function activateWithInstalledDistribution(
const path =
selectedQuery?.fsPath || window.activeTextEditor?.document.uri.fsPath;
if (qs !== undefined && path) {
if (await cliServer.cliConstraints.supportsResolveQlref()) {
const resolved = await cliServer.resolveQlref(path);
const uri = Uri.file(resolved.resolvedPath);
await window.showTextDocument(uri, { preview: false });
} else {
void showAndLogErrorMessage(
"Jumping from a .qlref file to the .ql file it references is not " +
"supported with the CLI version you are running.\n" +
`Please upgrade your CLI to version ${CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_QLREF} or later to use this feature.`,
);
}
const resolved = await cliServer.resolveQlref(path);
const uri = Uri.file(resolved.resolvedPath);
await window.showTextDocument(uri, { preview: false });
}
}

Expand Down Expand Up @@ -1014,19 +1006,6 @@ async function activateWithInstalledDistribution(
});
}

if (
queryUris.length > 1 &&
!(await cliServer.cliConstraints.supportsNonDestructiveUpgrades())
) {
// Try to upgrade the current database before running any queries
// so that the user isn't confronted with multiple upgrade
// requests for each query to run.
// Only do it if running multiple queries since this check is
// performed on each query run anyway.
// Don't do this with non destructive upgrades as the user won't see anything anyway.
await databaseUI.tryUpgradeCurrentDatabase(progress, token);
}

wrappedProgress({
maxStep: queryUris.length,
step: queryUris.length - queriesRemaining,
Expand Down
1 change: 0 additions & 1 deletion extensions/ql-vscode/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ export class CachedOperation<U> {
* `cli.CodeQLCliServer.resolveDatabase` and use the first entry in the
* `languages` property.
*
* @see cli.CliVersionConstraint.supportsLanguageName
* @see cli.CodeQLCliServer.resolveDatabase
*/
export const dbSchemeToLanguage = {
Expand Down
10 changes: 2 additions & 8 deletions extensions/ql-vscode/src/legacy-query-server/legacyRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ export class LegacyQueryRunner extends QueryRunner {
token: CancellationToken,
dbItem: DatabaseItem,
): Promise<void> {
if (
dbItem.contents &&
(await this.qs.cliServer.cliConstraints.supportsDatabaseRegistration())
) {
if (dbItem.contents) {
const databases: Dataset[] = [
{
dbDir: dbItem.contents.datasetUri.fsPath,
Expand All @@ -97,10 +94,7 @@ export class LegacyQueryRunner extends QueryRunner {
token: CancellationToken,
dbItem: DatabaseItem,
): Promise<void> {
if (
dbItem.contents &&
(await this.qs.cliServer.cliConstraints.supportsDatabaseRegistration())
) {
if (dbItem.contents) {
const databases: Dataset[] = [
{
dbDir: dbItem.contents.datasetUri.fsPath,
Expand Down
Loading