Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version of platform-independent CDS extractor #169

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
31927be
WIP make the CDS extractor platform independent
data-douser Jan 23, 2025
c50380c
Merge branch 'advanced-security:main' into data-douser/extractor-dev-2
data-douser Jan 23, 2025
db64e01
Merge branch 'advanced-security:main' into data-douser/extractor-dev-2
data-douser Jan 23, 2025
54938b6
Improve extractor script comments and file paths
data-douser Jan 28, 2025
ea229d1
Add requested comment to extractor.js responsFiles
data-douser Jan 28, 2025
aed1fc6
WIP fixes for CDS extractor rewrite
data-douser Jan 29, 2025
d02234e
Fix CDS extractor JS undefined var
data-douser Jan 30, 2025
a17b8c2
Set cwd for CDS JS autobuild process
data-douser Jan 30, 2025
0b6994c
Another attempted fix for index-files.js cwd
data-douser Feb 4, 2025
2673f53
Document index-files change for grandfathered package.json
data-douser Feb 5, 2025
212820a
Remove shell quote from index-files logging
data-douser Feb 5, 2025
cc99914
index-files.js must compiles cds to file (not dir)
data-douser Feb 5, 2025
5d16df0
Attempted fix for missing CDS SARIF results
data-douser Feb 5, 2025
c9e02ed
WIP make the CDS extractor platform independent
data-douser Jan 23, 2025
9332311
Improve extractor script comments and file paths
data-douser Jan 28, 2025
a9b987a
Add requested comment to extractor.js responsFiles
data-douser Jan 28, 2025
5a49a25
WIP fixes for CDS extractor rewrite
data-douser Jan 29, 2025
caaadbb
Fix CDS extractor JS undefined var
data-douser Jan 30, 2025
c9c7cde
Set cwd for CDS JS autobuild process
data-douser Jan 30, 2025
c213d6b
Another attempted fix for index-files.js cwd
data-douser Feb 4, 2025
4f234be
Document index-files change for grandfathered package.json
data-douser Feb 5, 2025
b614751
Remove shell quote from index-files logging
data-douser Feb 5, 2025
08f8624
index-files.js must compiles cds to file (not dir)
data-douser Feb 5, 2025
dbc3ba7
Attempted fix for missing CDS SARIF results
data-douser Feb 5, 2025
c8b643c
Merge branch 'data-douser/extractor-dev-2' of github.com:data-douser/…
data-douser Feb 24, 2025
c410382
Merge branch 'main' into data-douser/extractor-dev-2
data-douser Mar 4, 2025
33d51d0
Improve handling of cds compile output files
data-douser Mar 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions extractors/cds/tools/autobuild.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off

type NUL && "%CODEQL_DIST%\codeql.exe" database index-files ^
--include-extension=.cds ^
--language cds ^
--prune **\node_modules\**\* ^
--prune **\.eslint\**\* ^
--total-size-limit=10m ^
-- ^
"%CODEQL_EXTRACTOR_CDS_WIP_DATABASE%"

exit /b %ERRORLEVEL%
15 changes: 5 additions & 10 deletions extractors/cds/tools/autobuild.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#!/bin/sh
#!/usr/bin/env bash

set -eu

# NOTE: the code below is copied in three places:
# - scripts/compile-cds.sh
# - extractors/cds/tools/autobuild.sh (here)
# - extractors/javascript/tools/pre-finalize.sh
# Any changes should be synchronized between these three places.

exec "${CODEQL_DIST}/codeql" database index-files \
--language cds \
--total-size-limit 10m \
--include-extension=.cds \
--language cds \
--prune **/node_modules/**/* \
--prune **/.eslint/**/* \
"$CODEQL_EXTRACTOR_CDS_WIP_DATABASE"
--total-size-limit=10m \
-- \
"$CODEQL_EXTRACTOR_CDS_WIP_DATABASE"
54 changes: 54 additions & 0 deletions extractors/cds/tools/index-files.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@echo off

if "%~1"=="" (
echo Usage: %0 ^<response_file_path^>
exit /b 1
)

where node >nul 2>nul
if %ERRORLEVEL% neq 0 (
echo node executable is required (in PATH) to run the 'index-files.js' script. Please install Node.js and try again.
exit /b 2
)

where npm >nul 2>nul
if %ERRORLEVEL% neq 0 (
echo npm executable is required (in PATH) to install the dependencies for the 'index-files.js' script.
exit /b 3
)

set "_response_file_path=%~1"
set "_script_dir=%~dp0"
REM Set _cwd before changing the working directory to the script directory.
set "_cwd=%CD%"

echo Checking response file for CDS files to index

REM Terminate early if the _response_file_path doesn't exist or is empty,
REM which indicates that no CDS files were selected or found.
if not exist "%_response_file_path%" (
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.
exit /b 0
)

REM Change to the directory of this script to ensure that npm looks up the
REM package.json file in the correct directory and installs the dependencies
REM (i.e. node_modules) relative to this directory. This is technically a
REM violation of the assumption that extractor scripts will be run with the
REM current working directory set to the root of the project source, but we
REM also need node_modules to be installed here and not in the project source
REM root, so we make a compromise of:
REM 1. changing to this script's directory;
REM 2. installing node dependencies here;
REM 3. passing the original working directory as a parameter to the
REM index-files.js script;
REM 4. expecting the index-files.js script to immediately change back to
REM the original working (aka the project source root) directory.

cd /d "%_script_dir%" && ^
echo Installing node package dependencies && ^
npm install --quiet --no-audit --no-fund && ^
echo Running the 'index-files.js' script && ^
node "%_script_dir%index-files.js" "%_response_file_path%" "%_cwd%"

exit /b %ERRORLEVEL%
Loading