@@ -2,12 +2,10 @@ import { determineCdsCommand } from './command';
22import { compileCdsToJson } from './compile' ;
33import { CompilationAttempt , CompilationTask , CompilationConfig } from './types' ;
44import { addCompilationDiagnostic } from '../../diagnostics' ;
5- import { cdsExtractorLog } from '../../logging' ;
5+ import { cdsExtractorLog , generateStatusReport } from '../../logging' ;
66import { CdsDependencyGraph , CdsProject } from '../parser/types' ;
77
8- /**
9- * Attempt compilation with a specific command and configuration
10- */
8+ /** Attempt compilation with a specific command and configuration. */
119function attemptCompilation (
1210 task : CompilationTask ,
1311 cdsCommand : string ,
@@ -92,7 +90,6 @@ function createCompilationTask(
9290 expectedOutputFiles : string [ ] ,
9391 projectDir : string ,
9492 useProjectLevelCompilation : boolean ,
95- priority : number = 0 ,
9693) : CompilationTask {
9794 return {
9895 id : `${ type } _${ projectDir } _${ Date . now ( ) } _${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) } ` ,
@@ -103,7 +100,6 @@ function createCompilationTask(
103100 projectDir,
104101 attempts : [ ] ,
105102 useProjectLevelCompilation,
106- priority,
107103 dependencies : [ ] ,
108104 } ;
109105}
@@ -171,18 +167,18 @@ function executeCompilationTask(
171167}
172168
173169/**
174- * Execute all compilation tasks for the dependency graph
170+ * Executes all compilation tasks for the provided {@link CdsDependencyGraph}.
171+ * Uses the provided `codeqlExePath` to run the CodeQL CLI, as needed, for
172+ * generating diagnositic warnings and/or errors for problems encountered while
173+ * running the CodeQL CDS extractor.
175174 */
176- export function executeCompilationTasks (
177- dependencyGraph : CdsDependencyGraph ,
178- codeqlExePath : string ,
179- ) : void {
175+ function executeCompilationTasks ( dependencyGraph : CdsDependencyGraph , codeqlExePath : string ) : void {
180176 cdsExtractorLog ( 'info' , 'Starting compilation execution for all projects...' ) ;
181177
182178 dependencyGraph . currentPhase = 'compiling' ;
183179 const compilationStartTime = new Date ( ) ;
184180
185- // Collect all tasks and sort by priority
181+ // Collect all compilation tasks from all projects.
186182 const allTasks : Array < { task : CompilationTask ; project : CdsProject } > = [ ] ;
187183
188184 for ( const project of dependencyGraph . projects . values ( ) ) {
@@ -191,10 +187,9 @@ export function executeCompilationTasks(
191187 }
192188 }
193189
194- // Sort by priority (higher priority first)
195- allTasks . sort ( ( a , b ) => b . task . priority - a . task . priority ) ;
196-
197- // Execute tasks sequentially (could be parallelized in the future)
190+ // Execute compilation tasks sequentially. There is room for optimization in the future.
191+ // For now, we keep it simple to ensure consistent debug information collection.
192+ cdsExtractorLog ( 'info' , `Executing ${ allTasks . length } compilation task(s)...` ) ;
198193 for ( const { task, project } of allTasks ) {
199194 try {
200195 executeCompilationTask ( task , project , dependencyGraph , codeqlExePath ) ;
@@ -239,79 +234,26 @@ export function executeCompilationTasks(
239234}
240235
241236/**
242- * Generate a comprehensive status report for the dependency graph
243- * Supports both normal execution and debug modes
244- */
245- export function generateStatusReport ( dependencyGraph : CdsDependencyGraph ) : string {
246- const summary = dependencyGraph . statusSummary ;
247- const lines : string [ ] = [ ] ;
248-
249- lines . push ( '=' . repeat ( 80 ) ) ;
250- lines . push ( `CDS EXTRACTOR STATUS REPORT` ) ;
251- lines . push ( '=' . repeat ( 80 ) ) ;
252- lines . push ( '' ) ;
253-
254- // Overall summary
255- lines . push ( 'OVERALL SUMMARY:' ) ;
256- lines . push ( ` Status: ${ summary . overallSuccess ? 'SUCCESS' : 'FAILED' } ` ) ;
257- lines . push ( ` Current Phase: ${ dependencyGraph . currentPhase . toUpperCase ( ) } ` ) ;
258- lines . push ( ` Projects: ${ summary . totalProjects } ` ) ;
259- lines . push ( ` CDS Files: ${ summary . totalCdsFiles } ` ) ;
260- lines . push ( ` JSON Files Generated: ${ summary . jsonFilesGenerated } ` ) ;
261- lines . push ( '' ) ;
262-
263- // Compilation summary
264- lines . push ( 'COMPILATION SUMMARY:' ) ;
265- lines . push ( ` Total Tasks: ${ summary . totalCompilationTasks } ` ) ;
266- lines . push ( ` Successful: ${ summary . successfulCompilations } ` ) ;
267- lines . push ( ` Failed: ${ summary . failedCompilations } ` ) ;
268- lines . push ( ` Skipped: ${ summary . skippedCompilations } ` ) ;
269- lines . push ( '' ) ;
270-
271- // Performance metrics
272- lines . push ( 'PERFORMANCE:' ) ;
273- lines . push ( ` Total Duration: ${ summary . performance . totalDurationMs } ms` ) ;
274- lines . push ( ` Parsing: ${ summary . performance . parsingDurationMs } ms` ) ;
275- lines . push ( ` Compilation: ${ summary . performance . compilationDurationMs } ms` ) ;
276- lines . push ( ` Extraction: ${ summary . performance . extractionDurationMs } ms` ) ;
277- lines . push ( '' ) ;
278-
279- // Errors and warnings
280- if ( summary . criticalErrors . length > 0 ) {
281- lines . push ( 'CRITICAL ERRORS:' ) ;
282- for ( const error of summary . criticalErrors ) {
283- lines . push ( ` - ${ error } ` ) ;
284- }
285- lines . push ( '' ) ;
286- }
287-
288- if ( summary . warnings . length > 0 ) {
289- lines . push ( 'WARNINGS:' ) ;
290- for ( const warning of summary . warnings ) {
291- lines . push ( ` - ${ warning } ` ) ;
292- }
293- lines . push ( '' ) ;
294- }
295-
296- lines . push ( '=' . repeat ( 80 ) ) ;
297-
298- return lines . join ( '\n' ) ;
299- }
300-
301- /**
302- * Main compilation orchestration function to replace the big for loop in cds-extractor.ts
303- * Now supports consistent debug information collection
237+ * Orchestrates the compilation process for CDS files based on a dependency graph.
238+ *
239+ * This function coordinates the planning and execution of compilation tasks,
240+ * tracks the compilation status, and generates a post-compilation report.
241+ *
242+ * @param dependencyGraph - The {@link CdsDependencyGraph} representing the CDS projects,
243+ * project dependencies, expected compilation tasks, and their statuses.
244+ * @param projectCacheDirMap - A map from project identifiers to their cache directory paths.
245+ * @param codeqlExePath - The path to the CodeQL executable. Used for generating diagnostic
246+ * messages as part of the broader CodeQL (JavaScript) extraction process.
247+ * @throws Will rethrow any errors encountered during compilation, after logging them.
304248 */
305249export function orchestrateCompilation (
306250 dependencyGraph : CdsDependencyGraph ,
307251 projectCacheDirMap : Map < string , string > ,
308252 codeqlExePath : string ,
309253) : void {
310254 try {
311- // Plan compilation tasks
312255 planCompilationTasks ( dependencyGraph , projectCacheDirMap ) ;
313256
314- // Execute compilation tasks
315257 executeCompilationTasks ( dependencyGraph , codeqlExePath ) ;
316258
317259 // Update overall status
@@ -322,9 +264,9 @@ export function orchestrateCompilation(
322264 dependencyGraph . statusSummary . overallSuccess = ! hasFailures ;
323265 dependencyGraph . currentPhase = hasFailures ? 'failed' : 'completed' ;
324266
325- // Generate and log status report
267+ // Generate and log a "Post-Compilation" status report, aka before the JavaScript extractor runs.
326268 const statusReport = generateStatusReport ( dependencyGraph ) ;
327- cdsExtractorLog ( 'info' , 'Final Status Report: \n' + statusReport ) ;
269+ cdsExtractorLog ( 'info' , 'CDS Extractor Status Report : Post-Compilation... \n' + statusReport ) ;
328270 } catch ( error ) {
329271 const errorMessage = `Compilation orchestration failed: ${ String ( error ) } ` ;
330272 cdsExtractorLog ( 'error' , errorMessage ) ;
@@ -343,10 +285,8 @@ export function orchestrateCompilation(
343285 }
344286}
345287
346- /**
347- * Plan compilation tasks for all projects in the dependency graph
348- */
349- export function planCompilationTasks (
288+ /** Plan compilation tasks for all projects in the dependency graph. */
289+ function planCompilationTasks (
350290 dependencyGraph : CdsDependencyGraph ,
351291 projectCacheDirMap : Map < string , string > ,
352292) : void {
@@ -379,7 +319,6 @@ export function planCompilationTasks(
379319 project . expectedOutputFiles ,
380320 projectDir ,
381321 true ,
382- 10 , // Higher priority for project-level compilation
383322 ) ;
384323 project . compilationTasks = [ task ] ;
385324 } else {
@@ -393,7 +332,6 @@ export function planCompilationTasks(
393332 [ expectedOutput ] ,
394333 projectDir ,
395334 false ,
396- 5 , // Lower priority for individual files
397335 ) ;
398336 tasks . push ( task ) ;
399337 }
0 commit comments