Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Jul 11, 2018
1 parent 7f3388c commit e50ebd2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ private string processVars(Project, Package)(string var, in Project project, in
private string getVariable(Project, Package)(string name, in Project project, in Package pack)
{
import std.process : environment;
import std.uni : asUpperCase;
Path path;
if (name == "PACKAGE_DIR")
path = pack.path;
Expand All @@ -1207,7 +1208,7 @@ private string getVariable(Project, Package)(string name, in Project project, in
if (name.endsWith("_PACKAGE_DIR")) {
auto pname = name[0 .. $-12];
foreach (prj; project.getTopologicalPackageList())
if (prj.name.toUpper().replace("-", "_") == pname)
if (prj.name.asUpperCase.map!(a => a == '-' ? '_' : a).equal(pname))
{
path = prj.path;
break;
Expand Down Expand Up @@ -1264,16 +1265,16 @@ unittest
auto pack = MockPackage("test");
enum isPath = true;

version (Posix) enum sep = "/";
else version (Windows) enum sep = `\`;
import std.path : dirSeparator;

static Path woSlash(Path p) { p.endsWithSlash = false; return p; }
// basic vars
assert(processVars("Hello $PACKAGE_DIR", proj, pack, !isPath) == "Hello "~woSlash(pack.path).toNativeString);
assert(processVars("Hello $ROOT_PACKAGE_DIR", proj, pack, !isPath) == "Hello "~woSlash(proj.rootPackage.path).toNativeString.chomp(sep));
assert(processVars("Hello $ROOT_PACKAGE_DIR", proj, pack, !isPath) == "Hello "~woSlash(proj.rootPackage.path).toNativeString.chomp(dirSeparator));
assert(processVars("Hello $DEP1_PACKAGE_DIR", proj, pack, !isPath) == "Hello "~woSlash(proj._dependencies[0].path).toNativeString);
// ${VAR} replacements
assert(processVars("Hello ${PACKAGE_DIR}"~sep~"foobar", proj, pack, !isPath) == "Hello "~(pack.path ~ "foobar").toNativeString);
assert(processVars("Hello $PACKAGE_DIR"~sep~"foobar", proj, pack, !isPath) == "Hello "~(pack.path ~ "foobar").toNativeString);
assert(processVars("Hello ${PACKAGE_DIR}"~dirSeparator~"foobar", proj, pack, !isPath) == "Hello "~(pack.path ~ "foobar").toNativeString);
assert(processVars("Hello $PACKAGE_DIR"~dirSeparator~"foobar", proj, pack, !isPath) == "Hello "~(pack.path ~ "foobar").toNativeString);
// test with isPath
assert(processVars("local", proj, pack, isPath) == (pack.path ~ "local").toNativeString);
// test other env variables
Expand Down

0 comments on commit e50ebd2

Please sign in to comment.