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

Use DC env variable as the default compiler #2047

Merged
merged 1 commit into from
Dec 1, 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
6 changes: 6 additions & 0 deletions changelog/env-d-compiler.dd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Use DC environment variable as default D compiler

dub now respects the `DC` environment variable, meaning that `DC=ldc2 dub build` will behave as `dub build --compiler=ldc2`.
In case both are supplied, the `--compiler` switch still has priority.
Note that when DUB recursively invokes itself, for example in `preGenerateCommands`,
it sets the `DC` variable to the compiler it is using, meaning that nested dub invocation will now use the same compiler.
6 changes: 5 additions & 1 deletion source/dub/dub.d
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,11 @@ class Dub {
import std.process : environment;
import std.range : front;

m_defaultCompiler = m_config.defaultCompiler.expandTilde;
// Env takes precedence
if (auto envCompiler = environment.get("DC"))
m_defaultCompiler = envCompiler;
else
m_defaultCompiler = m_config.defaultCompiler.expandTilde;
omerfirmak marked this conversation as resolved.
Show resolved Hide resolved
if (m_defaultCompiler.length && m_defaultCompiler.isAbsolute)
return;

Expand Down
6 changes: 6 additions & 0 deletions test/dc-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

. $(dirname "${BASH_SOURCE[0]}")/common.sh
cd ${CURR_DIR}/issue2012-dc-env

$DUB app.d ${DC}
Empty file added test/issue2012-dc-env/.no_build
Empty file.
18 changes: 18 additions & 0 deletions test/issue2012-dc-env/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env dub
/+ dub.sdl:
name "app"
+/

import std.format;

void main(string[] args)
{
version (LDC)
immutable expected = "ldc2";
version (DigitalMars)
immutable expected = "dmd";
version (GNU)
immutable expected = "gdc";

assert(expected == args[1], format!"Expected '%s' but got '%s'"(expected, args[1]));
}
2 changes: 2 additions & 0 deletions test/issue895-local-configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function cleanup {

trap cleanup EXIT

unset DC

if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF "Unknown compiler: $(dirname $CURR_DIR)/bin/foo"; then
rm ../bin/foo
die $LINENO 'DUB did not find the local configuration with an adjacent compiler.'
Expand Down