Skip to content

Commit 4eda67d

Browse files
committed
Fix duplicate source files on Windows due to mixed path separators (#3070)
1 parent 62bf8ed commit 4eda67d

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

source/dub/compilers/buildsettings.d

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,14 @@ void getPlatformSettings(in BuildSettingsTemplate this_, ref BuildSettings dst,
545545
// collect source files. Note: D source from 'sourcePaths' and C sources from 'cSourcePaths' are joint into 'sourceFiles'
546546
dst.addSourceFiles(collectFiles(this_.sourcePaths, "*.d"));
547547
dst.addSourceFiles(collectFiles(this_.cSourcePaths, "*.{c,i}"));
548+
version (Windows) {
549+
import std.path : buildNormalizedPath;
550+
import std.algorithm : map;
551+
import std.array : array;
552+
dst.sourceFiles = dst.sourceFiles.map!buildNormalizedPath.array;
553+
if (!dst.mainSourceFile.empty)
554+
dst.mainSourceFile = buildNormalizedPath(dst.mainSourceFile);
555+
}
548556
auto sourceFiles = dst.sourceFiles.sort();
549557

550558
// collect import files and remove sources

test/issue3070.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# Test for https://github.com/dlang/dub/issues/3070
3+
# Verify mixed path separators don't cause duplicate source file errors.
4+
set -e
5+
. $(dirname "${BASH_SOURCE[0]}")/common.sh
6+
cd ${CURR_DIR}/issue3070
7+
$DUB build --compiler=${DC} 2>&1
8+
echo "PASS: No duplicate source file error with mixed path separators."

test/issue3070/dub.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "issue3070",
3+
"description": "Test mixed path separators do not duplicate mainSourceFile",
4+
"targetType": "executable",
5+
"sourcePaths": ["src"],
6+
"mainSourceFile": "src/main.d"
7+
}

test/issue3070/src/main.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void main() {}

0 commit comments

Comments
 (0)