From c6b1d1dd870b3370d0a09fb4600e3a6b03326f35 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 23 Nov 2022 08:57:45 +0200 Subject: Rework diag_buffer interface to facilitate correct destruction order --- libbuild2/cc/compile-rule.cxx | 45 +++++++++++++++++++++++-------------------- libbuild2/cc/gcc.cxx | 6 +++--- libbuild2/cc/guess.cxx | 4 ++-- libbuild2/cc/link-rule.cxx | 24 ++++++++++++----------- libbuild2/cc/msvc.cxx | 6 +++--- 5 files changed, 45 insertions(+), 40 deletions(-) (limited to 'libbuild2/cc') diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx index 6ca1f0a..874674d 100644 --- a/libbuild2/cc/compile-rule.cxx +++ b/libbuild2/cc/compile-rule.cxx @@ -4009,13 +4009,14 @@ namespace build2 args, -1, -1, - dbuf.open (args[0], - false /* force */, - fdstream_mode::non_blocking | - fdstream_mode::skip), + diag_buffer::pipe (ctx), nullptr, // CWD env.empty () ? nullptr : env.data ()); + dbuf.open (args[0], + move (pr.in_efd), + fdstream_mode::non_blocking | + fdstream_mode::skip); try { gcc_module_mapper_state mm_state (skip_count, imports); @@ -4126,8 +4127,6 @@ namespace build2 // diagnostics (if things go badly we will restart with this // support). // - using pipe = process::pipe; - if (drmp == nullptr) // Dependency info goes to stdout. { assert (!sense_diag); // Note: could support if necessary. @@ -4135,39 +4134,42 @@ namespace build2 // For VC with /P the dependency info and diagnostics all go // to stderr so redirect it to stdout. // - pipe err ( - cclass == compiler_class::msvc ? pipe {-1, 1} : // stdout - !gen ? pipe {-1, -2} : // null - dbuf.open (args[0], - sense_diag /* force */, - fdstream_mode::non_blocking)); + int err ( + cclass == compiler_class::msvc ? 1 : // stdout + !gen ? -2 : // /dev/null + diag_buffer::pipe (ctx, sense_diag /* force */)); pr = process ( cpath, args, 0, -1, - move (err), + err, nullptr, // CWD env.empty () ? nullptr : env.data ()); + + dbuf.open (args[0], + move (pr.in_efd), + fdstream_mode::non_blocking); // Skip on stdout. } else // Dependency info goes to temporary file. { // Since we only need to read from one stream (dbuf) let's // use the simpler blocking setup. // - pipe err ( - !gen && !sense_diag ? pipe {-1, -2} : // null - dbuf.open (args[0], sense_diag /* force */)); + int err ( + !gen && !sense_diag ? -2 : // /dev/null + diag_buffer::pipe (ctx, sense_diag /* force */)); pr = process (cpath, args, 0, 2, // Send stdout to stderr. - move (err), + err, nullptr, // CWD env.empty () ? nullptr : env.data ()); + dbuf.open (args[0], move (pr.in_efd)); dbuf.read (sense_diag /* force */); if (sense_diag) @@ -7343,8 +7345,6 @@ namespace build2 if (verb >= 3) print_process (args); - diag_buffer dbuf (ctx); - // @@ DRYRUN: Currently we discard the (partially) preprocessed file on // dry-run which is a waste. Even if we keep the file around (like we do // for the error case; see above), we currently have no support for @@ -7374,10 +7374,12 @@ namespace build2 process pr (cpath, args, - 0, 2, dbuf.open (args[0], filter), + 0, 2, diag_buffer::pipe (ctx, filter /* force */), nullptr, // CWD env.empty () ? nullptr : env.data ()); + diag_buffer dbuf (ctx, args[0], pr); + if (filter) msvc_filter_cl (dbuf, *sp); @@ -7444,10 +7446,11 @@ namespace build2 { process pr (cpath, args, - 0, 2, dbuf.open (args[0]), + 0, 2, diag_buffer::pipe (ctx), nullptr, // CWD env.empty () ? nullptr : env.data ()); + diag_buffer dbuf (ctx, args[0], pr); dbuf.read (); run_finish (dbuf, args, pr, 1 /* verbosity */); } diff --git a/libbuild2/cc/gcc.cxx b/libbuild2/cc/gcc.cxx index 0045c27..755b0d8 100644 --- a/libbuild2/cc/gcc.cxx +++ b/libbuild2/cc/gcc.cxx @@ -137,9 +137,9 @@ namespace build2 process pr (run_start ( env, args, - -2, /* stdin */ - -2, /* stdout */ - {-1, -1} /* stderr */)); + -2, /* stdin */ + -2, /* stdout */ + -1 /* stderr */)); try { ifdstream is ( diff --git a/libbuild2/cc/guess.cxx b/libbuild2/cc/guess.cxx index a0d7ee4..7a2ede9 100644 --- a/libbuild2/cc/guess.cxx +++ b/libbuild2/cc/guess.cxx @@ -186,7 +186,7 @@ namespace build2 args, -1 /* stdin */, -1 /* stdout */, - {-1, 1} /* stderr (to stdout) */)); + 1 /* stderr (to stdout) */)); string l, r; try { @@ -2179,7 +2179,7 @@ namespace build2 args, -2 /* stdin (to /dev/null) */, -1 /* stdout */, - {-1, 1} /* stderr (to stdout) */)); + 1 /* stderr (to stdout) */)); clang_msvc_info r; diff --git a/libbuild2/cc/link-rule.cxx b/libbuild2/cc/link-rule.cxx index 9bf86e6..20c6c62 100644 --- a/libbuild2/cc/link-rule.cxx +++ b/libbuild2/cc/link-rule.cxx @@ -2892,8 +2892,6 @@ namespace build2 env_ptrs.push_back (nullptr); } - diag_buffer dbuf (ctx); - // If targeting Windows, take care of the manifest. // path manifest; // Manifest itself (msvc) or compiled object file. @@ -2949,12 +2947,14 @@ namespace build2 // process pr (rc, args, - -1 /* stdin */, - 1 /* stdout */, - dbuf.open (args[0]) /* stderr */, - nullptr /* cwd */, + -1 /* stdin */, + 1 /* stdout */, + diag_buffer::pipe (ctx) /* stderr */, + nullptr /* cwd */, env_ptrs.empty () ? nullptr : env_ptrs.data ()); + diag_buffer dbuf (ctx, args[0], pr); + try { ofdstream os (move (pr.out_fd)); @@ -4038,12 +4038,14 @@ namespace build2 process pr (*ld, args, - 0 /* stdin */, - 2 /* stdout */, - dbuf.open (args[0], filter) /* stderr */, - nullptr /* cwd */, + 0 /* stdin */, + 2 /* stdout */, + diag_buffer::pipe (ctx, filter /* force */) /* stderr */, + nullptr /* cwd */, env_ptrs.empty () ? nullptr : env_ptrs.data ()); + diag_buffer dbuf (ctx, args[0], pr); + if (filter) msvc_filter_link (dbuf, t, ot); @@ -4127,7 +4129,7 @@ namespace build2 if (!ctx.dry_run) { - run (dbuf, + run (ctx, rl, args, 1 /* finish_verbosity */, diff --git a/libbuild2/cc/msvc.cxx b/libbuild2/cc/msvc.cxx index 8b9c05b..8fcbb0b 100644 --- a/libbuild2/cc/msvc.cxx +++ b/libbuild2/cc/msvc.cxx @@ -433,9 +433,9 @@ namespace build2 // process pr (run_start (ld, args, - 0 /* stdin */, - -1 /* stdout */, - {-1, 1} /* stderr (to stdout) */)); + 0 /* stdin */, + -1 /* stdout */, + 1 /* stderr (to stdout) */)); bool obj (false), dll (false); string s; -- cgit v1.1