aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-07-17 14:49:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-07-17 14:49:04 +0200
commit1580b9fe0ab2b242227cdd7601766bdfce5493e2 (patch)
treee06a0c32d76865fb232a82cf390f8728ddfe8b1a
parentc70cc15b6ebe49150661e025855dc22ceb235905 (diff)
Diagnose improper project/package arrangements in new command
-rw-r--r--bdep/new.cxx24
-rw-r--r--bdep/project.cxx27
-rw-r--r--bdep/project.hxx18
3 files changed, 50 insertions, 19 deletions
diff --git a/bdep/new.cxx b/bdep/new.cxx
index 37a7b67..2b5402b 100644
--- a/bdep/new.cxx
+++ b/bdep/new.cxx
@@ -158,6 +158,26 @@ namespace bdep
fail << "package directory " << out << " is not a subdirectory of "
<< "project directory " << prj;
+ // As a sanity check, verify none of the directories between us and the
+ // project look like packages.
+ //
+ project_package pp (
+ find_project_package (out, true /* ignore_not_found */));
+
+ if (!pp.project.empty ())
+ {
+ if (pp.project != prj)
+ fail << prj << " is not a project directory" <<
+ info << pp.project << " looks like a project directory";
+
+ if (pp.package)
+ fail << "package directory " << out << " is inside another "
+ << "package directory " << prj / *pp.package <<
+ info << "nested packages are not allowed";
+ }
+ else
+ warn << prj << " does not look like a project directory";
+
pkg = out.leaf (prj);
}
else
@@ -167,8 +187,8 @@ namespace bdep
prj = out;
}
- // If the output directory already exists, make sure it is
- // empty. Otherwise create it.
+ // If the output directory already exists, make sure it is empty.
+ // Otherwise create it.
//
if (!exists (out))
mk (out);
diff --git a/bdep/project.cxx b/bdep/project.cxx
index ba8a412..795e365 100644
--- a/bdep/project.cxx
+++ b/bdep/project.cxx
@@ -125,20 +125,8 @@ namespace bdep
return r;
}
- // Given a directory which can be a project root, a package root, or one of
- // their subdirectories, return the absolute project (first) and relative
- // package (second) directories. The package directory may be absent if the
- // given directory is not within a package root or empty if the project and
- // package roots are the same.
- //
- struct project_package
- {
- dir_path project;
- optional<dir_path> package;
- };
-
- static project_package
- find_project_packages (const dir_path& start)
+ project_package
+ find_project_package (const dir_path& start, bool ignore_nf)
{
dir_path prj;
optional<dir_path> pkg;
@@ -168,7 +156,7 @@ namespace bdep
}
// Check for the database file first since an (initialized) simple
- // project mosl likely won't have any *.manifest files.
+ // project most likely won't have any *.manifest files.
//
if (exists (d / bdep_file, true) ||
exists (d / packages_file, true) ||
@@ -188,7 +176,12 @@ namespace bdep
if (prj.empty ())
{
if (!pkg)
+ {
+ if (ignore_nf)
+ return project_package ();
+
fail << start << " is not a (sub)directory of a package or project";
+ }
// Project and package are the same.
//
@@ -277,7 +270,7 @@ namespace bdep
{
for (const dir_path& d: po.directory ())
{
- project_package p (find_project_packages (d));
+ project_package p (find_project_package (d));
// We only work on one project at a time.
//
@@ -313,7 +306,7 @@ namespace bdep
}
else
{
- project_package p (find_project_packages (path::current_directory ()));
+ project_package p (find_project_package (path::current_directory ()));
r.project = move (p.project);
diff --git a/bdep/project.hxx b/bdep/project.hxx
index 9e1ae8e..76d9522 100644
--- a/bdep/project.hxx
+++ b/bdep/project.hxx
@@ -156,6 +156,24 @@ namespace bdep
bool fallback_default = true,
bool validate = true);
+ // Given a directory which can be a project root, a package root, or one of
+ // their subdirectories, return the absolute project (first) and relative
+ // package (second) directories. The package directory may be absent if the
+ // given directory is not within a package root or empty if the project and
+ // package roots are the same.
+ //
+ // If ignore_not_found is true then insteading of issuing diagnostics and
+ // failing return empty project directory if no project is found.
+ //
+ struct project_package
+ {
+ dir_path project;
+ optional<dir_path> package;
+ };
+
+ project_package
+ find_project_package (const dir_path&, bool ignore_not_found = false);
+
// Given the project options (and CWD) locate the packages and their
// project. The result is an absolute and normalized project directory and a
// vector of relative (to the project directory) package locations.