Skip to content

Commit e3b5aa7

Browse files
committed
CDS extractor diagnostics must use relative paths
Updates the CDS extractor source code and unit tests in order to ensure that tool-level diagnostics only ever use relative paths.
1 parent 3e43fa7 commit e3b5aa7

File tree

9 files changed

+570
-130
lines changed

9 files changed

+570
-130
lines changed

extractors/cds/tools/cds-extractor.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ try {
183183
if (!extractorResult.success && extractorResult.error) {
184184
cdsExtractorLog('error', `Error running JavaScript extractor: ${extractorResult.error}`);
185185
if (codeqlExePath) {
186-
addJavaScriptExtractorDiagnostic(sourceRoot, extractorResult.error, codeqlExePath);
186+
addJavaScriptExtractorDiagnostic(
187+
sourceRoot,
188+
extractorResult.error,
189+
codeqlExePath,
190+
sourceRoot,
191+
);
187192
}
188193
logExtractorStop(false, 'JavaScript extractor failed');
189194
} else {
@@ -223,7 +228,12 @@ try {
223228
if (!extractorResult.success && extractorResult.error) {
224229
cdsExtractorLog('error', `Error running JavaScript extractor: ${extractorResult.error}`);
225230
if (codeqlExePath) {
226-
addJavaScriptExtractorDiagnostic(sourceRoot, extractorResult.error, codeqlExePath);
231+
addJavaScriptExtractorDiagnostic(
232+
sourceRoot,
233+
extractorResult.error,
234+
codeqlExePath,
235+
sourceRoot,
236+
);
227237
}
228238
logExtractorStop(false, 'JavaScript extractor failed');
229239
} else {
@@ -316,6 +326,7 @@ try {
316326
cdsFilePathsToProcess[0], // Use first file as representative
317327
`Compilation orchestration failed: ${String(error)}`,
318328
codeqlExePath,
329+
sourceRoot,
319330
);
320331
}
321332
}
@@ -350,7 +361,12 @@ if (!extractorResult.success && extractorResult.error) {
350361
// Use the first CDS file as a representative file for the diagnostic
351362
const firstProject = Array.from(dependencyGraph.projects.values())[0];
352363
const representativeFile = firstProject.cdsFiles[0] || sourceRoot;
353-
addJavaScriptExtractorDiagnostic(representativeFile, extractorResult.error, codeqlExePath);
364+
addJavaScriptExtractorDiagnostic(
365+
representativeFile,
366+
extractorResult.error,
367+
codeqlExePath,
368+
sourceRoot,
369+
);
354370
}
355371

356372
logExtractorStop(false, 'JavaScript extractor failed');

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

Lines changed: 71 additions & 24 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: 3 additions & 3 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/retry.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import type { CdsDependencyGraph, CdsProject } from '../parser';
1818
* Add diagnostics only for tasks with `status: failed` in the {@link CdsDependencyGraph}.
1919
* @param dependencyGraph The dependency graph to use as the source of truth for task status
2020
* @param codeqlExePath Path to CodeQL executable used to add a diagnostic notification
21+
* @param sourceRoot Source root directory to use for making file paths relative
2122
*/
2223
function addCompilationDiagnosticsForFailedTasks(
2324
dependencyGraph: CdsDependencyGraph,
2425
codeqlExePath: string,
26+
sourceRoot: string,
2527
): void {
2628
for (const project of dependencyGraph.projects.values()) {
2729
for (const task of project.compilationTasks) {
@@ -38,6 +40,7 @@ function addCompilationDiagnosticsForFailedTasks(
3840
sourceFile,
3941
task.errorSummary ?? 'Compilation failed',
4042
codeqlExePath,
43+
sourceRoot,
4144
);
4245
}
4346
}
@@ -191,7 +194,11 @@ export function orchestrateRetryAttempts(
191194
updateDependencyGraphWithRetryResults(dependencyGraph, result);
192195

193196
// Phase 5: Add diagnostics for definitively failed tasks.
194-
addCompilationDiagnosticsForFailedTasks(dependencyGraph, codeqlExePath);
197+
addCompilationDiagnosticsForFailedTasks(
198+
dependencyGraph,
199+
codeqlExePath,
200+
dependencyGraph.sourceRootDir,
201+
);
195202

196203
result.success = result.totalSuccessfulRetries > 0 || result.totalTasksRequiringRetry === 0;
197204
} catch (error) {

extractors/cds/tools/src/codeql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function runJavaScriptExtractor(
4343
if (result.error) {
4444
const errorMessage = `Error running JavaScript extractor: ${result.error.message}`;
4545
if (codeqlExePath) {
46-
addJavaScriptExtractorDiagnostic(sourceRoot, errorMessage, codeqlExePath);
46+
addJavaScriptExtractorDiagnostic(sourceRoot, errorMessage, codeqlExePath, sourceRoot);
4747
}
4848
return {
4949
success: false,
@@ -54,7 +54,7 @@ export function runJavaScriptExtractor(
5454
if (result.status !== 0) {
5555
const errorMessage = `JavaScript extractor failed with exit code ${String(result.status)}`;
5656
if (codeqlExePath) {
57-
addJavaScriptExtractorDiagnostic(sourceRoot, errorMessage, codeqlExePath);
57+
addJavaScriptExtractorDiagnostic(sourceRoot, errorMessage, codeqlExePath, sourceRoot);
5858
}
5959
return {
6060
success: false,

0 commit comments

Comments
 (0)