AST viewer: Address review comments
Clear the CLI server's pack cache before installing packs, to avoid race conditions where the new lock file is not detected during query running. Adjust some helper methods.
This commit is contained in:
@@ -970,9 +970,9 @@ export class CodeQLCliServer implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
async packResolveDependencies(dir: string, mode: 'use-lock'): Promise<{ [pack: string]: string }> {
|
||||
const args = ['--mode', mode, dir];
|
||||
const results: { [pack: string]: string } = await this.runJsonCodeQlCliCommand(['pack', 'resolve-dependencies'], args, 'Resolving pack dependencies');
|
||||
async packResolveDependencies(dir: string): Promise<{ [pack: string]: string }> {
|
||||
// Uses the default `--mode use-lock`, which creates the lock file if it doesn't exist.
|
||||
const results: { [pack: string]: string } = await this.runJsonCodeQlCliCommand(['pack', 'resolve-dependencies'], [dir], 'Resolving pack dependencies');
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,11 @@ export class TemplatePrintAstProvider {
|
||||
// Create a lock file so that we can resolve dependencies and library path
|
||||
// for the AST query.
|
||||
void logger.log(`Library pack ${packPath} is missing a lock file; creating a temporary lock file`);
|
||||
await this.cli.packResolveDependencies(packPath, 'use-lock');
|
||||
await this.cli.packResolveDependencies(packPath);
|
||||
// Clear CLI server pack cache before installing dependencies,
|
||||
// so that it picks up the new lock file, not the previously cached pack.
|
||||
void logger.log('Clearing the CodeQL CLI server\'s pack cache');
|
||||
await this.cli.clearCache();
|
||||
// Install dependencies.
|
||||
void logger.log(`Installing package dependencies for library pack ${packPath}`);
|
||||
await this.cli.packInstall(packPath);
|
||||
@@ -260,7 +264,7 @@ export class TemplatePrintAstProvider {
|
||||
const tempLockFilePath = path.resolve(packPath, 'codeql-pack.lock.yml');
|
||||
void logger.log(`Deleting temporary package lock file at ${tempLockFilePath}`);
|
||||
// It's fine if the file doesn't exist.
|
||||
fs.rmSync(path.resolve(packPath, 'codeql-pack.lock.yml'), { force: true });
|
||||
await fs.promises.rm(path.resolve(packPath, 'codeql-pack.lock.yml'), { force: true });
|
||||
}
|
||||
return {
|
||||
query: queryResult,
|
||||
|
||||
Reference in New Issue
Block a user