@@ -2,12 +2,10 @@ import { determineCdsCommand } from './command';
2
2
import { compileCdsToJson } from './compile' ;
3
3
import { CompilationAttempt , CompilationTask , CompilationConfig } from './types' ;
4
4
import { addCompilationDiagnostic } from '../../diagnostics' ;
5
- import { cdsExtractorLog } from '../../logging' ;
5
+ import { cdsExtractorLog , generateStatusReport } from '../../logging' ;
6
6
import { CdsDependencyGraph , CdsProject } from '../parser/types' ;
7
7
8
- /**
9
- * Attempt compilation with a specific command and configuration
10
- */
8
+ /** Attempt compilation with a specific command and configuration. */
11
9
function attemptCompilation (
12
10
task : CompilationTask ,
13
11
cdsCommand : string ,
@@ -92,7 +90,6 @@ function createCompilationTask(
92
90
expectedOutputFiles : string [ ] ,
93
91
projectDir : string ,
94
92
useProjectLevelCompilation : boolean ,
95
- priority : number = 0 ,
96
93
) : CompilationTask {
97
94
return {
98
95
id : `${ type } _${ projectDir } _${ Date . now ( ) } _${ Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) } ` ,
@@ -103,7 +100,6 @@ function createCompilationTask(
103
100
projectDir,
104
101
attempts : [ ] ,
105
102
useProjectLevelCompilation,
106
- priority,
107
103
dependencies : [ ] ,
108
104
} ;
109
105
}
@@ -171,18 +167,18 @@ function executeCompilationTask(
171
167
}
172
168
173
169
/**
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.
175
174
*/
176
- export function executeCompilationTasks (
177
- dependencyGraph : CdsDependencyGraph ,
178
- codeqlExePath : string ,
179
- ) : void {
175
+ function executeCompilationTasks ( dependencyGraph : CdsDependencyGraph , codeqlExePath : string ) : void {
180
176
cdsExtractorLog ( 'info' , 'Starting compilation execution for all projects...' ) ;
181
177
182
178
dependencyGraph . currentPhase = 'compiling' ;
183
179
const compilationStartTime = new Date ( ) ;
184
180
185
- // Collect all tasks and sort by priority
181
+ // Collect all compilation tasks from all projects.
186
182
const allTasks : Array < { task : CompilationTask ; project : CdsProject } > = [ ] ;
187
183
188
184
for ( const project of dependencyGraph . projects . values ( ) ) {
@@ -191,10 +187,9 @@ export function executeCompilationTasks(
191
187
}
192
188
}
193
189
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)...` ) ;
198
193
for ( const { task, project } of allTasks ) {
199
194
try {
200
195
executeCompilationTask ( task , project , dependencyGraph , codeqlExePath ) ;
@@ -239,79 +234,26 @@ export function executeCompilationTasks(
239
234
}
240
235
241
236
/**
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.
304
248
*/
305
249
export function orchestrateCompilation (
306
250
dependencyGraph : CdsDependencyGraph ,
307
251
projectCacheDirMap : Map < string , string > ,
308
252
codeqlExePath : string ,
309
253
) : void {
310
254
try {
311
- // Plan compilation tasks
312
255
planCompilationTasks ( dependencyGraph , projectCacheDirMap ) ;
313
256
314
- // Execute compilation tasks
315
257
executeCompilationTasks ( dependencyGraph , codeqlExePath ) ;
316
258
317
259
// Update overall status
@@ -322,9 +264,9 @@ export function orchestrateCompilation(
322
264
dependencyGraph . statusSummary . overallSuccess = ! hasFailures ;
323
265
dependencyGraph . currentPhase = hasFailures ? 'failed' : 'completed' ;
324
266
325
- // Generate and log status report
267
+ // Generate and log a "Post-Compilation" status report, aka before the JavaScript extractor runs.
326
268
const statusReport = generateStatusReport ( dependencyGraph ) ;
327
- cdsExtractorLog ( 'info' , 'Final Status Report: \n' + statusReport ) ;
269
+ cdsExtractorLog ( 'info' , 'CDS Extractor Status Report : Post-Compilation... \n' + statusReport ) ;
328
270
} catch ( error ) {
329
271
const errorMessage = `Compilation orchestration failed: ${ String ( error ) } ` ;
330
272
cdsExtractorLog ( 'error' , errorMessage ) ;
@@ -343,10 +285,8 @@ export function orchestrateCompilation(
343
285
}
344
286
}
345
287
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 (
350
290
dependencyGraph : CdsDependencyGraph ,
351
291
projectCacheDirMap : Map < string , string > ,
352
292
) : void {
@@ -379,7 +319,6 @@ export function planCompilationTasks(
379
319
project . expectedOutputFiles ,
380
320
projectDir ,
381
321
true ,
382
- 10 , // Higher priority for project-level compilation
383
322
) ;
384
323
project . compilationTasks = [ task ] ;
385
324
} else {
@@ -393,7 +332,6 @@ export function planCompilationTasks(
393
332
[ expectedOutput ] ,
394
333
projectDir ,
395
334
false ,
396
- 5 , // Lower priority for individual files
397
335
) ;
398
336
tasks . push ( task ) ;
399
337
}
0 commit comments