From d369ab42f2d3bc52086dc7d9b79510dce5e80513 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 9 Mar 2018 16:21:14 +0200 Subject: Add support for executing bpkg --- bdep/common.cli | 28 ++++++++++++++++++---- bdep/init.cxx | 1 + bdep/types.hxx | 8 +++++++ bdep/utility.cxx | 10 +++++++- bdep/utility.hxx | 18 ++++++++++++-- bdep/utility.txx | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 128 insertions(+), 9 deletions(-) diff --git a/bdep/common.cli b/bdep/common.cli index 168233b..80c01db 100644 --- a/bdep/common.cli +++ b/bdep/common.cli @@ -2,8 +2,7 @@ // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -// @@ TODO -//include ; +include ; "\section=1" "\name=bdep-common-options" @@ -79,6 +78,29 @@ namespace bdep \li|Even more detailed information.||" } + path --bpkg + { + "", + "The package manager program to be used for build configuration + management. This should be the path to the \cb{bpkg} executable. You + can also specify additional options that should be passed to the + package manager program with \cb{--bpkg-option}. + + If the package manager program is not explicitly specified, then + \cb{bdep} will by default use \cb{bpkg} plus an executable suffix if + one was specified when building \cb{bdep}. So, for example, if + \cb{bdep} name was set to \cb{bdep-1.0}, then it will look for + \cb{bpkg-1.0}." + } + + strings --bpkg-option + { + "", + "Additional option to be passed to the package manager program. See + \cb{--bpkg} for more information on the package manager program. + Repeat this option to specify multiple package manager options." + } + path --build { "", @@ -100,8 +122,6 @@ namespace bdep multiple build options." } - //@@ TODO: add --bpkg and --bpkg-option - string --pager // String to allow empty value. { "", diff --git a/bdep/init.cxx b/bdep/init.cxx index 2355498..44eb37e 100644 --- a/bdep/init.cxx +++ b/bdep/init.cxx @@ -114,6 +114,7 @@ namespace bdep //@@ TODO: print project/package(s) being initialized. t.commit (); + return 0; } } diff --git a/bdep/types.hxx b/bdep/types.hxx index 4f3ec13..f4393ab 100644 --- a/bdep/types.hxx +++ b/bdep/types.hxx @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -86,6 +87,13 @@ namespace bdep using paths = std::vector; using dir_paths = std::vector; + // + // + using butl::process; + using butl::process_path; + using butl::process_exit; + using butl::process_error; + // // using butl::auto_fd; diff --git a/bdep/utility.cxx b/bdep/utility.cxx index 0ed41b9..f8ef1df 100644 --- a/bdep/utility.cxx +++ b/bdep/utility.cxx @@ -26,6 +26,8 @@ namespace bdep const path repositories_file ("repositories.manifest"); const path configurations_file ("configurations.manifest"); + dir_path exec_dir; + bool exists (const path& f, bool ignore_error) { @@ -98,5 +100,11 @@ namespace bdep } } - dir_path exec_dir; + const char* + name_bpkg (const common_options& co) + { + return co.bpkg_specified () + ? co.bpkg ().string ().c_str () + : "bpkg" BDEP_EXE_SUFFIX; + } } diff --git a/bdep/utility.hxx b/bdep/utility.hxx index af85355..36a405c 100644 --- a/bdep/utility.hxx +++ b/bdep/utility.hxx @@ -14,8 +14,7 @@ #include -#include // casecmp(), reverse_iterate(), etc - +#include // casecmp(), reverse_iterate(), etc #include #include @@ -89,6 +88,21 @@ namespace bdep void rm (const path&, uint16_t verbosity = 3); + // Run the bpkg process. + // + class common_options; + + const char* + name_bpkg (const common_options&); + + template + process + start_bpkg (const common_options&, O&& out, E&& err, A&&... args); + + template + process_exit + run_bpkg (const common_options&, A&&... args); + // Manifest parsing and serialization. // // For parsing, if path is '-', then read from stdin. diff --git a/bdep/utility.txx b/bdep/utility.txx index 38f0e35..9256bc7 100644 --- a/bdep/utility.txx +++ b/bdep/utility.txx @@ -4,15 +4,83 @@ #include // cin -#include - #include #include #include +#include namespace bdep { + // *_bpkg() + // + template + process + start_bpkg (const common_options& co, + O&& out, + E&& err, + A&&... args) + { + const char* bpkg (name_bpkg (co)); + + try + { + process_path pp (process::path_search (bpkg, exec_dir)); + + // Forward our --build* options. + // + cstrings ops; + + if (co.build_specified ()) + { + ops.push_back ("--build"); + ops.push_back (co.build ().string ().c_str ()); + } + + for (const string& o: co.build_option ()) + { + ops.push_back ("--build-option"); + ops.push_back (o.c_str ()); + } + + return process_start_callback ( + [] (const char* const args[], size_t n) + { + if (verb >= 2) + print_process (args, n); + }, + 0 /* stdin */, + forward (out), + forward (err), + pp, + ops, + co.bpkg_option (), + forward (args)...); + } + catch (const process_error& e) + { + fail << "unable to execute " << bpkg << ": " << e << endf; + } + } + + template + process_exit + run_bpkg (const common_options& co, A&&... args) + { + process pr (start_bpkg (co, + 1 /* stdout */, + 2 /* stderr */, + forward (args)...)); + pr.wait (); + + const process_exit& e (*pr.exit); + + if (!e.normal ()) + fail << "process " << name_bpkg (co) << " " << e; + + return e; + } + // *_manifest() // template -- cgit v1.1