Rust: fix gzip compression

This commit is contained in:
Paolo Tranquilli
2025-05-28 14:13:21 +02:00
parent 7ccae93a12
commit a86dfe173e
3 changed files with 25 additions and 8 deletions

View File

@@ -55,7 +55,7 @@ pub struct Config {
pub cargo_all_targets: bool,
pub logging_flamegraph: Option<PathBuf>,
pub logging_verbosity: Option<String>,
pub compression: Compression,
pub trap_compression: Compression,
pub inputs: Vec<PathBuf>,
pub qltest: bool,
pub qltest_cargo_check: bool,

View File

@@ -1,4 +1,3 @@
use crate::config::Compression;
use crate::{config, generated};
use codeql_extractor::{extractor, file_paths, trap};
use ra_ap_ide_db::line_index::LineCol;
@@ -9,7 +8,7 @@ use std::path::{Path, PathBuf};
use tracing::debug;
pub use trap::Label as UntypedLabel;
pub use trap::Writer;
pub use trap::{Compression, Writer};
pub trait AsTrapKeyPart {
fn as_key_part(&self) -> String;
@@ -245,8 +244,7 @@ impl TrapFile {
pub fn commit(&self) -> std::io::Result<()> {
std::fs::create_dir_all(self.path.parent().unwrap())?;
self.writer
.write_to_file(&self.path, self.compression.into())
self.writer.write_to_file(&self.path, self.compression)
}
}
@@ -261,12 +259,16 @@ impl TrapFileProvider {
std::fs::create_dir_all(&trap_dir)?;
Ok(TrapFileProvider {
trap_dir,
compression: cfg.compression,
compression: cfg.trap_compression.into(),
})
}
pub fn create(&self, category: &str, key: impl AsRef<Path>) -> TrapFile {
let path = file_paths::path_for(&self.trap_dir.join(category), key.as_ref(), "trap");
let path = file_paths::path_for(
&self.trap_dir.join(category),
key.as_ref(),
self.compression.extension(),
);
debug!("creating trap file {}", path.display());
let mut writer = trap::Writer::new();
extractor::populate_empty_location(&mut writer);

View File

@@ -10,7 +10,22 @@ def test_rust_project(codeql, rust, rust_project, check_source_archive, rust_che
codeql.database.create()
@pytest.mark.ql_test(None)
def test_do_not_print_env(codeql, rust, cargo, check_env_not_dumped, rust_check_diagnostics):
# parametrizing `rust_edition` allows us to skip the default parametrization over all editions
@pytest.mark.parametrize("rust_edition", [2024])
def test_do_not_print_env(codeql, rust, rust_edition, cargo, check_env_not_dumped, rust_check_diagnostics):
codeql.database.create(_env={
"CODEQL_EXTRACTOR_RUST_VERBOSE": "2",
})
@pytest.mark.ql_test("steps.ql", expected=".cargo.expected")
@pytest.mark.parametrize(("rust_edition", "compression", "suffix"), [
pytest.param(2024, "gzip", ".gz", id="gzip"),
])
def test_compression(codeql, rust, rust_edition, compression, suffix, cargo, rust_check_diagnostics, cwd):
codeql.database.create(cleanup=False, _env={
"CODEQL_EXTRACTOR_RUST_TRAP_COMPRESSION": compression,
})
trap_files = [*(cwd / "test-db" / "trap").rglob("*.trap*")]
assert trap_files
files_with_wrong_format = [f for f in trap_files if f.suffix != suffix and f.name != "metadata.trap.gz"]
assert not files_with_wrong_format, f"Found trap files with wrong format: {files_with_wrong_format}"