diff options
-rw-r--r-- | bpkg/pkg-command | 8 | ||||
-rw-r--r-- | bpkg/pkg-command.cxx | 77 | ||||
-rw-r--r-- | bpkg/types | 6 |
3 files changed, 73 insertions, 18 deletions
diff --git a/bpkg/pkg-command b/bpkg/pkg-command index 4acbdf4..fca85c0 100644 --- a/bpkg/pkg-command +++ b/bpkg/pkg-command @@ -6,6 +6,8 @@ #define BPKG_PKG_COMMAND #include <bpkg/types> +#include <bpkg/utility> + #include <bpkg/forward> // selected_package #include <bpkg/configuration-options> @@ -23,6 +25,12 @@ namespace bpkg const dir_path& configuration, const common_options&, const shared_ptr<selected_package>&); + + void + pkg_command (const string& cmd, + const dir_path& configuration, + const common_options&, + const vector<shared_ptr<selected_package>>&); } #endif // BPKG_PKG_COMMAND diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index 281b326..c52038c 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -24,11 +24,11 @@ namespace bpkg { tracer trace ("pkg_command"); + level4 ([&]{trace << "command: " << cmd;}); + assert (p->state == package_state::configured); assert (p->out_root); // Should be present since configured. - level4 ([&]{trace << "command: " << cmd;}); - dir_path out_root (c / *p->out_root); // Always relative. level4 ([&]{trace << "out_root: " << out_root;}); @@ -40,6 +40,41 @@ namespace bpkg run_b (o, bspec); } + void + pkg_command (const string& cmd, + const dir_path& c, + const common_options& o, + const vector<shared_ptr<selected_package>>& ps) + { + tracer trace ("pkg_command"); + + level4 ([&]{trace << "command: " << cmd;}); + + // Form the buildspec. + // + string bspec (cmd + "("); + + for (const shared_ptr<selected_package>& p: ps) + { + assert (p->state == package_state::configured); + assert (p->out_root); // Should be present since configured. + + dir_path out_root (c / *p->out_root); // Always relative. + level4 ([&]{trace << p->name << " out_root: " << out_root;}); + + if (bspec.back () != '(') + bspec += ' '; + bspec += out_root.string (); + bspec += '/'; + } + + bspec += ')'; + + level4 ([&]{trace << "buildspec: " << bspec;}); + + run_b (o, bspec); + } + int pkg_command (const string& cmd, const configuration_options& o, @@ -54,28 +89,38 @@ namespace bpkg fail << "package name argument expected" << info << "run 'bpkg help pkg-" << cmd << "' for more information"; - string n (args.next ()); + vector<shared_ptr<selected_package>> ps; + { + database db (open (c, trace)); + transaction t (db.begin ()); - database db (open (c, trace)); + while (args.more ()) + { + string n (args.next ()); + shared_ptr<selected_package> p (db.find<selected_package> (n)); - transaction t (db.begin ()); - shared_ptr<selected_package> p (db.find<selected_package> (n)); - t.commit (); + if (p == nullptr) + fail << "package " << n << " does not exist in configuration " << c; - if (p == nullptr) - fail << "package " << n << " does not exist in configuration " << c; + if (p->state != package_state::configured) + fail << "package " << n << " is " << p->state << + info << "expected it to be configured"; - if (p->state != package_state::configured) - fail << "package " << n << " is " << p->state << - info << "expected it to be configured"; + level4 ([&]{trace << p->name << " " << p->version;}); + ps.push_back (move (p)); + } - level4 ([&]{trace << p->name << " " << p->version;}); + t.commit (); + } - pkg_command (cmd, c, o, p); + pkg_command (cmd, c, o, ps); if (verb) - text << cmd << (cmd.back () != 'e' ? "ed " : "d ") - << p->name << " " << p->version; + { + for (const shared_ptr<selected_package>& p: ps) + text << cmd << (cmd.back () != 'e' ? "ed " : "d ") + << p->name << " " << p->version; + } return 0; } @@ -28,8 +28,10 @@ namespace bpkg using std::size_t; using std::string; - using strings = std::vector<string>; - using cstrings = std::vector<const char*>; + using std::vector; + + using strings = vector<string>; + using cstrings = vector<const char*>; using butl::optional; using butl::nullopt; |