33 compileCdsToJson ,
44 determineCdsCommand ,
55 findProjectForCdsFile ,
6- writeParserDebugInfo ,
76} from './src/cds' ;
7+ import { CdsProjectMapWithDebugSignals } from './src/cds/parser/types' ;
88import { runJavaScriptExtractor } from './src/codeql' ;
99import { addCompilationDiagnostic } from './src/diagnostics' ;
1010import { configureLgtmIndexFilters , setupAndValidateEnvironment } from './src/environment' ;
@@ -25,42 +25,14 @@ if (!validationResult.isValid) {
2525// Get the validated and sanitized arguments
2626const { runMode, sourceRoot, responseFile } = validationResult . args ! ;
2727
28- // Handle debug parser mode
29- if ( runMode === ( RunMode . DEBUG_PARSER as string ) ) {
30- console . log ( 'Running CDS Parser in debug mode...' ) ;
31- console . log ( `Source Root Directory: ${ sourceRoot } ` ) ;
32-
33- // Use the project-aware parser as the main entry point
34- const scriptDir = __dirname ;
35- const projectMap = buildCdsProjectDependencyGraph ( sourceRoot , runMode , scriptDir ) ;
36-
37- if ( projectMap . size === 0 ) {
38- console . warn ( 'No CDS projects found. Cannot generate debug information.' ) ;
39- process . exit ( 1 ) ;
40- }
41-
42- // Check if debug information was successfully written
43- if ( runMode === 'debug-parser' && ! writeParserDebugInfo ( projectMap , sourceRoot , scriptDir ) ) {
44- console . warn ( 'Failed to write debug information.' ) ;
45- process . exit ( 1 ) ;
46- }
47-
48- console . log ( 'Debug parser process completed successfully.' ) ;
49- process . exit ( 0 ) ;
50- } else if ( runMode === ( RunMode . AUTOBUILD as string ) ) {
28+ // Check for autobuild mode
29+ if ( runMode === ( RunMode . AUTOBUILD as string ) ) {
5130 console . log ( 'Autobuild mode is not implemented yet.' ) ;
5231 process . exit ( 1 ) ;
5332}
5433
55- // Force this script, and any process it spawns, to use the project (source) root
56- // directory as the current working directory.
57- process . chdir ( sourceRoot ) ;
58-
59- console . log (
60- `INFO: CodeQL CDS extractor using run mode '${ runMode } ' for scan of project source root directory '${ sourceRoot } '.` ,
61- ) ;
62-
63- // Setup the environment and validate all requirements.
34+ // Setup the environment and validate all requirements first, before changing directory
35+ // This ensures we can properly locate the CodeQL tools
6436const {
6537 success : envSetupSuccess ,
6638 errorMessages,
@@ -80,6 +52,16 @@ if (!envSetupSuccess) {
8052 process . exit ( 1 ) ;
8153}
8254
55+ // Force this script, and any process it spawns, to use the project (source) root
56+ // directory as the current working directory.
57+ process . chdir ( sourceRoot ) ;
58+
59+ console . log (
60+ `INFO: CodeQL CDS extractor using run mode '${ runMode } ' for scan of project source root directory '${ sourceRoot } '.` ,
61+ ) ;
62+ console . log ( `DEBUG: CodeQL executable path: ${ codeqlExePath } ` ) ;
63+ console . log ( `DEBUG: Current working directory: ${ process . cwd ( ) } ` ) ;
64+
8365// Only process response file for INDEX_FILES mode
8466let cdsFilePathsToProcess : string [ ] = [ ] ;
8567if ( runMode === ( RunMode . INDEX_FILES as string ) ) {
@@ -99,10 +81,25 @@ if (runMode === (RunMode.INDEX_FILES as string)) {
9981console . log ( 'Detecting CDS projects and analyzing their structure...' ) ;
10082
10183// Build the project dependency graph using the project-aware parser
102- const projectMap = buildCdsProjectDependencyGraph ( sourceRoot , runMode ) ;
84+ // Pass the script directory (__dirname) to support debug-parser mode internally
85+ const projectMap = buildCdsProjectDependencyGraph ( sourceRoot , runMode , __dirname ) ;
86+
87+ // Cast to the interface with debug signals to properly handle debug mode
88+ const typedProjectMap = projectMap as CdsProjectMapWithDebugSignals ;
89+
90+ // Check if we're in debug-parser mode and should exit (based on signals from buildCdsProjectDependencyGraph)
91+ if ( typedProjectMap . __debugParserSuccess ) {
92+ console . log ( 'Debug parser mode completed successfully.' ) ;
93+ process . exit ( 0 ) ;
94+ } else if ( typedProjectMap . __debugParserFailure ) {
95+ console . warn ( 'No CDS projects found. Cannot generate debug information.' ) ;
96+ process . exit ( 1 ) ;
97+ }
10398
10499// Install dependencies using the new caching approach
105100console . log ( 'Installing required CDS compiler versions using cached approach...' ) ;
101+ console . log ( `DEBUG: Before installDependencies - CodeQL path: ${ codeqlExePath } ` ) ;
102+ console . log ( `DEBUG: Current working directory: ${ process . cwd ( ) } ` ) ;
106103const projectCacheDirMap = installDependencies ( projectMap , sourceRoot , codeqlExePath ) ;
107104
108105// Determine the CDS command to use.
@@ -140,6 +137,7 @@ for (const rawCdsFilePath of cdsFilePathsToProcess) {
140137// Configure the "LGTM" index filters for proper extraction.
141138configureLgtmIndexFilters ( ) ;
142139
140+ console . log ( `DEBUG: CODEQL_DIST before runJavaScriptExtractor: ${ process . env . CODEQL_DIST } ` ) ;
143141// Run CodeQL's JavaScript extractor to process the compiled JSON files.
144142const extractorResult = runJavaScriptExtractor ( sourceRoot , autobuildScriptPath , codeqlExePath ) ;
145143if ( ! extractorResult . success && extractorResult . error ) {
0 commit comments