diff options
-rw-r--r-- | bdep/new.cxx | 6 | ||||
-rw-r--r-- | bdep/project.cxx | 21 | ||||
-rw-r--r-- | bdep/project.hxx | 19 | ||||
-rw-r--r-- | tests/init.testscript | 7 | ||||
-rw-r--r-- | tests/release.testscript | 2 |
5 files changed, 40 insertions, 15 deletions
diff --git a/bdep/new.cxx b/bdep/new.cxx index 4cf7cc9..b531242 100644 --- a/bdep/new.cxx +++ b/bdep/new.cxx @@ -761,8 +761,9 @@ cmd_new (cmd_new_options&& o, cli::group_scanner& args) // Get the actual project/package information as "seen" from the output // directory. // - project_package pp ( - find_project_package (out, true /* ignore_not_found */)); + project_package pp (find_project_package (out, + true /* allow_subdir */, + true /* ignore_not_found */)); // Finalize the tentative project directory and do some sanity checks // (nested packages, etc; you would be surprised what people come up @@ -3034,6 +3035,7 @@ options_files (const char*, const cmd_new_options& o, const strings&) // Get the actual project directory. // project_package pp (find_project_package (*start, + true /* allow_subdir */, true /* ignore_not_found */)); if (!pp.project.empty ()) diff --git a/bdep/project.cxx b/bdep/project.cxx index 936a78f..7190045 100644 --- a/bdep/project.cxx +++ b/bdep/project.cxx @@ -127,7 +127,9 @@ namespace bdep } project_package - find_project_package (const dir_path& start, bool ignore_nf) + find_project_package (const dir_path& start, + bool allow_subdir, + bool ignore_nf) { dir_path prj; optional<dir_path> pkg; @@ -170,6 +172,12 @@ namespace bdep prj = move (d); break; } + + // If this directory is not a package nor project root and search from + // within their subdirs is disallowed, then bail out to fail. + // + if (!allow_subdir && !pkg) + break; } if (prj.empty ()) @@ -179,7 +187,10 @@ namespace bdep if (ignore_nf) return project_package (); - fail << start << " is not a (sub)directory of a package or project"; + fail << start << " is not a " + << (allow_subdir + ? "(sub)directory of a package or project" + : "package or project directory"); } // Project and package are the same. @@ -298,7 +309,8 @@ namespace bdep if (!exists (d)) fail << "project/package directory " << d << " does not exist"; - project_package p (find_project_package (d)); + project_package p ( + find_project_package (d, false /* allow_subdir */)); // We only work on one project at a time. // @@ -334,7 +346,8 @@ namespace bdep } else { - project_package p (find_project_package (current_directory ())); + project_package p ( + find_project_package (current_directory (), true /* allow_subdir */)); r.project = move (p.project); diff --git a/bdep/project.hxx b/bdep/project.hxx index 35b9441..86b833f 100644 --- a/bdep/project.hxx +++ b/bdep/project.hxx @@ -178,13 +178,13 @@ 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. + // Given a directory which can be a project root, a package root, or, if + // requested, 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 + // If ignore_not_found is true then instead of issuing diagnostics and // failing return empty project directory if no project is found. // struct project_package @@ -194,7 +194,9 @@ namespace bdep }; project_package - find_project_package (const dir_path&, bool ignore_not_found = false); + find_project_package (const dir_path&, + bool allow_subdir, + 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 @@ -227,7 +229,8 @@ namespace bdep }; // Search project packages in the specified directories or the current - // directory if none were specified. + // directory if none were specified. Fail if the specified directories are + // not project or package root directories. // project_packages find_project_packages (const dir_paths&, diff --git a/tests/init.testscript b/tests/init.testscript index a0aef6d..ba67b56 100644 --- a/tests/init.testscript +++ b/tests/init.testscript @@ -219,6 +219,13 @@ deinit += -d prj created new library package libprj in $~/prj/libprj/ EOE + # While at it, make sure we fail if misspell the package directory. + # + mkdir prj/libpr; + $init --all -d prj/libpr 2>>/~"%EOE%" != 0; + error: prj/libpr/ is not a package or project directory + EOE + $init --all -d prj/libprj 2>>/~"%EOE%"; initializing in project $~/prj/ synchronizing: diff --git a/tests/release.testscript b/tests/release.testscript index c39bbba..6c89987 100644 --- a/tests/release.testscript +++ b/tests/release.testscript @@ -705,7 +705,7 @@ log2 = $gp2 log '--pretty=format:"%d %s"' Create EOO - tag = $release --tag --push -q --yes -d prj/prj + tag = $release --tag --push -q --yes -d prj : update : |