Skip to content

Commit bc74af7

Browse files
committed
QL: resolve imports across qlpacks
1 parent 236989f commit bc74af7

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ module YAML {
21432143
exists(YAMLEntry entry |
21442144
entry.isRoot() and
21452145
entry.getKey().getQualifiedName() = name and
2146-
result = entry.getValue().getValue() and
2146+
result = entry.getValue().getValue().trim() and
21472147
entry.getLocation().getFile() = file
21482148
)
21492149
}
@@ -2190,6 +2190,13 @@ module YAML {
21902190
)
21912191
}
21922192

2193+
/**
2194+
* Gets a QLPack that this QLPack depends on.
2195+
*/
2196+
QLPack getADependency() {
2197+
exists(string name | hasDependency(name, _) | result.getName().replaceAll("-", "/") = name)
2198+
}
2199+
21932200
Location getLocation() {
21942201
// hacky, just pick the first node in the file.
21952202
result =

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ private predicate resolveQualifiedName(Import imp, ContainerOrModule m, int i) {
100100
exists(Container c, Container parent |
101101
// should ideally look at `qlpack.yml` files
102102
parent = imp.getLocation().getFile().getParentContainer+() and
103-
exists(parent.getFile("qlpack.yml")) and
104-
c.getParentContainer() = parent and
103+
exists(YAML::QLPack pack |
104+
pack.getFile().getParentContainer() = parent and
105+
c.getParentContainer() = pack.getADependency*().getFile().getParentContainer()
106+
) and
105107
q = m.getName()
106108
|
107109
m = TFile(c)

0 commit comments

Comments
 (0)