Skip to content

Commit 9ffdfb2

Browse files
authored
Merge pull request #7441 from erik-krogh/ql-for-ql-next
QL-for-QL: Followup changes
2 parents 313e0c6 + 8b53cca commit 9ffdfb2

File tree

13 files changed

+9511
-12453
lines changed

13 files changed

+9511
-12453
lines changed

.github/labeler.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ documentation:
2626
- "**/*.qhelp"
2727
- "**/*.md"
2828
- docs/**/*
29+
30+
"QL-for-QL":
31+
- ql/**/*

.github/workflows/check-change-note.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- "*/ql/src/**/*.ql"
88
- "*/ql/src/**/*.qll"
99
- "!**/experimental/**"
10+
- "!ql/**"
1011

1112
jobs:
1213
check-change-note:

.github/workflows/ql-for-ql-build.yml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@v2
1717
- name: Find codeql
1818
id: find-codeql
19-
uses: github/codeql-action/init@esbena/ql
19+
uses: github/codeql-action/init@erik-krogh/ql
2020
with:
2121
languages: javascript # does not matter
2222
- name: Get CodeQL version
@@ -56,22 +56,39 @@ jobs:
5656

5757
steps:
5858
- uses: actions/checkout@v2
59-
- uses: actions/cache@v2
59+
- name: Cache entire extractor
60+
id: cache-extractor
61+
uses: actions/cache@v2
62+
with:
63+
path: |
64+
ql/target/release/ql-autobuilder
65+
ql/target/release/ql-autobuilder.exe
66+
ql/target/release/ql-extractor
67+
ql/target/release/ql-extractor.exe
68+
key: ${{ runner.os }}-extractor-${{ hashFiles('ql/**/Cargo.lock') }}-${{ hashFiles('ql/**/*.rs') }}
69+
- name: Cache cargo
70+
if: steps.cache-extractor.outputs.cache-hit != 'true'
71+
uses: actions/cache@v2
6072
with:
6173
path: |
6274
~/.cargo/registry
6375
~/.cargo/git
6476
ql/target
65-
key: ${{ runner.os }}-rust-cargo-${{ hashFiles('**/Cargo.lock') }}
77+
key: ${{ runner.os }}-rust-cargo-${{ hashFiles('ql/**/Cargo.lock') }}
6678
- name: Check formatting
79+
if: steps.cache-extractor.outputs.cache-hit != 'true'
6780
run: cd ql; cargo fmt --all -- --check
6881
- name: Build
82+
if: steps.cache-extractor.outputs.cache-hit != 'true'
6983
run: cd ql; cargo build --verbose
7084
- name: Run tests
85+
if: steps.cache-extractor.outputs.cache-hit != 'true'
7186
run: cd ql; cargo test --verbose
7287
- name: Release build
88+
if: steps.cache-extractor.outputs.cache-hit != 'true'
7389
run: cd ql; cargo build --release
7490
- name: Generate dbscheme
91+
if: steps.cache-extractor.outputs.cache-hit != 'true'
7592
run: ql/target/release/ql-generator --dbscheme ql/ql/src/ql.dbscheme --library ql/ql/src/codeql_ql/ast/internal/TreeSitter.qll
7693
- uses: actions/upload-artifact@v2
7794
with:
@@ -120,6 +137,9 @@ jobs:
120137
retention-days: 1
121138
analyze:
122139
runs-on: ubuntu-latest
140+
strategy:
141+
matrix:
142+
folder: [cpp, csharp, java, javascript, python, ql, ruby]
123143

124144
needs:
125145
- package
@@ -146,12 +166,27 @@ jobs:
146166

147167
- name: Checkout repository
148168
uses: actions/checkout@v2
169+
- name: Create CodeQL config file
170+
run: |
171+
echo "paths:" > ${CONF}
172+
echo " - ${FOLDER}" >> ${CONF}
173+
echo "paths-ignore:" >> ${CONF}
174+
echo " - ql/ql/test" >> ${CONF}
175+
echo "Config file: "
176+
cat ${CONF}
177+
env:
178+
CONF: ./ql-for-ql-config.yml
179+
FOLDER: ${{ matrix.folder }}
149180

150181
- name: Initialize CodeQL
151-
uses: github/codeql-action/init@esbena/ql
182+
uses: github/codeql-action/init@erik-krogh/ql
152183
with:
153184
languages: ql
154185
db-location: ${{ runner.temp }}/db
186+
config-file: ./ql-for-ql-config.yml
155187

156188
- name: Perform CodeQL Analysis
157-
uses: github/codeql-action/analyze@esbena/ql
189+
uses: github/codeql-action/analyze@erik-krogh/ql
190+
with:
191+
category: "ql-for-ql-${{ matrix.folder }}"
192+

.github/workflows/ql-for-ql-dataset_measure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626

2727
- name: Find codeql
2828
id: find-codeql
29-
uses: github/codeql-action/init@esbena/ql
29+
uses: github/codeql-action/init@erik-krogh/ql
3030
with:
3131
languages: javascript # does not matter
3232
- uses: actions/cache@v2

.github/workflows/ql-for-ql-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ on:
44
push:
55
branches: [main]
66
paths:
7-
- ql/*
7+
- "ql/**"
88
pull_request:
99
branches: [main]
1010
paths:
11-
- ql/*
11+
- "ql/**"
1212

1313
env:
1414
CARGO_TERM_COLOR: always
@@ -20,7 +20,7 @@ jobs:
2020
- uses: actions/checkout@v2
2121
- name: Find codeql
2222
id: find-codeql
23-
uses: github/codeql-action/init@esbena/ql
23+
uses: github/codeql-action/init@erik-krogh/ql
2424
with:
2525
languages: javascript # does not matter
2626
- uses: actions/cache@v2

ql/autobuilder/src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,29 @@ fn main() -> std::io::Result<()> {
1515
let mut cmd = Command::new(codeql);
1616
cmd.arg("database")
1717
.arg("index-files")
18-
.arg("--include-extension=.ql")
19-
.arg("--include-extension=.qll")
20-
.arg("--include-extension=.dbscheme")
21-
.arg("--include=**/qlpack.yml")
2218
.arg("--size-limit=5m")
2319
.arg("--language=ql")
2420
.arg("--working-dir=.")
2521
.arg(db);
2622

23+
let mut has_include_dir = false; // TODO: This is a horrible hack, wait for the post-merge discussion in https://github.com/github/codeql/pull/7444 to be resolved
2724
for line in env::var("LGTM_INDEX_FILTERS")
2825
.unwrap_or_default()
2926
.split('\n')
3027
{
3128
if let Some(stripped) = line.strip_prefix("include:") {
3229
cmd.arg("--include").arg(stripped);
30+
has_include_dir = true;
3331
} else if let Some(stripped) = line.strip_prefix("exclude:") {
3432
cmd.arg("--exclude").arg(stripped);
3533
}
3634
}
35+
if !has_include_dir {
36+
cmd.arg("--include-extension=.ql")
37+
.arg("--include-extension=.qll")
38+
.arg("--include-extension=.dbscheme")
39+
.arg("--include=**/qlpack.yml");
40+
}
3741
let exit = &cmd.spawn()?.wait()?;
3842
std::process::exit(exit.code().unwrap_or(1))
3943
}

ql/extractor/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ fn main() -> std::io::Result<()> {
127127
lines
128128
.par_iter()
129129
.try_for_each(|line| {
130+
// only consider files that end with .ql/.qll/.dbscheme/qlpack.yml
131+
// TODO: This is a bad fix, wait for the post-merge discussion in https://github.com/github/codeql/pull/7444 to be resolved
132+
if !line.ends_with(".ql")
133+
&& !line.ends_with(".qll")
134+
&& !line.ends_with(".dbscheme")
135+
&& !line.ends_with("qlpack.yml")
136+
{
137+
return Ok(());
138+
}
130139
let path = PathBuf::from(line).canonicalize()?;
131140
let src_archive_file = path_for(&src_archive_dir, &path, "");
132141
let source = std::fs::read(&path)?;

ql/ql/src/codeql_ql/ast/Ast.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class AstNode extends TAstNode {
5858
*/
5959
cached
6060
AstNode getAChild(string pred) {
61-
pred = directMember("getAnAnnotation") and result = getAnAnnotation()
61+
pred = directMember("getAnAnnotation") and result = this.getAnAnnotation()
6262
or
63-
pred = directMember("getQLDoc") and result = getQLDoc()
63+
pred = directMember("getQLDoc") and result = this.getQLDoc()
6464
}
6565

6666
/**
@@ -606,7 +606,7 @@ class FieldDecl extends TFieldDecl, AstNode {
606606
/** Holds if this field is annotated as overriding another field. */
607607
predicate isOverride() { this.hasAnnotation("override") }
608608

609-
string getName() { result = getVarDecl().getName() }
609+
string getName() { result = this.getVarDecl().getName() }
610610

611611
override QLDoc getQLDoc() { result = any(Class c).getQLDocFor(this) }
612612
}
@@ -673,7 +673,7 @@ class Module extends TModule, ModuleDeclaration {
673673

674674
override string getAPrimaryQlClass() { result = "Module" }
675675

676-
override string getName() { result = mod.getName().(QL::ModuleName).getChild().getValue() }
676+
override string getName() { result = mod.getName().getChild().getValue() }
677677

678678
/**
679679
* Gets a member of the module.
@@ -699,7 +699,7 @@ class Module extends TModule, ModuleDeclaration {
699699
}
700700

701701
/**
702-
* Something that can be member of a module.
702+
* A member of a module.
703703
*/
704704
class ModuleMember extends TModuleMember, AstNode {
705705
/** Holds if this member is declared as `private`. */
@@ -771,7 +771,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
771771
/**
772772
* Gets a field in this class.
773773
*/
774-
FieldDecl getAField() { result = getMember(_) }
774+
FieldDecl getAField() { result = this.getMember(_) }
775775

776776
/**
777777
* Gets a super-type referenced in the `extends` part of the class declaration.
@@ -814,7 +814,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
814814
}
815815

816816
/** Holds if this class is abstract. */
817-
predicate isAbstract() { hasAnnotation("abstract") }
817+
predicate isAbstract() { this.hasAnnotation("abstract") }
818818
}
819819

820820
/**

ql/ql/src/codeql_ql/ast/internal/Module.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private predicate resolveQualifiedName(Import imp, ContainerOrModule m, int i) {
105105
(
106106
exists(Container c, Container parent |
107107
// should ideally look at `qlpack.yml` files
108-
parent = imp.getLocation().getFile().getParentContainer+() and
108+
parent = pragma[only_bind_out](imp.getLocation()).getFile().getParentContainer+() and
109109
exists(YAML::QLPack pack |
110110
pack.getFile().getParentContainer() = parent and
111111
c.getParentContainer() = pack.getADependency*().getFile().getParentContainer()
@@ -122,7 +122,8 @@ private predicate resolveQualifiedName(Import imp, ContainerOrModule m, int i) {
122122
definesModule(container, q, m, _) and
123123
(
124124
exists(container.(Folder_).getFolder().getFile("qlpack.yml")) or
125-
container.(Folder_).getFolder() = imp.getLocation().getFile().getParentContainer() or
125+
container.(Folder_).getFolder() =
126+
pragma[only_bind_out](imp.getLocation()).getFile().getParentContainer() or
126127
not container instanceof Folder_
127128
)
128129
)
@@ -194,7 +195,7 @@ private module Cached {
194195
not m = TFile(any(File f | f.getExtension() = "ql")) and
195196
not exists(me.getQualifier()) and
196197
exists(ContainerOrModule enclosing, string name | resolveModuleExprHelper(me, enclosing, name) |
197-
definesModule(enclosing.getEnclosing*(), name, m, _)
198+
definesModule(enclosing, name, m, _)
198199
)
199200
or
200201
exists(FileOrModule mid |
@@ -205,7 +206,7 @@ private module Cached {
205206

206207
pragma[noinline]
207208
private predicate resolveModuleExprHelper(ModuleExpr me, ContainerOrModule enclosing, string name) {
208-
enclosing = getEnclosingModule(me) and
209+
enclosing = getEnclosingModule(me).getEnclosing*() and
209210
name = me.getName()
210211
}
211212
}

ql/ql/src/ide-contextual-queries/printAst.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import codeql.IDEContextual
1717
*/
1818
external string selectedSourceFile();
1919

20-
/**
21-
* Overrides the configuration to print only nodes in the selected source file.
22-
*/
20+
// Overrides the configuration to print only nodes in the selected source file.
2321
class Cfg extends PrintAstConfiguration {
2422
override predicate shouldPrintNode(AstNode n) {
2523
super.shouldPrintNode(n) and

0 commit comments

Comments
 (0)