Skip to content

Commit 2ce996b

Browse files
authored
Merge pull request #23313 from github/ruby/zstd
Ruby: Use Zstandard compression by default
2 parents 820d0a5 + 0d65894 commit 2ce996b

7 files changed

Lines changed: 31 additions & 21 deletions

File tree

‎ql/extractor/src/extractor.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ pub fn run(options: Options) -> std::io::Result<()> {
5151
},
5252
],
5353
trap_dir: options.output_dir,
54-
trap_compression: trap::Compression::from_env("CODEQL_QL_TRAP_COMPRESSION"),
54+
trap_compression: trap::Compression::from_env(
55+
"CODEQL_QL_TRAP_COMPRESSION",
56+
trap::Compression::Gzip,
57+
),
5558
source_archive_dir: options.source_archive_dir,
5659
file_lists: vec![options.file_list],
5760
};

‎ruby/codeql-extractor.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ options:
3030
title: Controls compression for the TRAP files written by the extractor.
3131
description: >
3232
This option is only intended for use in debugging the extractor. Accepted
33-
values are 'gzip' (the default, to write gzip-compressed TRAP) 'zstd' (to
34-
write Zstandard-compressed TRAP) and 'none' (to write uncompressed TRAP).
33+
values are 'zstd' (the default, to write Zstandard-compressed TRAP),
34+
'gzip' (to write gzip-compressed TRAP), and 'none' (to write uncompressed TRAP).
3535
type: string
3636
pattern: "^(none|gzip|zstd)$"

‎ruby/extractor/src/extractor.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ pub fn run(options: &Options) -> std::io::Result<()> {
5656
"threads"
5757
}
5858
);
59-
let trap_compression =
60-
match trap::Compression::from_env("CODEQL_EXTRACTOR_RUBY_OPTION_TRAP_COMPRESSION") {
61-
Ok(x) => x,
62-
Err(e) => {
63-
main_thread_logger.write(
64-
main_thread_logger
65-
.new_entry("configuration-error", "Configuration error")
66-
.message("{}; using gzip.", &[diagnostics::MessageArg::Code(&e)])
67-
.severity(diagnostics::Severity::Warning),
68-
);
69-
trap::Compression::Gzip
70-
}
71-
};
59+
let trap_compression = trap::Compression::from_env(
60+
"CODEQL_EXTRACTOR_RUBY_OPTION_TRAP_COMPRESSION",
61+
trap::Compression::Zstd,
62+
)
63+
.unwrap_or_else(|e| {
64+
main_thread_logger.write(
65+
main_thread_logger
66+
.new_entry("configuration-error", "Configuration error")
67+
.message("{}; using zstd.", &[diagnostics::MessageArg::Code(&e)])
68+
.severity(diagnostics::Severity::Warning),
69+
);
70+
trap::Compression::Zstd
71+
});
7272
drop(main_thread_logger);
7373
rayon::ThreadPoolBuilder::new()
7474
.num_threads(num_threads)

‎ruby/ql/integration-tests/compression/test.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33

44
@pytest.mark.parametrize(("compression", "suffix"), [
5+
pytest.param(None, [".zst"], id="default"),
56
pytest.param("none", [], id="none"),
67
pytest.param("gzip", [".gz"], id="gzip"),
78
pytest.param("zstd", [".zst"], id="zstd"),
89
])
9-
def test(codeql, ruby, compression, suffix, cwd):
10+
def test(codeql, ruby, compression, suffix, cwd, monkeypatch):
11+
# Ensure the default case does not inherit a compression setting from the environment.
12+
monkeypatch.delenv("CODEQL_EXTRACTOR_RUBY_OPTION_TRAP_COMPRESSION", raising=False)
1013
codeql.database.create(
1114
_env={
1215
"CODEQL_EXTRACTOR_RUBY_OPTION_TRAP_COMPRESSION": compression,
13-
}
16+
} if compression is not None else {}
1417
)
1518
trap_files = [*(cwd / "test-db" / "trap").rglob("*.trap*")]
1619
assert trap_files, "No trap files found"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* The default compression used to compress TRAP files is now Zstandard instead of gzip.

‎shared/tree-sitter-extractor/src/trap.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,13 @@ impl Compression {
295295
pub const ZSTD_LEVEL: i32 = 2;
296296
pub const GZIP_LEVEL: flate2::Compression = flate2::Compression::fast();
297297

298-
pub fn from_env(var_name: &str) -> Result<Compression, String> {
298+
pub fn from_env(var_name: &str, default: Compression) -> Result<Compression, String> {
299299
match std::env::var(var_name) {
300300
Ok(method) => match Compression::from_string(&method) {
301301
Some(c) => Ok(c),
302302
None => Err(format!("Unknown compression method '{method}'")),
303303
},
304-
// Default compression method if the env var isn't set:
305-
Err(_) => Ok(Compression::Gzip),
304+
Err(_) => Ok(default),
306305
}
307306
}
308307

‎unified/extractor/src/extractor.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
6464
trap_dir: options.output_dir,
6565
trap_compression: trap::Compression::from_env(
6666
"CODEQL_EXTRACTOR_UNIFIED_OPTION_TRAP_COMPRESSION",
67+
trap::Compression::Gzip,
6768
),
6869
source_archive_dir: options.source_archive_dir,
6970
file_lists: vec![options.file_list, builtins_list],

0 commit comments

Comments
 (0)