Skip to content

Commit 4d4cc33

Browse files
committed
Setup python extractor for installed deps
1 parent 1c95faf commit 4d4cc33

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

lib/finalize-db.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/finalize-db.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/finalize-db.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from '@actions/core';
2+
import * as exec from '@actions/exec';
23
import * as io from '@actions/io';
34
import * as fs from 'fs';
45
import * as path from 'path';
@@ -9,12 +10,47 @@ import * as sharedEnv from './shared-environment';
910
import * as upload_lib from './upload-lib';
1011
import * as util from './util';
1112

13+
14+
async function setupPythonExtractor() {
15+
const codeqlPython = process.env["CODEQL_PYTHON"];
16+
if (codeqlPython === undefined || codeqlPython.length === 0) {
17+
// If CODEQL_PYTHON is not set, no dependencies were installed, so we don't need to do anything
18+
return;
19+
}
20+
21+
let output = '';
22+
const options = {
23+
listeners: {
24+
stdout: (data: Buffer) => {
25+
output += data.toString();
26+
}
27+
}
28+
};
29+
30+
await exec.exec(
31+
codeqlPython,
32+
['-c', 'import os; import pip; print(os.path.dirname(os.path.dirname(pip.__file__)))'],
33+
options);
34+
core.info('Setting LGTM_INDEX_IMPORT_PATH=' + output);
35+
process.env['LGTM_INDEX_IMPORT_PATH'] = output;
36+
37+
output = '';
38+
await exec.exec(codeqlPython, ['-c', 'import sys; print(sys.version_info[0])'], options);
39+
core.info('Setting LGTM_PYTHON_SETUP_VERSION=' + output);
40+
process.env['LGTM_PYTHON_SETUP_VERSION'] = output;
41+
}
42+
1243
async function createdDBForScannedLanguages(databaseFolder: string) {
1344
const scannedLanguages = process.env[sharedEnv.CODEQL_ACTION_SCANNED_LANGUAGES];
1445
if (scannedLanguages) {
1546
const codeql = getCodeQL();
1647
for (const language of scannedLanguages.split(',')) {
1748
core.startGroup('Extracting ' + language);
49+
50+
if (language === 'python') {
51+
await setupPythonExtractor();
52+
}
53+
1854
await codeql.extractScannedLanguage(path.join(databaseFolder, language), language);
1955
core.endGroup();
2056
}

0 commit comments

Comments
 (0)