Skip to content

Commit 9cdadaa

Browse files
committed
Exclude paths that start with ".." from recursive globbing
This mainly targets `importPaths ".."`, but to some degree applies to all paths that may occur in a package description file. One use case for requiring such a declaration is when the module root is outside the Dub project root. For example, the library "foo" containing a D module "foo.bar" may be in a directory called "foo" and have "bar.d" at the directory root (same directory as "dub.sdl"). Currently, setting importPaths to ".." has the unpleasant side effect of scanning the entire parent directory (which may host other, unrelated projects). Dub does this for reasons such as caching; the build process itself does not require a list of all files that may or may not be imported, as the compiler discovers them not by globbing, but by path construction and file existence checks, based on the names of imported modules and the list of import paths specified with -I. Ideally, Dub should NEVER recursively glob the importPaths list, and instead communicate with the compiler to discover the full list of files that were actually imported (e.g. from compilers' verbose output). However, this change (which should not affect canonical use cases) should facilitate this particular directory structure.
1 parent 9d16313 commit 9cdadaa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

source/dub/recipe/packagerecipe.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ struct BuildSettingsTemplate {
494494
continue;
495495

496496
foreach (spath; paths) {
497+
// exclude paths outside projects' roots from recursive globbing
498+
import std.algorithm : startsWith;
499+
import std.path : pathSplitter;
500+
if (spath.pathSplitter.startsWith("..".only)) {
501+
logDiagnostic("Not globbing path outside project root: %s", spath);
502+
continue;
503+
}
504+
497505
enforce(!spath.empty, "Paths must not be empty strings.");
498506
auto path = NativePath(spath);
499507
if (!path.absolute) path = base_path ~ path;

0 commit comments

Comments
 (0)