Ensure anonymous and scope-less packs can be used as remote queries
When we generate the synthetic pack, just ensure that there is a valid name.
This commit is contained in:
@@ -118,7 +118,7 @@ export async function displayQuickQuery(
|
||||
// Only rewrite the qlpack file if the database has changed
|
||||
if (shouldRewrite) {
|
||||
const quickQueryQlpackYaml: any = {
|
||||
name: 'quick-query',
|
||||
name: 'vscode/quick-query',
|
||||
version: '1.0.0',
|
||||
libraryPathDependencies: [qlpack]
|
||||
};
|
||||
|
||||
@@ -119,6 +119,9 @@ async function generateQueryPack(cliServer: cli.CodeQLCliServer, queryFile: stri
|
||||
})
|
||||
});
|
||||
|
||||
// ensure the qlpack.yml has a valid name
|
||||
await ensureQueryPackName(queryPackDir);
|
||||
|
||||
void logger.log(`Copied ${copiedCount} files to ${queryPackDir}`);
|
||||
|
||||
language = await findLanguage(cliServer, Uri.file(targetQueryFileName));
|
||||
@@ -161,6 +164,25 @@ async function generateQueryPack(cliServer: cli.CodeQLCliServer, queryFile: stri
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the qlpack.yml has a valid name. For local purposes,
|
||||
* Anonymous packs and names that are not prefixed by a scope (ie `<foo>/`)
|
||||
* are sufficient. But in order to create a pack, the name must be prefixed.
|
||||
*
|
||||
* @param queryPackDir the directory containing the query pack.
|
||||
*/
|
||||
async function ensureQueryPackName(queryPackDir: string) {
|
||||
const pack = yaml.safeLoad(await fs.readFile(path.join(queryPackDir, 'qlpack.yml'), 'utf8')) as { name: string; };
|
||||
if (!pack.name || !pack.name.includes('/')) {
|
||||
if (!pack.name) {
|
||||
pack.name = 'codeql-remote/query';
|
||||
} else if (!pack.name.includes('/')) {
|
||||
pack.name = `codeql-remote/${pack.name}`;
|
||||
}
|
||||
await fs.writeFile(path.join(queryPackDir, 'qlpack.yml'), yaml.safeDump(pack));
|
||||
}
|
||||
}
|
||||
|
||||
async function createRemoteQueriesTempDirectory() {
|
||||
const remoteQueryDir = await tmp.dir({ dir: tmpDir.name, unsafeCleanup: true });
|
||||
const queryPackDir = path.join(remoteQueryDir.path, 'query-pack');
|
||||
|
||||
@@ -141,7 +141,7 @@ describe('Remote queries', function() {
|
||||
expect(fs.existsSync(path.join(queryPackDir, 'not-in-pack.ql'))).to.be.false;
|
||||
|
||||
// the compiled pack
|
||||
const compiledPackDir = path.join(queryPackDir, '.codeql/pack/codeql-remote/query/1.0.0/');
|
||||
const compiledPackDir = path.join(queryPackDir, '.codeql/pack/codeql-remote/query/0.0.0/');
|
||||
printDirectoryContents(compiledPackDir);
|
||||
expect(fs.existsSync(path.join(compiledPackDir, 'query.ql'))).to.be.true;
|
||||
expect(fs.existsSync(path.join(compiledPackDir, 'qlpack.yml'))).to.be.true;
|
||||
@@ -155,7 +155,7 @@ describe('Remote queries', function() {
|
||||
// should have generated a correct qlpack file
|
||||
const qlpackContents: any = yaml.safeLoad(fs.readFileSync(path.join(compiledPackDir, 'qlpack.yml'), 'utf8'));
|
||||
expect(qlpackContents.name).to.equal('codeql-remote/query');
|
||||
expect(qlpackContents.version).to.equal('1.0.0');
|
||||
expect(qlpackContents.version).to.equal('0.0.0');
|
||||
expect(qlpackContents.dependencies?.['codeql/javascript-all']).to.equal('*');
|
||||
|
||||
// dependencies
|
||||
|
||||
Reference in New Issue
Block a user