Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include copyFiles and extraDependencyFiles in visuald projects. #2099

Merged
merged 1 commit into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 57 additions & 36 deletions source/dub/generators/generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,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.
maxhaton marked this conversation as resolved.
Show resolved Hide resolved
*/
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 @@ -686,8 +742,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 @@ -743,40 +797,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.