aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-14 14:34:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-14 14:34:12 +0200
commit7acf8ce6111e3740decd39b92c3383fcbdd00e21 (patch)
tree2c9c6d75bbac9b3b8a4dc9e7b46df01ba0ca3bf2
parentc8f2a2c0776aee57af6af10d4a0128befbc1fdeb (diff)
Implement fetch command
-rw-r--r--bdep/bdep.cli9
-rw-r--r--bdep/bdep.cxx2
-rw-r--r--bdep/buildfile11
-rw-r--r--bdep/config.cxx2
-rw-r--r--bdep/fetch.cli47
-rw-r--r--bdep/fetch.cxx59
-rw-r--r--bdep/fetch.hxx20
-rw-r--r--bdep/init.cli2
-rw-r--r--bdep/init.cxx24
-rw-r--r--bdep/sync.cli2
-rw-r--r--bdep/sync.cxx22
-rw-r--r--bdep/utility.txx21
-rwxr-xr-xdoc/cli.sh2
13 files changed, 197 insertions, 26 deletions
diff --git a/bdep/bdep.cli b/bdep/bdep.cli
index 12992d9..ac70b62 100644
--- a/bdep/bdep.cli
+++ b/bdep/bdep.cli
@@ -66,12 +66,17 @@ namespace bdep
bool init
{
- "\l{bdep-init(1)} \- initialize project in configurations"
+ "\l{bdep-init(1)} \- initialize project in build configurations"
}
bool sync
{
- "\l{bdep-sync(1)} \- synchronize project and configurations"
+ "\l{bdep-sync(1)} \- synchronize project and build configurations"
+ }
+
+ bool fetch
+ {
+ "\l{bdep-fetch(1)} \- fetch list of available project dependencies"
}
bool config
diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx
index ef4a6ec..c51285e 100644
--- a/bdep/bdep.cxx
+++ b/bdep/bdep.cxx
@@ -25,6 +25,7 @@
#include <bdep/new.hxx>
#include <bdep/init.hxx>
#include <bdep/sync.hxx>
+#include <bdep/fetch.hxx>
#include <bdep/config.hxx>
using namespace std;
@@ -268,6 +269,7 @@ try
COMMAND_IMPL (new_, new, "new");
COMMAND_IMPL (init, init, "init");
COMMAND_IMPL (sync, sync, "sync");
+ COMMAND_IMPL (fetch, fetch, "fetch");
COMMAND_IMPL (config, config, "config");
assert (false);
diff --git a/bdep/buildfile b/bdep/buildfile
index 7559ed0..3bda74b 100644
--- a/bdep/buildfile
+++ b/bdep/buildfile
@@ -19,10 +19,11 @@ bdep-options \
common-options \
project-options \
help-options \
-config-options \
+new-options \
init-options \
sync-options \
-new-options
+fetch-options \
+config-options
exe{bdep}: {hxx ixx txx cxx}{** -{$options_topics} -*-odb -version} \
{hxx ixx cxx}{$options_topics} \
@@ -53,10 +54,12 @@ if $cli.configured
#
cli.cxx{help-options}: cli{help}
- cli.cxx{config-options}: cli{config}
+ cli.cxx{new-options}: cli{new}
cli.cxx{init-options}: cli{init}
cli.cxx{sync-options}: cli{sync}
- cli.cxx{new-options}: cli{new}
+ cli.cxx{fetch-options}: cli{fetch}
+ cli.cxx{config-options}: cli{config}
+
# Option length must be the same to get commands/topics/options aligned.
#
diff --git a/bdep/config.cxx b/bdep/config.cxx
index 1e646a3..9f94a29 100644
--- a/bdep/config.cxx
+++ b/bdep/config.cxx
@@ -92,7 +92,7 @@ namespace bdep
}
int
- cmd_config (const cmd_config_options& o, cli::scanner& args)
+ cmd_config (const cmd_config_options& o, cli::scanner&)
{
//@@ TODO: get subcommand and pass to tracer.
diff --git a/bdep/fetch.cli b/bdep/fetch.cli
new file mode 100644
index 0000000..f5e17d3
--- /dev/null
+++ b/bdep/fetch.cli
@@ -0,0 +1,47 @@
+// file : bdep/fetch.cli
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+include <bdep/project.cli>;
+
+"\section=1"
+"\name=bdep-fetch"
+"\summary=fetch list of available project dependencies"
+
+namespace bdep
+{
+ {
+ "<options>
+ <prj-spec> <prj-dir>
+ <cfg-spec> <cfg-name> <cfg-dir>",
+
+ "\h|SYNOPSIS|
+
+ \c{\b{bdep fetch} [<options>] [\b{--full}|\b{-F}] [<prj-spec>] [<cfg-spec>]}
+
+ \c{<prj-spec> = \b{--directory}|\b{-d} <prj-dir>\n
+ <cfg-spec> = (\b{@}<cfg-name> | \b{--config}|\b{-c} <cfg-dir>)... | \b{--all}|\b{-a}}
+
+ \h|DESCRIPTION|
+
+ The \cb{fetch} command re-fetches the list of available packages in the
+ project's prerequisite and complement repositories, recursively.
+
+ If the \cb{--full|-F} option is specified, then instead \cb{fetch}
+ performs a full re-fetch of all the repositories added to the
+ configuration. This mode is primarily useful when a configuration (and
+ some of the prerequisite/complement repositories) are shared between
+ several projects. In this situation an incremental fetch may result in
+ an inconsistent repository state."
+ }
+
+ class cmd_fetch_options: project_options
+ {
+ "\h|FETCH OPTIONS|"
+
+ bool --full|-F
+ {
+ "Perform a full re-fetch of all the repositories."
+ }
+ };
+}
diff --git a/bdep/fetch.cxx b/bdep/fetch.cxx
new file mode 100644
index 0000000..6231d8b
--- /dev/null
+++ b/bdep/fetch.cxx
@@ -0,0 +1,59 @@
+// file : bdep/fetch.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <bdep/fetch.hxx>
+
+#include <bdep/database.hxx>
+#include <bdep/diagnostics.hxx>
+
+using namespace std;
+
+namespace bdep
+{
+ int
+ cmd_fetch (const cmd_fetch_options& o, cli::scanner&)
+ {
+ tracer trace ("fetch");
+
+ dir_path prj (
+ find_project_packages (o, true /* ignore_packages */).project);
+
+ database db (open (prj, trace));
+
+ transaction t (db.begin ());
+ configurations cfgs (find_configurations (prj, t, o));
+ t.commit ();
+
+ bool first (true);
+ for (const shared_ptr<configuration>& c: cfgs)
+ {
+ if (c->packages.empty ())
+ {
+ info << "no packages initialized in configuration " << *c;
+ continue;
+ }
+
+ // If we are fetching in multiple configurations, separate them with a
+ // blank line and print the configuration name/directory.
+ //
+ if (verb && cfgs.size () > 1)
+ {
+ text << (first ? "" : "\n")
+ << "fetching in configuration " << *c;
+
+ first = false;
+ }
+
+ // Let's use the repository name rather than the location as a sanity
+ // check (the repository must have been added as part of init).
+ //
+ run_bpkg (o,
+ "fetch",
+ "-d", c->path,
+ (o.full () ? nullptr : ("dir:" + prj.string ()).c_str ()));
+ }
+
+ return 0;
+ }
+}
diff --git a/bdep/fetch.hxx b/bdep/fetch.hxx
new file mode 100644
index 0000000..0f036cd
--- /dev/null
+++ b/bdep/fetch.hxx
@@ -0,0 +1,20 @@
+// file : bdep/fetch.hxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#ifndef BDEP_FETCH_HXX
+#define BDEP_FETCH_HXX
+
+#include <bdep/types.hxx>
+#include <bdep/utility.hxx>
+
+#include <bdep/project.hxx>
+#include <bdep/fetch-options.hxx>
+
+namespace bdep
+{
+ int
+ cmd_fetch (const cmd_fetch_options&, cli::scanner& args);
+}
+
+#endif // BDEP_FETCH_HXX
diff --git a/bdep/init.cli b/bdep/init.cli
index e4b7e2d..d853010 100644
--- a/bdep/init.cli
+++ b/bdep/init.cli
@@ -6,7 +6,7 @@ include <bdep/project.cli>;
"\section=1"
"\name=bdep-init"
-"\summary=initialize project in configurations"
+"\summary=initialize project in build configurations"
namespace bdep
{
diff --git a/bdep/init.cxx b/bdep/init.cxx
index f41a62b..5fce13f 100644
--- a/bdep/init.cxx
+++ b/bdep/init.cxx
@@ -68,8 +68,20 @@ namespace bdep
// We do each configuration in a separate transaction so that our state
// reflects the bpkg configuration as closely as possible.
//
+ bool first (true);
for (const shared_ptr<configuration>& c: cfgs)
{
+ // If we are initializing in multiple configurations, separate them with
+ // a blank line and print the configuration name/directory.
+ //
+ if (verb && cfgs.size () > 1)
+ {
+ text << (first ? "" : "\n")
+ << "initializing in configuration " << *c;
+
+ first = false;
+ }
+
transaction t (db.begin ());
// Add project repository to the configuration. Note that we don't fetch
@@ -97,6 +109,11 @@ namespace bdep
continue;
}
+ // If we are initializing multiple packages, print their names.
+ //
+ if (verb && pkgs.size () > 1)
+ text << "initializing package " << p.name;
+
c->packages.push_back (package_state {p.name});
}
@@ -119,9 +136,8 @@ namespace bdep
const dir_path& prj (pp.project);
- text << prj;
- for (const package_location& pl: pp.packages)
- text << " " << pl.name << " " << (prj / pl.path);
+ if (verb)
+ text << "initializing project " << prj;
// Create .bdep/.
//
@@ -187,8 +203,6 @@ namespace bdep
//
cmd_init (o, prj, db, cfgs, pp.packages);
- //@@ TODO: print project/package(s) being initialized? (analog to new?)
-
return 0;
}
}
diff --git a/bdep/sync.cli b/bdep/sync.cli
index 27c62ff..bd19edf 100644
--- a/bdep/sync.cli
+++ b/bdep/sync.cli
@@ -6,7 +6,7 @@ include <bdep/project.cli>;
"\section=1"
"\name=bdep-sync"
-"\summary=synchronize project and configurations"
+"\summary=synchronize project and build configurations"
namespace bdep
{
diff --git a/bdep/sync.cxx b/bdep/sync.cxx
index e84fa0f..257cd20 100644
--- a/bdep/sync.cxx
+++ b/bdep/sync.cxx
@@ -18,6 +18,24 @@ namespace bdep
{
assert (!c->packages.empty ());
+ // Do a separate fetch instead of letting pkg-build do it. This way we get
+ // better control of the diagnostics (no "fetching ..." for the project
+ // itself). We also make sure that if the user specifies a repository for
+ // a dependency to upgrade, then that repository is listed as part of the
+ // project prerequisites/complements. Or, in other words, we only want to
+ // allow specifying the location as a proxy for specifying version (i.e.,
+ // "I want this dependency upgraded to the latest version available from
+ // this repository").
+ //
+ // We also use the repository name rather than then location as a sanity
+ // check (the repository must have been added as part of init).
+ //
+ run_bpkg (co,
+ "fetch",
+ "-d", c->path,
+ "--shallow",
+ "dir:" + prj.string ());
+
// Prepare the pkg-spec.
//
string spec;
@@ -35,9 +53,9 @@ namespace bdep
run_bpkg (co,
"build",
"-d", c->path,
- //"--fetch-shallow",
+ "--no-fetch",
"--configure-only",
- //"--keep-out",
+ "--keep-out",
spec);
}
diff --git a/bdep/utility.txx b/bdep/utility.txx
index 9e94196..8a4236b 100644
--- a/bdep/utility.txx
+++ b/bdep/utility.txx
@@ -76,17 +76,20 @@ namespace bdep
// Map verbosity level. If we are running quiet or at level 1, then run
// bpkg quiet. Otherwise, run it at the same level as us.
//
- bool quiet (true); // Maybe will become an argument one day.
+ bool quiet (false); // Maybe will become an argument one day.
+
string vl;
- if (verb <= (quiet ? 1 : 0))
- ops.push_back ("-q");
- else if (verb == 2)
- ops.push_back ("-v");
- else if (verb > 2)
+ switch (verb)
{
- vl = to_string (verb);
- ops.push_back ("--verbose");
- ops.push_back (vl.c_str ());
+ case 0: ops.push_back ( "-q"); break;
+ case 1: ops.push_back (quiet ? "-q" : "--no-result"); break;
+ case 2: ops.push_back ( "-v"); break;
+ default:
+ {
+ vl = to_string (verb);
+ ops.push_back ("--verbose");
+ ops.push_back (vl.c_str ());
+ }
}
// Forward our --build* options.
diff --git a/doc/cli.sh b/doc/cli.sh
index bac954e..a10c1d2 100755
--- a/doc/cli.sh
+++ b/doc/cli.sh
@@ -56,7 +56,7 @@ o="--suppress-undocumented --output-prefix bdep- --class-doc bdep::common_option
compile "common" $o --output-suffix "-options" --class-doc bdep::common_options=long
compile "bdep" $o --output-prefix "" --class-doc bdep::commands=short --class-doc bdep::topics=short
-pages="config help init sync new"
+pages="config help init sync new fetch"
for p in $pages; do
compile $p $o