Skip to content

Commit ad6e405

Browse files
authored
Merge pull request #169 from data-douser/data-douser/extractor-dev-2
Initial version of platform-independent CDS extractor
2 parents 8117102 + 4d78f9e commit ad6e405

11 files changed

+4103
-162
lines changed

extractors/cds/tools/autobuild.cmd

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@echo off
2+
3+
type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
4+
--include-extension=.cds ^
5+
--language cds ^
6+
--prune **\node_modules\**\* ^
7+
--prune **\.eslint\**\* ^
8+
--total-size-limit=10m ^
9+
-- ^
10+
"%CODEQL_EXTRACTOR_CDS_WIP_DATABASE%"
11+
12+
exit /b %ERRORLEVEL%

extractors/cds/tools/autobuild.sh

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
set -eu
44

5-
# NOTE: the code below is copied in three places:
6-
# - scripts/compile-cds.sh
7-
# - extractors/cds/tools/autobuild.sh (here)
8-
# - extractors/javascript/tools/pre-finalize.sh
9-
# Any changes should be synchronized between these three places.
10-
115
exec "${CODEQL_DIST}/codeql" database index-files \
12-
--language cds \
13-
--total-size-limit 10m \
146
--include-extension=.cds \
7+
--language cds \
158
--prune **/node_modules/**/* \
169
--prune **/.eslint/**/* \
17-
"$CODEQL_EXTRACTOR_CDS_WIP_DATABASE"
10+
--total-size-limit=10m \
11+
-- \
12+
"$CODEQL_EXTRACTOR_CDS_WIP_DATABASE"

extractors/cds/tools/index-files.cmd

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
@echo off
2+
3+
if "%~1"=="" (
4+
echo Usage: %0 ^<response_file_path^>
5+
exit /b 1
6+
)
7+
8+
where node >nul 2>nul
9+
if %ERRORLEVEL% neq 0 (
10+
echo node executable is required (in PATH) to run the 'index-files.js' script. Please install Node.js and try again.
11+
exit /b 2
12+
)
13+
14+
where npm >nul 2>nul
15+
if %ERRORLEVEL% neq 0 (
16+
echo npm executable is required (in PATH) to install the dependencies for the 'index-files.js' script.
17+
exit /b 3
18+
)
19+
20+
set "_response_file_path=%~1"
21+
set "_script_dir=%~dp0"
22+
REM Set _cwd before changing the working directory to the script directory.
23+
set "_cwd=%CD%"
24+
25+
echo Checking response file for CDS files to index
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.
29+
if not exist "%_response_file_path%" (
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.
31+
exit /b 0
32+
)
33+
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+
48+
cd /d "%_script_dir%" && ^
49+
echo Installing node package dependencies && ^
50+
npm install --quiet --no-audit --no-fund && ^
51+
echo Running the 'index-files.js' script && ^
52+
node "%_script_dir%index-files.js" "%_response_file_path%" "%_cwd%"
53+
54+
exit /b %ERRORLEVEL%

0 commit comments

Comments
 (0)