diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 56836a4..ece9887 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -669,6 +669,62 @@ /** + Calls delegates on files and directories in the given path that match any globs. +*/ +void findFilesMatchingGlobs(in NativePath path, in string[] globList, void delegate(string file) addFile, void delegate(string dir) addDir) +{ + import std.path : globMatch; + + string[] globs; + foreach (f; globList) + { + if (f.canFind("*", "?") || + (f.canFind("{") && f.balancedParens('{', '}')) || + (f.canFind("[") && f.balancedParens('[', ']'))) + { + globs ~= f; + } + else + { + if (f.isDir) + addDir(f); + else + addFile(f); + } + } + if (globs.length) // Search all files for glob matches + foreach (f; dirEntries(path.toNativeString(), SpanMode.breadth)) + foreach (glob; globs) + if (f.name().globMatch(glob)) + { + if (f.isDir) + addDir(f); + else + addFile(f); + break; + } +} + + +/** + Calls delegates on files in the given path that match any globs. + + If a directory matches a glob, the delegate is called on all existing files inside it recursively + in depth-first pre-order. +*/ +void findFilesMatchingGlobs(in NativePath path, in string[] globList, void delegate(string file) addFile) +{ + void addDir(string dir) + { + foreach (f; dirEntries(dir, SpanMode.breadth)) + addFile(f); + } + + findFilesMatchingGlobs(path, globList, addFile, &addDir); +} + + +/** Runs pre-build commands and performs other required setup before project files are generated. */ private void prepareGeneration(in Package pack, in Project proj, in GeneratorSettings settings, @@ -686,8 +742,6 @@ private void finalizeGeneration(in Package pack, in Project proj, in GeneratorSettings settings, in BuildSettings buildsettings, NativePath target_path, bool generate_binary) { - import std.path : globMatch; - if (buildsettings.postGenerateCommands.length && !isRecursiveInvocation(pack.name)) { logInfo("Running post-generate commands for %s...", pack.name); runBuildCommands(buildsettings.postGenerateCommands, pack, proj, settings, buildsettings); @@ -743,40 +797,7 @@ } catch(Exception e) logWarn("Failed to copy %s to %s: %s", src.toNativeString(), dst.toNativeString(), e.msg); } logInfo("Copying files for %s...", pack.name); - string[] globs; - foreach (f; buildsettings.copyFiles) - { - if (f.canFind("*", "?") || - (f.canFind("{") && f.balancedParens('{', '}')) || - (f.canFind("[") && f.balancedParens('[', ']'))) - { - globs ~= f; - } - else - { - if (f.isDir) - tryCopyDir(f); - else - tryCopyFile(f); - } - } - if (globs.length) // Search all files for glob matches - { - foreach (f; dirEntries(pack.path.toNativeString(), SpanMode.breadth)) - { - foreach (glob; globs) - { - if (f.name().globMatch(glob)) - { - if (f.isDir) - tryCopyDir(f); - else - tryCopyFile(f); - break; - } - } - } - } + findFilesMatchingGlobs(pack.path, buildsettings.copyFiles, &tryCopyFile, &tryCopyDir); } } diff --git a/source/dub/generators/visuald.d b/source/dub/generators/visuald.d index ad87809..3781b47 100644 --- a/source/dub/generators/visuald.d +++ b/source/dub/generators/visuald.d @@ -156,7 +156,8 @@ auto ret = appender!(char[])(); - auto project_file_dir = m_project.rootPackage.path ~ projFileName(packname).parentPath; + auto root_package_path = m_project.rootPackage.path; + auto project_file_dir = root_package_path ~ projFileName(packname).parentPath; ret.put("\n"); ret.formattedWrite(" %s\n", guid(packname)); @@ -198,6 +199,8 @@ foreach(s; files.importFiles) addFile(s, false); foreach(s; files.stringImportFiles) addFile(s, false); + findFilesMatchingGlobs(root_package_path, files.copyFiles, s => addFile(s, false)); + findFilesMatchingGlobs(root_package_path, files.extraDependencyFiles, s => addFile(s, false)); // Create folders and files ret.formattedWrite(" ", getPackageFileName(packname)); diff --git a/test/issue1053-extra-files-visuald.sh b/test/issue1053-extra-files-visuald.sh new file mode 100755 index 0000000..845f93f --- /dev/null +++ b/test/issue1053-extra-files-visuald.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +. $(dirname "${BASH_SOURCE[0]}")/common.sh +cd "${CURR_DIR}/issue1053-extra-files-visuald" || die "Could not cd." + +"$DUB" generate visuald + +if [ `grep -c -e "saturate.vert" .dub/extra_files.visualdproj` -ne 1 ]; then + die $LINENO 'Regression of issue #1053.' +fi + +if [ `grep -c -e "warp.geom" .dub/extra_files.visualdproj` -ne 1 ]; then + die $LINENO 'Regression of issue #1053.' +fi + +if [ `grep -c -e "LICENSE.txt" .dub/extra_files.visualdproj` -ne 1 ]; then + die $LINENO 'Regression of issue #1053.' +fi + +if [ `grep -c -e "README.txt" .dub/extra_files.visualdproj` -ne 1 ]; then + die $LINENO 'Regression of issue #1053.' +fi diff --git a/test/issue1053-extra-files-visuald/dub.json b/test/issue1053-extra-files-visuald/dub.json new file mode 100644 index 0000000..a24bc8d --- /dev/null +++ b/test/issue1053-extra-files-visuald/dub.json @@ -0,0 +1,11 @@ +{ + "name": "extra_files", + "targetType": "executable", + "extraDependencyFiles": [ + "shaders/*" + ], + "copyFiles": [ + "text/LICENSE.txt", + "text/README.txt" + ] +} diff --git a/test/issue1053-extra-files-visuald/shaders/saturate.vert b/test/issue1053-extra-files-visuald/shaders/saturate.vert new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/issue1053-extra-files-visuald/shaders/saturate.vert diff --git a/test/issue1053-extra-files-visuald/shaders/warp.geom b/test/issue1053-extra-files-visuald/shaders/warp.geom new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/issue1053-extra-files-visuald/shaders/warp.geom diff --git a/test/issue1053-extra-files-visuald/source/app.d b/test/issue1053-extra-files-visuald/source/app.d new file mode 100644 index 0000000..ab73b3a --- /dev/null +++ b/test/issue1053-extra-files-visuald/source/app.d @@ -0,0 +1 @@ +void main() {} diff --git a/test/issue1053-extra-files-visuald/text/LICENSE.txt b/test/issue1053-extra-files-visuald/text/LICENSE.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/issue1053-extra-files-visuald/text/LICENSE.txt diff --git a/test/issue1053-extra-files-visuald/text/README.txt b/test/issue1053-extra-files-visuald/text/README.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/issue1053-extra-files-visuald/text/README.txt