mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
Add consistency checks
This commit is contained in:
@@ -18,6 +18,8 @@ class UsedInSource extends GeneratedDeclaration {
|
||||
this = any(Expr e | e.getEnclosingCallable().fromSource()).getType()
|
||||
or
|
||||
this = any(RefType t | t.fromSource())
|
||||
or
|
||||
this = any(TypeAccess ta | ta.fromSource())
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -25,3 +27,21 @@ class UsedInSource extends GeneratedDeclaration {
|
||||
from GeneratedTopLevel t
|
||||
where not t.fromSource()
|
||||
select t.getQualifiedName(), t.stubFile()
|
||||
|
||||
module Consistency {
|
||||
query predicate noGeneratedStubs(string s) {
|
||||
exists(GeneratedTopLevel t | s = t.getQualifiedName() |
|
||||
not t.fromSource() and
|
||||
not exists(t.stubFile())
|
||||
)
|
||||
}
|
||||
|
||||
query predicate multipleGeneratedStubs(string s) {
|
||||
exists(GeneratedTopLevel t | s = t.getQualifiedName() |
|
||||
not t.fromSource() and
|
||||
strictcount(t.stubFile()) > 1
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import Consistency
|
||||
|
||||
@@ -128,6 +128,10 @@ private class IndirectType extends GeneratedType {
|
||||
this = getAContainedType(t.getAGeneratedType()).(RefType).getSourceDeclaration()
|
||||
)
|
||||
or
|
||||
this.getSourceDeclaration() instanceof GeneratedType
|
||||
or
|
||||
this = any(GeneratedType t).getSourceDeclaration()
|
||||
or
|
||||
exists(GeneratedType t | this = t.(BoundedType).getATypeBound().getType())
|
||||
or
|
||||
exists(GeneratedDeclaration decl |
|
||||
|
||||
@@ -120,10 +120,21 @@ if run(['codeql', 'bqrs', 'decode', outputBqrsFile, '--format=json', '--output',
|
||||
with open(outputJsonFile) as f:
|
||||
results = json.load(f)
|
||||
|
||||
if not '#select' in results or not 'tuples' in results['#select']:
|
||||
try:
|
||||
results['#select']['tuples']
|
||||
results['noGeneratedStubs']['tuples']
|
||||
results['multipleGeneratedStubs']['tuples']
|
||||
except ValueError:
|
||||
print('Unexpected JSON output - no tuples found')
|
||||
exit(1)
|
||||
|
||||
for (typ,) in results['noGeneratedStubs']['tuples']:
|
||||
print(f"WARNING: No stubs generated for {typ}. This is probably a bug.")
|
||||
|
||||
for (typ,) in results['multipleGeneratedStubs']['tuples']:
|
||||
print(
|
||||
f"WARNING: Multiple stubs generated for {typ}. This is probably a bug. One will be chosen arbitrarily.")
|
||||
|
||||
for (typ, stub) in results['#select']['tuples']:
|
||||
stubFile = os.path.join(stubDir, typ.replace(".", "/") + ".java")
|
||||
os.makedirs(os.path.dirname(stubFile), exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user