diff options
-rw-r--r-- | bdep/common.cli | 28 | ||||
-rw-r--r-- | bdep/init.cxx | 1 | ||||
-rw-r--r-- | bdep/types.hxx | 8 | ||||
-rw-r--r-- | bdep/utility.cxx | 10 | ||||
-rw-r--r-- | bdep/utility.hxx | 18 | ||||
-rw-r--r-- | 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 <bdep/types.hxx>; +include <bdep/types.hxx>; "\section=1" "\name=bdep-common-options" @@ -79,6 +78,29 @@ namespace bdep \li|Even more detailed information.||" } + path --bpkg + { + "<path>", + "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 + { + "<opt>", + "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 { "<path>", @@ -100,8 +122,6 @@ namespace bdep multiple build options." } - //@@ TODO: add --bpkg and --bpkg-option - string --pager // String to allow empty value. { "<path>", 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 <odb/sqlite/forward.hxx> #include <libbutl/path.mxx> +#include <libbutl/process.mxx> #include <libbutl/optional.mxx> #include <libbutl/fdstream.mxx> @@ -86,6 +87,13 @@ namespace bdep using paths = std::vector<path>; using dir_paths = std::vector<dir_path>; + // <libbutl/process.mxx> + // + using butl::process; + using butl::process_path; + using butl::process_exit; + using butl::process_error; + // <libbutl/fdstream.mxx> // 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 <libbutl/ft/lang.hxx> -#include <libbutl/utility.mxx> // casecmp(), reverse_iterate(), etc - +#include <libbutl/utility.mxx> // casecmp(), reverse_iterate(), etc #include <libbutl/filesystem.mxx> #include <bdep/types.hxx> @@ -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 <typename O, typename E, typename... A> + process + start_bpkg (const common_options&, O&& out, E&& err, A&&... args); + + template <typename... A> + 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 <iostream> // cin -#include <libbutl/fdstream.mxx> - #include <libbutl/manifest-parser.mxx> #include <libbutl/manifest-serializer.mxx> #include <bdep/diagnostics.hxx> +#include <bdep/common-options.hxx> namespace bdep { + // *_bpkg() + // + template <typename O, typename E, typename... A> + 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<O> (out), + forward<E> (err), + pp, + ops, + co.bpkg_option (), + forward<A> (args)...); + } + catch (const process_error& e) + { + fail << "unable to execute " << bpkg << ": " << e << endf; + } + } + + template <typename... A> + process_exit + run_bpkg (const common_options& co, A&&... args) + { + process pr (start_bpkg (co, + 1 /* stdout */, + 2 /* stderr */, + forward<A> (args)...)); + pr.wait (); + + const process_exit& e (*pr.exit); + + if (!e.normal ()) + fail << "process " << name_bpkg (co) << " " << e; + + return e; + } + // *_manifest() // template <typename T> |