Skip to content

Commit a86dfe1

Browse files
author
Paolo Tranquilli
committed
Rust: fix gzip compression
1 parent 7ccae93 commit a86dfe1

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

rust/extractor/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct Config {
5555
pub cargo_all_targets: bool,
5656
pub logging_flamegraph: Option<PathBuf>,
5757
pub logging_verbosity: Option<String>,
58-
pub compression: Compression,
58+
pub trap_compression: Compression,
5959
pub inputs: Vec<PathBuf>,
6060
pub qltest: bool,
6161
pub qltest_cargo_check: bool,

rust/extractor/src/trap.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::config::Compression;
21
use crate::{config, generated};
32
use codeql_extractor::{extractor, file_paths, trap};
43
use ra_ap_ide_db::line_index::LineCol;
@@ -9,7 +8,7 @@ use std::path::{Path, PathBuf};
98
use tracing::debug;
109

1110
pub use trap::Label as UntypedLabel;
12-
pub use trap::Writer;
11+
pub use trap::{Compression, Writer};
1312

1413
pub trait AsTrapKeyPart {
1514
fn as_key_part(&self) -> String;
@@ -245,8 +244,7 @@ impl TrapFile {
245244

246245
pub fn commit(&self) -> std::io::Result<()> {
247246
std::fs::create_dir_all(self.path.parent().unwrap())?;
248-
self.writer
249-
.write_to_file(&self.path, self.compression.into())
247+
self.writer.write_to_file(&self.path, self.compression)
250248
}
251249
}
252250

@@ -261,12 +259,16 @@ impl TrapFileProvider {
261259
std::fs::create_dir_all(&trap_dir)?;
262260
Ok(TrapFileProvider {
263261
trap_dir,
264-
compression: cfg.compression,
262+
compression: cfg.trap_compression.into(),
265263
})
266264
}
267265

268266
pub fn create(&self, category: &str, key: impl AsRef<Path>) -> TrapFile {
269-
let path = file_paths::path_for(&self.trap_dir.join(category), key.as_ref(), "trap");
267+
let path = file_paths::path_for(
268+
&self.trap_dir.join(category),
269+
key.as_ref(),
270+
self.compression.extension(),
271+
);
270272
debug!("creating trap file {}", path.display());
271273
let mut writer = trap::Writer::new();
272274
extractor::populate_empty_location(&mut writer);

rust/ql/integration-tests/hello-project/test_project.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@ def test_rust_project(codeql, rust, rust_project, check_source_archive, rust_che
1010
codeql.database.create()
1111

1212
@pytest.mark.ql_test(None)
13-
def test_do_not_print_env(codeql, rust, cargo, check_env_not_dumped, rust_check_diagnostics):
13+
# parametrizing `rust_edition` allows us to skip the default parametrization over all editions
14+
@pytest.mark.parametrize("rust_edition", [2024])
15+
def test_do_not_print_env(codeql, rust, rust_edition, cargo, check_env_not_dumped, rust_check_diagnostics):
1416
codeql.database.create(_env={
1517
"CODEQL_EXTRACTOR_RUST_VERBOSE": "2",
1618
})
19+
20+
@pytest.mark.ql_test("steps.ql", expected=".cargo.expected")
21+
@pytest.mark.parametrize(("rust_edition", "compression", "suffix"), [
22+
pytest.param(2024, "gzip", ".gz", id="gzip"),
23+
])
24+
def test_compression(codeql, rust, rust_edition, compression, suffix, cargo, rust_check_diagnostics, cwd):
25+
codeql.database.create(cleanup=False, _env={
26+
"CODEQL_EXTRACTOR_RUST_TRAP_COMPRESSION": compression,
27+
})
28+
trap_files = [*(cwd / "test-db" / "trap").rglob("*.trap*")]
29+
assert trap_files
30+
files_with_wrong_format = [f for f in trap_files if f.suffix != suffix and f.name != "metadata.trap.gz"]
31+
assert not files_with_wrong_format, f"Found trap files with wrong format: {files_with_wrong_format}"

0 commit comments

Comments
 (0)