Skip to content

Commit 9c8d331

Browse files
committed
Remove check for mrvaPackCreate CLI feature
1 parent 24f0a25 commit 9c8d331

File tree

3 files changed

+16
-183
lines changed

3 files changed

+16
-183
lines changed

extensions/ql-vscode/src/codeql-cli/cli-version.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ interface VersionResult {
1111

1212
export interface CliFeatures {
1313
featuresInVersionResult?: boolean;
14-
mrvaPackCreate?: boolean;
1514
generateSummarySymbolMap?: boolean;
1615
queryServerRunQueries?: boolean;
1716
}

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,10 +1910,6 @@ export class CliVersionConstraint {
19101910
/**/
19111911
}
19121912

1913-
async supportsMrvaPackCreate(): Promise<boolean> {
1914-
return (await this.cli.getFeatures()).mrvaPackCreate === true;
1915-
}
1916-
19171913
async supportsGenerateSummarySymbolMap(): Promise<boolean> {
19181914
return (await this.cli.getFeatures()).generateSummarySymbolMap === true;
19191915
}

extensions/ql-vscode/src/variant-analysis/run-remote-query.ts

Lines changed: 16 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CancellationToken } from "vscode";
2-
import { Uri, window } from "vscode";
3-
import { join, sep, basename, relative } from "path";
4-
import { dump, load } from "js-yaml";
2+
import { window } from "vscode";
3+
import { join, basename, relative } from "path";
4+
import { dump } from "js-yaml";
55
import { copy, writeFile, readFile, mkdirp, remove } from "fs-extra";
66
import { nanoid } from "nanoid";
77
import { tmpDir } from "../tmp-dir";
@@ -27,13 +27,7 @@ import {
2727
} from "./repository-selection";
2828
import type { Repository } from "./shared/repository";
2929
import type { DbManager } from "../databases/db-manager";
30-
import {
31-
getQlPackFilePath,
32-
FALLBACK_QLPACK_FILENAME,
33-
QLPACK_FILENAMES,
34-
QLPACK_LOCK_FILENAMES,
35-
} from "../common/ql";
36-
import type { QlPackFile } from "../packaging/qlpack-file";
30+
import { FALLBACK_QLPACK_FILENAME } from "../common/ql";
3731
import { expandShortPaths } from "../common/short-paths";
3832
import type { QlPackDetails } from "./ql-pack-details";
3933
import type { ModelPackDetails } from "../common/model-pack-details";
@@ -68,8 +62,6 @@ async function generateQueryPack(
6862
);
6963

7064
const mustSynthesizePack = qlPackDetails.qlPackFilePath === undefined;
71-
const cliSupportsMrvaPackCreate =
72-
await cliServer.cliConstraints.supportsMrvaPackCreate();
7365

7466
let targetPackPath: string;
7567
let needsInstall: boolean;
@@ -87,15 +79,6 @@ async function generateQueryPack(
8779

8880
// Install packs, since we just synthesized a dependency on the language's standard library.
8981
needsInstall = true;
90-
} else if (!cliSupportsMrvaPackCreate) {
91-
// We need to copy the query pack to a temporary directory and then fix it up to work with MRVA.
92-
targetPackPath = tmpDir.queryPackDir;
93-
await copyExistingQueryPack(cliServer, qlPackDetails, targetPackPath);
94-
95-
// We should already have all the dependencies available, but these older versions of the CLI
96-
// have a bug where they will not search `--additional-packs` during validation in `codeql pack bundle`.
97-
// Installing the packs will ensure that any extension packs get put in the right place.
98-
needsInstall = true;
9982
} else {
10083
// The CLI supports creating a MRVA query pack directly from the source pack.
10184
targetPackPath = qlPackDetails.qlPackRootPath;
@@ -113,27 +96,18 @@ async function generateQueryPack(
11396
await cliServer.clearCache();
11497
}
11598

116-
let precompilationOpts: string[];
117-
if (cliSupportsMrvaPackCreate) {
118-
const queryOpts = qlPackDetails.queryFiles.flatMap((q) => [
119-
"--query",
120-
join(targetPackPath, relative(qlPackDetails.qlPackRootPath, q)),
121-
]);
122-
123-
precompilationOpts = [
124-
"--mrva",
125-
...queryOpts,
126-
// We need to specify the extension packs as dependencies so that they are included in the MRVA pack.
127-
// The version range doesn't matter, since they'll always be found by source lookup.
128-
...extensionPacks.map((p) => `--extension-pack=${p.name}@*`),
129-
];
130-
} else {
131-
precompilationOpts = ["--qlx"];
132-
133-
if (extensionPacks.length > 0) {
134-
await addExtensionPacksAsDependencies(targetPackPath, extensionPacks);
135-
}
136-
}
99+
const queryOpts = qlPackDetails.queryFiles.flatMap((q) => [
100+
"--query",
101+
join(targetPackPath, relative(qlPackDetails.qlPackRootPath, q)),
102+
]);
103+
104+
const precompilationOpts = [
105+
"--mrva",
106+
...queryOpts,
107+
// We need to specify the extension packs as dependencies so that they are included in the MRVA pack.
108+
// The version range doesn't matter, since they'll always be found by source lookup.
109+
...extensionPacks.map((p) => `--extension-pack=${p.name}@*`),
110+
];
137111

138112
const bundlePath = tmpDir.bundleFile;
139113
void extLogger.log(
@@ -181,59 +155,6 @@ async function createNewQueryPack(
181155
);
182156
}
183157

184-
async function copyExistingQueryPack(
185-
cliServer: CodeQLCliServer,
186-
qlPackDetails: QlPackDetails,
187-
targetPackPath: string,
188-
) {
189-
const toCopy = await cliServer.packPacklist(
190-
qlPackDetails.qlPackRootPath,
191-
false,
192-
);
193-
194-
// Also include query files that contain extensible predicates. These query files are not
195-
// needed for the query to run, but they are needed for the query pack to pass deep validation
196-
// of data extensions.
197-
const metadata = await cliServer.generateExtensiblePredicateMetadata(
198-
qlPackDetails.qlPackRootPath,
199-
);
200-
metadata.extensible_predicates.forEach((predicate) => {
201-
if (predicate.path.endsWith(".ql")) {
202-
toCopy.push(join(qlPackDetails.qlPackRootPath, predicate.path));
203-
}
204-
});
205-
206-
[
207-
// also copy the lock file (either new name or old name) and the query file itself. These are not included in the packlist.
208-
...QLPACK_LOCK_FILENAMES.map((f) => join(qlPackDetails.qlPackRootPath, f)),
209-
...qlPackDetails.queryFiles,
210-
].forEach((absolutePath) => {
211-
if (absolutePath) {
212-
toCopy.push(absolutePath);
213-
}
214-
});
215-
216-
let copiedCount = 0;
217-
await copy(qlPackDetails.qlPackRootPath, targetPackPath, {
218-
filter: (file: string) =>
219-
// copy file if it is in the packlist, or it is a parent directory of a file in the packlist
220-
!!toCopy.find((f) => {
221-
// Normalized paths ensure that Windows drive letters are capitalized consistently.
222-
const normalizedPath = Uri.file(f).fsPath;
223-
const matches =
224-
normalizedPath === file || normalizedPath.startsWith(file + sep);
225-
if (matches) {
226-
copiedCount++;
227-
}
228-
return matches;
229-
}),
230-
});
231-
232-
void extLogger.log(`Copied ${copiedCount} files to ${targetPackPath}`);
233-
234-
await fixPackFile(targetPackPath, qlPackDetails);
235-
}
236-
237158
interface RemoteQueryTempDir {
238159
remoteQueryDir: string;
239160
queryPackDir: string;
@@ -351,42 +272,6 @@ export async function prepareRemoteQueryRun(
351272
};
352273
}
353274

354-
/**
355-
* Fixes the qlpack.yml or codeql-pack.yml file to be correct in the context of the MRVA request.
356-
*
357-
* Performs the following fixes:
358-
*
359-
* - Updates the default suite of the query pack. This is used to ensure
360-
* only the specified query is run.
361-
* - Ensures the query pack name is set to the name expected by the server.
362-
* - Removes any `${workspace}` version references from the qlpack.yml or codeql-pack.yml file. Converts them
363-
* to `*` versions.
364-
*
365-
* @param targetPackPath The path to the directory containing the target pack
366-
* @param qlPackDetails The details of the original QL pack
367-
*/
368-
async function fixPackFile(
369-
targetPackPath: string,
370-
qlPackDetails: QlPackDetails,
371-
): Promise<void> {
372-
const packPath = await getQlPackFilePath(targetPackPath);
373-
374-
// This should not happen since we create the pack ourselves.
375-
if (!packPath) {
376-
throw new Error(
377-
`Could not find ${QLPACK_FILENAMES.join(
378-
" or ",
379-
)} file in '${targetPackPath}'`,
380-
);
381-
}
382-
const qlpack = load(await readFile(packPath, "utf8")) as QlPackFile;
383-
384-
updateDefaultSuite(qlpack, qlPackDetails);
385-
removeWorkspaceRefs(qlpack);
386-
387-
await writeFile(packPath, dump(qlpack));
388-
}
389-
390275
async function getExtensionPacksToInject(
391276
cliServer: CodeQLCliServer,
392277
workspaceFolders: string[],
@@ -415,41 +300,6 @@ async function getExtensionPacksToInject(
415300
return result;
416301
}
417302

418-
async function addExtensionPacksAsDependencies(
419-
queryPackDir: string,
420-
extensionPacks: ModelPackDetails[],
421-
): Promise<void> {
422-
const qlpackFile = await getQlPackFilePath(queryPackDir);
423-
if (!qlpackFile) {
424-
throw new Error(
425-
`Could not find ${QLPACK_FILENAMES.join(
426-
" or ",
427-
)} file in '${queryPackDir}'`,
428-
);
429-
}
430-
431-
const syntheticQueryPack = load(
432-
await readFile(qlpackFile, "utf8"),
433-
) as QlPackFile;
434-
435-
const dependencies = syntheticQueryPack.dependencies ?? {};
436-
extensionPacks.forEach(({ name }) => {
437-
// Add this extension pack as a dependency. It doesn't matter which
438-
// version we specify, since we are guaranteed that the extension pack
439-
// is resolved from source at the given path.
440-
dependencies[name] = "*";
441-
});
442-
443-
syntheticQueryPack.dependencies = dependencies;
444-
445-
await writeFile(qlpackFile, dump(syntheticQueryPack));
446-
}
447-
448-
function updateDefaultSuite(qlpack: QlPackFile, qlPackDetails: QlPackDetails) {
449-
delete qlpack.defaultSuiteFile;
450-
qlpack.defaultSuite = generateDefaultSuite(qlPackDetails);
451-
}
452-
453303
function generateDefaultSuite(qlPackDetails: QlPackDetails) {
454304
const queries = qlPackDetails.queryFiles.map((query) => {
455305
const relativePath = relative(qlPackDetails.qlPackRootPath, query);
@@ -550,15 +400,3 @@ async function getControllerRepoFromApi(
550400
}
551401
}
552402
}
553-
554-
function removeWorkspaceRefs(qlpack: QlPackFile) {
555-
if (!qlpack.dependencies) {
556-
return;
557-
}
558-
559-
for (const [key, value] of Object.entries(qlpack.dependencies)) {
560-
if (value === "${workspace}") {
561-
qlpack.dependencies[key] = "*";
562-
}
563-
}
564-
}

0 commit comments

Comments
 (0)