Skip to content

Commit 08961e9

Browse files
committed
Fixes for CDS extractor compilation task retry
1 parent 9c01e2b commit 08961e9

File tree

10 files changed

+218
-55
lines changed

10 files changed

+218
-55
lines changed

extractors/cds/tools/dist/cds-extractor.bundle.js

Lines changed: 38 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extractors/cds/tools/dist/cds-extractor.bundle.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ import { fileExists, dirExists, recursivelyRenameJsonFiles } from '../../filesys
99
import { cdsExtractorLog } from '../../logging';
1010
import { BasicCdsProject } from '../parser/types';
1111

12+
/**
13+
* Parses a command string for use with spawnSync, handling multi-word commands like 'npx cds'.
14+
* @param commandString The command string to parse (e.g., 'npx cds' or 'cds')
15+
* @returns Object with executable and args arrays for spawnSync
16+
*/
17+
function parseCommandForSpawn(commandString: string): { executable: string; baseArgs: string[] } {
18+
const parts = commandString.trim().split(/\s+/);
19+
const executable = parts[0];
20+
const baseArgs = parts.slice(1);
21+
return { executable, baseArgs };
22+
}
23+
1224
/**
1325
* Compiles a CDS file to JSON using robust, project-aware compilation only.
1426
* This function has been refactored to align with the autobuild.md vision by removing all
@@ -100,7 +112,6 @@ export function compileCdsToJson(
100112
projectDir,
101113
cdsCommand,
102114
spawnOptions,
103-
versionInfo,
104115
);
105116
}
106117
} catch (error) {
@@ -126,11 +137,11 @@ function compileProjectLevel(
126137
projectDir: string,
127138
cdsCommand: string,
128139
spawnOptions: SpawnSyncOptions,
129-
_versionInfo: string,
140+
versionInfo: string,
130141
): CdsCompilationResult {
131142
cdsExtractorLog(
132143
'info',
133-
`${resolvedCdsFilePath} is part of a CAP project - using project-aware compilation ${_versionInfo}...`,
144+
`${resolvedCdsFilePath} is part of a CAP project - using project-aware compilation ${versionInfo}...`,
134145
);
135146

136147
// For project-level compilation, compile the entire project together
@@ -190,7 +201,7 @@ function compileProjectLevel(
190201
'--to',
191202
'json',
192203
'--dest',
193-
'model.cds.json', // TODO : replace `model.cds.json` with `model.<session_id>.cds.json`
204+
'model.cds.json', // TODO: Replace `model.cds.json` with `model.<session_id>.cds.json`
194205
'--locations',
195206
'--log-level',
196207
'warn',
@@ -202,7 +213,11 @@ function compileProjectLevel(
202213
`Running compilation task for CDS project '${projectDir}': command='${cdsCommand}' args='${JSON.stringify(compileArgs)}'`,
203214
);
204215

205-
const result = spawnSync(cdsCommand, compileArgs, spawnOptions);
216+
// Parse command for proper spawnSync execution
217+
const { executable, baseArgs } = parseCommandForSpawn(cdsCommand);
218+
const allArgs = [...baseArgs, ...compileArgs];
219+
220+
const result = spawnSync(executable, allArgs, spawnOptions);
206221

207222
if (result.error) {
208223
cdsExtractorLog('error', `SpawnSync error: ${result.error.message}`);
@@ -242,7 +257,7 @@ function compileProjectLevel(
242257
`CDS compiler generated JSON to output directory: ${projectJsonOutPath}`,
243258
);
244259
// Recursively rename generated .json files to have a .cds.json extension
245-
// TODO : replace or remove this in favor of session-specific file suffixes (i.e. `.<session_id>.cds.json`).
260+
// TODO: Replace or remove this in favor of session-specific file suffixes (i.e. `.<session_id>.cds.json`).
246261
recursivelyRenameJsonFiles(projectJsonOutPath);
247262
} else {
248263
cdsExtractorLog('info', `CDS compiler generated JSON to file: ${projectJsonOutPath}`);
@@ -266,15 +281,14 @@ function compileProjectLevel(
266281
* @param cdsCommand The CDS command to use
267282
* @param spawnOptions Pre-configured spawn options
268283
* @param versionInfo Version information for logging
269-
* @returns Compilation result
284+
* @returns The {@link CdsCompilationResult}
270285
*/
271286
function compileRootFileAsProject(
272287
resolvedCdsFilePath: string,
273288
sourceRoot: string,
274289
projectDir: string,
275290
cdsCommand: string,
276291
spawnOptions: SpawnSyncOptions,
277-
_versionInfo: string,
278292
): CdsCompilationResult {
279293
// Calculate project base directory and file path relative to project
280294
const projectBaseDir = join(sourceRoot, projectDir);
@@ -304,7 +318,11 @@ function compileRootFileAsProject(
304318
);
305319

306320
// Execute the compilation
307-
const result = spawnSync(cdsCommand, compileArgs, spawnOptions);
321+
// Parse command for proper spawnSync execution
322+
const { executable, baseArgs } = parseCommandForSpawn(cdsCommand);
323+
const allArgs = [...baseArgs, ...compileArgs];
324+
325+
const result = spawnSync(executable, allArgs, spawnOptions);
308326

309327
if (result.error) {
310328
cdsExtractorLog('error', `SpawnSync error: ${result.error.message}`);

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { determineCdsCommand } from './command';
22
import { compileCdsToJson } from './compile';
33
import { orchestrateRetryAttempts } from './retry';
4-
import { CompilationAttempt, CompilationTask, CompilationConfig } from './types';
4+
import {
5+
CompilationAttempt,
6+
CompilationTask,
7+
CompilationConfig,
8+
ValidatedCdsCommand,
9+
} from './types';
510
import { updateCdsDependencyGraphStatus } from './validator';
611
import { cdsExtractorLog, generateStatusReport } from '../../logging';
712
import { CdsDependencyGraph, CdsProject } from '../parser/types';
@@ -92,6 +97,19 @@ function createCompilationTask(
9297
projectDir: string,
9398
useProjectLevelCompilation: boolean,
9499
): CompilationTask {
100+
// Create default commands for tasks - these should be updated later with proper commands
101+
const defaultPrimaryCommand: ValidatedCdsCommand = {
102+
executable: 'cds',
103+
args: [],
104+
originalCommand: 'cds',
105+
};
106+
107+
const defaultRetryCommand: ValidatedCdsCommand = {
108+
executable: 'npx',
109+
args: ['cds'],
110+
originalCommand: 'npx cds',
111+
};
112+
95113
return {
96114
id: `${type}_${projectDir}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
97115
type,
@@ -102,6 +120,8 @@ function createCompilationTask(
102120
attempts: [],
103121
useProjectLevelCompilation,
104122
dependencies: [],
123+
primaryCommand: defaultPrimaryCommand,
124+
retryCommand: defaultRetryCommand,
105125
};
106126
}
107127

0 commit comments

Comments
 (0)