aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-18 06:59:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-18 06:59:28 +0200
commitcae11509203061e894e6310c35ea50ae818af3a7 (patch)
treee9d38297725b9d8ef4442366432cdee8f9ccf28c
parentb18e54a088e84ed31f320d69b904af3f999adb2b (diff)
Implement pkg-update command
-rw-r--r--bpkg/bpkg-options.cli7
-rw-r--r--bpkg/bpkg.cxx2
-rw-r--r--bpkg/buildfile2
-rw-r--r--bpkg/cfg-create.cxx2
-rw-r--r--bpkg/pkg-configure.cxx2
-rw-r--r--bpkg/pkg-disfigure.cxx2
-rw-r--r--bpkg/pkg-update17
-rw-r--r--bpkg/pkg-update-options.cli33
-rw-r--r--bpkg/pkg-update.cxx64
-rwxr-xr-xbpkg/test.sh29
-rw-r--r--bpkg/utility7
-rw-r--r--bpkg/utility.cxx6
12 files changed, 165 insertions, 8 deletions
diff --git a/bpkg/bpkg-options.cli b/bpkg/bpkg-options.cli
index e694c3b..9e2e6b2 100644
--- a/bpkg/bpkg-options.cli
+++ b/bpkg/bpkg-options.cli
@@ -70,6 +70,13 @@ namespace bpkg
""
};
+ bool pkg-update
+ {
+ "<pkg>",
+ "Update package.",
+ ""
+ };
+
bool cfg-create
{
"[<conf>]",
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index a6862c4..0df2613 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -22,6 +22,7 @@
#include <bpkg/pkg-purge>
#include <bpkg/pkg-configure>
#include <bpkg/pkg-disfigure>
+#include <bpkg/pkg-update>
#include <bpkg/cfg-create>
#include <bpkg/rep-create>
@@ -179,6 +180,7 @@ try
PKG_COMMAND (purge);
PKG_COMMAND (configure);
PKG_COMMAND (disfigure);
+ PKG_COMMAND (update);
// cfg-* commands
//
diff --git a/bpkg/buildfile b/bpkg/buildfile
index b24fedb..e8f156e 100644
--- a/bpkg/buildfile
+++ b/bpkg/buildfile
@@ -20,6 +20,7 @@ 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} \
cxx{cfg-create} cli.cxx{cfg-create-options} \
cxx{rep-create} cli.cxx{rep-create-options} \
$libs
@@ -47,5 +48,6 @@ 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}
diff --git a/bpkg/cfg-create.cxx b/bpkg/cfg-create.cxx
index d780657..44728b8 100644
--- a/bpkg/cfg-create.cxx
+++ b/bpkg/cfg-create.cxx
@@ -112,7 +112,7 @@ namespace bpkg
// Configure.
//
- run_b ("configure(" + c.string () + "/)", vars);
+ run_b ("configure(" + c.string () + "/)", true, vars); // Run quiet.
// Create the database.
//
diff --git a/bpkg/pkg-configure.cxx b/bpkg/pkg-configure.cxx
index 65355ba..169772c 100644
--- a/bpkg/pkg-configure.cxx
+++ b/bpkg/pkg-configure.cxx
@@ -90,7 +90,7 @@ namespace bpkg
//
try
{
- run_b (bspec);
+ run_b (bspec, true, vars); // Run quiet.
}
catch (const failed&)
{
diff --git a/bpkg/pkg-disfigure.cxx b/bpkg/pkg-disfigure.cxx
index fca5dd7..e064cba 100644
--- a/bpkg/pkg-disfigure.cxx
+++ b/bpkg/pkg-disfigure.cxx
@@ -69,7 +69,7 @@ namespace bpkg
try
{
if (exists (out_root))
- run_b (bspec);
+ run_b (bspec, true); // Run quiet.
// Make sure the out directory is gone unless it is the same as src.
//
diff --git a/bpkg/pkg-update b/bpkg/pkg-update
new file mode 100644
index 0000000..0ff4b0d
--- /dev/null
+++ b/bpkg/pkg-update
@@ -0,0 +1,17 @@
+// file : bpkg/pkg-update -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BPKG_PKG_UPDATE
+#define BPKG_PKG_UPDATE
+
+#include <bpkg/types>
+#include <bpkg/pkg-update-options>
+
+namespace bpkg
+{
+ void
+ pkg_update (const pkg_update_options&, cli::scanner& args);
+}
+
+#endif // BPKG_PKG_UPDATE
diff --git a/bpkg/pkg-update-options.cli b/bpkg/pkg-update-options.cli
new file mode 100644
index 0000000..e9fbbb2
--- /dev/null
+++ b/bpkg/pkg-update-options.cli
@@ -0,0 +1,33 @@
+// file : bpkg/pkg-update-options.cli
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+include <bpkg/common-options.cli>;
+
+/*
+"\section=1"
+"\name=bpkg-pkg-update"
+
+"\h{SYNOPSIS}
+
+bpkg pkg-update <pkg>"
+
+"\h{DESCRIPTION}
+
+The \cb{pkg-update} command updates the previously configured
+(\cb{pkg-configure}) package. Underneath, this command doesn't
+do much more than run (\cb{b update})."
+*/
+
+namespace bpkg
+{
+ class pkg_update_options: common_options
+ {
+ dir_path --directory|-d (".")
+ {
+ "<dir>",
+ "Assume configuration is in <dir> rather than in the current working
+ directory."
+ };
+ };
+}
diff --git a/bpkg/pkg-update.cxx b/bpkg/pkg-update.cxx
new file mode 100644
index 0000000..015a628
--- /dev/null
+++ b/bpkg/pkg-update.cxx
@@ -0,0 +1,64 @@
+// file : bpkg/pkg-update.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <bpkg/pkg-update>
+
+#include <bpkg/types>
+#include <bpkg/package>
+#include <bpkg/package-odb>
+#include <bpkg/utility>
+#include <bpkg/database>
+#include <bpkg/diagnostics>
+
+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<package> p (db.find<package> (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;
+ }
+}
diff --git a/bpkg/test.sh b/bpkg/test.sh
index 66ff1ad..b7282b6 100755
--- a/bpkg/test.sh
+++ b/bpkg/test.sh
@@ -262,3 +262,32 @@ chmod 755 $out $out/build
rm -r $out
test pkg-purge -f $pkg
stat unknown
+
+##
+## pkg-update
+##
+
+fail pkg-update # package name expected
+fail pkg-update $pkg # no such package
+test pkg-fetch -e $pkga
+fail pkg-update $pkg # wrong package state
+test pkg-purge $pkg
+
+# src == out
+#
+test pkg-fetch -e $pkga
+test pkg-unpack $pkg
+test pkg-configure $pkg
+test pkg-update $pkg
+test pkg-update $pkg
+test pkg-disfigure $pkg
+test pkg-purge $pkg
+
+# src != out
+#
+test pkg-unpack -e $pkgd
+test pkg-configure $pkg
+test pkg-update $pkg
+test pkg-update $pkg
+test pkg-disfigure $pkg
+test pkg-purge $pkg
diff --git a/bpkg/utility b/bpkg/utility
index ffe5b94..32ae252 100644
--- a/bpkg/utility
+++ b/bpkg/utility
@@ -48,10 +48,13 @@ namespace bpkg
inline void
run (const cstrings& args) {run (args.data ());}
- // Run build2, mapping verbosity levels.
+ // Run build2, mapping verbosity levels. If quiet is true, then
+ // run build2 quiet if our verbosity level is 1.
//
void
- run_b (const string& buildspec, const strings& vars = strings ());
+ run_b (const string& buildspec,
+ bool quiet = false,
+ const strings& vars = strings ());
// Call a function if there is an exception.
//
diff --git a/bpkg/utility.cxx b/bpkg/utility.cxx
index b122545..db47476 100644
--- a/bpkg/utility.cxx
+++ b/bpkg/utility.cxx
@@ -151,7 +151,7 @@ namespace bpkg
}
void
- run_b (const string& bspec, const strings& vars)
+ run_b (const string& bspec, bool quiet, const strings& vars)
{
cstrings args {"b"};
@@ -160,11 +160,11 @@ namespace bpkg
// as us.
//
string vl;
- if (verb <= 1)
+ if (verb <= (quiet ? 1 : 0))
args.push_back ("-q");
else if (verb == 2)
args.push_back ("-v");
- else
+ else if (verb > 2)
{
vl = to_string (verb);
args.push_back ("--verbose");