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

Commit 999e458

Browse files
authored
Add option to force customization
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.
1 parent 1334473 commit 999e458

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

.github/workflows/build-bundles.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
- main
1010
workflow_dispatch:
1111

12+
env:
13+
FORCE_CUSTOMIZATION: "false"
14+
1215
jobs:
1316
prepare-bundles-matrix:
1417
name: "Prepare CodeQL bundle matrix"
@@ -64,23 +67,32 @@ jobs:
6467
qlquery_path=codeql/qlpacks/codeql/$lang-queries/$qlquery_version
6568
fi
6669
67-
if [ -f $qllib_path/Customizations.qll ];
68-
then
69-
mkdir $qllib_path/customizations
70-
cp $lang_path/*.qll $qllib_path/customizations
71-
72-
# Import custom modules
73-
for module_path in $lang_path/*.qll; do
74-
module_file=${module_path##*/}
75-
module_name=${module_file%.*}
76-
echo "import customizations.$module_name" >> $qllib_path/Customizations.qll
77-
done
78-
79-
# Rebuild cache
80-
rm -r $qlquery_path/.cache
81-
codeql/codeql query compile --search-path codeql --threads 0 $qlquery_path
70+
if [ -d $qllib_path ]; then
71+
if [ ! -f $qllib_path/Customizations.qll ] && [ "$FORCE_CUSTOMIZATION" = "true" ]; then
72+
echo "::warning::Forcing customization for language $lang"
73+
echo "import $lang" > $qllib_path/Customizations.qll
74+
sed -i -e '0,/^import/s//private import Customizations\nimport/' $qllib_path/$lang.qll
75+
fi
76+
77+
if [ -f $qllib_path/Customizations.qll ]; then
78+
mkdir $qllib_path/customizations
79+
cp $lang_path/*.qll $qllib_path/customizations
80+
81+
# Import custom modules
82+
for module_path in $lang_path/*.qll; do
83+
module_file=${module_path##*/}
84+
module_name=${module_file%.*}
85+
echo "import customizations.$module_name" >> $qllib_path/Customizations.qll
86+
done
87+
88+
# Rebuild cache
89+
rm -r $qlquery_path/.cache
90+
codeql/codeql query compile --search-path codeql --threads 0 $qlquery_path
91+
else
92+
echo "::warning::Skipping customization for language $lang, because it doesn't have a Customizations.qll"
93+
fi
8294
else
83-
echo "Skipping customization for language $lang, because it doesn't have a Customizations.qll"
95+
echo "::error::Unable to customize language $lang, because it is not present in the CodeQL Bundle $CODEQL_BUNDLE"
8496
fi
8597
done
8698

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ At current this repository will work with the following languages:
1313
- C#
1414
- Go
1515

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

1820
# Using the Custom CodeQL Bundle
1921

customizations/ruby/CustomSources.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import ruby
2+
import codeql.ruby.dataflow.RemoteFlowSources
3+
4+
class CustomSource extends RemoteFlowSource::Range {
5+
CustomSource() { this.asExpr().getExpr().(MethodCall).getMethodName() = "source" }
6+
7+
override string getSourceType() { result = "test" }
8+
}

0 commit comments

Comments
 (0)