Skip to content

Commit 7a05f80

Browse files
committed
Fix project-aware CDS compile file paths
Fixes a regression where the project base directory was being used to set the `cwd` of the process spawned for running the CDS compiler for "project-aware" compilation. Adds unit tests to ensure the `cwd` is always set to the value of the `sourceRoot` directory. Further refactoring of the `cds/compiler` and `cds/parser` packages within the source code of the CDS extractor. This commit is expected to actually cause more problems with existing queries, despite fixing the relative-file-path problem / regression. Some changes to existing CodeQL queries and/or expected results may be required as, at this point, the JSON data generated by the CDS compiler (via the CDS extractor) seems valid.
1 parent 27743ba commit 7a05f80

File tree

10 files changed

+971
-149
lines changed

10 files changed

+971
-149
lines changed

extractors/cds/tools/cds-extractor.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,31 @@ for (const [, project] of projectMap.entries()) {
9696

9797
console.log('Processing CDS files to JSON ...');
9898

99-
// Evaluate each `.cds` source file to determine if it should be compiled to JSON.
100-
// TODO : use project.cdsFilesToCompile instead of cdsFiles, to avoid compiling files
101-
// that are already imported by other files in the same project.
102-
for (const rawCdsFilePath of cdsFilePathsToProcess) {
99+
// Collect files that need compilation, handling project-level compilation
100+
const cdsFilesToCompile: string[] = [];
101+
const projectsForProjectLevelCompilation = new Set<string>();
102+
103+
for (const [projectDir, project] of projectMap.entries()) {
104+
if (project.cdsFilesToCompile.includes('__PROJECT_LEVEL_COMPILATION__')) {
105+
// This project needs project-level compilation
106+
projectsForProjectLevelCompilation.add(projectDir);
107+
// We'll only compile one file per project to trigger project-level compilation
108+
// Use the first CDS file as a representative
109+
if (project.cdsFiles.length > 0) {
110+
cdsFilesToCompile.push(project.cdsFiles[0]);
111+
}
112+
} else {
113+
// Normal individual file compilation
114+
cdsFilesToCompile.push(...project.cdsFilesToCompile);
115+
}
116+
}
117+
118+
console.log(
119+
`Found ${cdsFilePathsToProcess.length} total CDS files, ${cdsFilesToCompile.length} files to compile (${projectsForProjectLevelCompilation.size} project-level compilations)`,
120+
);
121+
122+
// Evaluate each `.cds` source file that should be compiled to JSON.
123+
for (const rawCdsFilePath of cdsFilesToCompile) {
103124
try {
104125
// Find which project this CDS file belongs to, to use the correct cache directory
105126
const projectDir = findProjectForCdsFile(rawCdsFilePath, sourceRoot, projectMap);

0 commit comments

Comments
 (0)