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/manifest-utility.cxx | 120 ++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 73 deletions(-) (limited to 'bpkg/manifest-utility.cxx') diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx index 0f64b30..0e0c792 100644 --- a/bpkg/manifest-utility.cxx +++ b/bpkg/manifest-utility.cxx @@ -6,8 +6,6 @@ #include #include -#include -#include // operator<<(ostream, process_path) #include #include @@ -200,92 +198,68 @@ namespace bpkg optional package_version (const common_options& o, const dir_path& d) { - const char* b (name_b (o)); + fdpipe pipe (open_pipe ()); + + process pr (start_b (o, + pipe, 2 /* stderr */, + verb_b::quiet, + "info:", + d.representation ())); + + // Shouldn't throw, unless something is severely damaged. + // + pipe.out.close (); try { - process_path pp (process::path_search (b, exec_dir)); - - fdpipe pipe (open_pipe ()); - - process pr ( - process_start_callback ( - [] (const char* const args[], size_t n) - { - if (verb >= 2) - print_process (args, n); - }, - 0 /* stdin */, pipe /* stdout */, 2 /* stderr */, - pp, - - verb < 2 - ? strings ({"-q"}) - : verb == 2 - ? strings ({"-v"}) - : strings ({"--verbose", to_string (verb)}), - - o.build_option (), - "info:", - d.representation ())); - - // Shouldn't throw, unless something is severely damaged. - // - pipe.out.close (); + optional r; - try + ifdstream is (move (pipe.in), + fdstream_mode::skip, + ifdstream::badbit); + + for (string l; !eof (getline (is, l)); ) { - optional r; + if (l.compare (0, 9, "version: ") == 0) + try + { + string v (l, 9); - ifdstream is (move (pipe.in), - fdstream_mode::skip, - ifdstream::badbit); + // An empty version indicates that the version module is not + // enabled for the project. + // + if (!v.empty ()) + r = version (v); - for (string l; !eof (getline (is, l)); ) + break; + } + catch (const invalid_argument&) { - if (l.compare (0, 9, "version: ") == 0) - try - { - string v (l, 9); - - // An empty version indicates that the version module is not - // enabled for the project. - // - if (!v.empty ()) - r = version (v); - - break; - } - catch (const invalid_argument&) - { - fail << "no package version in '" << l << "'" << - info << "produced by '" << pp << "'; use --build to override"; - } + fail << "no package version in '" << l << "'" << + info << "produced by '" << name_b (o) << "'; use --build to " + << "override"; } - - is.close (); - - if (pr.wait ()) - return r; - - // Fall through. } - catch (const io_error&) - { - if (pr.wait ()) - fail << "unable to read '" << b << "' output"; - // Fall through. - } + is.close (); - // We should only get here if the child exited with an error status. - // - assert (!pr.wait ()); + if (pr.wait ()) + return r; - fail << "unable to obtain version using '" << b << "'" << endf; + // Fall through. } - catch (const process_error& e) + catch (const io_error&) { - fail << "unable to execute '" << b << "': " << e << endf; + if (pr.wait ()) + fail << "unable to read '" << name_b (o) << "' output"; + + // Fall through. } + + // We should only get here if the child exited with an error status. + // + assert (!pr.wait ()); + + fail << "unable to obtain version using '" << name_b (o) << "'" << endf; } } -- cgit v1.1