diff --git a/source/dub/compilers/buildsettings.d b/source/dub/compilers/buildsettings.d index 9826ea1..beebd0f 100644 --- a/source/dub/compilers/buildsettings.d +++ b/source/dub/compilers/buildsettings.d @@ -96,7 +96,6 @@ void addStringImportPaths(in string[] value...) { add(stringImportPaths, value); } void prependStringImportPaths(in string[] value...) { prepend(stringImportPaths, value); } void addImportFiles(in string[] value...) { add(importFiles, value); } - void removeImportFiles(in string[] value...) { removePaths(importFiles, value); } void addStringImportFiles(in string[] value...) { addSI(stringImportFiles, value); } void addPreGenerateCommands(in string[] value...) { add(preGenerateCommands, value, false); } void addPostGenerateCommands(in string[] value...) { add(postGenerateCommands, value, false); } diff --git a/source/dub/recipe/packagerecipe.d b/source/dub/recipe/packagerecipe.d index b475b61..e76d487 100644 --- a/source/dub/recipe/packagerecipe.d +++ b/source/dub/recipe/packagerecipe.d @@ -173,7 +173,7 @@ dst.addSourceFiles(this.mainSourceFile); } - void collectFiles(string method)(in string[][string] paths_map, string pattern) + string[] collectFiles(in string[][string] paths_map, string pattern) { auto files = appender!(string[]); @@ -192,24 +192,29 @@ foreach (d; dirEntries(path.toNativeString(), pattern, SpanMode.depth)) { import std.path : baseName; - if (baseName(d.name)[0] == '.' || isDir(d.name)) continue; + if (baseName(d.name)[0] == '.' || d.isDir) continue; auto src = Path(d.name).relativeTo(base_path); files ~= src.toNativeString(); } } } - __traits(getMember, dst, method)(files.data); + return files.data; } - // collect files from all source/import folders - collectFiles!"addSourceFiles"(sourcePaths, "*.d"); - collectFiles!"addImportFiles"(importPaths, "*.{d,di}"); - dst.removeImportFiles(dst.sourceFiles); - collectFiles!"addStringImportFiles"(stringImportPaths, "*"); + // collect source files + dst.addSourceFiles(collectFiles(sourcePaths, "*.d")); + auto sourceFiles = dst.sourceFiles.sort(); - // ensure a deterministic order of files as passed to the compiler - dst.sourceFiles.sort(); + // collect import files and remove sources + import std.algorithm : copy, setDifference; + + auto importFiles = collectFiles(importPaths, "*.{d,di}").sort(); + immutable nremoved = importFiles.setDifference(sourceFiles).copy(importFiles.release).length; + importFiles = importFiles[0 .. $ - nremoved]; + dst.addImportFiles(importFiles.release); + + dst.addStringImportFiles(collectFiles(stringImportPaths, "*")); getPlatformSetting!("dflags", "addDFlags")(dst, platform); getPlatformSetting!("lflags", "addLFlags")(dst, platform);