From: Joel Rosdahl Date: Tue, 11 Aug 2020 18:47:48 +0000 (+0200) Subject: Util::send_to_stderr: Refactor to take Context parameter X-Git-Tag: v4.0~196 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=03921c691c74ace2926f256553829e347a767a7a;p=thirdparty%2Fccache.git Util::send_to_stderr: Refactor to take Context parameter --- diff --git a/src/ResultRetriever.cpp b/src/ResultRetriever.cpp index c9ac883f3..09090e2ec 100644 --- a/src/ResultRetriever.cpp +++ b/src/ResultRetriever.cpp @@ -138,7 +138,7 @@ void ResultRetriever::on_entry_end() { if (m_dest_file_type == FileType::stderr_output) { - Util::send_to_stderr(m_dest_data, m_ctx.args_info.strip_diagnostics_colors); + Util::send_to_stderr(m_ctx, m_dest_data); } else if (m_dest_file_type == FileType::dependency && !m_dest_path.empty()) { write_dependency_file(); } diff --git a/src/Util.cpp b/src/Util.cpp index f1591a27a..d2c1046ba 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -1162,15 +1162,15 @@ same_program_name(const std::string& program_name, } void -send_to_stderr(const std::string& text, bool strip_colors) +send_to_stderr(const Context& ctx, const std::string& text) { const std::string* text_to_send = &text; - std::string stripped_text; + std::string modified_text; - if (strip_colors) { + if (ctx.args_info.strip_diagnostics_colors) { try { - stripped_text = Util::strip_ansi_csi_seqs(text); - text_to_send = &stripped_text; + modified_text = strip_ansi_csi_seqs(text); + text_to_send = &modified_text; } catch (const Error&) { // Fall through } diff --git a/src/Util.hpp b/src/Util.hpp index b9682cfd6..28c0af880 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -368,8 +368,8 @@ bool same_program_name(const std::string& program_name, const std::string& canonical_program_name); // Send `text` to STDERR_FILENO, optionally stripping ANSI color sequences if -// `strip_colors` is true. Throws `Error` on error. -void send_to_stderr(const std::string& text, bool strip_colors); +// `ctx.args_info.strip_diagnostics_colors` is true. Throws `Error` on error. +void send_to_stderr(const Context& ctx, const std::string& text); // Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows. void set_cloexec_flag(int fd); diff --git a/src/ccache.cpp b/src/ccache.cpp index e3f333255..734dae6a6 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -899,8 +899,7 @@ to_cache(Context& ctx, log("Compiler gave exit status {}", status); // We can output stderr immediately instead of rerunning the compiler. - Util::send_to_stderr(Util::read_file(tmp_stderr_path), - ctx.args_info.strip_diagnostics_colors); + Util::send_to_stderr(ctx, Util::read_file(tmp_stderr_path)); throw Failure(STATS_STATUS, status); } @@ -991,8 +990,7 @@ to_cache(Context& ctx, } // Everything OK. - Util::send_to_stderr(Util::read_file(tmp_stderr_path), - ctx.args_info.strip_diagnostics_colors); + Util::send_to_stderr(ctx, Util::read_file(tmp_stderr_path)); } // Find the result name by running the compiler in preprocessor mode and