Skip to content

Commit e981fbd

Browse files
Merge pull request #165 from advanced-security/lcartey/address-perf-issues
CDL: Improve performance by simplifying CDS location identification
2 parents ac8dd07 + 237b4b5 commit e981fbd

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

.github/workflows/run-codeql-unit-tests-javascript.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,20 @@ jobs:
8787
# Compile .cds files to .cds.json files.
8888
- name: Compile CAP CDS files
8989
run: |
90-
for cds_file in $(find . -type f \( -iname '*.cds' \) -print)
90+
for test_dir in $(find . -type f -name '*.expected' -exec dirname {} \;);
9191
do
92-
echo "I am compiling $cds_file"
93-
cds compile $cds_file \
94-
-2 json \
95-
-o "$cds_file.json" \
96-
--locations
92+
# The CDS compiler produces locations relative to the working directory
93+
# so we switch to the test directory before running the compiler.
94+
pushd $test_dir
95+
for cds_file in $(find . -type f \( -iname '*.cds' \) -print)
96+
do
97+
echo "I am compiling $cds_file"
98+
cds compile $cds_file \
99+
-2 json \
100+
-o "$cds_file.json" \
101+
--locations
102+
done
103+
popd
97104
done
98105
99106
- name: Run test suites
@@ -105,7 +112,7 @@ jobs:
105112
CODEQL_STDLIB_IDENT: ${{matrix.codeql_standard_library_ident}}
106113
RUNNER_TMP: ${{ runner.temp }}
107114
LGTM_INDEX_XML_MODE: all
108-
LGTM_INDEX_FILETYPES: ".json:JSON"
115+
LGTM_INDEX_FILETYPES: ".json:JSON\n.cds:JSON"
109116

110117
shell: bash
111118
run: >

javascript/frameworks/cap/lib/advanced_security/javascript/frameworks/cap/CDL.qll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ abstract class CdlObject extends JsonObject {
1414
exists(Location loc, JsonValue locValue |
1515
loc = this.getLocation() and
1616
locValue = this.getPropValue("$location") and
17-
path =
18-
any(File f |
19-
f.getAbsolutePath()
20-
.matches("%" + locValue.getPropValue("file").getStringValue() + ".json")
21-
).getAbsolutePath().regexpReplaceAll("\\.json$", "") and
17+
// The path in the cds.json file is relative to the working directory used when running
18+
// the cds compile command. In our extractor, that's always the root of the repository,
19+
// so we can identify the sourceLocationPrefix to find the path of the root of the repo
20+
// then append the relative path
21+
exists(string sourceLocationPrefix |
22+
sourceLocationPrefix(sourceLocationPrefix) and
23+
path =
24+
sourceLocationPrefix.regexpReplaceAll("/$", "") + "/" +
25+
locValue.getPropValue("file").getStringValue()
26+
) and
2227
if
2328
not exists(locValue.getPropValue("line")) and
2429
not exists(locValue.getPropValue("col"))

qlt.conf.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"CodeQLCLI": "2.19.0",
3-
"CodeQLStandardLibrary": "codeql-cli/v2.19.0",
4-
"CodeQLCLIBundle": "codeql-bundle-v2.19.0"
2+
"CodeQLCLI": "2.19.4",
3+
"CodeQLStandardLibrary": "codeql-cli/v2.19.4",
4+
"CodeQLCLIBundle": "codeql-bundle-v2.19.4"
55
}

0 commit comments

Comments
 (0)