Use features properly in setupPythonExtractor

This commit is contained in:
Rasmus Wriedt Larsen 2023-05-12 09:55:22 +02:00
parent eb8a70647a
commit b8f39fe0f5
No known key found for this signature in database
2 changed files with 19 additions and 17 deletions

View file

@ -237,7 +237,8 @@ async function run() {
threads,
memory,
config,
logger
logger,
features
);
if (actionsUtil.getRequiredInput("skip-queries") !== "true") {

View file

@ -10,7 +10,7 @@ import { DatabaseCreationTimings } from "./actions-util";
import * as analysisPaths from "./analysis-paths";
import { CodeQL, getCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { FeatureEnablement } from "./feature-flags";
import { FeatureEnablement, Feature } from "./feature-flags";
import { isScannedLanguage, Language } from "./languages";
import { Logger } from "./logging";
import { endTracingForCluster } from "./tracer-config";
@ -80,23 +80,20 @@ export interface QueriesStatusReport {
analyze_failure_language?: string;
}
async function setupPythonExtractor(logger: Logger) {
async function setupPythonExtractor(logger: Logger, features: FeatureEnablement, codeql: CodeQL) {
const codeqlPython = process.env["CODEQL_PYTHON"];
if (codeqlPython === undefined || codeqlPython.length === 0) {
// If CODEQL_PYTHON is not set, no dependencies were installed, so we don't need to do anything
return;
}
// CODEQL_EXTRACTOR_PYTHON_DISABLE_LIBRARY_EXTRACTION is the internal environment
// variable used by the python extractor. This is set in init-action.ts only if the
// feature-flag is enabled.
if (
(process.env["CODEQL_EXTRACTOR_PYTHON_DISABLE_LIBRARY_EXTRACTION"] || "")
.length > 0
) {
if (await features.getValue(
Feature.DisablePythonDependencyInstallation,
codeql
)) {
logger.warning(
"Library extraction is disabled now. Please remove your logic that sets the CODEQL_PYTHON environment variable." +
"\nIf you used CODEQL_PYTHON to force the version of Python to analyze as, please use CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION instead, such as CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=2.7 or CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=3.11."
"\nIf you used CODEQL_PYTHON to force the version of Python to analyze as, please use CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION instead, such as CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=2.7 or CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=3.11."
);
return;
}
@ -133,7 +130,8 @@ async function setupPythonExtractor(logger: Logger) {
export async function createdDBForScannedLanguages(
codeql: CodeQL,
config: configUtils.Config,
logger: Logger
logger: Logger,
features: FeatureEnablement
) {
// Insert the LGTM_INDEX_X env vars at this point so they are set when
// we extract any scanned languages.
@ -147,7 +145,7 @@ export async function createdDBForScannedLanguages(
logger.startGroup(`Extracting ${language}`);
if (language === Language.python) {
await setupPythonExtractor(logger);
await setupPythonExtractor(logger, features, codeql);
}
await codeql.extractScannedLanguage(config, language);
@ -179,12 +177,13 @@ async function finalizeDatabaseCreation(
config: configUtils.Config,
threadsFlag: string,
memoryFlag: string,
logger: Logger
logger: Logger,
features: FeatureEnablement
): Promise<DatabaseCreationTimings> {
const codeql = await getCodeQL(config.codeQLCmd);
const extractionStart = performance.now();
await createdDBForScannedLanguages(codeql, config, logger);
await createdDBForScannedLanguages(codeql, config, logger, features);
const extractionTime = performance.now() - extractionStart;
const trapImportStart = performance.now();
@ -488,7 +487,8 @@ export async function runFinalize(
threadsFlag: string,
memoryFlag: string,
config: configUtils.Config,
logger: Logger
logger: Logger,
features: FeatureEnablement
): Promise<DatabaseCreationTimings> {
try {
await del(outputDir, { force: true });
@ -503,7 +503,8 @@ export async function runFinalize(
config,
threadsFlag,
memoryFlag,
logger
logger,
features
);
// WARNING: This does not _really_ end tracing, as the tracer will restore its