Skip to content

Commit 6f16845

Browse files
authored
Merge pull request github#1933 from github/aeisenberg/codeql-pack-yml
Ensure remote queries can handle codeql-pack.yml files
2 parents 3fe3117 + 77c6706 commit 6f16845

File tree

4 files changed

+45
-23
lines changed

4 files changed

+45
-23
lines changed

extensions/ql-vscode/src/remote-queries/run-remote-query.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { DbManager } from "../databases/db-manager";
3434
export interface QlPack {
3535
name: string;
3636
version: string;
37+
library?: boolean;
3738
dependencies: { [key: string]: string };
3839
defaultSuite?: Array<Record<string, unknown>>;
3940
defaultSuiteFile?: string;
@@ -66,7 +67,7 @@ async function generateQueryPack(
6667
const targetQueryFileName = join(queryPackDir, packRelativePath);
6768

6869
let language: string | undefined;
69-
if (await pathExists(join(originalPackRoot, "qlpack.yml"))) {
70+
if (await getExistingPackFile(originalPackRoot)) {
7071
// don't include ql files. We only want the queryFile to be copied.
7172
const toCopy = await cliServer.packPacklist(originalPackRoot, false);
7273

@@ -162,7 +163,7 @@ async function generateQueryPack(
162163
async function findPackRoot(queryFile: string): Promise<string> {
163164
// recursively find the directory containing qlpack.yml
164165
let dir = dirname(queryFile);
165-
while (!(await pathExists(join(dir, "qlpack.yml")))) {
166+
while (!(await getExistingPackFile(dir))) {
166167
dir = dirname(dir);
167168
if (isFileSystemRoot(dir)) {
168169
// there is no qlpack.yml in this directory or any parent directory.
@@ -174,6 +175,16 @@ async function findPackRoot(queryFile: string): Promise<string> {
174175
return dir;
175176
}
176177

178+
async function getExistingPackFile(dir: string) {
179+
if (await pathExists(join(dir, "qlpack.yml"))) {
180+
return join(dir, "qlpack.yml");
181+
}
182+
if (await pathExists(join(dir, "codeql-pack.yml"))) {
183+
return join(dir, "codeql-pack.yml");
184+
}
185+
return undefined;
186+
}
187+
177188
function isFileSystemRoot(dir: string): boolean {
178189
const pathObj = parse(dir);
179190
return pathObj.root === dir && pathObj.base === "";
@@ -314,7 +325,14 @@ async function fixPackFile(
314325
queryPackDir: string,
315326
packRelativePath: string,
316327
): Promise<void> {
317-
const packPath = join(queryPackDir, "qlpack.yml");
328+
const packPath = await getExistingPackFile(queryPackDir);
329+
330+
// This should not happen since we create the pack ourselves.
331+
if (!packPath) {
332+
throw new Error(
333+
`Could not find qlpack.yml or codeql-pack.yml file in '${queryPackDir}'`,
334+
);
335+
}
318336
const qlpack = load(await readFile(packPath, "utf8")) as QlPack;
319337

320338
// update pack name
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: github/remote-query-pack
22
version: 0.0.0
33
dependencies:
4-
# The workspace reference will be removed before creating the MRVA pack.
54
codeql/javascript-all: '*'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: github/remote-query-pack
22
version: 0.0.0
33
dependencies:
4-
codeql/javascript-all: '${workspace}'
4+
codeql/javascript-all: ${workspace}

extensions/ql-vscode/test/vscode-tests/cli-integration/remote-queries/remote-queries-manager.test.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ describe("Remote queries", () => {
277277

278278
// check a few files that we know should exist and others that we know should not
279279
expect(packFS.fileExists("subfolder/in-pack.ql")).toBe(true);
280-
expect(packFS.fileExists("qlpack.yml")).toBe(true);
280+
expect(packFS.fileExists("codeql-pack.yml")).toBe(true);
281281
// depending on the cli version, we should have one of these files
282282
expect(
283283
packFS.fileExists("qlpack.lock.yml") ||
@@ -289,13 +289,13 @@ describe("Remote queries", () => {
289289
// the compiled pack
290290
verifyQlPack(
291291
"subfolder/in-pack.ql",
292-
packFS.fileContents("qlpack.yml"),
292+
packFS.fileContents("codeql-pack.yml"),
293293
"0.0.0",
294294
);
295295

296296
// should have generated a correct qlpack file
297297
const qlpackContents: any = load(
298-
packFS.fileContents("qlpack.yml").toString("utf-8"),
298+
packFS.fileContents("codeql-pack.yml").toString("utf-8"),
299299
);
300300
expect(qlpackContents.name).toBe("codeql-remote/query");
301301
expect(qlpackContents.version).toBe("0.0.0");
@@ -333,22 +333,27 @@ describe("Remote queries", () => {
333333
// don't check the build metadata since it is variable
334334
delete (qlPack as any).buildMetadata;
335335

336-
expect(qlPack).toEqual({
337-
name: "codeql-remote/query",
338-
version: packVersion,
339-
dependencies: {
340-
"codeql/javascript-all": "*",
341-
},
342-
library: false,
343-
defaultSuite: [
344-
{
345-
description: "Query suite for variant analysis",
346-
},
347-
{
348-
query: queryPath,
336+
expect(qlPack).toEqual(
337+
expect.objectContaining({
338+
name: "codeql-remote/query",
339+
version: packVersion,
340+
dependencies: {
341+
"codeql/javascript-all": "*",
349342
},
350-
],
351-
});
343+
defaultSuite: [
344+
{
345+
description: "Query suite for variant analysis",
346+
},
347+
{
348+
query: queryPath,
349+
},
350+
],
351+
}),
352+
);
353+
354+
// v2.11.6 and later set this to false.
355+
// Earlier versions don't set it at all.
356+
expect(qlPack.library).toBeFalsy();
352357
}
353358

354359
function getFile(file: string): Uri {

0 commit comments

Comments
 (0)