Skip to content

Commit 29cefc1

Browse files
committed
config-utils: populate getOverlayDatabaseMode()
This commit populates getOverlayDatabaseMode() in config-utils with the same code from getOverlayDatabaseMode() in init.
1 parent 4b4a2ad commit 29cefc1

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/config-utils.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ import { CachingKind, getCachingKind } from "./caching-utils";
1010
import { CodeQL } from "./codeql";
1111
import { shouldPerformDiffInformedAnalysis } from "./diff-informed-analysis-utils";
1212
import { Feature, FeatureEnablement } from "./feature-flags";
13+
import { getGitRoot } from "./git-utils";
1314
import { Language, parseLanguage } from "./languages";
1415
import { Logger } from "./logging";
15-
import { OverlayDatabaseMode } from "./overlay-database-utils";
16+
import {
17+
CODEQL_OVERLAY_MINIMUM_VERSION,
18+
OverlayDatabaseMode,
19+
} from "./overlay-database-utils";
1620
import { RepositoryNwo } from "./repository";
1721
import { downloadTrapCaches } from "./trap-caching";
1822
import {
1923
GitHubVersion,
2024
prettyPrintPack,
2125
ConfigurationError,
2226
BuildMode,
27+
codeQlVersionAtLeast,
2328
} from "./util";
2429

2530
// Property names from the user-supplied config file.
@@ -742,6 +747,38 @@ async function getOverlayDatabaseMode(
742747
buildMode: BuildMode | undefined,
743748
logger: Logger,
744749
): Promise<OverlayDatabaseMode> {
750+
const overlayDatabaseMode = process.env.CODEQL_OVERLAY_DATABASE_MODE;
751+
752+
if (
753+
overlayDatabaseMode === OverlayDatabaseMode.Overlay ||
754+
overlayDatabaseMode === OverlayDatabaseMode.OverlayBase
755+
) {
756+
if (buildMode !== BuildMode.None) {
757+
logger.warning(
758+
`Cannot build an ${overlayDatabaseMode} database because ` +
759+
`build-mode is set to "${buildMode}" instead of "none". ` +
760+
"Falling back to creating a normal full database instead.",
761+
);
762+
return OverlayDatabaseMode.None;
763+
}
764+
if (!(await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION))) {
765+
logger.warning(
766+
`Cannot build an ${overlayDatabaseMode} database because ` +
767+
`the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` +
768+
"Falling back to creating a normal full database instead.",
769+
);
770+
return OverlayDatabaseMode.None;
771+
}
772+
if ((await getGitRoot(sourceRoot)) === undefined) {
773+
logger.warning(
774+
`Cannot build an ${overlayDatabaseMode} database because ` +
775+
`the source root "${sourceRoot}" is not inside a git repository. ` +
776+
"Falling back to creating a normal full database instead.",
777+
);
778+
return OverlayDatabaseMode.None;
779+
}
780+
return overlayDatabaseMode as OverlayDatabaseMode;
781+
}
745782
return OverlayDatabaseMode.None;
746783
}
747784

0 commit comments

Comments
 (0)