11import * as core from '@actions/core' ;
2+ import * as exec from '@actions/exec' ;
23import * as io from '@actions/io' ;
34import * as fs from 'fs' ;
45import * as path from 'path' ;
@@ -9,12 +10,47 @@ import * as sharedEnv from './shared-environment';
910import * as upload_lib from './upload-lib' ;
1011import * 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+
1243async 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