Skip to content

Commit

Permalink
Use features properly in setupPythonExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus Wriedt Larsen committed May 12, 2023
1 parent eb8a706 commit b8f39fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/analyze-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ async function run() {
threads,
memory,
config,
logger
logger,
features
);

if (actionsUtil.getRequiredInput("skip-queries") !== "true") {
Expand Down
33 changes: 17 additions & 16 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 });
Expand All @@ -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
Expand Down

0 comments on commit b8f39fe

Please sign in to comment.