mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Rust: restrict extracted files queries
This commit is contained in:
@@ -6,6 +6,7 @@ private import codeql.rust.elements.SourceFile
|
|||||||
private import codeql.rust.elements.AstNode
|
private import codeql.rust.elements.AstNode
|
||||||
private import codeql.rust.elements.Comment
|
private import codeql.rust.elements.Comment
|
||||||
private import codeql.rust.Diagnostics
|
private import codeql.rust.Diagnostics
|
||||||
|
private import codeql.rust.internal.ExtractorStep
|
||||||
|
|
||||||
private module Input implements InputSig {
|
private module Input implements InputSig {
|
||||||
abstract class ContainerBase extends @container {
|
abstract class ContainerBase extends @container {
|
||||||
@@ -36,7 +37,9 @@ class Folder = Impl::Folder;
|
|||||||
/** A file. */
|
/** A file. */
|
||||||
class File extends Container, Impl::File {
|
class File extends Container, Impl::File {
|
||||||
/** Holds if this file was extracted from ordinary source code. */
|
/** Holds if this file was extracted from ordinary source code. */
|
||||||
predicate fromSource() { any() }
|
predicate fromSource() {
|
||||||
|
exists(ExtractorStep s | s.getAction() = "Extract" and s.getFile() = this)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of lines containing code in this file. This value
|
* Gets the number of lines containing code in this file. This value
|
||||||
@@ -58,11 +61,20 @@ class File extends Container, Impl::File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A source file that was extracted.
|
||||||
|
*
|
||||||
|
* TODO: rename `SourceFile` from the generated AST to give that name to this class.
|
||||||
|
*/
|
||||||
|
class ExtractedFile extends File {
|
||||||
|
ExtractedFile() { this.fromSource() }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A successfully extracted file, that is, a file that was extracted and
|
* A successfully extracted file, that is, a file that was extracted and
|
||||||
* contains no extraction errors or warnings.
|
* contains no extraction errors or warnings.
|
||||||
*/
|
*/
|
||||||
class SuccessfullyExtractedFile extends File {
|
class SuccessfullyExtractedFile extends ExtractedFile {
|
||||||
SuccessfullyExtractedFile() {
|
SuccessfullyExtractedFile() {
|
||||||
not exists(Diagnostic d |
|
not exists(Diagnostic d |
|
||||||
d.getLocation().getFile() = this and
|
d.getLocation().getFile() = this and
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import codeql.files.FileSystem
|
|||||||
*/
|
*/
|
||||||
class ExtractorStep extends @extractor_step {
|
class ExtractorStep extends @extractor_step {
|
||||||
/**
|
/**
|
||||||
* The string representation of this extractor step.
|
* Gets the string representation of this extractor step.
|
||||||
*/
|
*/
|
||||||
string toString() {
|
string toString() {
|
||||||
exists(File file, string action |
|
exists(File file, string action |
|
||||||
@@ -17,17 +17,17 @@ class ExtractorStep extends @extractor_step {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The action this extractor step carried out.
|
* Gets the action this extractor step carried out.
|
||||||
*/
|
*/
|
||||||
string getAction() { extractor_steps(this, result, _, _) }
|
string getAction() { extractor_steps(this, result, _, _) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The file the extractor step was carried out on.
|
* Gets the file the extractor step was carried out on.
|
||||||
*/
|
*/
|
||||||
File getFile() { extractor_steps(this, _, result, _) }
|
File getFile() { extractor_steps(this, _, result, _) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The duration of the extractor step in milliseconds.
|
* Gets the duration of the extractor step in milliseconds.
|
||||||
*/
|
*/
|
||||||
int getDurationMs() { extractor_steps(this, _, _, result) }
|
int getDurationMs() { extractor_steps(this, _, _, result) }
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,6 @@
|
|||||||
|
|
||||||
import rust
|
import rust
|
||||||
|
|
||||||
from File f
|
from ExtractedFile f
|
||||||
where exists(f.getRelativePath())
|
where exists(f.getRelativePath())
|
||||||
select f, "File successfully extracted."
|
select f, "File successfully extracted."
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import codeql.files.FileSystem
|
|||||||
/** Gets the SARIF severity to associate with an error. */
|
/** Gets the SARIF severity to associate with an error. */
|
||||||
int getSeverity() { result = 2 }
|
int getSeverity() { result = 2 }
|
||||||
|
|
||||||
from ExtractionError error, File f
|
from ExtractionError error, ExtractedFile f
|
||||||
where
|
where
|
||||||
f = error.getLocation().getFile() and
|
f = error.getLocation().getFile() and
|
||||||
exists(f.getRelativePath())
|
exists(f.getRelativePath())
|
||||||
|
|||||||
@@ -21,10 +21,13 @@ where
|
|||||||
or
|
or
|
||||||
key = "Extraction warnings" and value = count(ExtractionWarning w)
|
key = "Extraction warnings" and value = count(ExtractionWarning w)
|
||||||
or
|
or
|
||||||
key = "Files extracted - total" and value = count(File f | exists(f.getRelativePath()))
|
key = "Files extracted - total" and value = count(ExtractedFile f | exists(f.getRelativePath()))
|
||||||
or
|
or
|
||||||
key = "Files extracted - with errors" and
|
key = "Files extracted - with errors" and
|
||||||
value = count(File f | exists(f.getRelativePath()) and not f instanceof SuccessfullyExtractedFile)
|
value =
|
||||||
|
count(ExtractedFile f |
|
||||||
|
exists(f.getRelativePath()) and not f instanceof SuccessfullyExtractedFile
|
||||||
|
)
|
||||||
or
|
or
|
||||||
key = "Files extracted - without errors" and
|
key = "Files extracted - without errors" and
|
||||||
value = count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))
|
value = count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
| a_file.rs:0:0:0:0 | a_file.rs |
|
| Cargo.toml:0:0:0:0 | Cargo.toml | fromSource: no |
|
||||||
| another_file.rs:0:0:0:0 | another_file.rs |
|
| a_file.rs:0:0:0:0 | a_file.rs | fromSource: yes |
|
||||||
| lib.rs:0:0:0:0 | lib.rs |
|
| another_file.rs:0:0:0:0 | another_file.rs | fromSource: yes |
|
||||||
|
| lib.rs:0:0:0:0 | lib.rs | fromSource: yes |
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import rust
|
import rust
|
||||||
|
|
||||||
from File f
|
from File f, string fromSource
|
||||||
where exists(f.getRelativePath())
|
where
|
||||||
select f
|
exists(f.getRelativePath()) and
|
||||||
|
if f.fromSource() then fromSource = "fromSource: yes" else fromSource = "fromSource: no"
|
||||||
|
select f, fromSource
|
||||||
|
|||||||
@@ -5,4 +5,3 @@
|
|||||||
| main.rs:0:0:0:0 | main.rs | File successfully extracted. |
|
| main.rs:0:0:0:0 | main.rs | File successfully extracted. |
|
||||||
| my_macro.rs:0:0:0:0 | my_macro.rs | File successfully extracted. |
|
| my_macro.rs:0:0:0:0 | my_macro.rs | File successfully extracted. |
|
||||||
| my_struct.rs:0:0:0:0 | my_struct.rs | File successfully extracted. |
|
| my_struct.rs:0:0:0:0 | my_struct.rs | File successfully extracted. |
|
||||||
| options.yml:0:0:0:0 | options.yml | File successfully extracted. |
|
|
||||||
|
|||||||
@@ -5,4 +5,5 @@
|
|||||||
| lib.rs:0:0:0:0 | lib.rs | 5 |
|
| lib.rs:0:0:0:0 | lib.rs | 5 |
|
||||||
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 |
|
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 |
|
||||||
| error.rs:0:0:0:0 | error.rs | 3 |
|
| error.rs:0:0:0:0 | error.rs | 3 |
|
||||||
|
| Cargo.toml:0:0:0:0 | Cargo.toml | 0 |
|
||||||
| options.yml:0:0:0:0 | options.yml | 0 |
|
| options.yml:0:0:0:0 | options.yml | 0 |
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
| Elements unextracted | 0 |
|
| Elements unextracted | 0 |
|
||||||
| Extraction errors | 0 |
|
| Extraction errors | 0 |
|
||||||
| Extraction warnings | 7 |
|
| Extraction warnings | 7 |
|
||||||
| Files extracted - total | 8 |
|
| Files extracted - total | 7 |
|
||||||
| Files extracted - with errors | 3 |
|
| Files extracted - with errors | 3 |
|
||||||
| Files extracted - without errors | 5 |
|
| Files extracted - without errors | 4 |
|
||||||
| Inconsistencies - AST | 0 |
|
| Inconsistencies - AST | 0 |
|
||||||
| Inconsistencies - CFG | 0 |
|
| Inconsistencies - CFG | 0 |
|
||||||
| Inconsistencies - data flow | 0 |
|
| Inconsistencies - data flow | 0 |
|
||||||
|
|||||||
Reference in New Issue
Block a user