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

Actually copy copyFiles when building in Visual Studio. #2105

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/visuald-copyfiles.dd
@@ -0,0 +1,5 @@
copyFiles can now be used in VisualD projects.

Files that are needed for the application to run can be specified in the `copyFiles` build option,
which causes these files to be copied to the target path. The dub generator for VisualD now replicates
this behaviour, so that this kind of applications can be successfully debugged in Visual Studio.
42 changes: 27 additions & 15 deletions source/dub/generators/visuald.d
Expand Up @@ -169,38 +169,38 @@ class VisualDGenerator : ProjectGenerator {
// Add all files
auto files = targets[packname].buildSettings;
SourceFile[string] sourceFiles;
void addSourceFile(NativePath file_path, NativePath structure_path, bool build)
void addSourceFile(NativePath file_path, NativePath structure_path, SourceFile.Action action)
{
auto key = file_path.toString();
auto sf = sourceFiles.get(key, SourceFile.init);
sf.filePath = file_path;
if (!sf.build) {
sf.build = build;
if (sf.action == SourceFile.Action.none) {
sf.action = action;
sf.structurePath = structure_path;
}
sourceFiles[key] = sf;
}

void addFile(string s, bool build) {
void addFile(string s, SourceFile.Action action) {
auto sp = NativePath(s);
assert(sp.absolute, format("Source path in %s expected to be absolute: %s", packname, s));
//if( !sp.absolute ) sp = pack.path ~ sp;
addSourceFile(sp.relativeTo(project_file_dir), determineStructurePath(sp, targets[packname]), build);
addSourceFile(sp.relativeTo(project_file_dir), determineStructurePath(sp, targets[packname]), action);
}

foreach (p; targets[packname].packages)
if (!p.recipePath.empty)
addFile(p.recipePath.toNativeString(), false);
addFile(p.recipePath.toNativeString(), SourceFile.Action.none);

if (files.targetType == TargetType.staticLibrary)
foreach(s; files.sourceFiles.filter!(s => !isLinkerFile(settings.platform, s))) addFile(s, true);
foreach(s; files.sourceFiles.filter!(s => !isLinkerFile(settings.platform, s))) addFile(s, SourceFile.Action.build);
else
foreach(s; files.sourceFiles.filter!(s => !s.endsWith(".lib"))) addFile(s, true);
foreach(s; files.sourceFiles.filter!(s => !s.endsWith(".lib"))) addFile(s, SourceFile.Action.build);

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));
foreach(s; files.importFiles) addFile(s, SourceFile.Action.none);
foreach(s; files.stringImportFiles) addFile(s, SourceFile.Action.none);
findFilesMatchingGlobs(root_package_path, files.copyFiles, s => addFile(s, SourceFile.Action.copy));
findFilesMatchingGlobs(root_package_path, files.extraDependencyFiles, s => addFile(s, SourceFile.Action.none));

// Create folders and files
ret.formattedWrite(" <Folder name=\"%s\">", getPackageFileName(packname));
Expand All @@ -223,7 +223,18 @@ class VisualDGenerator : ProjectGenerator {
ret.formattedWrite("\n <Folder name=\"%s\">", cur[same + idx].name);
lastFolder = cur;
}
ret.formattedWrite("\n <File %spath=\"%s\" />", source.build ? "" : "tool=\"None\" ", source.filePath.toNativeString());
final switch (source.action) with (SourceFile.Action)
{
case none:
ret.formattedWrite("\n <File path=\"%s\" tool=\"None\" />", source.filePath.toNativeString());
break;
case build:
ret.formattedWrite("\n <File path=\"%s\" />", source.filePath.toNativeString());
break;
case copy:
ret.formattedWrite("\n <File customcmd=\"copy /Y $(InputPath) $(TargetDir)\" path=\"%s\" tool=\"Custom\" />", source.filePath.toNativeString());
break;
}
}
// Finalize all open folders
foreach(unused; 0..lastFolder.length)
Expand Down Expand Up @@ -463,9 +474,10 @@ class VisualDGenerator : ProjectGenerator {
private struct SourceFile {
NativePath structurePath;
NativePath filePath;
bool build;
enum Action { none, build, copy };
Action action = Action.none;

size_t toHash() const nothrow @trusted { return structurePath.toHash() ^ filePath.toHash() ^ (build * 0x1f3e7b2c); }
size_t toHash() const nothrow @trusted { return structurePath.toHash() ^ filePath.toHash() ^ (action * 0x1f3e7b2c); }
int opCmp(ref const SourceFile rhs) const { return sortOrder(this, rhs); }
// "a < b" for folder structures (deepest folder first, else lexical)
private final static int sortOrder(ref const SourceFile a, ref const SourceFile b) {
Expand Down
4 changes: 4 additions & 0 deletions test/issue1053-extra-files-visuald.sh
Expand Up @@ -20,3 +20,7 @@ fi
if [ `grep -c -e "README.txt" .dub/extra_files.visualdproj` -ne 1 ]; then
die $LINENO 'Regression of issue #1053.'
fi

if [ `grep -e "README.txt" .dub/extra_files.visualdproj | grep -c -e "copy /Y $(InputPath) $(TargetDir)"` -ne 1 ]; then
veelo marked this conversation as resolved.
Show resolved Hide resolved
die $LINENO 'Copying of copyFiles seems broken for visuald.'
fi