diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 340197e..8184818 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -17,7 +17,7 @@ import dub.packagemanager; import dub.project; -import std.algorithm : map, filter, canFind; +import std.algorithm : map, filter, canFind, balancedParens; import std.array : array; import std.array; import std.exception; @@ -278,22 +278,42 @@ mkdirRecurse(buildsettings.targetPath); if (buildsettings.copyFiles.length) { - logInfo("Copying files for %s...", pack); - foreach (f; dirEntries(pack_path.toNativeString(), SpanMode.breadth)) + void tryCopyFile(string file) { - foreach(copyGlob; buildsettings.copyFiles) + auto src = Path(file); + if (!src.absolute) src = pack_path ~ src; + auto dst = target_path ~ Path(file).head; + logDiagnostic(" %s to %s", src.toNativeString(), dst.toNativeString()); + try { + copyFile(src, dst, true); + } catch logWarn("Failed to copy %s to %s", src.toNativeString(), dst.toNativeString()); + } + logInfo("Copying files for %s...", pack); + string[] globs; + foreach (f; buildsettings.copyFiles) + { + if (f.canFind("*", "?") || + (f.canFind("{") && f.balancedParens('{', '}')) || + (f.canFind("[") && f.balancedParens('[', ']'))) { - if(f.globMatch(copyGlob)) + globs ~= f; + } + else + { + tryCopyFile(f); + } + } + if (globs.length) // Search all files for glob matches + { + foreach (f; dirEntries(pack_path.toNativeString(), SpanMode.breadth)) + { + foreach (glob; globs) { - auto src = Path(f); - if (!src.absolute) src = pack_path ~ src; - auto dst = target_path ~ Path(f).head; - logDiagnostic(" %s to %s", src.toNativeString(), dst.toNativeString()); - try { - copyFile(src, dst, true); - } catch logWarn("Failed to copy to %s", dst.toNativeString()); - - break; + if (f.globMatch(glob)) + { + tryCopyFile(f); + break; + } } } }