Skip to content

Commit 21d41e1

Browse files
committed
config-utils: populate getOverlayDatabaseMode()
This commit populates getOverlayDatabaseMode() in config-utils with the same code from getOverlayDatabaseMode() in init.
1 parent 2d6db8f commit 21d41e1

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.
@@ -744,6 +749,38 @@ async function getOverlayDatabaseMode(
744749
buildMode: BuildMode | undefined,
745750
logger: Logger,
746751
): Promise<OverlayDatabaseMode> {
752+
const overlayDatabaseMode = process.env.CODEQL_OVERLAY_DATABASE_MODE;
753+
754+
if (
755+
overlayDatabaseMode === OverlayDatabaseMode.Overlay ||
756+
overlayDatabaseMode === OverlayDatabaseMode.OverlayBase
757+
) {
758+
if (buildMode !== BuildMode.None) {
759+
logger.warning(
760+
`Cannot build an ${overlayDatabaseMode} database because ` +
761+
`build-mode is set to "${buildMode}" instead of "none". ` +
762+
"Falling back to creating a normal full database instead.",
763+
);
764+
return OverlayDatabaseMode.None;
765+
}
766+
if (!(await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION))) {
767+
logger.warning(
768+
`Cannot build an ${overlayDatabaseMode} database because ` +
769+
`the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` +
770+
"Falling back to creating a normal full database instead.",
771+
);
772+
return OverlayDatabaseMode.None;
773+
}
774+
if ((await getGitRoot(sourceRoot)) === undefined) {
775+
logger.warning(
776+
`Cannot build an ${overlayDatabaseMode} database because ` +
777+
`the source root "${sourceRoot}" is not inside a git repository. ` +
778+
"Falling back to creating a normal full database instead.",
779+
);
780+
return OverlayDatabaseMode.None;
781+
}
782+
return overlayDatabaseMode as OverlayDatabaseMode;
783+
}
747784
return OverlayDatabaseMode.None;
748785
}
749786

0 commit comments

Comments
 (0)