From 9accdefc33940d713828195313ca1a0eb0de030f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 18 Sep 2015 07:50:38 +0200 Subject: Generalize pkg_update() to pkg_command() to be used for clean, test, etc --- bpkg/buildfile | 51 +++++++++++++++++++++----------- bpkg/pkg-command | 21 ++++++++++++++ bpkg/pkg-command.cxx | 66 ++++++++++++++++++++++++++++++++++++++++++ bpkg/pkg-common-options.cli | 18 ++++++++++++ bpkg/pkg-configure-options.cli | 10 ++----- bpkg/pkg-disfigure-options.cli | 10 ++----- bpkg/pkg-fetch-options.cli | 11 ++----- bpkg/pkg-purge-options.cli | 11 ++----- bpkg/pkg-status-options.cli | 10 ++----- bpkg/pkg-unpack-options.cli | 11 ++----- bpkg/pkg-update | 8 +++-- bpkg/pkg-update-options.cli | 10 ++----- bpkg/pkg-update.cxx | 64 ---------------------------------------- 13 files changed, 159 insertions(+), 142 deletions(-) create mode 100644 bpkg/pkg-command create mode 100644 bpkg/pkg-command.cxx create mode 100644 bpkg/pkg-common-options.cli delete mode 100644 bpkg/pkg-update.cxx diff --git a/bpkg/buildfile b/bpkg/buildfile index e8f156e..2e840ca 100644 --- a/bpkg/buildfile +++ b/bpkg/buildfile @@ -13,6 +13,8 @@ exe{bpkg}: cxx{package package-odb database diagnostics utility} \ cli.cxx{common-options} cxx{types-parsers} \ cxx{bpkg} cli.cxx{bpkg-options} \ cxx{help} cli.cxx{help-options} \ + cli.cxx{pkg-common-options} \ + cxx{pkg-command} \ cxx{pkg-verify} cli.cxx{pkg-verify-options} \ cxx{pkg-status} cli.cxx{pkg-status-options} \ cxx{pkg-fetch} cli.cxx{pkg-fetch-options} \ @@ -20,34 +22,49 @@ exe{bpkg}: cxx{package package-odb database diagnostics utility} \ cxx{pkg-purge} cli.cxx{pkg-purge-options} \ cxx{pkg-configure} cli.cxx{pkg-configure-options} \ cxx{pkg-disfigure} cli.cxx{pkg-disfigure-options} \ - cxx{pkg-update} cli.cxx{pkg-update-options} \ + cli.cxx{pkg-update-options} \ cxx{cfg-create} cli.cxx{cfg-create-options} \ cxx{rep-create} cli.cxx{rep-create-options} \ $libs +# Option length must be the same to get commands/topics/options aligned. +# cli.options += -I $src_root --include-with-brackets --include-prefix bpkg \ --guard-prefix BPKG --cxx-prologue "#include " \ --cli-namespace bpkg::cli --generate-file-scanner --generate-specifier \ ---generate-parse --long-usage --exclude-base +--generate-parse --long-usage --option-length 22 -# Option length must be the same to get commands/topics/options lists -# aligned in the general help. -# cli.cxx{common-options}: cli{common-options} -cli.cxx{common-options}: cli.options += --option-length 22 --short-usage +cli.cxx{common-options}: cli.options += --short-usage cli.cxx{bpkg-options}: cli{bpkg-options} -cli.cxx{bpkg-options}: cli.options += --option-length 22 --short-usage +cli.cxx{bpkg-options}: cli.options += --short-usage cli.cxx{help-options}: cli{help-options} +cli.cxx{help-options}: cli.options += --exclude-base + +# pkg-* +# +cli.cxx{pkg-common-options}: cli{pkg-common-options} +cli.cxx{pkg-common-options}: cli.options += --exclude-base + +cli.cxx{pkg-status-options}: cli{pkg-status-options} +cli.cxx{pkg-fetch-options}: cli{pkg-fetch-options} +cli.cxx{pkg-unpack-options}: cli{pkg-unpack-options} +cli.cxx{pkg-purge-options}: cli{pkg-purge-options} +cli.cxx{pkg-configure-options}: cli{pkg-configure-options} +cli.cxx{pkg-disfigure-options}: cli{pkg-disfigure-options} +cli.cxx{pkg-update-options}: cli{pkg-update-options} -cli.cxx{pkg-verify-options}: cli{pkg-verify-options} -cli.cxx{pkg-status-options}: cli{pkg-status-options} -cli.cxx{pkg-fetch-options}: cli{pkg-fetch-options} -cli.cxx{pkg-unpack-options}: cli{pkg-unpack-options} -cli.cxx{pkg-purge-options}: cli{pkg-purge-options} -cli.cxx{pkg-configure-options}: cli{pkg-configure-options} -cli.cxx{pkg-disfigure-options}: cli{pkg-disfigure-options} -cli.cxx{pkg-update-options}: cli{pkg-update-options} -cli.cxx{cfg-create-options}: cli{cfg-create-options} -cli.cxx{rep-create-options}: cli{rep-create-options} +cli.cxx{pkg-verify-options}: cli{pkg-verify-options} +cli.cxx{pkg-verify-options}: cli.options += --exclude-base + +# cfg-* +# +cli.cxx{cfg-create-options}: cli{cfg-create-options} +cli.cxx{cfg-create-options}: cli.options += --exclude-base + +# rep-* +# +cli.cxx{rep-create-options}: cli{rep-create-options} +cli.cxx{rep-create-options}: cli.options += --exclude-base diff --git a/bpkg/pkg-command b/bpkg/pkg-command new file mode 100644 index 0000000..225a112 --- /dev/null +++ b/bpkg/pkg-command @@ -0,0 +1,21 @@ +// file : bpkg/pkg-command -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_PKG_COMMAND +#define BPKG_PKG_COMMAND + +#include +#include + +namespace bpkg +{ + // Common pkg-{update,clean,test,install,...} implementation. + // + void + pkg_command (const string& cmd, // Without the 'pkg-' prefix. + const pkg_common_options&, + cli::scanner& args); +} + +#endif // BPKG_PKG_COMMAND diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx new file mode 100644 index 0000000..b4e2893 --- /dev/null +++ b/bpkg/pkg-command.cxx @@ -0,0 +1,66 @@ +// file : bpkg/pkg-command.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace butl; + +namespace bpkg +{ + void + pkg_command (const string& cmd, + const pkg_common_options& o, + cli::scanner& args) + { + tracer trace ("pkg_command"); + level4 ([&]{trace << "command: " << cmd;}); + + const dir_path& c (o.directory ()); + level4 ([&]{trace << "configuration: " << c;}); + + if (!args.more ()) + fail << "package name argument expected" << + info << "run 'bpkg help pkg-" << cmd << "' for more information"; + + string n (args.next ()); + + database db (open (c, trace)); + + transaction t (db.begin ()); + shared_ptr p (db.find (n)); + t.commit (); + + if (p == nullptr) + fail << "package " << n << " does not exist in configuration " << c; + + if (p->state != state::configured) + fail << "package " << n << " is " << p->state << + info << "expected it to be configured"; + + level4 ([&]{trace << p->name << " " << p->version;}); + + assert (p->out_root); // Should be present since configured. + dir_path out_root (c / *p->out_root); // Always relative. + level4 ([&]{trace << "out_root: " << out_root;}); + + // Form the buildspec. + // + string bspec (cmd + "(" + out_root.string () + "/)"); + level4 ([&]{trace << "buildspec: " << bspec;}); + + run_b (bspec); + + if (verb) + text << cmd << (cmd.back () != 'e' ? "ed " : "d ") + << p->name << " " << p->version; + } +} diff --git a/bpkg/pkg-common-options.cli b/bpkg/pkg-common-options.cli new file mode 100644 index 0000000..d7097ff --- /dev/null +++ b/bpkg/pkg-common-options.cli @@ -0,0 +1,18 @@ +// file : bpkg/pkg-common-options.cli +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +include ; + +namespace bpkg +{ + class pkg_common_options: common_options + { + dir_path --directory|-d (".") + { + "", + "Assume configuration is in rather than in the current working + directory." + }; + }; +} diff --git a/bpkg/pkg-configure-options.cli b/bpkg/pkg-configure-options.cli index d1850c6..85e4fa9 100644 --- a/bpkg/pkg-configure-options.cli +++ b/bpkg/pkg-configure-options.cli @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -include ; +include ; /* "\section=1" @@ -24,13 +24,7 @@ after the package name." namespace bpkg { - class pkg_configure_options: common_options + class pkg_configure_options: pkg_common_options { - dir_path --directory|-d (".") - { - "", - "Assume configuration is in rather than in the current working - directory." - }; }; } diff --git a/bpkg/pkg-disfigure-options.cli b/bpkg/pkg-disfigure-options.cli index 7e451e8..9ffe20b 100644 --- a/bpkg/pkg-disfigure-options.cli +++ b/bpkg/pkg-disfigure-options.cli @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -include ; +include ; /* "\section=1" @@ -20,13 +20,7 @@ The \cb{pkg-disfigure} command disfigures the previously configured namespace bpkg { - class pkg_disfigure_options: common_options + class pkg_disfigure_options: pkg_common_options { - dir_path --directory|-d (".") - { - "", - "Assume configuration is in rather than in the current working - directory." - }; }; } diff --git a/bpkg/pkg-fetch-options.cli b/bpkg/pkg-fetch-options.cli index 0ad0531..54a2f50 100644 --- a/bpkg/pkg-fetch-options.cli +++ b/bpkg/pkg-fetch-options.cli @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -include ; +include ; /* "\section=1" @@ -27,15 +27,8 @@ attempt to remove the archive when the package is purged with the namespace bpkg { - class pkg_fetch_options: common_options + class pkg_fetch_options: pkg_common_options { - dir_path --directory|-d (".") - { - "", - "Assume configuration is in rather than in the current working - directory." - }; - bool --existing|-e { "Treat the argument as an existing package archive path rather than diff --git a/bpkg/pkg-purge-options.cli b/bpkg/pkg-purge-options.cli index 8d7d61b..2341b74 100644 --- a/bpkg/pkg-purge-options.cli +++ b/bpkg/pkg-purge-options.cli @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -include ; +include ; /* "\section=1" @@ -26,15 +26,8 @@ this mode)." namespace bpkg { - class pkg_purge_options: common_options + class pkg_purge_options: pkg_common_options { - dir_path --directory|-d (".") - { - "", - "Assume configuration is in rather than in the current working - directory." - }; - bool --keep|-k { "Keep the package archive. Note that in this mode the package is diff --git a/bpkg/pkg-status-options.cli b/bpkg/pkg-status-options.cli index 700f5fa..b094e34 100644 --- a/bpkg/pkg-status-options.cli +++ b/bpkg/pkg-status-options.cli @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -include ; +include ; /* "\section=1" @@ -22,13 +22,7 @@ Note that the status is written to \cb{STDOUT}, not \cb{STDERR}. namespace bpkg { - class pkg_status_options: common_options + class pkg_status_options: pkg_common_options { - dir_path --directory|-d (".") - { - "", - "Assume configuration is in rather than in the current working - directory." - }; }; } diff --git a/bpkg/pkg-unpack-options.cli b/bpkg/pkg-unpack-options.cli index 7ffcc62..06fda13 100644 --- a/bpkg/pkg-unpack-options.cli +++ b/bpkg/pkg-unpack-options.cli @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -include ; +include ; /* "\section=1" @@ -27,15 +27,8 @@ command." namespace bpkg { - class pkg_unpack_options: common_options + class pkg_unpack_options: pkg_common_options { - dir_path --directory|-d (".") - { - "", - "Assume configuration is in rather than in the current working - directory." - }; - bool --existing|-e { "Treat the argument as an existing package directory path rather than diff --git a/bpkg/pkg-update b/bpkg/pkg-update index 0ff4b0d..4c89e66 100644 --- a/bpkg/pkg-update +++ b/bpkg/pkg-update @@ -6,12 +6,16 @@ #define BPKG_PKG_UPDATE #include +#include #include namespace bpkg { - void - pkg_update (const pkg_update_options&, cli::scanner& args); + inline void + pkg_update (const pkg_update_options& o, cli::scanner& args) + { + pkg_command ("update", o, args); + } } #endif // BPKG_PKG_UPDATE diff --git a/bpkg/pkg-update-options.cli b/bpkg/pkg-update-options.cli index e9fbbb2..d259ce3 100644 --- a/bpkg/pkg-update-options.cli +++ b/bpkg/pkg-update-options.cli @@ -2,7 +2,7 @@ // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file -include ; +include ; /* "\section=1" @@ -21,13 +21,7 @@ do much more than run (\cb{b update})." namespace bpkg { - class pkg_update_options: common_options + class pkg_update_options: pkg_common_options { - dir_path --directory|-d (".") - { - "", - "Assume configuration is in rather than in the current working - directory." - }; }; } diff --git a/bpkg/pkg-update.cxx b/bpkg/pkg-update.cxx deleted file mode 100644 index 015a628..0000000 --- a/bpkg/pkg-update.cxx +++ /dev/null @@ -1,64 +0,0 @@ -// file : bpkg/pkg-update.cxx -*- C++ -*- -// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd -// license : MIT; see accompanying LICENSE file - -#include - -#include -#include -#include -#include -#include -#include - -using namespace std; -using namespace butl; - -namespace bpkg -{ - void - pkg_update (const pkg_update_options& o, cli::scanner& args) - { - tracer trace ("pkg_update"); - - const dir_path& c (o.directory ()); - level4 ([&]{trace << "configuration: " << c;}); - - if (!args.more ()) - fail << "package name argument expected" << - info << "run 'bpkg help pkg-update' for more information"; - - string n (args.next ()); - - database db (open (c, trace)); - - transaction t (db.begin ()); - shared_ptr p (db.find (n)); - t.commit (); - - if (p == nullptr) - fail << "package " << n << " does not exist in configuration " << c; - - if (p->state != state::configured) - fail << "package " << n << " is " << p->state << - info << "expected it to be configured"; - - level4 ([&]{trace << p->name << " " << p->version;}); - - assert (p->out_root); // Should be present since configured. - dir_path out_root (c / *p->out_root); // Always relative. - level4 ([&]{trace << "out_root: " << out_root;}); - - // Form the buildspec. - // - string bspec ("update(" + out_root.string () + "/)"); - level4 ([&]{trace << "buildspec: " << bspec;}); - - // Update. - // - run_b (bspec); - - if (verb) - text << "updated " << p->name << " " << p->version; - } -} -- cgit v1.1