aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bdep/config.cxx49
-rw-r--r--bdep/config.hxx22
-rw-r--r--bdep/init.cxx6
-rw-r--r--bdep/init.hxx1
-rw-r--r--bdep/new.cxx11
-rw-r--r--bdep/project.cxx12
-rw-r--r--bdep/project.hxx2
7 files changed, 72 insertions, 31 deletions
diff --git a/bdep/config.cxx b/bdep/config.cxx
index d0b641e..21dfa38 100644
--- a/bdep/config.cxx
+++ b/bdep/config.cxx
@@ -116,9 +116,27 @@ namespace bdep
name = move (s);
}
+ // Verify the configuration directory is not inside one of the packages.
+ //
+ static void
+ verify_configuration_path (const dir_path& cfg,
+ const dir_path& prj,
+ const package_locations& pkgs)
+ {
+ for (const package_location& p: pkgs)
+ {
+ dir_path d (prj / p.path); // Should already be normalized.
+
+ if (cfg.sub (d))
+ fail << "configuration directory " << cfg << " is inside package "
+ << p.name << " (" << d << ")";
+ }
+ }
+
shared_ptr<configuration>
cmd_config_add (const configuration_add_options& ao,
const dir_path& prj,
+ const package_locations& pkgs,
database& db,
dir_path path,
optional<string> name,
@@ -133,6 +151,17 @@ namespace bdep
if (!exists (path))
fail << "configuration directory " << path << " does not exist";
+ // Make sure the configuration path is absolute and normalized. Also
+ // derive relative to project directory path if possible.
+ //
+ path.complete ();
+ path.normalize ();
+
+ verify_configuration_path (path, prj, pkgs);
+
+ optional<dir_path> rel_path;
+ try {rel_path = path.relative (prj);} catch (const invalid_path&) {}
+
transaction t (db.begin ());
using count = configuration_count;
@@ -171,15 +200,6 @@ namespace bdep
}
}
- // Make sure the configuration path is absolute and normalized. Also
- // derive relative to project directory path if possible.
- //
- path.complete ();
- path.normalize ();
-
- optional<dir_path> rel_path;
- try {rel_path = path.relative (prj);} catch (const invalid_path&) {}
-
shared_ptr<configuration> r (
new configuration {
id,
@@ -237,14 +257,22 @@ namespace bdep
cmd_config_create (const common_options& co,
const configuration_add_options& ao,
const dir_path& prj,
+ const package_locations& pkgs,
database& db,
dir_path path,
cli::scanner& cfg_args,
optional<string> name,
optional<uint64_t> id)
{
+ // Similar logic to *_add().
+ //
translate_path_name (prj, path, name);
+ path.complete ();
+ path.normalize ();
+
+ verify_configuration_path (path, prj, pkgs);
+
// Call bpkg to create the configuration.
//
{
@@ -262,6 +290,7 @@ namespace bdep
return cmd_config_add (ao,
prj,
+ package_locations {}, // Already verified.
db,
move (path),
move (name),
@@ -306,6 +335,7 @@ namespace bdep
cmd_config_add (o,
prj,
+ load_packages (prj, true /* allow_empty */),
db,
move (path),
move (name),
@@ -354,6 +384,7 @@ namespace bdep
cmd_config_create (o,
o,
prj,
+ load_packages (prj, true /* allow_empty */),
db,
move (path),
args,
diff --git a/bdep/config.hxx b/bdep/config.hxx
index e191312..300bb03 100644
--- a/bdep/config.hxx
+++ b/bdep/config.hxx
@@ -15,22 +15,24 @@ namespace bdep
{
shared_ptr<configuration>
cmd_config_add (const configuration_add_options&,
- const dir_path& prj,
+ const dir_path& prj,
+ const package_locations&,
database&,
- dir_path path,
- optional<string> name,
- optional<uint64_t> id = nullopt,
- const char* what = "added");
+ dir_path path,
+ optional<string> name,
+ optional<uint64_t> id = nullopt,
+ const char* what = "added");
shared_ptr<configuration>
cmd_config_create (const common_options&,
const configuration_add_options&,
- const dir_path& prj,
+ const dir_path& prj,
+ const package_locations&,
database&,
- dir_path path,
- cli::scanner& args,
- optional<string> name,
- optional<uint64_t> id = nullopt);
+ dir_path path,
+ cli::scanner& args,
+ optional<string> name,
+ optional<uint64_t> id = nullopt);
int
cmd_config (cmd_config_options&&, cli::scanner& args);
diff --git a/bdep/init.cxx b/bdep/init.cxx
index 5534575..d3dd7fc 100644
--- a/bdep/init.cxx
+++ b/bdep/init.cxx
@@ -20,6 +20,7 @@ namespace bdep
cmd_init_config (const configuration_name_options& o,
const configuration_add_options& ao,
const dir_path& prj,
+ const package_locations& ps,
database& db,
const dir_path& cfg,
cli::scanner& args,
@@ -37,8 +38,8 @@ namespace bdep
cmd_config_validate_add (o, m, nm, id);
return ca
- ? cmd_config_add ( ao, prj, db, cfg, move (nm), move (id))
- : cmd_config_create (o, ao, prj, db, cfg, args, move (nm), move (id));
+ ? cmd_config_add ( ao, prj, ps, db, cfg, move (nm), move (id))
+ : cmd_config_create (o, ao, prj, ps, db, cfg, args, move (nm), move (id));
}
void
@@ -185,6 +186,7 @@ namespace bdep
o,
o,
prj,
+ load_packages (prj),
db,
ca ? o.config_add () : o.config_create (),
args,
diff --git a/bdep/init.hxx b/bdep/init.hxx
index cf2a78d..adebbcf 100644
--- a/bdep/init.hxx
+++ b/bdep/init.hxx
@@ -19,6 +19,7 @@ namespace bdep
cmd_init_config (const configuration_name_options&,
const configuration_add_options&,
const dir_path& prj,
+ const package_locations&,
database&,
const dir_path& cfg,
cli::scanner& cfg_args,
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 2892262..e5f4329 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -996,22 +996,25 @@ namespace bdep
if (ca || cc)
{
+ package_locations pkgs;
+
+ if (t != type::empty)
+ pkgs.push_back (package_location {n, dir_path ()}); // prj == pkg
+
configurations cfgs {
cmd_init_config (
o,
o,
prj,
+ pkgs,
db,
ca ? o.config_add () : o.config_create (),
args,
ca,
cc)};
- if (t != type::empty)
- {
- package_locations pkgs {{n, dir_path ()}}; // project == package
+ if (!pkgs.empty ())
cmd_init (o, prj, db, cfgs, pkgs, scan_arguments (args) /* pkg_args */);
- }
}
return 0;
diff --git a/bdep/project.cxx b/bdep/project.cxx
index e553a1d..59ba21e 100644
--- a/bdep/project.cxx
+++ b/bdep/project.cxx
@@ -202,7 +202,7 @@ namespace bdep
}
static package_locations
- load_package_locations (const dir_path& prj)
+ load_package_locations (const dir_path& prj, bool allow_empty = false)
{
package_locations pls;
@@ -221,7 +221,7 @@ namespace bdep
// While an empty repository is legal, in our case it doesn't make much
// sense and will just further complicate things.
//
- if (ms.empty ())
+ if (ms.empty () && !allow_empty)
fail << "no packages listed in " << f;
for (package_manifest& m: ms)
@@ -236,8 +236,10 @@ namespace bdep
pls.push_back (package_location {string (), move (d)});
}
}
- else
+ else if (exists (prj / manifest_file))
pls.push_back (package_location {string (), dir_path ()});
+ else if (!allow_empty)
+ fail << "no packages in project " << prj;
return pls;
}
@@ -257,9 +259,9 @@ namespace bdep
}
package_locations
- load_packages (const dir_path& prj)
+ load_packages (const dir_path& prj, bool allow_empty)
{
- package_locations pls (load_package_locations (prj));
+ package_locations pls (load_package_locations (prj, allow_empty));
load_package_names (prj, pls);
return pls;
}
diff --git a/bdep/project.hxx b/bdep/project.hxx
index 652c2e8..20d3cf7 100644
--- a/bdep/project.hxx
+++ b/bdep/project.hxx
@@ -169,7 +169,7 @@ namespace bdep
using package_locations = vector<package_location>;
package_locations
- load_packages (const dir_path& prj);
+ load_packages (const dir_path& prj, bool allow_empty = false);
struct project_packages
{