Skip to content

Commit 5d16df0

Browse files
committed
Attempted fix for missing CDS SARIF results
Avoids changing directory when running the `cds` compiler, which ensures that paths generated in .cds.json files are relative to the "source root" directory. This replicates the behavior of the original index-files.sh (shell) script, which works but is probably not correct.
1 parent cc99914 commit 5d16df0

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

extractors/cds/tools/index-files.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { execFileSync, spawnSync } = require('child_process');
22
const { existsSync, readFileSync, statSync, writeFileSync } = require('fs');
33
const { arch, platform } = require('os');
4-
const { basename, dirname, join, resolve } = require('path');
4+
const { dirname, join, resolve } = require('path');
55
const { quote } = require('shell-quote');
66

77
// Terminate early if this script is not invoked with the required arguments.
@@ -161,16 +161,19 @@ try {
161161
}
162162

163163
packageJsonDirs.forEach((dir) => {
164-
console.log(`Installing '@sap/cds-dk' into ${dir} to enable CDS compilation ...`);
164+
console.log(`Installing node dependencies from ${dir}/package.json ...`);
165165
execFileSync(
166166
'npm',
167-
['install', '--quiet', '--no-audit', '--no-fund', '--no-save', '@sap/cds-dk'],
167+
['install', '--quiet', '--no-audit', '--no-fund'],
168168
{ cwd: dir, stdio: 'inherit' }
169169
);
170-
console.log(`Installing node packages into ${dir} to enable CDS compilation ...`);
170+
// Order is important here. Install dependencies from package.json in the directory,
171+
// then install the CDS development kit (`@sap/cds-dk`) in the directory. Reversing
172+
// this order causes cyclic install-remove behavior.
173+
console.log(`Installing '@sap/cds-dk' into ${dir} to enable CDS compilation ...`);
171174
execFileSync(
172175
'npm',
173-
['install', '--quiet', '--no-audit', '--no-fund'],
176+
['install', '--quiet', '--no-audit', '--no-fund', '--no-save', '@sap/cds-dk'],
174177
{ cwd: dir, stdio: 'inherit' }
175178
);
176179
});
@@ -201,7 +204,7 @@ responseFiles.forEach(rawCdsFilePath => {
201204
'--locations',
202205
'--log-level', 'warn'
203206
],
204-
{ cwd: dirname(cdsFilePath), shell: true, stdio: 'pipe' }
207+
{ shell: true, stdio: 'pipe' }
205208
);
206209
if (result.error || result.status !== 0 || !result.stdout) {
207210
const errorMessage = `Could not compile the file ${cdsFilePath}.\nReported error(s):\n\`\`\`\n${result.stderr.toString()}\n\`\`\``;

scripts/compile-cds.cmd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@echo off
2+
3+
if not defined CODEQL_EXTRACTOR_CDS_SKIP_EXTRACTION (
4+
type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
5+
--include-extension=.cds ^
6+
--language cds ^
7+
--prune **\node_modules\**\* ^
8+
--prune **\.eslint\**\* ^
9+
--total-size-limit=10m ^
10+
-- ^
11+
"%CODEQL_EXTRACTOR_JAVASCRIPT_WIP_DATABASE%"
12+
)
13+
14+
exit /b %ERRORLEVEL%

scripts/compile-cds.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# To use this script with the CodeQL CLI:
44
# 1. Set the `codeql database create` `--search-path`` argument to the `extractors/` directory in this repository, e.g.:
@@ -32,14 +32,16 @@ set -eu
3232
# - extractors/javascript/tools/pre-finalize.sh
3333
# Any changes should be synchronized between these three places.
3434

35-
# Do not extract CDS files if the CODEQL_EXTRACTOR_CDS_SKIP_EXTRACTION environment variable is set
35+
# Do not extract CDS files if the CODEQL_EXTRACTOR_CDS_SKIP_EXTRACTION
36+
# environment variable is set.
3637
if [ -z "${CODEQL_EXTRACTOR_CDS_SKIP_EXTRACTION:-}" ]; then
3738
# Call the index-files command with the CDS extractor
38-
"$CODEQL_DIST/codeql" database index-files \
39-
--language cds \
40-
--total-size-limit 10m \
39+
"${CODEQL_DIST}/codeql" database index-files \
4140
--include-extension=.cds \
41+
--language cds \
4242
--prune **/node_modules/**/* \
4343
--prune **/.eslint/**/* \
44+
--total-size-limit=10m \
45+
-- \
4446
"$CODEQL_EXTRACTOR_JAVASCRIPT_WIP_DATABASE"
4547
fi

0 commit comments

Comments
 (0)