You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changes the way the index-files.js script is invoked such that the
original `--source-root` directory is used, where possible, as the
current working directory for any work performed with within the
extractor. Passes the original working directory as a parameter of
the index-files.js script to allow that (child) script to run from
the project/source root while ensuring node package dependencies
are still installed in `extractors/cds/tools/node_modules`.
Copy file name to clipboardExpand all lines: extractors/cds/tools/index-files.cmd
+22-6Lines changed: 22 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -19,20 +19,36 @@ if %ERRORLEVEL% neq 0 (
19
19
20
20
set"_response_file_path=%~1"
21
21
set"_script_dir=%~dp0"
22
+
REM Set _cwd before changing the working directory to the script directory.
23
+
set"_cwd=%CD%"
22
24
23
25
echo Checking response file for CDS files to index
24
26
27
+
REM Terminate early if the _response_file_path doesn't exist or is empty,
28
+
REM which indicates that no CDS files were selected or found.
25
29
ifnotexist"%_response_file_path%" (
26
30
echo 'codeql database index-files --language cds' command terminated early as response file '%_response_file_path%' does not exist or is empty. This is because no CDS files were selected or found.
27
31
exit /b 0
28
32
)
29
33
30
-
REM Change to the directory of this script to ensure that npm looks up
31
-
REM the package.json file in the correct directory and installs the
32
-
REM dependencies (i.e. node_modules) relative to this directory.
34
+
REM Change to the directory of this script to ensure that npm looks up the
35
+
REM package.json file in the correct directory and installs the dependencies
36
+
REM (i.e. node_modules) relative to this directory. This is technically a
37
+
REM violation of the assumption that extractor scripts will be run with the
38
+
REM current working directory set to the root of the project source, but we
39
+
REM also need node_modules to be installed here and not in the project source
40
+
REM root, so we make a compromise of:
41
+
REM 1. changing to this script's directory;
42
+
REM 2. installing node dependencies here;
43
+
REM 3. passing the original working directory as a parameter to the
44
+
REM index-files.js script;
45
+
REM 4. expecting the index-files.js script to immediately change back to
46
+
REM the original working (aka the project source root) directory.
47
+
33
48
cd /d "%_script_dir%"&&^
34
-
echo Installing node package dependencies and running the 'index-files.js' script &&^
console.warn(`'${codeqlExe} database index-files --language cds' terminated early due to internal error: could not find project root directory '${projectRootDir}'.`);
28
+
if(!existsSync(sourceRoot)){
29
+
console.warn(`'${codeqlExe} database index-files --language cds' terminated early due to internal error: could not find project root directory '${sourceRoot}'.`);
20
30
process.exit(0);
21
31
}
22
32
@@ -265,13 +275,15 @@ console.log(
265
275
* 'javascript' extractor.
266
276
*
267
277
* IMPORTANT: The JavaScript extractor autobuild script must be invoked with
268
-
* the current working directory set to the project root directory because it
269
-
* assumes it is running from there. Without the `cwd` property set to the
270
-
* project root directory, the autobuild script will not detect the .cds.json
271
-
* files as being in the project and will not index them.
278
+
* the current working directory set to the project (source) root directory
279
+
* because it assumes it is running from there. The JavaScript extractor will
280
+
* only find the .cds files to index (to the database) if those file are
281
+
* relative to where the autobuild script is invoked from, which should be the
282
+
* same as the `--source-root` argument passed to the `codeql database create`
0 commit comments