Skip to content

Commit

Permalink
Merge pull request #2099 from veelo/issue1053-visuald-extra-files
Browse files Browse the repository at this point in the history
Include copyFiles and extraDependencyFiles in visuald projects.
  • Loading branch information
maxhaton authored Feb 1, 2021
2 parents 92cc346 + 3600feb commit 7b88ce7
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 37 deletions.
93 changes: 57 additions & 36 deletions source/dub/generators/generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,62 @@ ProjectGenerator createProjectGenerator(string generator_type, Project project)
}


/**
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.
*/
Expand All @@ -689,8 +745,6 @@ private void prepareGeneration(in Package pack, in Project proj, in GeneratorSet
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);
Expand Down Expand Up @@ -746,40 +800,7 @@ private void finalizeGeneration(in Package pack, in Project proj, in GeneratorSe
} 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);
}

}
Expand Down
5 changes: 4 additions & 1 deletion source/dub/generators/visuald.d
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class VisualDGenerator : ProjectGenerator {

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("<DProject>\n");
ret.formattedWrite(" <ProjectGuid>%s</ProjectGuid>\n", guid(packname));

Expand Down Expand Up @@ -198,6 +199,8 @@ class VisualDGenerator : ProjectGenerator {

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(" <Folder name=\"%s\">", getPackageFileName(packname));
Expand Down
22 changes: 22 additions & 0 deletions test/issue1053-extra-files-visuald.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test/issue1053-extra-files-visuald/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "extra_files",
"targetType": "executable",
"extraDependencyFiles": [
"shaders/*"
],
"copyFiles": [
"text/LICENSE.txt",
"text/README.txt"
]
}
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/issue1053-extra-files-visuald/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void main() {}
Empty file.
Empty file.

0 comments on commit 7b88ce7

Please sign in to comment.