aboutsummaryrefslogtreecommitdiff
path: root/bdep/init.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bdep/init.cxx')
-rw-r--r--bdep/init.cxx51
1 files changed, 45 insertions, 6 deletions
diff --git a/bdep/init.cxx b/bdep/init.cxx
index 44eb37e..1e864eb 100644
--- a/bdep/init.cxx
+++ b/bdep/init.cxx
@@ -6,6 +6,7 @@
#include <bdep/config.hxx>
#include <bdep/project.hxx>
+#include <bdep/project-odb.hxx>
#include <bdep/database.hxx>
#include <bdep/diagnostics.hxx>
@@ -24,8 +25,8 @@ namespace bdep
const dir_path& prj (pp.project);
text << prj;
- for (const dir_path& d: pp.packages)
- text << " " << (prj / d);
+ for (const package_location& pl: pp.packages)
+ text << " " << pl.name << " " << (prj / pl.path);
// Create .bdep/.
//
@@ -103,17 +104,55 @@ namespace bdep
// Fall through.
}
- transaction t (db.begin ());
-
// If this is the default mode, then find the configurations the user
// wants us to use.
//
if (cfgs.empty ())
+ {
+ transaction t (db.begin ());
cfgs = find_configurations (prj, t, o);
+ t.commit ();
+ }
- //@@ TODO: print project/package(s) being initialized.
+ // Initialize each package in each configuration skipping those that are
+ // already initialized. Do each configuration in a separate transaction so
+ // that our state reflects the bpkg configuration as closely as possible.
+ //
+ for (const shared_ptr<configuration>& c: cfgs)
+ {
+ transaction t (db.begin ());
+
+ // Add project repository to the configuration. Note that we don't fetch
+ // it since sync is going to do it anyway.
+ //
+ run_bpkg (o,
+ "add",
+ "-d", c->path,
+ "--type", "dir",
+ prj);
+
+ for (const package_location& p: pp.packages)
+ {
+ if (find_if (c->packages.begin (),
+ c->packages.end (),
+ [&p] (const package_state& s)
+ {
+ return p.name == s.name;
+ }) != c->packages.end ())
+ {
+ info << "package " << p.name << " is already initialized "
+ << "in configuration " << *c;
+ continue;
+ }
+
+ c->packages.push_back (package_state {p.name});
+ }
- t.commit ();
+ db.update (c);
+ t.commit ();
+ }
+
+ //@@ TODO: print project/package(s) being initialized.
return 0;
}