Skip to content

Commit

Permalink
Mutually exclude mainSourceFile of different configurations
Browse files Browse the repository at this point in the history
Unless explicitly added to sourceFiles, a configuration will exclude
other configurations' mainSourceFile's.
  • Loading branch information
omerfirmak committed Nov 18, 2020
1 parent 3b31d99 commit 4b6d451
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 0 deletions.
25 changes: 25 additions & 0 deletions source/dub/package_.d
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Package {

checkDubRequirements();
fillWithDefaults();
mutuallyExcludeMainFiles();
}

/** Searches the given directory for package recipe files.
Expand Down Expand Up @@ -740,6 +741,30 @@ class Package {
cnames[c.name] = true;
}
}

private void mutuallyExcludeMainFiles()
{
import std.stdio;
string[] allMainFiles;
foreach (ref config; m_info.configurations)
if (!config.buildSettings.mainSourceFile.empty())
allMainFiles ~= config.buildSettings.mainSourceFile;

if (allMainFiles.length == 0)
return;

foreach (ref config; m_info.configurations) {
import std.algorithm.searching : canFind;
auto bs = &config.buildSettings;
auto otherMainFiles = allMainFiles.filter!(elem => (elem != bs.mainSourceFile)).array;

if (bs.sourceFiles.length == 0)
bs.excludedSourceFiles[""] ~= otherMainFiles;
else
foreach (suffix, arr; bs.sourceFiles)
bs.excludedSourceFiles[suffix] ~= otherMainFiles.filter!(elem => !canFind(arr, elem)).array;
}
}
}

private string determineVersionFromSCM(NativePath path)
Expand Down
Empty file added test/mutex-main-1/.no_run
Empty file.
Empty file added test/mutex-main-1/.no_test
Empty file.
24 changes: 24 additions & 0 deletions test/mutex-main-1/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"description": "A minimal D application.",
"name": "mutex-main",
"targetType": "executable",

"configurations": [
{
"name": "app",
"targetName": "app",
"mainSourceFile": "source/app.d"
},
{
"name": "app2",
"targetName": "app2",
"mainSourceFile": "source/app2.d"
},
{
"name": "failapp",
"targetName": "failapp",
"mainSourceFile": "source/app.d",
"sourceFiles": ["source/app2.d"]
}
]
}
8 changes: 8 additions & 0 deletions test/mutex-main-1/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module app;

import std.stdio;

void main()
{
writeln("Edit source/app.d to start your project.");
}
8 changes: 8 additions & 0 deletions test/mutex-main-1/source/app2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module app2;

import std.stdio;

void main()
{
writeln("Edit source/app2.d to start your project.");
}
Empty file added test/mutex-main-2/.no_run
Empty file.
Empty file added test/mutex-main-2/.no_test
Empty file.
24 changes: 24 additions & 0 deletions test/mutex-main-2/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"description": "A minimal D application.",
"name": "mutex-main",
"targetType": "executable",

"configurations": [
{
"name": "app2",
"targetName": "app2",
"mainSourceFile": "source/app2.d"
},
{
"name": "app",
"targetName": "app",
"mainSourceFile": "source/app.d"
},
{
"name": "failapp",
"targetName": "failapp",
"mainSourceFile": "source/app.d",
"sourceFiles": ["source/app2.d"]
}
]
}
8 changes: 8 additions & 0 deletions test/mutex-main-2/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module app;

import std.stdio;

void main()
{
writeln("Edit source/app.d to start your project.");
}
8 changes: 8 additions & 0 deletions test/mutex-main-2/source/app2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module app2;

import std.stdio;

void main()
{
writeln("Edit source/app2.d to start your project.");
}
Empty file added test/mutex-main-3/.fail_build
Empty file.
Empty file added test/mutex-main-3/.no_run
Empty file.
Empty file added test/mutex-main-3/.no_test
Empty file.
24 changes: 24 additions & 0 deletions test/mutex-main-3/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"description": "A minimal D application.",
"name": "mutex-main",
"targetType": "executable",

"configurations": [
{
"name": "failapp",
"targetName": "failapp",
"mainSourceFile": "source/app.d",
"sourceFiles": ["source/app2.d"]
},
{
"name": "app",
"targetName": "app",
"mainSourceFile": "source/app.d",
},
{
"name": "app2",
"targetName": "app2",
"mainSourceFile": "source/app2.d"
}
]
}
8 changes: 8 additions & 0 deletions test/mutex-main-3/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module app;

import std.stdio;

void main()
{
writeln("Edit source/app.d to start your project.");
}
8 changes: 8 additions & 0 deletions test/mutex-main-3/source/app2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module app2;

import std.stdio;

void main()
{
writeln("Edit source/app2.d to start your project.");
}

0 comments on commit 4b6d451

Please sign in to comment.