aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-11-07 06:53:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-11-08 11:08:03 +0200
commitcc9337a5877b0164e97f30ba4814aff906f01c4e (patch)
tree2cfcbe1cbec7cc63de1197a584b61e9e051f0992 /libbuild2
parent14c7315c523f41fb22ae16251d67ce6885545e3a (diff)
Add diag_buffer::open_eof()
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/diagnostics.cxx15
-rw-r--r--libbuild2/diagnostics.hxx23
2 files changed, 33 insertions, 5 deletions
diff --git a/libbuild2/diagnostics.cxx b/libbuild2/diagnostics.cxx
index 21e3345..01bd43f 100644
--- a/libbuild2/diagnostics.cxx
+++ b/libbuild2/diagnostics.cxx
@@ -141,7 +141,7 @@ namespace build2
const fail_mark fail ("error");
const fail_end endf;
- // diag_buffer
+ // diag_buffer
//
process::pipe diag_buffer::
open (const char* args0, bool force, fdstream_mode m)
@@ -180,6 +180,17 @@ namespace build2
return r;
}
+ void diag_buffer::
+ open_eof (const char* args0)
+ {
+ assert (state_ == state::closed && args0 != nullptr);
+
+ serial = ctx_.sched.serial ();
+ nobuf = !serial && ctx_.no_diag_buffer;
+ this->args0 = args0;
+ state_ = state::eof;
+ }
+
bool diag_buffer::
read (bool force)
{
@@ -303,6 +314,8 @@ namespace build2
void diag_buffer::
write (const string& s, bool nl, bool force)
{
+ assert (state_ != state::closed);
+
// Similar logic to read() above.
//
if ((serial || nobuf) && !force)
diff --git a/libbuild2/diagnostics.hxx b/libbuild2/diagnostics.hxx
index 8b60703..b53d375 100644
--- a/libbuild2/diagnostics.hxx
+++ b/libbuild2/diagnostics.hxx
@@ -562,6 +562,15 @@ namespace build2
bool force = false,
fdstream_mode mode = fdstream_mode::skip);
+ // Open the buffer in the state as if after read() returned false, that
+ // is, the stream corresponding to the parent's end of the pipe reached
+ // EOF and has been closed. This is primarily useful when the diagnostics
+ // is being read in a custom way (for example, it has been merged to
+ // stdout) and all we want is to be able to call write() and close().
+ //
+ void
+ open_eof (const char* args0);
+
// Check whether the buffer has been opened with the open() call and
// hasn't yet been closed.
//
@@ -574,10 +583,16 @@ namespace build2
return state_ != state::closed;
}
- // Read the diagnostics from the parent end of the pipe if one was opened
- // and buffer/stream it as necessary or forced. Return true if there could
- // be more diagnostics to read (only possible in the non-blocking mode)
- // and false otherwise, in which case also close the stream.
+ // Read the diagnostics from the parent's end of the pipe if one was
+ // opened and buffer/stream it as necessary or forced. Return true if
+ // there could be more diagnostics to read (only possible in the non-
+ // blocking mode) and false otherwise, in which case also close the
+ // stream.
+ //
+ // Note that the force argument here (as well as in write() below) and
+ // in open() above are independent. Specifically, force in open() forces
+ // the opening of the pipe while force in read() and write() forces
+ // the buffering of the diagnostics.
//
// Instead of calling this function you can perform custom reading and, if
// necessary, buffering of the diagnostics by accessing the input stream