diff --git a/source/dub/generators/generator.d b/source/dub/generators/generator.d index 533a1c4..52a745b 100644 --- a/source/dub/generators/generator.d +++ b/source/dub/generators/generator.d @@ -332,6 +332,36 @@ mkdirRecurse(buildsettings.targetPath); if (buildsettings.copyFiles.length) { + void copyFolderRec(Path folder, Path dstfolder) + { + mkdirRecurse(dstfolder.toNativeString()); + foreach (de; iterateDirectory(folder.toNativeString())) { + if (de.isDirectory) { + copyFolderRec(folder ~ de.name, dstfolder ~ de.name); + } else { + try copyFile(folder ~ de.name, dstfolder ~ de.name, true); + catch (Exception e) { + logWarn("Failed to copy file %s: %s", (folder ~ de.name).toNativeString(), e.msg); + } + } + } + } + + void tryCopyDir(string file) + { + auto src = Path(file); + if (!src.absolute) src = pack_path ~ src; + auto dst = target_path ~ Path(file).head; + if (src == dst) { + logDiagnostic("Skipping copy of %s (same source and destination)", file); + return; + } + logDiagnostic(" %s to %s", src.toNativeString(), dst.toNativeString()); + try { + copyFolderRec(src, dst); + } catch(Exception e) logWarn("Failed to copy %s to %s: %s", src.toNativeString(), dst.toNativeString(), e.msg); + } + void tryCopyFile(string file) { auto src = Path(file); @@ -358,7 +388,10 @@ } else { - tryCopyFile(f); + if (f.isDir) + tryCopyDir(f); + else + tryCopyFile(f); } } if (globs.length) // Search all files for glob matches @@ -369,13 +402,17 @@ { if (f.globMatch(glob)) { - tryCopyFile(f); + if (f.isDir) + tryCopyDir(f); + else + tryCopyFile(f); break; } } } } } + } } diff --git a/test/3-copyFiles/data/file_to_copy.txt b/test/3-copyFiles/data/file_to_copy.txt new file mode 100644 index 0000000..ece63c0 --- /dev/null +++ b/test/3-copyFiles/data/file_to_copy.txt @@ -0,0 +1 @@ +file_to_copy.txt content diff --git a/test/3-copyFiles/data/file_to_copy_mask1.txt b/test/3-copyFiles/data/file_to_copy_mask1.txt new file mode 100644 index 0000000..1d3b950 --- /dev/null +++ b/test/3-copyFiles/data/file_to_copy_mask1.txt @@ -0,0 +1 @@ +file_to_copy_mask1.txt content \ No newline at end of file diff --git a/test/3-copyFiles/data/file_to_copy_mask2.txt b/test/3-copyFiles/data/file_to_copy_mask2.txt new file mode 100644 index 0000000..49421e2 --- /dev/null +++ b/test/3-copyFiles/data/file_to_copy_mask2.txt @@ -0,0 +1 @@ +file_to_copy_mask2.txt content diff --git a/test/3-copyFiles/data/res/.nocopy/file_inside_dot_prefixed_dir.txt b/test/3-copyFiles/data/res/.nocopy/file_inside_dot_prefixed_dir.txt new file mode 100644 index 0000000..2ef267e --- /dev/null +++ b/test/3-copyFiles/data/res/.nocopy/file_inside_dot_prefixed_dir.txt @@ -0,0 +1 @@ +some content diff --git a/test/3-copyFiles/data/res/hdpi/file1.txt b/test/3-copyFiles/data/res/hdpi/file1.txt new file mode 100644 index 0000000..20d74d4 --- /dev/null +++ b/test/3-copyFiles/data/res/hdpi/file1.txt @@ -0,0 +1 @@ +hdpi/file1 content diff --git a/test/3-copyFiles/data/res/hdpi/file2.txt b/test/3-copyFiles/data/res/hdpi/file2.txt new file mode 100644 index 0000000..e313178 --- /dev/null +++ b/test/3-copyFiles/data/res/hdpi/file2.txt @@ -0,0 +1 @@ +hdpi/file2 content diff --git a/test/3-copyFiles/data/res/hdpi/file3.txt b/test/3-copyFiles/data/res/hdpi/file3.txt new file mode 100644 index 0000000..8f9119d --- /dev/null +++ b/test/3-copyFiles/data/res/hdpi/file3.txt @@ -0,0 +1 @@ +hdpi/file3 content diff --git a/test/3-copyFiles/data/res/hdpi/nested_dir/nested_file.txt b/test/3-copyFiles/data/res/hdpi/nested_dir/nested_file.txt new file mode 100644 index 0000000..3bd1ae7 --- /dev/null +++ b/test/3-copyFiles/data/res/hdpi/nested_dir/nested_file.txt @@ -0,0 +1 @@ +hdpi/nested_dir/nested_file.txt content diff --git a/test/3-copyFiles/data/res/i18n/resource_en.txt b/test/3-copyFiles/data/res/i18n/resource_en.txt new file mode 100644 index 0000000..000868e --- /dev/null +++ b/test/3-copyFiles/data/res/i18n/resource_en.txt @@ -0,0 +1 @@ +i18n - english resources \ No newline at end of file diff --git a/test/3-copyFiles/data/res/i18n/resource_fr.txt b/test/3-copyFiles/data/res/i18n/resource_fr.txt new file mode 100644 index 0000000..26b25f2 --- /dev/null +++ b/test/3-copyFiles/data/res/i18n/resource_fr.txt @@ -0,0 +1 @@ +i18n - french resources diff --git a/test/3-copyFiles/data/res/ldpi/file1.txt b/test/3-copyFiles/data/res/ldpi/file1.txt new file mode 100644 index 0000000..6a90d50 --- /dev/null +++ b/test/3-copyFiles/data/res/ldpi/file1.txt @@ -0,0 +1 @@ +ldpi/file1 content diff --git a/test/3-copyFiles/data/res/ldpi/file2.txt b/test/3-copyFiles/data/res/ldpi/file2.txt new file mode 100644 index 0000000..5da1d05 --- /dev/null +++ b/test/3-copyFiles/data/res/ldpi/file2.txt @@ -0,0 +1 @@ +ldpi/file2 content diff --git a/test/3-copyFiles/data/res/ldpi/file3.txt b/test/3-copyFiles/data/res/ldpi/file3.txt new file mode 100644 index 0000000..acca5e8 --- /dev/null +++ b/test/3-copyFiles/data/res/ldpi/file3.txt @@ -0,0 +1 @@ +ldpi/file3 content diff --git a/test/3-copyFiles/data/res/mdpi/file1.txt b/test/3-copyFiles/data/res/mdpi/file1.txt new file mode 100644 index 0000000..57586c8 --- /dev/null +++ b/test/3-copyFiles/data/res/mdpi/file1.txt @@ -0,0 +1 @@ +mdpi/file1 content diff --git a/test/3-copyFiles/data/res/mdpi/file2.txt b/test/3-copyFiles/data/res/mdpi/file2.txt new file mode 100644 index 0000000..6435c1e --- /dev/null +++ b/test/3-copyFiles/data/res/mdpi/file2.txt @@ -0,0 +1 @@ +mdpi/file2 content diff --git a/test/3-copyFiles/data/res/mdpi/file3.txt b/test/3-copyFiles/data/res/mdpi/file3.txt new file mode 100644 index 0000000..fb88bd0 --- /dev/null +++ b/test/3-copyFiles/data/res/mdpi/file3.txt @@ -0,0 +1 @@ +mdpi/file3 content diff --git a/test/3-copyFiles/dub.json b/test/3-copyFiles/dub.json new file mode 100644 index 0000000..e9216ff --- /dev/null +++ b/test/3-copyFiles/dub.json @@ -0,0 +1,10 @@ +{ + "name": "copyfiles-test", + "targetType": "executable", + "targetPath": "bin", + "copyFiles": [ + "data/res", + "data/res/*dpi", + "data/file_to_copy.txt", + "data/file_to_copy_mask*.txt"] +} diff --git a/test/3-copyFiles/source/app.d b/test/3-copyFiles/source/app.d new file mode 100644 index 0000000..dbab869 --- /dev/null +++ b/test/3-copyFiles/source/app.d @@ -0,0 +1,6 @@ +import std.stdio; + +void main() +{ + writeln(__FUNCTION__); +}