aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/diagnostics.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-11-04 07:08:29 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-11-08 11:08:03 +0200
commit14c7315c523f41fb22ae16251d67ce6885545e3a (patch)
tree6549e740968af5e2e5034fcb7cf53690d2705222 /libbuild2/diagnostics.cxx
parent94fb1117dd8c32dd4732b792300f1b6b3cb6af8f (diff)
Add force flag to diag_buffer::read(), diag_buffer::write()
Diffstat (limited to 'libbuild2/diagnostics.cxx')
-rw-r--r--libbuild2/diagnostics.cxx203
1 files changed, 102 insertions, 101 deletions
diff --git a/libbuild2/diagnostics.cxx b/libbuild2/diagnostics.cxx
index 3b0415c..21e3345 100644
--- a/libbuild2/diagnostics.cxx
+++ b/libbuild2/diagnostics.cxx
@@ -47,7 +47,101 @@ namespace build2
//
const int stream_verb_index = ostream::xalloc ();
- // diag_buffer
+ // print_process()
+ //
+ void
+ print_process (const char* const* args, size_t n)
+ {
+ diag_record dr (text);
+ print_process (dr, args, n);
+ }
+
+ void
+ print_process (diag_record& dr,
+ const char* const* args, size_t n)
+ {
+ dr << butl::process_args {args, n};
+ }
+
+ void
+ print_process (const process_env& pe, const char* const* args, size_t n)
+ {
+ diag_record dr (text);
+ print_process (dr, pe, args, n);
+ }
+
+ void
+ print_process (diag_record& dr,
+ const process_env& pe, const char* const* args, size_t n)
+ {
+ if (pe.env ())
+ dr << pe << ' ';
+
+ dr << butl::process_args {args, n};
+ }
+
+ // Diagnostic facility, project specifics.
+ //
+
+ void simple_prologue_base::
+ operator() (const diag_record& r) const
+ {
+ stream_verb (r.os, sverb_);
+
+ if (type_ != nullptr)
+ r << type_ << ": ";
+
+ if (mod_ != nullptr)
+ r << mod_ << "::";
+
+ if (name_ != nullptr)
+ r << name_ << ": ";
+ }
+
+ void location_prologue_base::
+ operator() (const diag_record& r) const
+ {
+ stream_verb (r.os, sverb_);
+
+ if (!loc_.empty ())
+ {
+ r << loc_.file << ':';
+
+ if (!diag_no_line)
+ {
+ if (loc_.line != 0)
+ {
+ r << loc_.line << ':';
+
+ if (!diag_no_column)
+ {
+ if (loc_.column != 0)
+ r << loc_.column << ':';
+ }
+ }
+ }
+
+ r << ' ';
+ }
+
+ if (type_ != nullptr)
+ r << type_ << ": ";
+
+ if (mod_ != nullptr)
+ r << mod_ << "::";
+
+ if (name_ != nullptr)
+ r << name_ << ": ";
+ }
+
+ const basic_mark error ("error");
+ const basic_mark warn ("warning");
+ const basic_mark info ("info");
+ const basic_mark text (nullptr, nullptr, nullptr); // No type/data/frame.
+ const fail_mark fail ("error");
+ const fail_end endf;
+
+ // diag_buffer
//
process::pipe diag_buffer::
open (const char* args0, bool force, fdstream_mode m)
@@ -87,7 +181,7 @@ namespace build2
}
bool diag_buffer::
- read ()
+ read (bool force)
{
assert (state_ == state::opened);
@@ -118,7 +212,7 @@ namespace build2
if (is.blocking ())
{
- if (serial || nobuf)
+ if ((serial || nobuf) && !force)
{
// This is the case where we are called after custom processing.
//
@@ -167,9 +261,10 @@ namespace build2
else
{
// We do not support finishing off after the custom processing in
- // the non-blocking mode (but could probably do if necessary).
+ // the non-blocking mode unless forced to buffer (but could probably
+ // do if necessary).
//
- assert (!(serial || nobuf));
+ assert (!(serial || nobuf) || force);
fdstreambuf& sb (*static_cast<fdstreambuf*> (is.rdbuf ()));
@@ -206,11 +301,11 @@ namespace build2
}
void diag_buffer::
- write (const string& s, bool nl)
+ write (const string& s, bool nl, bool force)
{
// Similar logic to read() above.
//
- if (serial || nobuf)
+ if ((serial || nobuf) && !force)
{
assert (buf.empty ());
@@ -340,100 +435,6 @@ namespace build2
state_ = state::closed;
}
- // print_process()
- //
- void
- print_process (const char* const* args, size_t n)
- {
- diag_record dr (text);
- print_process (dr, args, n);
- }
-
- void
- print_process (diag_record& dr,
- const char* const* args, size_t n)
- {
- dr << butl::process_args {args, n};
- }
-
- void
- print_process (const process_env& pe, const char* const* args, size_t n)
- {
- diag_record dr (text);
- print_process (dr, pe, args, n);
- }
-
- void
- print_process (diag_record& dr,
- const process_env& pe, const char* const* args, size_t n)
- {
- if (pe.env ())
- dr << pe << ' ';
-
- dr << butl::process_args {args, n};
- }
-
- // Diagnostic facility, project specifics.
- //
-
- void simple_prologue_base::
- operator() (const diag_record& r) const
- {
- stream_verb (r.os, sverb_);
-
- if (type_ != nullptr)
- r << type_ << ": ";
-
- if (mod_ != nullptr)
- r << mod_ << "::";
-
- if (name_ != nullptr)
- r << name_ << ": ";
- }
-
- void location_prologue_base::
- operator() (const diag_record& r) const
- {
- stream_verb (r.os, sverb_);
-
- if (!loc_.empty ())
- {
- r << loc_.file << ':';
-
- if (!diag_no_line)
- {
- if (loc_.line != 0)
- {
- r << loc_.line << ':';
-
- if (!diag_no_column)
- {
- if (loc_.column != 0)
- r << loc_.column << ':';
- }
- }
- }
-
- r << ' ';
- }
-
- if (type_ != nullptr)
- r << type_ << ": ";
-
- if (mod_ != nullptr)
- r << mod_ << "::";
-
- if (name_ != nullptr)
- r << name_ << ": ";
- }
-
- const basic_mark error ("error");
- const basic_mark warn ("warning");
- const basic_mark info ("info");
- const basic_mark text (nullptr, nullptr, nullptr); // No type/data/frame.
- const fail_mark fail ("error");
- const fail_end endf;
-
// diag_do(), etc.
//
string