Skip to content

Commit c41597c

Browse files
committed
CDS extractor cleanup checkpoint 1
1 parent 257fac2 commit c41597c

File tree

13 files changed

+35
-153
lines changed

13 files changed

+35
-153
lines changed

extractors/cds/tools/cds-extractor.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { join } from 'path';
22

33
import { sync as globSync } from 'glob';
44

5-
import { determineCdsCommand } from './src/cds';
65
import { orchestrateCompilation } from './src/cds/compiler';
76
import { buildCdsProjectDependencyGraph } from './src/cds/parser';
87
import { runJavaScriptExtractor } from './src/codeql';
@@ -99,7 +98,7 @@ try {
9998
for (const [projectDir, project] of dependencyGraph.projects.entries()) {
10099
cdsExtractorLog(
101100
'info',
102-
`Project: ${projectDir}, Status: ${project.status}, CDS files: ${project.cdsFiles.length}, Files to compile: ${project.cdsFilesToCompile.length}`,
101+
`Project: ${projectDir}, Status: ${project.status}, CDS files: ${project.cdsFiles.length}, Compilations to run: ${project.cdsFilesToCompile.length}`,
103102
);
104103
}
105104
} else {
@@ -187,18 +186,6 @@ for (const project of dependencyGraph.projects.values()) {
187186
cdsFilePathsToProcess.push(...project.cdsFiles);
188187
}
189188

190-
// Initialize CDS command cache early to avoid repeated testing during compilation.
191-
// This is a critical optimization that avoids testing commands for every single file.
192-
logPerformanceTrackingStart('CDS Command Cache Initialization');
193-
try {
194-
determineCdsCommand(undefined, sourceRoot);
195-
logPerformanceTrackingStop('CDS Command Cache Initialization');
196-
cdsExtractorLog('info', 'CDS command cache initialized successfully');
197-
} catch (error) {
198-
logPerformanceTrackingStop('CDS Command Cache Initialization');
199-
cdsExtractorLog('warn', `CDS command cache initialization failed: ${String(error)}`);
200-
}
201-
202189
// TODO : Improve logging / debugging of dependencyGraph.statusSummary. Just log the JSON?
203190
cdsExtractorLog(
204191
'info',

extractors/cds/tools/src/cds/compiler/graph.ts

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { determineCdsCommand } from './command';
22
import { compileCdsToJson } from './compile';
3-
import {
4-
AlternativeCdsCommand,
5-
CompilationAttempt,
6-
CompilationTask,
7-
CompilationConfig,
8-
} from './types';
3+
import { CompilationAttempt, CompilationTask, CompilationConfig } from './types';
94
import { addCompilationDiagnostic } from '../../diagnostics';
105
import { cdsExtractorLog } from '../../logging';
116
import { CdsDependencyGraph, CdsProject } from '../parser/types';
@@ -113,20 +108,15 @@ function createCompilationTask(
113108
};
114109
}
115110

116-
/**
117-
* Create compilation configuration with retry alternatives
118-
*/
119111
function createCompilationConfig(
120-
primaryCommand: string,
121-
primaryCacheDir: string | undefined,
112+
cdsCommand: string,
113+
cacheDir: string | undefined,
122114
useProjectLevel: boolean,
123-
alternatives: AlternativeCdsCommand[] = [],
124115
): CompilationConfig {
125116
return {
126-
primaryCdsCommand: primaryCommand,
127-
primaryCacheDir,
117+
cdsCommand: cdsCommand,
118+
cacheDir: cacheDir,
128119
useProjectLevelCompilation: useProjectLevel,
129-
alternativeCommands: alternatives,
130120
versionCompatibility: {
131121
isCompatible: true, // Will be validated during planning
132122
},
@@ -135,7 +125,7 @@ function createCompilationConfig(
135125
}
136126

137127
/**
138-
* Execute a single compilation task with retry logic
128+
* Execute a single compilation task
139129
*/
140130
function executeCompilationTask(
141131
task: CompilationTask,
@@ -150,58 +140,26 @@ function executeCompilationTask(
150140
throw new Error(`No compilation configuration found for project ${project.projectDir}`);
151141
}
152142

153-
let lastError: Error | undefined;
154-
155-
// Try primary command first
156-
const primaryAttempt = attemptCompilation(
143+
const compilationAttempt = attemptCompilation(
157144
task,
158-
config.primaryCdsCommand,
159-
config.primaryCacheDir,
145+
config.cdsCommand,
146+
config.cacheDir,
160147
dependencyGraph,
161148
);
162149

163-
if (primaryAttempt.result.success) {
150+
if (compilationAttempt.result.success) {
164151
task.status = 'success';
165152
dependencyGraph.statusSummary.successfulCompilations++;
166153
return;
167154
}
168155

169-
lastError = primaryAttempt.error
170-
? new Error(primaryAttempt.error.message)
171-
: new Error('Primary compilation failed');
172-
task.status = 'retry';
173-
174-
// Try alternative commands if primary failed
175-
for (const alternative of config.alternativeCommands) {
176-
if (task.attempts.length >= config.maxRetryAttempts) {
177-
break;
178-
}
179-
180-
cdsExtractorLog(
181-
'info',
182-
`Retrying compilation for ${task.sourceFiles[0]} with alternative command: ${alternative.strategy}`,
183-
);
184-
185-
const retryAttempt = attemptCompilation(
186-
task,
187-
alternative.command,
188-
alternative.cacheDir,
189-
dependencyGraph,
190-
);
191-
192-
if (retryAttempt.result.success) {
193-
task.status = 'success';
194-
dependencyGraph.statusSummary.successfulCompilations++;
195-
dependencyGraph.statusSummary.retriedCompilations++;
196-
return;
197-
}
198-
199-
lastError = retryAttempt.error ? new Error(retryAttempt.error.message) : lastError;
200-
}
156+
// Compilation failed - mark task as failed
157+
const lastError = compilationAttempt.error
158+
? new Error(compilationAttempt.error.message)
159+
: new Error('Compilation failed');
201160

202-
// All attempts failed
203161
task.status = 'failed';
204-
task.errorSummary = lastError?.message || 'All compilation attempts failed';
162+
task.errorSummary = lastError?.message || 'Compilation failed';
205163
dependencyGraph.statusSummary.failedCompilations++;
206164

207165
// Add diagnostic for failed compilation
@@ -308,7 +266,6 @@ export function generateStatusReport(dependencyGraph: CdsDependencyGraph): strin
308266
lines.push(` Successful: ${summary.successfulCompilations}`);
309267
lines.push(` Failed: ${summary.failedCompilations}`);
310268
lines.push(` Skipped: ${summary.skippedCompilations}`);
311-
lines.push(` Retried: ${summary.retriedCompilations}`);
312269
lines.push('');
313270

314271
// Performance metrics
@@ -401,7 +358,7 @@ export function planCompilationTasks(
401358
try {
402359
const cacheDir = projectCacheDirMap.get(projectDir);
403360

404-
// Determine primary CDS command
361+
// Determine CDS command
405362
const cdsCommand = determineCdsCommand(cacheDir, dependencyGraph.sourceRootDir);
406363

407364
// Create compilation configuration

extractors/cds/tools/src/cds/compiler/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export {
99
} from './graph';
1010
export { findProjectForCdsFile } from './project';
1111
export type {
12-
AlternativeCdsCommand,
1312
CdsCompilationResult,
1413
CompilationAttempt,
1514
CompilationStatus,

extractors/cds/tools/src/cds/compiler/types.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
/** Types for the `src/cds/compiler` package. */
22

3-
/**
4-
* Alternative CDS command configuration for retry scenarios
5-
*/
6-
export interface AlternativeCdsCommand {
7-
/** The command string */
8-
command: string;
9-
/** Cache directory to use with this command */
10-
cacheDir?: string;
11-
/** Strategy identifier (e.g., 'global-cds', 'npx-cds-dk') */
12-
strategy: string;
13-
/** Version information if available */
14-
version?: string;
15-
/** Priority for trying this command (higher = try first) */
16-
priority: number;
17-
/** Whether this command has been tested successfully */
18-
tested: boolean;
19-
}
20-
213
/**
224
* Result of a CDS compilation attempt
235
*/
@@ -67,8 +49,7 @@ export type CompilationStatus =
6749
| 'in_progress' // Compilation is currently running
6850
| 'success' // Compilation completed successfully
6951
| 'failed' // Compilation failed
70-
| 'skipped' // Compilation was skipped (e.g., already compiled)
71-
| 'retry'; // Marked for retry with different configuration
52+
| 'skipped'; // Compilation was skipped (e.g., already compiled)
7253

7354
/**
7455
* Compilation task representing a unit of work (file or project-level compilation)
@@ -99,17 +80,15 @@ export interface CompilationTask {
9980
}
10081

10182
/**
102-
* Compilation configuration with retry alternatives
83+
* Compilation configuration for managing compilation commands and retries.
10384
*/
10485
export interface CompilationConfig {
105-
/** Primary CDS command to use */
106-
primaryCdsCommand: string;
107-
/** Primary cache directory */
108-
primaryCacheDir?: string;
86+
/** CDS command to use */
87+
cdsCommand: string;
88+
/** Cache directory */
89+
cacheDir?: string;
10990
/** Whether to use project-level compilation */
11091
useProjectLevelCompilation: boolean;
111-
/** Alternative commands to try if primary fails */
112-
alternativeCommands: AlternativeCdsCommand[];
11392
/** Version compatibility information */
11493
versionCompatibility: {
11594
isCompatible: boolean;

extractors/cds/tools/src/cds/parser/functions.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,23 +410,19 @@ export function determineCdsFilesToCompile(
410410
return [];
411411
}
412412

413-
// If there's only one CDS file, it should be compiled individually
413+
// If there's only one CDS file, it should be compiled individually.
414414
if (project.cdsFiles.length === 1) {
415415
return [...project.cdsFiles];
416416
}
417417

418-
// Check if this looks like a CAP project with typical directory structure
419418
const absoluteProjectDir = join(sourceRootDir, project.projectDir);
420419
const hasCapStructure = hasTypicalCapDirectoryStructure(project.cdsFiles);
421-
const isCapProject = isLikelyCdsProject(absoluteProjectDir);
420+
const hasCapDeps = hasPackageJsonWithCapDeps(absoluteProjectDir);
422421

423422
// Use project-level compilation only if:
424-
// 1. It has CAP package.json dependencies OR
423+
// 1. It has CAP package.json dependencies, OR
425424
// 2. It has the typical CAP directory structure (db/, srv/ etc.)
426-
if (
427-
project.cdsFiles.length > 1 &&
428-
(hasCapStructure || (isCapProject && hasPackageJsonWithCapDeps(absoluteProjectDir)))
429-
) {
425+
if (project.cdsFiles.length > 1 && (hasCapStructure || hasCapDeps)) {
430426
// For CAP projects, we should use project-level compilation
431427
// Return a special marker that indicates the entire project should be compiled together
432428
return ['__PROJECT_LEVEL_COMPILATION__'];

extractors/cds/tools/src/cds/parser/graph.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ export function buildCdsProjectDependencyGraph(
257257
successfulCompilations: 0,
258258
failedCompilations: 0,
259259
skippedCompilations: 0,
260-
retriedCompilations: 0,
261260
jsonFilesGenerated: 0,
262261
criticalErrors: [],
263262
warnings: [],

extractors/cds/tools/src/cds/parser/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ export interface ExtractionStatusSummary {
141141
failedCompilations: number;
142142
/** Skipped compilation tasks */
143143
skippedCompilations: number;
144-
/** Tasks that required retries */
145-
retriedCompilations: number;
146144
/** JSON files generated */
147145
jsonFilesGenerated: number;
148146
/** Critical errors that stopped extraction */
@@ -192,7 +190,7 @@ export interface CdsProject extends BasicCdsProject {
192190
/** Unique identifier for this project */
193191
id: string;
194192

195-
/** Compilation configuration with retry support */
193+
/** Compilation configuration */
196194
enhancedCompilationConfig?: import('../compiler/types.js').CompilationConfig;
197195

198196
/** Compilation tasks for this project */
@@ -268,7 +266,7 @@ export interface CdsDependencyGraph {
268266

269267
/** Configuration and settings */
270268
config: {
271-
/** Maximum retry attempts for compilation */
269+
/** Maximum retry attempts for task re-execution */
272270
maxRetryAttempts: number;
273271
/** Whether to enable detailed logging */
274272
enableDetailedLogging: boolean;

extractors/cds/tools/src/packageManager/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export {
99
findBestAvailableVersion,
1010
getAvailableVersions,
1111
getCacheStatistics,
12-
logCacheStatistics,
1312
parseSemanticVersion,
1413
resolveCdsVersions,
1514
satisfiesRange,

extractors/cds/tools/src/packageManager/installer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { CdsDependencyCombination } from './types';
77
import { CdsDependencyGraph, CdsProject } from '../cds/parser/types';
88
import { DiagnosticSeverity } from '../diagnostics';
99
import { cdsExtractorLog } from '../logging';
10-
import { resolveCdsVersions, logCacheStatistics } from './versionResolver';
10+
import { resolveCdsVersions } from './versionResolver';
1111

1212
const cacheSubDirName = '.cds-extractor-cache';
1313

@@ -67,6 +67,10 @@ function extractUniqueDependencyCombinations(
6767
const cdsDkVersion = project.packageJson.devDependencies?.['@sap/cds-dk'] ?? cdsVersion;
6868

6969
// Resolve versions first to ensure we cache based on actual resolved versions
70+
cdsExtractorLog(
71+
'info',
72+
`Resolving available dependency versions for project '${project.projectDir}' with dependencies: [@sap/cds@${cdsVersion}, @sap/cds-dk@${cdsDkVersion}]`,
73+
);
7074
const resolvedVersions = resolveCdsVersions(cdsVersion, cdsDkVersion);
7175
const { resolvedCdsVersion, resolvedCdsDkVersion, ...rest } = resolvedVersions;
7276

@@ -303,7 +307,7 @@ export function installDependencies(
303307
cdsExtractorLog('info', 'All dependency combinations installed successfully.');
304308
}
305309

306-
// Log project to cache directory mappings for transparency
310+
// Log project-to-cache-directory mappings for transparency.
307311
if (projectCacheDirMap.size > 0) {
308312
cdsExtractorLog('info', `Project to cache directory mappings:`);
309313
for (const [projectDir, cacheDir] of Array.from(projectCacheDirMap.entries())) {
@@ -317,9 +321,6 @@ export function installDependencies(
317321
);
318322
}
319323

320-
// Log cache statistics for debugging and performance monitoring
321-
logCacheStatistics();
322-
323324
return projectCacheDirMap;
324325
}
325326

extractors/cds/tools/src/packageManager/versionResolver.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,12 @@ export function getAvailableVersions(packageName: string): string[] {
134134
// Check cache first
135135
if (availableVersionsCache.has(packageName)) {
136136
cacheStats.hits++;
137-
cdsExtractorLog(
138-
'info',
139-
`Using cached versions for ${packageName} (cache hit rate: ${cacheStats.hitRate}%)`,
140-
);
141137
return availableVersionsCache.get(packageName)!;
142138
}
143139

144140
// Cache miss - fetch from npm
145141
cacheStats.misses++;
146142
try {
147-
cdsExtractorLog(
148-
'info',
149-
`Fetching available versions for ${packageName} from npm registry (cache miss ${cacheStats.misses})...`,
150-
);
151143
const output = execSync(`npm view ${packageName} versions --json`, {
152144
encoding: 'utf8',
153145
timeout: 30000, // 30 second timeout
@@ -164,10 +156,6 @@ export function getAvailableVersions(packageName: string): string[] {
164156

165157
// Cache the result
166158
availableVersionsCache.set(packageName, versionArray);
167-
cdsExtractorLog(
168-
'info',
169-
`Cached ${versionArray.length} versions for ${packageName} (cache hit rate: ${cacheStats.hitRate}%)`,
170-
);
171159

172160
return versionArray;
173161
} catch (error) {
@@ -196,17 +184,6 @@ export function getCacheStatistics(): {
196184
};
197185
}
198186

199-
/**
200-
* Log current cache statistics
201-
*/
202-
export function logCacheStatistics(): void {
203-
const stats = getCacheStatistics();
204-
cdsExtractorLog(
205-
'info',
206-
`Package version cache statistics: ${stats.hits} hits, ${stats.misses} misses, ${stats.hitRate}% hit rate, ${stats.cachedPackages.length} packages cached: [${stats.cachedPackages.join(', ')}]`,
207-
);
208-
}
209-
210187
/**
211188
* Parse a semantic version string
212189
* @param version Version string to parse (e.g., "6.1.3", "^6.0.0", "~6.1.0", "latest")

0 commit comments

Comments
 (0)