diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-05-19 14:50:16 +0300 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-05-27 08:35:29 +0200 |
commit | db05f8ead4c2b5ef8a27c3ffc6b20c291b0e7c8c (patch) | |
tree | 5bed4bd0901e6abd728b53bbeed31489af4d1e4b /libbuild2/script/script.cxx | |
parent | 9054e7e2fd59e2222258e2dce3a3300c8d16fb05 (diff) |
Set proper build script command default redirects
Also add printing of set and exit pseudo-builtin command arguments for
verb >= 2 as we do for normal builtins.
Diffstat (limited to 'libbuild2/script/script.cxx')
-rw-r--r-- | libbuild2/script/script.cxx | 102 |
1 files changed, 79 insertions, 23 deletions
diff --git a/libbuild2/script/script.cxx b/libbuild2/script/script.cxx index db34084..349b05e 100644 --- a/libbuild2/script/script.cxx +++ b/libbuild2/script/script.cxx @@ -272,14 +272,17 @@ namespace build2 // Redirects. // - if (c.in.effective ().type != redirect_type::none) - print_redirect (c.in.effective (), "<"); + // Print the none redirect (no data allowed) if/when the respective + // syntax is invened. + // + if (c.in && c.in->effective ().type != redirect_type::none) + print_redirect (c.in->effective (), "<"); - if (c.out.effective ().type != redirect_type::none) - print_redirect (c.out.effective (), ">"); + if (c.out && c.out->effective ().type != redirect_type::none) + print_redirect (c.out->effective (), ">"); - if (c.err.effective ().type != redirect_type::none) - print_redirect (c.err.effective (), "2>"); + if (c.err && c.err->effective ().type != redirect_type::none) + print_redirect (c.err->effective (), "2>"); for (const auto& p: c.cleanups) { @@ -307,17 +310,20 @@ namespace build2 { // Here-documents. // - if (c.in.type == redirect_type::here_doc_literal || - c.in.type == redirect_type::here_doc_regex) - print_doc (c.in); - - if (c.out.type == redirect_type::here_doc_literal || - c.out.type == redirect_type::here_doc_regex) - print_doc (c.out); - - if (c.err.type == redirect_type::here_doc_literal || - c.err.type == redirect_type::here_doc_regex) - print_doc (c.err); + if (c.in && + (c.in->type == redirect_type::here_doc_literal || + c.in->type == redirect_type::here_doc_regex)) + print_doc (*c.in); + + if (c.out && + (c.out->type == redirect_type::here_doc_literal || + c.out->type == redirect_type::here_doc_regex)) + print_doc (*c.out); + + if (c.err && + (c.err->type == redirect_type::here_doc_literal || + c.err->type == redirect_type::here_doc_regex)) + print_doc (*c.err); } } @@ -400,7 +406,7 @@ namespace build2 } redirect:: - redirect (redirect&& r) + redirect (redirect&& r) noexcept : type (r.type), modifiers (move (r.modifiers)), end (move (r.end)), @@ -441,6 +447,17 @@ namespace build2 } } + redirect& redirect:: + operator= (redirect&& r) noexcept + { + if (this != &r) + { + this->~redirect (); + new (this) redirect (move (r)); // Assume noexcept move-constructor. + } + return *this; + } + redirect:: ~redirect () { @@ -468,14 +485,53 @@ namespace build2 } } - redirect& redirect:: - operator= (redirect&& r) + redirect:: + redirect (const redirect& r) + : type (r.type), + modifiers (r.modifiers), + end (r.end), + end_line (r.end_line), + end_column (r.end_column) { - if (this != &r) + switch (type) { - this->~redirect (); - new (this) redirect (move (r)); // Assume noexcept move-constructor. + case redirect_type::none: + case redirect_type::pass: + case redirect_type::null: + case redirect_type::trace: break; + + case redirect_type::merge: fd = r.fd; break; + + case redirect_type::here_str_literal: + case redirect_type::here_doc_literal: + { + new (&str) string (r.str); + break; + } + case redirect_type::here_str_regex: + case redirect_type::here_doc_regex: + { + new (®ex) regex_lines (r.regex); + break; + } + case redirect_type::file: + { + new (&file) file_type (r.file); + break; + } + case redirect_type::here_doc_ref: + { + new (&ref) reference_wrapper<const redirect> (r.ref); + break; + } } + } + + redirect& redirect:: + operator= (const redirect& r) + { + if (this != &r) + *this = redirect (r); // Reduce to move-assignment. return *this; } |