aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-02 20:47:06 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-12-08 14:26:22 +0300
commit121a075bc2558003990377843393ca27d784f50f (patch)
treed9f518948706af1e092dcecf7c7b9b4cc34433f0
parent3c40652f128e7d20e92e595495bb09691edb7a43 (diff)
Fix buildscript assertion failure on redirecting command stderr to stdout
-rw-r--r--libbuild2/script/run.cxx14
-rw-r--r--tests/recipe/buildscript/testscript23
2 files changed, 36 insertions, 1 deletions
diff --git a/libbuild2/script/run.cxx b/libbuild2/script/run.cxx
index 182696b..90ddc4d 100644
--- a/libbuild2/script/run.cxx
+++ b/libbuild2/script/run.cxx
@@ -1552,8 +1552,20 @@ namespace build2
// Merge standard streams.
//
bool mo (out != nullptr && out->type == redirect_type::merge);
- if (mo || err.type == redirect_type::merge)
+ bool me (err.type == redirect_type::merge);
+
+ if (mo || me)
{
+ // Note that while the parser verifies that there is no stdout/stderr
+ // mutual redirects specified on the command line, we can still end up
+ // with mutual redirects here since one of such redirects can be
+ // provided as a default by the script environment implementation
+ // which the parser is not aware of at the time of parsing the command
+ // line.
+ //
+ if (mo && me)
+ fail (ll) << "stdout and stderr redirected to each other";
+
auto_fd& self (mo ? ofd.out : efd);
auto_fd& other (mo ? efd : ofd.out);
diff --git a/tests/recipe/buildscript/testscript b/tests/recipe/buildscript/testscript
index d1adc36..2603f62 100644
--- a/tests/recipe/buildscript/testscript
+++ b/tests/recipe/buildscript/testscript
@@ -83,6 +83,29 @@
$* clean 2>-
}
+ : mutual-redirects
+ :
+ {
+ echo 'bar' >=bar;
+
+ cat <<EOI >=buildfile;
+ foo: bar
+ % [diag=cp]
+ {{
+ echo 'copying' 2>&1
+ cp $path($<) $path($>)
+ }}
+ EOI
+
+ $* 2>>~%EOE% != 0;
+ cp file{foo}
+ buildfile:4:3: error: stdout and stderr redirected to each other
+ %.+
+ EOE
+
+ $* clean 2>-
+ }
+
: untracked-var
:
{