Include base database OIDs when bundling database

This commit is contained in:
Henry Mercer
2026-01-09 18:58:32 +00:00
parent d6efb85cdf
commit d32cd4ddde
12 changed files with 156 additions and 43 deletions

View File

@@ -147,11 +147,19 @@ export interface CodeQL {
): Promise<void>;
/**
* Run 'codeql database bundle'.
*
* @param tryAlsoIncludeRelativePaths Additional paths that should be included in the bundle if possible.
*
* These paths are relative to the database root.
*
* Older versions of the CodeQL CLI do not support including additional paths in the bundle.
* In those cases, this parameter will be ignored.
*/
databaseBundle(
databasePath: string,
outputFilePath: string,
dbName: string,
tryAlsoIncludeRelativePaths: string[],
): Promise<void>;
/**
* Run 'codeql database run-queries'. If no `queries` are specified, then the CLI
@@ -911,6 +919,7 @@ async function getCodeQLForCmd(
databasePath: string,
outputFilePath: string,
databaseName: string,
tryAlsoIncludeRelativePaths: string[],
): Promise<void> {
const args = [
"database",
@@ -920,6 +929,16 @@ async function getCodeQLForCmd(
`--name=${databaseName}`,
...getExtraOptionsFromEnv(["database", "bundle"]),
];
if (
await this.supportsFeature(ToolsFeature.BundleSupportsIncludeOption)
) {
args.push(
...tryAlsoIncludeRelativePaths.flatMap((relativePath) => [
"--include",
relativePath,
]),
);
}
await new toolrunner.ToolRunner(cmd, args).exec();
},
async databaseExportDiagnostics(

View File

@@ -17,6 +17,7 @@ import { getCommitOid, getFileOidsUnderPath } from "./git-utils";
import { Logger, withGroupAsync } from "./logging";
import {
CleanupLevel,
getBaseDatabaseOidsFilePath,
getCodeQLDatabasePath,
getErrorMessage,
isInTestMode,
@@ -98,10 +99,6 @@ async function readBaseDatabaseOidsFile(
}
}
function getBaseDatabaseOidsFilePath(config: Config): string {
return path.join(config.dbLocation, "base-database-oids.json");
}
/**
* Writes a JSON file containing the source-root-relative paths of files under
* `sourceRoot` that have changed (added, removed, or modified) from the overlay

View File

@@ -16,6 +16,12 @@ import { EnvVar } from "./environment";
import { Language } from "./languages";
import { Logger } from "./logging";
/**
* The name of the file containing the base database OIDs, as stored in the
* root of the database location.
*/
const BASE_DATABASE_OIDS_FILE_NAME = "base-database-oids.json";
/**
* Specifies bundle versions that are known to be broken
* and will not be used if found in the toolcache.
@@ -728,6 +734,10 @@ export async function codeQlVersionAtLeast(
return semver.gte((await codeql.getVersion()).version, requiredVersion);
}
export function getBaseDatabaseOidsFilePath(config: Config): string {
return path.join(config.dbLocation, BASE_DATABASE_OIDS_FILE_NAME);
}
// Create a bundle for the given DB, if it doesn't already exist
export async function bundleDb(
config: Config,
@@ -745,7 +755,9 @@ export async function bundleDb(
if (fs.existsSync(databaseBundlePath)) {
await fs.promises.rm(databaseBundlePath, { force: true });
}
await codeql.databaseBundle(databasePath, databaseBundlePath, dbName);
await codeql.databaseBundle(databasePath, databaseBundlePath, dbName, [
BASE_DATABASE_OIDS_FILE_NAME,
]);
return databaseBundlePath;
}