Skip to content

Commit

Permalink
Recursively apply dependencyBuildSettings
Browse files Browse the repository at this point in the history
For now, only "dflags" is used
  • Loading branch information
omerfirmak committed Nov 27, 2020
1 parent 86afb94 commit e61a1d5
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 3 deletions.
18 changes: 18 additions & 0 deletions changelog/dependency-build-settings.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Let custom build settings to be defined for dependencies

For example;
`
{
"description": "A simple vibe.d server application.",
"license": "proprietary",
"name": "dubtest",

"dependencies": {
"vibe-d": { "version" : "~>0.9.2", "dflags" : ["-preview=in"] }
}
}
`

`-preview=in` will be applied to `vibe-d` and all of its dependencies.
Any BuildSettings field can be used, parsing support is present. But,
for now only, dflags is taken into account when compiling.
31 changes: 28 additions & 3 deletions source/dub/generators/generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,45 @@ class ProjectGenerator
visited.clear();

// 1. downwards inherits versions, debugVersions, and inheritable build settings
static void configureDependencies(const scope ref TargetInfo ti, TargetInfo[string] targets, size_t level = 0)
static void configureDependencies(const scope ref TargetInfo ti, TargetInfo[string] targets,
BuildSettings[string] dependBS, size_t level = 0)
{

static void applyForcedSettings(const scope ref BuildSettings forced, ref BuildSettings child) {
child.addDFlags(forced.dflags);
}

// do not use `visited` here as dependencies must inherit
// configurations from *all* of their parents
logDebug("%sConfigure dependencies of %s, deps:%(%s, %)", ' '.repeat(2 * level), ti.pack.name, ti.dependencies);
foreach (depname; ti.dependencies)
{
BuildSettings forcedSettings;
auto pti = &targets[depname];
mergeFromDependent(ti.buildSettings, pti.buildSettings);
configureDependencies(*pti, targets, level + 1);

if (auto matchedSettings = depname in dependBS)
forcedSettings = *matchedSettings;
else if (auto matchedSettings = "*" in dependBS)
forcedSettings = *matchedSettings;

applyForcedSettings(forcedSettings, pti.buildSettings);
configureDependencies(*pti, targets, ["*" : forcedSettings], level + 1);
}
}

configureDependencies(*roottarget, targets);
BuildSettings[string] dependencyBuildSettings;
foreach (key, value; rootPackage.recipe.buildSettings.dependencyBuildSettings)
{
BuildSettings buildSettings;
if (auto target = key in targets)
{
value.getPlatformSettings(buildSettings, genSettings.platform, target.pack.path);
buildSettings.processVars(m_project, target.pack, buildSettings, genSettings, true);
dependencyBuildSettings[key] = buildSettings;
}
}
configureDependencies(*roottarget, targets, dependencyBuildSettings);

// 2. add Have_dependency_xyz for all direct dependencies of a target
// (includes incorporated non-target dependencies and their dependencies)
Expand Down
4 changes: 4 additions & 0 deletions test/depen-build-settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
depend.json
depend2.json
depen-build-settings.json
depen-build-settings
Empty file.
5 changes: 5 additions & 0 deletions test/depen-build-settings/depend/depend2/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"targetType": "library",
"description": "A minimal D application.",
"name": "depend2"
}
6 changes: 6 additions & 0 deletions test/depen-build-settings/depend/depend2/source/depend2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import std.stdio;

extern (C) void depend2_func()
{
writeln("depend2_func");
}
9 changes: 9 additions & 0 deletions test/depen-build-settings/depend/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"targetType": "library",
"description": "A minimal D application.",
"name": "depend1",

"dependencies": {
"depend2": { "version" : "*" }
}
}
9 changes: 9 additions & 0 deletions test/depen-build-settings/depend/source/depend.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import std.stdio;

extern (C) void depend2_func();

extern (C) void depend1_func()
{
writeln("depend1_func");
depend2_func();
}
8 changes: 8 additions & 0 deletions test/depen-build-settings/dub.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"description": "A minimal D application.",
"name": "depen-build-settings",

"dependencies": {
"depend1": { "version" : "*", "dflags" : ["-X"] }
}
}
7 changes: 7 additions & 0 deletions test/depen-build-settings/dub.selections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"fileVersion": 1,
"versions": {
"depend1": {"path":"depend/"},
"depend2": {"path":"depend/depend2/"}
}
}
12 changes: 12 additions & 0 deletions test/depen-build-settings/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import std.stdio;
import std.file;

extern (C) void depend1_func();

void main()
{
writeln("Edit source/app.d to start your project.");
depend1_func();
assert(exists("depend2.json"));
assert(exists("depend.json"));
}

0 comments on commit e61a1d5

Please sign in to comment.