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

the DFLAGS env variable is not handled when `--build` is passed #1645

Open
ghost opened this issue Feb 3, 2019 · 2 comments

Comments

@ghost
Copy link

commented Feb 3, 2019

System information

  • dub version: 1.13.0
  • OS Platform and distribution: Linux Fedora 28, x86_64
  • compiler version dmd-2.084.0

Bug Description

The environment variables like DFLAGS are not passed to the compiler when --build is passed to dub

How to reproduce?

Let's use a simple d program for that:

void main(string[] args)
{
    string[string] env;
    env["DFLAGS"] = "-StopCompilingBecauseThisSwitchIsInvalidAndSomwhatLooooongish";
    execute(["git", "clone", "https://github.com/Basile-z/styx.git"]);
    // this one return 0...
    writeln(execute(["dub", "build", "--config=library", "--build=debug"], env, Config.none, size_t.max, "./styx"));
    // this one return 2...
    writeln(execute(["dub", "build", "--config=library", ], env, Config.none, size_t.max, "./styx"));
}  

Expected Behavior

The first execute should return 2.

@ghost ghost changed the title the custom DFLAGS env variable is not handled when `--build` is passed the DFLAGS env variable is not handled when `--build` is passed Feb 3, 2019

@vporton

This comment has been minimized.

Copy link

commented Feb 11, 2019

It looks like for me that the fix is very simple:

diff --git a/source/dub/package_.d b/source/dub/package_.d
index 1c1858e..8128ceb 100644
--- a/source/dub/package_.d
+++ b/source/dub/package_.d
@@ -401,12 +401,9 @@ class Package {
        */
        void addBuildTypeSettings(ref BuildSettings settings, in BuildPlatform platform, string build_type)
        const {
-               if (build_type == "$DFLAGS") {
-                       import std.process;
-                       string dflags = environment.get("DFLAGS");
-                       settings.addDFlags(dflags.split());
-                       return;
-               }
+               import std.process;
+               string dflags = environment.get("DFLAGS", "");
+               settings.addDFlags(dflags.split());

                if (auto pbt = build_type in m_info.buildTypes) {
                        logDiagnostic("Using custom build type '%s'.", build_type);

I've successfully compiled the patched version, but didn't test it.

@WebFreak001

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

when the DFLAGS environment variable is specified it switches to a special build mode called "DFLAGS", which is only used when not overriden

According to the docs the DFLAGS should be stronger though:

--build= | Specifies the type of build to perform. Note that setting the DFLAGS environment variable will override the build type with custom flags. Possible names:     debug (default), plain, release, release-debug, release-nobounds, unittest, profile, profile-gc, docs, ddox, cov, unittest-cov, syntax and custom types

if (m_buildType.length == 0) {
if (environment.get("DFLAGS") !is null) m_buildType = "$DFLAGS";
else m_buildType = default_build_type;
}

I think this was probably added to avoid conflicts in DFLAGS when there is an environment variable but it's overriden with the argument.

Changing it might break stuff expecting DFLAGS to be overriden. Not sure what the best solution would be here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.