From b8f39fe0f585010cb8e8b1fbf510586bd0f8b9fe Mon Sep 17 00:00:00 2001 From: Rasmus Wriedt Larsen Date: Fri, 12 May 2023 09:55:22 +0200 Subject: [PATCH] Use features properly in `setupPythonExtractor` --- src/analyze-action.ts | 3 ++- src/analyze.ts | 33 +++++++++++++++++---------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 9d5908d26..09f1a70a6 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -237,7 +237,8 @@ async function run() { threads, memory, config, - logger + logger, + features ); if (actionsUtil.getRequiredInput("skip-queries") !== "true") { diff --git a/src/analyze.ts b/src/analyze.ts index f16264760..6da8d6d3e 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -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 { 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 { 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