From e50ebd2378c9812084defebbdf6a49f1381e2bd0 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Wed, 11 Jul 2018 05:21:37 +0200 Subject: [PATCH] Address review --- source/dub/project.d | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/dub/project.d b/source/dub/project.d index e36b09dce0..bd397317a2 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -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; @@ -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; @@ -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