Skip to content

Commit fe123b3

Browse files
committed
Inject extension pack dependencies into MRVA packs
If the user requests that extension packs be included in their MRVA run, then do the following: 1. Search the workspace for all extension packs 2. Add each extension pack as an explicit and direct dependency on the generated pack. It is ok to use `*` as a dependency since we are guaranteed that exactly one version of each injected extension pack dependency is available when the pack is being compiled. If we find multiple paths to an extension pack of the same name, this is an error since it is ambiguous which path to use.
1 parent 5d85da5 commit fe123b3

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ async function createNewQueryPack(
163163
},
164164
defaultSuite: generateDefaultSuite(packRelativePath),
165165
};
166+
if (await cliServer.useExtensionPacks()) {
167+
injectExtensionPacks(cliServer, syntheticQueryPack, workspaceFolders);
168+
}
166169
await writeFile(
167170
join(queryPackDir, FALLBACK_QLPACK_FILENAME),
168171
dump(syntheticQueryPack),
@@ -382,10 +385,36 @@ async function fixPackFile(
382385
qlpack.name = QUERY_PACK_NAME;
383386
updateDefaultSuite(qlpack, packRelativePath);
384387
removeWorkspaceRefs(qlpack);
388+
if (await cliServer.useExtensionPacks()) {
389+
injectExtensionPacks(cliServer, qlpack, workspaceFolders);
390+
}
385391

386392
await writeFile(packPath, dump(qlpack));
387393
}
388394

395+
function injectExtensionPacks(
396+
cliServer: cli.CodeQLCliServer,
397+
qlpack: QlPack,
398+
workspaceFolders: string[],
399+
) {
400+
const extensionPacks = cliServer.resolveQlpacks(workspaceFolders, true);
401+
Object.entries(extensionPacks).forEach(([name, paths]) => {
402+
// We are guaranteed that there is at least one path found for each extension pack.
403+
// If there are multiple paths, then we have a problem. This means that there is
404+
// ambiguity in which path to use. This is an error.
405+
if (paths.length > 1) {
406+
throw new Error(
407+
`Multiple versions of extension pack '${name}' found: ${paths.join(
408+
", ",
409+
)}`,
410+
);
411+
}
412+
// Add this extension pack as a dependency. It doesn't matter which
413+
// version we specify, since we are guaranteed that the extension pack
414+
// is resolved from source at the given path.
415+
qlpack.dependencies[name] = "*";
416+
});
417+
}
389418

390419
function updateDefaultSuite(qlpack: QlPack, packRelativePath: string) {
391420
delete qlpack.defaultSuiteFile;

0 commit comments

Comments
 (0)