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

Dont export DFLAGS & LFLAGS by default #2048

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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