Skip to content

Commit

Permalink
Don't export DFLAGS & LFLAGS to nested invocations by default
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak authored and Geod24 committed Dec 7, 2020
1 parent 57f89af commit 4c6a19e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 10 additions & 0 deletions changelog/dont-propagate-flags.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
`DFLAGS` and `LFLAGS` no longer propagate to nested `dub` invocations

`DFLAGS` and `LFLAGS` will no longer be exported as environment variables by default
when invoking pre-generate, pre-build, pre-run, post-generate, post-build, or post-run commands.

If the previous behavior is still desired, they can be accessed using `$DFLAGS` and `$LFLAGS` in dub.json
E.g.:
`preGenerateCommands : ["DFLAGS=$DFLAGS env | grep DFLAGS"]`

will output DFLAGS environment variable with all the dflags used.
2 changes: 0 additions & 2 deletions source/dub/generators/generator.d
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,6 @@ void runBuildCommands(in string[] commands, in Package pack, in Project proj,
string[string] env = environment.toAA();
// TODO: do more elaborate things here
// TODO: escape/quote individual items appropriately
env["DFLAGS"] = join(cast(string[])build_settings.dflags, " ");
env["LFLAGS"] = join(cast(string[])build_settings.lflags," ");
env["VERSIONS"] = join(cast(string[])build_settings.versions," ");
env["LIBS"] = join(cast(string[])build_settings.libs," ");
env["SOURCE_FILES"] = join(cast(string[])build_settings.sourceFiles," ");
Expand Down
13 changes: 13 additions & 0 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,15 @@ private string getVariable(Project, Package)(string name, in Project project, in

if (name == "BUILD_TYPE") return gsettings.buildType;

if (name == "DFLAGS" || name == "LFLAGS")
{
auto buildSettings = pack.getBuildSettings(gsettings.platform, gsettings.config);
if (name == "DFLAGS")
return join(buildSettings.dflags," ");
else if (name == "LFLAGS")
return join(buildSettings.lflags," ");
}

auto envvar = environment.get(name);
if (envvar !is null) return envvar;

Expand All @@ -1419,6 +1428,10 @@ unittest
}
string name;
NativePath path;
BuildSettings getBuildSettings(in BuildPlatform platform, string config) const
{
return BuildSettings();
}
}

static struct MockProject
Expand Down

0 comments on commit 4c6a19e

Please sign in to comment.