Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Commit

Permalink
Add option to force customization
Browse files Browse the repository at this point in the history
Add the option to force customization for languages that don't have a Customization.qll.
This enable customization for Ruby for which the Customization.qll hasn't been integrated into the latest CodeQL Bundle.
  • Loading branch information
rvermeulen authored Dec 15, 2021
1 parent 1334473 commit 999e458
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
44 changes: 28 additions & 16 deletions .github/workflows/build-bundles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
- main
workflow_dispatch:

env:
FORCE_CUSTOMIZATION: "false"

jobs:
prepare-bundles-matrix:
name: "Prepare CodeQL bundle matrix"
Expand Down Expand Up @@ -64,23 +67,32 @@ jobs:
qlquery_path=codeql/qlpacks/codeql/$lang-queries/$qlquery_version
fi
if [ -f $qllib_path/Customizations.qll ];
then
mkdir $qllib_path/customizations
cp $lang_path/*.qll $qllib_path/customizations
# Import custom modules
for module_path in $lang_path/*.qll; do
module_file=${module_path##*/}
module_name=${module_file%.*}
echo "import customizations.$module_name" >> $qllib_path/Customizations.qll
done
# Rebuild cache
rm -r $qlquery_path/.cache
codeql/codeql query compile --search-path codeql --threads 0 $qlquery_path
if [ -d $qllib_path ]; then
if [ ! -f $qllib_path/Customizations.qll ] && [ "$FORCE_CUSTOMIZATION" = "true" ]; then
echo "::warning::Forcing customization for language $lang"
echo "import $lang" > $qllib_path/Customizations.qll
sed -i -e '0,/^import/s//private import Customizations\nimport/' $qllib_path/$lang.qll
fi
if [ -f $qllib_path/Customizations.qll ]; then
mkdir $qllib_path/customizations
cp $lang_path/*.qll $qllib_path/customizations
# Import custom modules
for module_path in $lang_path/*.qll; do
module_file=${module_path##*/}
module_name=${module_file%.*}
echo "import customizations.$module_name" >> $qllib_path/Customizations.qll
done
# Rebuild cache
rm -r $qlquery_path/.cache
codeql/codeql query compile --search-path codeql --threads 0 $qlquery_path
else
echo "::warning::Skipping customization for language $lang, because it doesn't have a Customizations.qll"
fi
else
echo "Skipping customization for language $lang, because it doesn't have a Customizations.qll"
echo "::error::Unable to customize language $lang, because it is not present in the CodeQL Bundle $CODEQL_BUNDLE"
fi
done
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ At current this repository will work with the following languages:
- C#
- Go

Support for Ruby is being added.
Official support for Ruby will be added when the `Customizations.qll` is made available in the selected CodeQL bundles specified in the `bundles.json`.
As an unofficial workaround you can change the environment variable `FORCE_CUSTOMIZATION` in the `.github/build-bundles.yml` to `"true"`.
The forced customization will create a `Customizations.qll` file and prepend it to the language specific library (e.g., `cpp.qll`, `ruby.qll`).

# Using the Custom CodeQL Bundle

Expand Down
8 changes: 8 additions & 0 deletions customizations/ruby/CustomSources.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ruby
import codeql.ruby.dataflow.RemoteFlowSources

class CustomSource extends RemoteFlowSource::Range {
CustomSource() { this.asExpr().getExpr().(MethodCall).getMethodName() = "source" }

override string getSourceType() { result = "test" }
}

0 comments on commit 999e458

Please sign in to comment.