Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 885e89a

Browse files
author
Paolo Tranquilli
committed
Rust: first running tests
1 parent 7e1290a commit 885e89a

37 files changed

Lines changed: 531 additions & 64 deletions

rust/.generated.list

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/.gitattributes

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/codegen/README.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

rust/codeql-extractor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: "rust"
22
display_name: "Rust"
33
version: 0.1.0
44
column_kind: "utf8"
5+
legacy_qltest_extraction: true
56
build_modes:
67
- none
78
github_api_languages:

rust/extractor/src/config.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::path::PathBuf;
2+
use anyhow::Context;
23
use serde::{Deserialize, Serialize, Serializer, Deserializer};
34
use serde_with;
45
use figment::{Figment, providers::{Env, Serialized}};
@@ -48,7 +49,9 @@ struct CliArgs {
4849
#[arg(long)]
4950
compression: Option<Compression>,
5051
#[arg(short, long, action = ArgAction::Count)]
51-
pub verbose: u8,
52+
verbose: u8,
53+
#[arg(long)]
54+
inputs_file: Option<PathBuf>,
5255

5356
inputs: Vec<PathBuf>,
5457
}
@@ -58,10 +61,15 @@ fn is_default<T: Default + PartialEq>(t: &T) -> bool {
5861
}
5962

6063
impl Config {
61-
pub fn extract() -> figment::Result<Config> {
62-
Figment::new()
64+
pub fn extract() -> anyhow::Result<Config> {
65+
let mut cli_args = CliArgs::parse();
66+
if let Some(inputs_file) = cli_args.inputs_file.take() {
67+
let inputs_list = std::fs::read_to_string(inputs_file).context("reading file list")?;
68+
cli_args.inputs.extend(inputs_list.split("\n").map(PathBuf::from));
69+
}
70+
Ok(Figment::new()
6371
.merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_"))
64-
.merge(Serialized::defaults(CliArgs::parse()))
65-
.extract()
72+
.merge(Serialized::defaults(cli_args))
73+
.extract().context("loading configuration")?)
6674
}
6775
}

rust/extractor/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ fn main() -> anyhow::Result<()> {
3535
prefill_caches: false,
3636
};
3737
for input in cfg.inputs {
38-
load_workspace_at(&input, &config, &load_config, &no_progress)?;
39-
let (db, vfs, _macro_server) = load_workspace_at(&input, &config, &load_config, &no_progress)?;
38+
let (db, vfs, _macro_server) = load_workspace_at(&input, &config, &load_config, &no_progress).context("loading inputs")?;
4039
let crates = <dyn DefDatabase>::crate_graph(&db);
4140
for crate_id in crates.iter().take(1) {
4241
let krate = Crate::from(crate_id);
@@ -49,7 +48,7 @@ fn main() -> anyhow::Result<()> {
4948
&krate,
5049
&vfs,
5150
&archiver,
52-
).emit_crate()?;
51+
).emit_crate().context("writing trap file")?;
5352
}
5453
}
5554
Ok(())
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `Element`.
43
*/
54

65
private import codeql.rust.generated.Element
76

8-
class Element extends Generated::Element { }
7+
class Element extends Generated::Element {
8+
predicate isUnknown() { none() } // compatibility with test generation, to be fixed
9+
}
Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,111 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `File`.
43
*/
54

65
private import codeql.rust.generated.File
6+
private import codeql.rust.elements.Location
7+
private import codeql.rust.elements.UnknownLocation
78

8-
class File extends Generated::File { }
9+
class File extends Generated::File {
10+
/** toString */
11+
override string toString() { result = this.getAbsolutePath() }
12+
13+
/** Gets the absolute path of this file. */
14+
string getAbsolutePath() { result = this.getName() }
15+
16+
/** Gets the full name of this file. */
17+
string getFullName() { result = this.getAbsolutePath() }
18+
19+
/** Gets the URL of this file. */
20+
string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
21+
22+
/**
23+
* Holds if either,
24+
* - `part` is the base name of this container and `i = 1`, or
25+
* - `part` is the stem of this container and `i = 2`, or
26+
* - `part` is the extension of this container and `i = 3`.
27+
*/
28+
cached
29+
private predicate splitAbsolutePath(string part, int i) {
30+
part = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", i)
31+
}
32+
33+
/** Gets the base name of this file. */
34+
string getBaseName() { this.splitAbsolutePath(result, 1) }
35+
36+
/**
37+
* Gets the extension of this container, that is, the suffix of its base name
38+
* after the last dot character, if any.
39+
*
40+
* In particular,
41+
*
42+
* - if the name does not include a dot, there is no extension, so this
43+
* predicate has no result;
44+
* - if the name ends in a dot, the extension is the empty string;
45+
* - if the name contains multiple dots, the extension follows the last dot.
46+
*
47+
* Here are some examples of absolute paths and the corresponding extensions
48+
* (surrounded with quotes to avoid ambiguity):
49+
*
50+
* <table border="1">
51+
* <tr><th>Absolute path</th><th>Extension</th></tr>
52+
* <tr><td>"/tmp/tst.txt"</td><td>"txt"</td></tr>
53+
* <tr><td>"/tmp/.classpath"</td><td>"classpath"</td></tr>
54+
* <tr><td>"/bin/bash"</td><td>not defined</td></tr>
55+
* <tr><td>"/tmp/tst2."</td><td>""</td></tr>
56+
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
57+
* </table>
58+
*/
59+
string getExtension() { this.splitAbsolutePath(result, 3) }
60+
61+
/**
62+
* Gets the stem of this container, that is, the prefix of its base name up to
63+
* (but not including) the last dot character if there is one, or the entire
64+
* base name if there is not.
65+
*
66+
* Here are some examples of absolute paths and the corresponding stems
67+
* (surrounded with quotes to avoid ambiguity):
68+
*
69+
* <table border="1">
70+
* <tr><th>Absolute path</th><th>Stem</th></tr>
71+
* <tr><td>"/tmp/tst.txt"</td><td>"tst"</td></tr>
72+
* <tr><td>"/tmp/.classpath"</td><td>""</td></tr>
73+
* <tr><td>"/bin/bash"</td><td>"bash"</td></tr>
74+
* <tr><td>"/tmp/tst2."</td><td>"tst2"</td></tr>
75+
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
76+
* </table>
77+
*/
78+
string getStem() { this.splitAbsolutePath(result, 2) }
79+
80+
/**
81+
* Gets the number of lines containing code in this file. This value
82+
* is approximate.
83+
*/
84+
int getNumberOfLinesOfCode() {
85+
result =
86+
count(int line |
87+
exists(Location loc |
88+
not loc instanceof UnknownLocation and loc.getFile() = this and loc.getStartLine() = line
89+
)
90+
)
91+
}
92+
93+
/**
94+
* Gets the relative path of this file from the root folder of the
95+
* analyzed source location. The relative path of the root folder itself
96+
* would be the empty string.
97+
*
98+
* This has no result if the file is outside the source root, that is,
99+
* if the root folder is not a reflexive, transitive parent of this file.
100+
*/
101+
string getRelativePath() {
102+
exists(string absPath, string pref |
103+
absPath = this.getAbsolutePath() and sourceLocationPrefix(pref)
104+
|
105+
absPath = pref and result = ""
106+
or
107+
absPath = pref.regexpReplaceAll("/$", "") + "/" + result and
108+
not result.matches("/%")
109+
)
110+
}
111+
}

rust/ql/lib/codeql/rust/elements/Function.qll

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/Locatable.qll

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)