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, threads,
memory, memory,
config, config,
logger logger,
features
); );
if (actionsUtil.getRequiredInput("skip-queries") !== "true") { if (actionsUtil.getRequiredInput("skip-queries") !== "true") {

View file

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