Skip to content

Commit 140d369

Browse files
committed
Remove unsupported version constraints
This removes all CodeQL CLI version constraints for unsupported CLI versions (< 2.7.6). The oldest supported CLI version is 2.7.6 since GHES 3.3 recommends using CodeQL CLI 2.7.6.
1 parent 2c19b32 commit 140d369

File tree

18 files changed

+71
-512
lines changed

18 files changed

+71
-512
lines changed

extensions/ql-vscode/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [UNRELEASED]
44

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

78
## 1.7.7 - 13 December 2022
89

extensions/ql-vscode/src/cli.ts

+4-155
Original file line numberDiff line numberDiff line change
@@ -1125,10 +1125,7 @@ export class CodeQLCliServer implements Disposable {
11251125
];
11261126
if (targetDbScheme) {
11271127
args.push("--target-dbscheme", targetDbScheme);
1128-
if (
1129-
allowDowngradesIfPossible &&
1130-
(await this.cliConstraints.supportsDowngrades())
1131-
) {
1128+
if (allowDowngradesIfPossible) {
11321129
args.push("--allow-downgrades");
11331130
}
11341131
}
@@ -1210,10 +1207,8 @@ export class CodeQLCliServer implements Disposable {
12101207
if (searchPath !== undefined) {
12111208
args.push("--search-path", join(...searchPath));
12121209
}
1213-
if (await this.cliConstraints.supportsAllowLibraryPacksInResolveQueries()) {
1214-
// All of our usage of `codeql resolve queries` needs to handle library packs.
1215-
args.push("--allow-library-packs");
1216-
}
1210+
// All of our usage of `codeql resolve queries` needs to handle library packs.
1211+
args.push("--allow-library-packs");
12171212
args.push(suite);
12181213
return this.runJsonCodeQlCliCommand<string[]>(
12191214
["resolve", "queries"],
@@ -1300,12 +1295,9 @@ export class CodeQLCliServer implements Disposable {
13001295
}
13011296

13021297
async generateDil(qloFile: string, outFile: string): Promise<void> {
1303-
const extraArgs = (await this.cliConstraints.supportsDecompileDil())
1304-
? ["--kind", "dil", "-o", outFile, qloFile]
1305-
: ["-o", outFile, qloFile];
13061298
await this.runCodeQlCliCommand(
13071299
["query", "decompile"],
1308-
extraArgs,
1300+
["--kind", "dil", "-o", outFile, qloFile],
13091301
"Generating DIL",
13101302
);
13111303
}
@@ -1583,85 +1575,20 @@ export function shouldDebugCliServer() {
15831575
}
15841576

15851577
export class CliVersionConstraint {
1586-
/**
1587-
* CLI version where --kind=DIL was introduced
1588-
*/
1589-
public static CLI_VERSION_WITH_DECOMPILE_KIND_DIL = new SemVer("2.3.0");
1590-
1591-
/**
1592-
* CLI version where languages are exposed during a `codeql resolve database` command.
1593-
*/
1594-
public static CLI_VERSION_WITH_LANGUAGE = new SemVer("2.4.1");
1595-
1596-
public static CLI_VERSION_WITH_NONDESTURCTIVE_UPGRADES = new SemVer("2.4.2");
1597-
1598-
/**
1599-
* CLI version where `codeql resolve upgrades` supports
1600-
* the `--allow-downgrades` flag
1601-
*/
1602-
public static CLI_VERSION_WITH_DOWNGRADES = new SemVer("2.4.4");
1603-
1604-
/**
1605-
* CLI version where the `codeql resolve qlref` command is available.
1606-
*/
1607-
public static CLI_VERSION_WITH_RESOLVE_QLREF = new SemVer("2.5.1");
1608-
1609-
/**
1610-
* CLI version where database registration was introduced
1611-
*/
1612-
public static CLI_VERSION_WITH_DB_REGISTRATION = new SemVer("2.4.1");
1613-
1614-
/**
1615-
* CLI version where the `--allow-library-packs` option to `codeql resolve queries` was
1616-
* introduced.
1617-
*/
1618-
public static CLI_VERSION_WITH_ALLOW_LIBRARY_PACKS_IN_RESOLVE_QUERIES =
1619-
new SemVer("2.6.1");
1620-
1621-
/**
1622-
* CLI version where the `database unbundle` subcommand was introduced.
1623-
*/
1624-
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer("2.6.0");
1625-
1626-
/**
1627-
* CLI version where the `--no-precompile` option for pack creation was introduced.
1628-
*/
1629-
public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer("2.7.1");
1630-
1631-
/**
1632-
* CLI version where remote queries (variant analysis) are supported.
1633-
*/
1634-
public static CLI_VERSION_REMOTE_QUERIES = new SemVer("2.6.3");
1635-
16361578
/**
16371579
* CLI version where building QLX packs for remote queries is supported.
16381580
* (The options were _accepted_ by a few earlier versions, but only from
16391581
* 2.11.3 will it actually use the existing compilation cache correctly).
16401582
*/
16411583
public static CLI_VERSION_QLX_REMOTE = new SemVer("2.11.3");
16421584

1643-
/**
1644-
* CLI version where the `resolve ml-models` subcommand was introduced.
1645-
*/
1646-
public static CLI_VERSION_WITH_RESOLVE_ML_MODELS = new SemVer("2.7.3");
1647-
16481585
/**
16491586
* CLI version where the `resolve ml-models` subcommand was enhanced to work with packaging.
16501587
*/
16511588
public static CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS = new SemVer(
16521589
"2.10.0",
16531590
);
16541591

1655-
/**
1656-
* CLI version where the `--old-eval-stats` option to the query server was introduced.
1657-
*/
1658-
public static CLI_VERSION_WITH_OLD_EVAL_STATS = new SemVer("2.7.4");
1659-
1660-
/**
1661-
* CLI version where packaging was introduced.
1662-
*/
1663-
public static CLI_VERSION_WITH_PACKAGING = new SemVer("2.6.0");
1664-
16651592
/**
16661593
* CLI version where the `--evaluator-log` and related options to the query server were introduced,
16671594
* on a per-query server basis.
@@ -1702,94 +1629,16 @@ export class CliVersionConstraint {
17021629
return (await this.cli.getVersion()).compare(v) >= 0;
17031630
}
17041631

1705-
public async supportsDecompileDil() {
1706-
return this.isVersionAtLeast(
1707-
CliVersionConstraint.CLI_VERSION_WITH_DECOMPILE_KIND_DIL,
1708-
);
1709-
}
1710-
1711-
public async supportsLanguageName() {
1712-
return this.isVersionAtLeast(
1713-
CliVersionConstraint.CLI_VERSION_WITH_LANGUAGE,
1714-
);
1715-
}
1716-
1717-
public async supportsNonDestructiveUpgrades() {
1718-
return this.isVersionAtLeast(
1719-
CliVersionConstraint.CLI_VERSION_WITH_NONDESTURCTIVE_UPGRADES,
1720-
);
1721-
}
1722-
1723-
public async supportsDowngrades() {
1724-
return this.isVersionAtLeast(
1725-
CliVersionConstraint.CLI_VERSION_WITH_DOWNGRADES,
1726-
);
1727-
}
1728-
1729-
public async supportsResolveQlref() {
1730-
return this.isVersionAtLeast(
1731-
CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_QLREF,
1732-
);
1733-
}
1734-
1735-
public async supportsAllowLibraryPacksInResolveQueries() {
1736-
return this.isVersionAtLeast(
1737-
CliVersionConstraint.CLI_VERSION_WITH_ALLOW_LIBRARY_PACKS_IN_RESOLVE_QUERIES,
1738-
);
1739-
}
1740-
1741-
async supportsDatabaseRegistration() {
1742-
return this.isVersionAtLeast(
1743-
CliVersionConstraint.CLI_VERSION_WITH_DB_REGISTRATION,
1744-
);
1745-
}
1746-
1747-
async supportsDatabaseUnbundle() {
1748-
return this.isVersionAtLeast(
1749-
CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE,
1750-
);
1751-
}
1752-
1753-
async supportsNoPrecompile() {
1754-
return this.isVersionAtLeast(
1755-
CliVersionConstraint.CLI_VERSION_WITH_NO_PRECOMPILE,
1756-
);
1757-
}
1758-
1759-
async supportsRemoteQueries() {
1760-
return this.isVersionAtLeast(
1761-
CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES,
1762-
);
1763-
}
1764-
17651632
async supportsQlxRemote() {
17661633
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_QLX_REMOTE);
17671634
}
17681635

1769-
async supportsResolveMlModels() {
1770-
return this.isVersionAtLeast(
1771-
CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_ML_MODELS,
1772-
);
1773-
}
1774-
17751636
async supportsPreciseResolveMlModels() {
17761637
return this.isVersionAtLeast(
17771638
CliVersionConstraint.CLI_VERSION_WITH_PRECISE_RESOLVE_ML_MODELS,
17781639
);
17791640
}
17801641

1781-
async supportsOldEvalStats() {
1782-
return this.isVersionAtLeast(
1783-
CliVersionConstraint.CLI_VERSION_WITH_OLD_EVAL_STATS,
1784-
);
1785-
}
1786-
1787-
async supportsPackaging() {
1788-
return this.isVersionAtLeast(
1789-
CliVersionConstraint.CLI_VERSION_WITH_PACKAGING,
1790-
);
1791-
}
1792-
17931642
async supportsStructuredEvalLog() {
17941643
return this.isVersionAtLeast(
17951644
CliVersionConstraint.CLI_VERSION_WITH_STRUCTURED_EVAL_LOG,

extensions/ql-vscode/src/contextual/queryResolver.ts

+9-40
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,12 @@ export async function resolveQueries(
7474
qlpacks: QlPacksForLanguage,
7575
keyType: KeyType,
7676
): Promise<string[]> {
77-
const cliCanHandleLibraryPack =
78-
await cli.cliConstraints.supportsAllowLibraryPacksInResolveQueries();
7977
const packsToSearch: string[] = [];
80-
let blameCli: boolean;
8178

82-
if (cliCanHandleLibraryPack) {
83-
// The CLI can handle both library packs and query packs, so search both packs in order.
84-
packsToSearch.push(qlpacks.dbschemePack);
85-
if (qlpacks.queryPack !== undefined) {
86-
packsToSearch.push(qlpacks.queryPack);
87-
}
88-
// If we don't find the query, it's because it's not there, not because the CLI was unable to
89-
// search the pack.
90-
blameCli = false;
91-
} else {
92-
// Older CLIs can't handle `codeql resolve queries` with a suite that references a library pack.
93-
if (qlpacks.dbschemePackIsLibraryPack) {
94-
if (qlpacks.queryPack !== undefined) {
95-
// Just search the query pack, because some older library/query releases still had the
96-
// contextual queries in the query pack.
97-
packsToSearch.push(qlpacks.queryPack);
98-
}
99-
// If we don't find it, it's because the CLI was unable to search the library pack that
100-
// actually contains the query. Blame any failure on the CLI, not the packs.
101-
blameCli = true;
102-
} else {
103-
// We have an old CLI, but the dbscheme pack is old enough that it's still a unified pack with
104-
// both libraries and queries. Just search that pack.
105-
packsToSearch.push(qlpacks.dbschemePack);
106-
// Any CLI should be able to search the single query pack, so if we don't find it, it's
107-
// because the language doesn't support it.
108-
blameCli = false;
109-
}
79+
// The CLI can handle both library packs and query packs, so search both packs in order.
80+
packsToSearch.push(qlpacks.dbschemePack);
81+
if (qlpacks.queryPack !== undefined) {
82+
packsToSearch.push(qlpacks.queryPack);
11083
}
11184

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

11790
// No queries found. Determine the correct error message for the various scenarios.
118-
const errorMessage = blameCli
119-
? `Your current version of the CodeQL CLI, '${
120-
(await cli.getVersion()).version
121-
}', \
122-
is unable to use contextual queries from recent versions of the standard CodeQL libraries. \
123-
Please upgrade to the latest version of the CodeQL CLI.`
124-
: `No ${nameOfKeyType(keyType)} queries (tagged "${tagOfKeyType(
125-
keyType,
126-
)}") could be found in the current library path. \
91+
const errorMessage = `No ${nameOfKeyType(
92+
keyType,
93+
)} queries (tagged "${tagOfKeyType(
94+
keyType,
95+
)}") could be found in the current library path. \
12796
Try upgrading the CodeQL libraries. If that doesn't work, then ${nameOfKeyType(
12897
keyType,
12998
)} queries are not yet available \

extensions/ql-vscode/src/databaseFetcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ async function readAndUnzip(
321321
step: 9,
322322
message: `Unzipping into ${basename(unzipPath)}`,
323323
});
324-
if (cli && (await cli.cliConstraints.supportsDatabaseUnbundle())) {
324+
if (cli) {
325325
// Use the `database unbundle` command if the installed cli version supports it
326326
await cli.databaseUnbundle(zipFile, unzipPath);
327327
} else {

extensions/ql-vscode/src/databases.ts

-6
Original file line numberDiff line numberDiff line change
@@ -990,12 +990,6 @@ export class DatabaseManager extends DisposableObject {
990990
}
991991

992992
private async getPrimaryLanguage(dbPath: string) {
993-
if (!(await this.cli.cliConstraints.supportsLanguageName())) {
994-
// return undefined so that we recalculate on restart until the cli is at a version that
995-
// supports this feature. This recalculation is cheap since we avoid calling into the cli
996-
// unless we know it can return the langauges property.
997-
return undefined;
998-
}
999993
const dbInfo = await this.cli.resolveDatabase(dbPath);
1000994
return dbInfo.languages?.[0] || "";
1001995
}

extensions/ql-vscode/src/extension.ts

+4-25
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
zipArchiveScheme,
3434
} from "./archive-filesystem-provider";
3535
import QuickEvalCodeLensProvider from "./quickEvalCodeLensProvider";
36-
import { CodeQLCliServer, CliVersionConstraint } from "./cli";
36+
import { CodeQLCliServer } from "./cli";
3737
import {
3838
CliConfigListener,
3939
DistributionConfigListener,
@@ -820,17 +820,9 @@ async function activateWithInstalledDistribution(
820820
const path =
821821
selectedQuery?.fsPath || window.activeTextEditor?.document.uri.fsPath;
822822
if (qs !== undefined && path) {
823-
if (await cliServer.cliConstraints.supportsResolveQlref()) {
824-
const resolved = await cliServer.resolveQlref(path);
825-
const uri = Uri.file(resolved.resolvedPath);
826-
await window.showTextDocument(uri, { preview: false });
827-
} else {
828-
void showAndLogErrorMessage(
829-
"Jumping from a .qlref file to the .ql file it references is not " +
830-
"supported with the CLI version you are running.\n" +
831-
`Please upgrade your CLI to version ${CliVersionConstraint.CLI_VERSION_WITH_RESOLVE_QLREF} or later to use this feature.`,
832-
);
833-
}
823+
const resolved = await cliServer.resolveQlref(path);
824+
const uri = Uri.file(resolved.resolvedPath);
825+
await window.showTextDocument(uri, { preview: false });
834826
}
835827
}
836828

@@ -1014,19 +1006,6 @@ async function activateWithInstalledDistribution(
10141006
});
10151007
}
10161008

1017-
if (
1018-
queryUris.length > 1 &&
1019-
!(await cliServer.cliConstraints.supportsNonDestructiveUpgrades())
1020-
) {
1021-
// Try to upgrade the current database before running any queries
1022-
// so that the user isn't confronted with multiple upgrade
1023-
// requests for each query to run.
1024-
// Only do it if running multiple queries since this check is
1025-
// performed on each query run anyway.
1026-
// Don't do this with non destructive upgrades as the user won't see anything anyway.
1027-
await databaseUI.tryUpgradeCurrentDatabase(progress, token);
1028-
}
1029-
10301009
wrappedProgress({
10311010
maxStep: queryUris.length,
10321011
step: queryUris.length - queriesRemaining,

extensions/ql-vscode/src/helpers.ts

-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ export class CachedOperation<U> {
540540
* `cli.CodeQLCliServer.resolveDatabase` and use the first entry in the
541541
* `languages` property.
542542
*
543-
* @see cli.CliVersionConstraint.supportsLanguageName
544543
* @see cli.CodeQLCliServer.resolveDatabase
545544
*/
546545
export const dbSchemeToLanguage = {

extensions/ql-vscode/src/legacy-query-server/legacyRunner.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ export class LegacyQueryRunner extends QueryRunner {
7474
token: CancellationToken,
7575
dbItem: DatabaseItem,
7676
): Promise<void> {
77-
if (
78-
dbItem.contents &&
79-
(await this.qs.cliServer.cliConstraints.supportsDatabaseRegistration())
80-
) {
77+
if (dbItem.contents) {
8178
const databases: Dataset[] = [
8279
{
8380
dbDir: dbItem.contents.datasetUri.fsPath,
@@ -97,10 +94,7 @@ export class LegacyQueryRunner extends QueryRunner {
9794
token: CancellationToken,
9895
dbItem: DatabaseItem,
9996
): Promise<void> {
100-
if (
101-
dbItem.contents &&
102-
(await this.qs.cliServer.cliConstraints.supportsDatabaseRegistration())
103-
) {
97+
if (dbItem.contents) {
10498
const databases: Dataset[] = [
10599
{
106100
dbDir: dbItem.contents.datasetUri.fsPath,

0 commit comments

Comments
 (0)