Skip to content

Commit f5dc1cf

Browse files
authored
fix: Make --quiet flag work again
2 parents a5b8bc8 + d31ea87 commit f5dc1cf

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/ccextractor.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ int main(int argc, char *argv[])
435435

436436
int compile_ret = ccxr_parse_parameters(argc, argv);
437437

438+
// Update the Rust logger target after parsing so --quiet is respected
439+
ccxr_update_logger_target();
440+
438441
if (compile_ret == EXIT_NO_INPUT_FILES)
439442
{
440443
print_usage();

src/lib_ccx/lib_ccx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ struct lib_ccx_ctx *init_libraries(struct ccx_s_options *opt);
160160
void dinit_libraries(struct lib_ccx_ctx **ctx);
161161

162162
extern void ccxr_init_basic_logger();
163+
extern void ccxr_update_logger_target();
163164

164165
// ccextractor.c
165166
void print_end_msg(void);

src/rust/lib_ccxr/src/util/log.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ impl<'a> CCExtractorLogger {
269269
self.target
270270
}
271271

272+
/// Sets the target for logging messages.
273+
pub fn set_target(&mut self, target: OutputTarget) {
274+
self.target = target;
275+
}
276+
272277
/// Check if the messages are intercepted by GUI.
273278
pub fn is_gui_mode(&self) -> bool {
274279
self.gui_mode

src/rust/src/libccxr_exports/mod.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ pub unsafe extern "C" fn ccxr_init_basic_logger() {
3333
.unwrap_or(DebugMessageFlag::VERBOSE);
3434
let mask = DebugMessageMask::new(debug_mask, debug_mask_on_debug);
3535
let gui_mode_reports = ccx_options.gui_mode_reports != 0;
36+
// CCX_MESSAGES_QUIET=0, CCX_MESSAGES_STDOUT=1, CCX_MESSAGES_STDERR=2
3637
let messages_target = match ccx_options.messages_target {
37-
0 => OutputTarget::Stdout,
38-
1 => OutputTarget::Stderr,
39-
2 => OutputTarget::Quiet,
38+
0 => OutputTarget::Quiet,
39+
1 => OutputTarget::Stdout,
40+
2 => OutputTarget::Stderr,
4041
_ => OutputTarget::Stderr, // Default to stderr for invalid values
4142
};
4243
let _ = set_logger(CCExtractorLogger::new(
@@ -46,6 +47,28 @@ pub unsafe extern "C" fn ccxr_init_basic_logger() {
4647
));
4748
}
4849

50+
/// Updates the logger target after command-line arguments have been parsed.
51+
/// This is needed because the logger is initialized before argument parsing,
52+
/// and options like --quiet need to be applied afterwards.
53+
///
54+
/// # Safety
55+
///
56+
/// `ccx_options` in C must be properly initialized and the logger must have
57+
/// been initialized via `ccxr_init_basic_logger` before calling this function.
58+
#[no_mangle]
59+
pub unsafe extern "C" fn ccxr_update_logger_target() {
60+
// CCX_MESSAGES_QUIET=0, CCX_MESSAGES_STDOUT=1, CCX_MESSAGES_STDERR=2
61+
let messages_target = match ccx_options.messages_target {
62+
0 => OutputTarget::Quiet,
63+
1 => OutputTarget::Stdout,
64+
2 => OutputTarget::Stderr,
65+
_ => OutputTarget::Stderr,
66+
};
67+
if let Some(mut logger) = logger_mut() {
68+
logger.set_target(messages_target);
69+
}
70+
}
71+
4972
/// Rust equivalent for `verify_crc32` function in C. Uses C-native types as input and output.
5073
///
5174
/// # Safety

0 commit comments

Comments
 (0)