From 2df57d72b65012674e6bc64dec66d9b3fd7f993b Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 14 May 2018 14:10:56 +0300 Subject: Fallback to output directory removal for --keep-out on disfigure failure --- bpkg/satisfaction.cxx | 63 +++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 37 deletions(-) (limited to 'bpkg/satisfaction.cxx') diff --git a/bpkg/satisfaction.cxx b/bpkg/satisfaction.cxx index 9211ac0..8a61145 100644 --- a/bpkg/satisfaction.cxx +++ b/bpkg/satisfaction.cxx @@ -6,7 +6,6 @@ #include -#include #include #include @@ -100,7 +99,7 @@ namespace bpkg static version build2_version; void - satisfy_build2 (const common_options& co, + satisfy_build2 (const common_options& o, const string& pkg, const dependency& d) { @@ -110,53 +109,43 @@ namespace bpkg // if (build2_version.empty ()) { - const char* args[] = {name_b (co), "--version", nullptr}; + fdpipe pipe (open_pipe ()); - try - { - process_path pp (process::path_search (args[0], exec_dir)); + process pr (start_b (o, + pipe, 2 /* stderr */, + verb_b::quiet, + "--version")); - if (verb >= 3) - print_process (args); + // Shouldn't throw, unless something is severely damaged. + // + pipe.out.close (); - process pr (pp, args, 0, -1); // Redirect STDOUT to pipe. + string l; + try + { + ifdstream is (move (pipe.in), fdstream_mode::skip); + getline (is, l); + is.close (); - string l; - try + if (pr.wait () && l.compare (0, 7, "build2 ") == 0) { - ifdstream is (move (pr.in_ofd), fdstream_mode::skip); - getline (is, l); - is.close (); - - if (pr.wait () && l.compare (0, 7, "build2 ") == 0) + try { - try - { - build2_version = version (string (l, 7)); - } - catch (const invalid_argument&) {} // Fall through. + build2_version = version (string (l, 7)); } - - // Fall through. - } - catch (const io_error&) - { - pr.wait (); - // Fall through. + catch (const invalid_argument&) {} // Fall through. } - if (build2_version.empty ()) - fail << "unable to determine build2 version of " << args[0]; + // Fall through. } - catch (const process_error& e) + catch (const io_error&) { - error << "unable to execute " << args[0] << ": " << e; - - if (e.child) - exit (1); - - throw failed (); + pr.wait (); + // Fall through. } + + if (build2_version.empty ()) + fail << "unable to determine build2 version of " << name_b (o); } if (!satisfies (build2_version, d.constraint)) -- cgit v1.1