-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17835 from github/redsun82/rust-qltest
Rust: move `qltest` to rust code, add `options` with cargo check
- Loading branch information
Showing
20 changed files
with
197 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::config::Config; | ||
use anyhow::Context; | ||
use glob::glob; | ||
use itertools::Itertools; | ||
use log::info; | ||
use std::ffi::OsStr; | ||
use std::fs; | ||
use std::process::Command; | ||
|
||
fn dump_lib() -> anyhow::Result<()> { | ||
let path_iterator = glob("*.rs").context("globbing test sources")?; | ||
let paths = path_iterator | ||
.collect::<Result<Vec<_>, _>>() | ||
.context("fetching test sources")?; | ||
let lib = paths | ||
.iter() | ||
.map(|p| p.file_stem().expect("results of glob must have a name")) | ||
.filter(|&p| !["main", "lib"].map(OsStr::new).contains(&p)) | ||
.map(|p| format!("mod {};", p.to_string_lossy())) | ||
.join("\n"); | ||
fs::write("lib.rs", lib).context("writing lib.rs") | ||
} | ||
|
||
fn dump_cargo_manifest() -> anyhow::Result<()> { | ||
let mut manifest = String::from( | ||
r#"[workspace] | ||
[package] | ||
name = "test" | ||
version="0.0.1" | ||
edition="2021" | ||
[lib] | ||
path="lib.rs" | ||
"#, | ||
); | ||
if fs::exists("main.rs").context("checking existence of main.rs")? { | ||
manifest.push_str( | ||
r#"[[bin]] | ||
name = "main" | ||
path = "main.rs" | ||
"#, | ||
); | ||
} | ||
fs::write("Cargo.toml", manifest).context("writing Cargo.toml") | ||
} | ||
|
||
fn set_sources(config: &mut Config) -> anyhow::Result<()> { | ||
let path_iterator = glob("*.rs").context("globbing test sources")?; | ||
config.inputs = path_iterator | ||
.collect::<Result<Vec<_>, _>>() | ||
.context("fetching test sources")?; | ||
Ok(()) | ||
} | ||
|
||
pub(crate) fn prepare(config: &mut Config) -> anyhow::Result<()> { | ||
dump_lib()?; | ||
set_sources(config)?; | ||
dump_cargo_manifest()?; | ||
if config.qltest_cargo_check { | ||
let status = Command::new("cargo") | ||
.env("RUSTFLAGS", "-Awarnings") | ||
.arg("check") | ||
.arg("-q") | ||
.status() | ||
.context("spawning cargo check")?; | ||
if status.success() { | ||
info!("cargo check successful"); | ||
} else { | ||
anyhow::bail!("requested cargo check failed"); | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
| gen_module.rs:3:1:4:8 | Module | getNumberOfAttrs: | 0 | hasItemList: | no | hasName: | yes | hasVisibility: | no | | ||
| gen_module.rs:5:1:7:1 | Module | getNumberOfAttrs: | 0 | hasItemList: | yes | hasName: | yes | hasVisibility: | no | | ||
| lib.rs:2:1:2:15 | Module | getNumberOfAttrs: | 0 | hasItemList: | no | hasName: | yes | hasVisibility: | no | | ||
| lib.rs:1:1:1:15 | Module | getNumberOfAttrs: | 0 | hasItemList: | no | hasName: | yes | hasVisibility: | no | |
2 changes: 1 addition & 1 deletion
2
rust/ql/test/extractor-tests/generated/Module/Module_getName.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
| gen_module.rs:3:1:4:8 | Module | gen_module.rs:4:5:4:7 | Name | | ||
| gen_module.rs:5:1:7:1 | Module | gen_module.rs:5:5:5:7 | Name | | ||
| lib.rs:2:1:2:15 | Module | lib.rs:2:5:2:14 | Name | | ||
| lib.rs:1:1:1:15 | Module | lib.rs:1:5:1:14 | Name | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
| gen_name.rs:3:4:3:12 | Name | hasText: | yes | | ||
| lib.rs:2:5:2:12 | Name | hasText: | yes | | ||
| lib.rs:1:5:1:12 | Name | hasText: | yes | |
2 changes: 1 addition & 1 deletion
2
rust/ql/test/extractor-tests/generated/Name/Name_getText.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
| gen_name.rs:3:4:3:12 | Name | test_name | | ||
| lib.rs:2:5:2:12 | Name | gen_name | | ||
| lib.rs:1:5:1:12 | Name | gen_name | |
2 changes: 1 addition & 1 deletion
2
rust/ql/test/extractor-tests/generated/SourceFile/SourceFile.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
| gen_source_file.rs:1:1:6:2 | SourceFile | getNumberOfAttrs: | 0 | getNumberOfItems: | 1 | | ||
| lib.rs:1:1:2:21 | SourceFile | getNumberOfAttrs: | 0 | getNumberOfItems: | 1 | | ||
| lib.rs:1:1:1:20 | SourceFile | getNumberOfAttrs: | 0 | getNumberOfItems: | 1 | |
2 changes: 1 addition & 1 deletion
2
rust/ql/test/extractor-tests/generated/SourceFile/SourceFile_getItem.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
| gen_source_file.rs:1:1:6:2 | SourceFile | 0 | gen_source_file.rs:3:1:6:1 | test_source_file | | ||
| lib.rs:1:1:2:21 | SourceFile | 0 | lib.rs:2:1:2:20 | Module | | ||
| lib.rs:1:1:1:20 | SourceFile | 0 | lib.rs:1:1:1:20 | Module | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
qltest_cargo_check: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
qltest_cargo_check: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
qltest_cargo_check: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
qltest_cargo_check: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
qltest_cargo_check: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@echo off | ||
|
||
set "RUST_BACKTRACE=full" | ||
set "QLTEST_LOG=%CODEQL_EXTRACTOR_RUST_LOG_DIR%/qltest.log" | ||
|
||
type NUL && "%CODEQL_EXTRACTOR_RUST_ROOT%/tools/%CODEQL_PLATFORM%/extractor" --qltest >"%QLTEST_LOG%" | ||
|
||
if %ERRORLEVEL% neq 0 ( | ||
type "%QLTEST_LOG%" | ||
exit /b 1 | ||
) |
Oops, something went wrong.