Skip to content

Commit a76d1a3

Browse files
committed
config-utils: populate getOverlayDatabaseMode()
This commit populates getOverlayDatabaseMode() in config-utils with the same code from getOverlayDatabaseMode() in init.
1 parent 7707e09 commit a76d1a3

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.
@@ -724,6 +729,38 @@ async function getOverlayDatabaseMode(
724729
buildMode: BuildMode | undefined,
725730
logger: Logger,
726731
): Promise<OverlayDatabaseMode> {
732+
const overlayDatabaseMode = process.env.CODEQL_OVERLAY_DATABASE_MODE;
733+
734+
if (
735+
overlayDatabaseMode === OverlayDatabaseMode.Overlay ||
736+
overlayDatabaseMode === OverlayDatabaseMode.OverlayBase
737+
) {
738+
if (buildMode !== BuildMode.None) {
739+
logger.warning(
740+
`Cannot build an ${overlayDatabaseMode} database because ` +
741+
`build-mode is set to "${buildMode}" instead of "none". ` +
742+
"Falling back to creating a normal full database instead.",
743+
);
744+
return OverlayDatabaseMode.None;
745+
}
746+
if (!(await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION))) {
747+
logger.warning(
748+
`Cannot build an ${overlayDatabaseMode} database because ` +
749+
`the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` +
750+
"Falling back to creating a normal full database instead.",
751+
);
752+
return OverlayDatabaseMode.None;
753+
}
754+
if ((await getGitRoot(sourceRoot)) === undefined) {
755+
logger.warning(
756+
`Cannot build an ${overlayDatabaseMode} database because ` +
757+
`the source root "${sourceRoot}" is not inside a git repository. ` +
758+
"Falling back to creating a normal full database instead.",
759+
);
760+
return OverlayDatabaseMode.None;
761+
}
762+
return overlayDatabaseMode as OverlayDatabaseMode;
763+
}
727764
return OverlayDatabaseMode.None;
728765
}
729766

0 commit comments

Comments
 (0)