aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bdep/config.cxx102
-rw-r--r--bdep/config.hxx5
-rw-r--r--tests/config.testscript32
3 files changed, 131 insertions, 8 deletions
diff --git a/bdep/config.cxx b/bdep/config.cxx
index 4347b1d..af84c59 100644
--- a/bdep/config.cxx
+++ b/bdep/config.cxx
@@ -259,9 +259,12 @@ namespace bdep
verify_configuration_path (path, prj, pkgs);
- // Use bpkg-cfg-info to query the configuration type, unless specified
- // explicitly.
+ // If an existing configuration is being added, then use bpkg-cfg-info to
+ // query the configuration type and links, collecting the linked host
+ // configuration paths/types.
//
+ vector<pair<dir_path, string>> host_configs;
+
if (!type)
{
fdpipe pipe (open_pipe ()); // Text mode seems appropriate.
@@ -271,6 +274,7 @@ namespace bdep
pipe /* stdout */,
2 /* stderr */,
"cfg-info",
+ "--link",
"-d", path));
// Shouldn't throw, unless something is severely damaged.
@@ -282,19 +286,72 @@ namespace bdep
{
ifdstream is (move (pipe.in), fdstream_mode::skip, ifdstream::badbit);
+ // Retrieve the configuration type.
+ //
for (string l; !eof (getline (is, l)); )
{
+ if (l.empty ())
+ break;
+
+ // After configuration type is retrieved, continue reading till the
+ // end of the configuration information.
+ //
if (l.compare (0, 6, "type: ") == 0)
- {
type = string (l, 6);
- break;
- }
}
- is.close (); // Detect errors.
-
if (!type || type->empty ())
fail << "invalid bpkg-cfg-info output: no configuration type";
+
+ // Collect the linked host configurations.
+ //
+ if (!is.eof ())
+ {
+ dir_path d;
+ string t;
+
+ auto add_conf = [&d, &t, &host_configs] ()
+ {
+ if (d.empty ())
+ fail << "invalid bpkg-cfg-info output: no linked configuration "
+ << "path";
+
+ if (t.empty ())
+ fail << "invalid bpkg-cfg-info output: no linked configuration "
+ << "type";
+
+ if (t == "host" || t == "build2")
+ host_configs.emplace_back (move (d), move (t));
+
+ d.clear ();
+ t.clear ();
+ };
+
+ for (string l; !eof (getline (is, l)); )
+ {
+ if (l.empty ())
+ add_conf ();
+
+ if (l.compare (0, 6, "path: ") == 0)
+ {
+ try
+ {
+ d = dir_path (string (l, 6));
+ }
+ catch (const invalid_path&)
+ {
+ fail << "invalid bpkg-cfg-info output line '" << l
+ << "': invalid configuration path";
+ }
+ }
+ else if (l.compare (0, 6, "type: ") == 0)
+ t = string (l, 6);
+ }
+
+ add_conf (); // Add the remaining config.
+ }
+
+ is.close (); // Detect errors.
}
catch (const io_error&)
{
@@ -356,6 +413,24 @@ namespace bdep
!ao.no_auto_sync (),
id));
+ // Let's issue a single warning about non-associated host configurations
+ // (rather than for each of them) and do it after the configuration is
+ // reported as added. So just filter out the associated configurations at
+ // this stage.
+ //
+ for (auto i (host_configs.begin ()); i != host_configs.end (); )
+ {
+ using query = bdep::query<configuration>;
+
+ shared_ptr<configuration> c (
+ db.query_one<configuration> (query::path == i->first.string ()));
+
+ if (c != nullptr)
+ i = host_configs.erase (i);
+ else
+ ++i;
+ }
+
t.commit ();
if (verb)
@@ -365,6 +440,19 @@ namespace bdep
print_configuration (dr, r);
}
+ if (!host_configs.empty ())
+ {
+ diag_record dr (warn);
+ dr << what << " configuration " << *r << " already linked with host "
+ << "configurations";
+
+ for (const pair<dir_path, string>& lc: host_configs)
+ dr << info << "configuration of " << lc.second << " type: "
+ << lc.first;
+
+ dr << info << "consider adding them to this project";
+ }
+
return r;
}
diff --git a/bdep/config.hxx b/bdep/config.hxx
index b8ad1cc..9134bee 100644
--- a/bdep/config.hxx
+++ b/bdep/config.hxx
@@ -12,7 +12,10 @@
namespace bdep
{
- // If type is nullopt, then query the bpkg configuration type.
+ // If type is nullopt, then assume that an existing configuration is being
+ // added. If that's the case, query the bpkg configuration type and links
+ // and warn the user if any host or build2 configurations are linked, unless
+ // they are already associated with the project.
//
shared_ptr<configuration>
cmd_config_add (const common_options&,
diff --git a/tests/config.testscript b/tests/config.testscript
index cb8ed7e..b052a7b 100644
--- a/tests/config.testscript
+++ b/tests/config.testscript
@@ -227,6 +227,38 @@ deinit += -d prj
EOE
}
+: add-host-linked
+:
+: Test that the warning is issued when we add configuration that has a host
+: configuration linked to it, unless it is already associated with the
+: project.
+:
+{
+ $clone_root_prj;
+
+ $* create @cfg &prj-cfg/*** 2>!;
+ $* create --config-type host @host-cfg &prj-host-cfg/*** 2>!;
+
+ $* link @cfg @host-cfg 2>!;
+
+ $* remove --all 2>!;
+
+ $* add @cfg 2>>/"EOE";
+ added configuration @cfg $~/prj-cfg/ 3 target default,forwarded,auto-synchronized
+ warning: added configuration @cfg already linked with host configurations
+ info: configuration of host type: $~/prj-host-cfg/
+ info: consider adding them to this project
+ EOE
+
+ $* remove --all 2>!;
+
+ $* add @host-cfg 2>!;
+
+ $* add @cfg 2>>/"EOE"
+ added configuration @cfg $~/prj-cfg/ 5 target default,forwarded,auto-synchronized
+ EOE
+}
+
: move
:
{