mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02:00
Rust: add optional dependencies to ql tests
Also accept `options.yml` and `options.yaml` files as well for test options, to get YAML syntax highlighting. In a follow up PR we might make the extension mandatory.
This commit is contained in:
@@ -43,6 +43,7 @@ pub struct Config {
|
||||
pub inputs: Vec<PathBuf>,
|
||||
pub qltest: bool,
|
||||
pub qltest_cargo_check: bool,
|
||||
pub qltest_dependencies: Vec<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -61,7 +62,13 @@ impl Config {
|
||||
.ancestors()
|
||||
// only travel up while we're within the test pack
|
||||
.take_while_inclusive(|p| !p.join("qlpack.yml").exists())
|
||||
.map(|p| p.join("options"))
|
||||
.flat_map(|p| {
|
||||
[
|
||||
p.join("options"),
|
||||
p.join("options.yml"),
|
||||
p.join("options.yaml"),
|
||||
]
|
||||
})
|
||||
.filter(|p| p.exists())
|
||||
.collect_vec();
|
||||
option_files.reverse();
|
||||
|
||||
@@ -21,7 +21,7 @@ fn dump_lib() -> anyhow::Result<()> {
|
||||
fs::write("lib.rs", lib).context("writing lib.rs")
|
||||
}
|
||||
|
||||
fn dump_cargo_manifest() -> anyhow::Result<()> {
|
||||
fn dump_cargo_manifest(dependencies: &[String]) -> anyhow::Result<()> {
|
||||
let mut manifest = String::from(
|
||||
r#"[workspace]
|
||||
[package]
|
||||
@@ -40,6 +40,13 @@ path = "main.rs"
|
||||
"#,
|
||||
);
|
||||
}
|
||||
if !dependencies.is_empty() {
|
||||
manifest.push_str("[dependencies]\n");
|
||||
for dep in dependencies {
|
||||
manifest.push_str(dep);
|
||||
manifest.push('\n');
|
||||
}
|
||||
}
|
||||
fs::write("Cargo.toml", manifest).context("writing Cargo.toml")
|
||||
}
|
||||
|
||||
@@ -54,7 +61,7 @@ fn set_sources(config: &mut Config) -> anyhow::Result<()> {
|
||||
pub(crate) fn prepare(config: &mut Config) -> anyhow::Result<()> {
|
||||
dump_lib()?;
|
||||
set_sources(config)?;
|
||||
dump_cargo_manifest()?;
|
||||
dump_cargo_manifest(&config.qltest_dependencies)?;
|
||||
if config.qltest_cargo_check {
|
||||
let status = Command::new("cargo")
|
||||
.env("RUSTFLAGS", "-Awarnings")
|
||||
|
||||
Reference in New Issue
Block a user