diff --git a/source/dub/project.d b/source/dub/project.d index 5f94b25..8a807a9 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -1151,7 +1151,7 @@ dst.addDFlags(processVars(project, pack, gsettings, settings.dflags)); dst.addLFlags(processVars(project, pack, gsettings, settings.lflags)); dst.addLibs(processVars(project, pack, gsettings, settings.libs)); - dst.addSourceFiles(processVars(project, pack, gsettings, settings.sourceFiles, true)); + dst.addSourceFiles(processVars!true(project, pack, gsettings, settings.sourceFiles, true)); dst.addImportFiles(processVars(project, pack, gsettings, settings.importFiles, true)); dst.addStringImportFiles(processVars(project, pack, gsettings, settings.stringImportFiles, true)); dst.addCopyFiles(processVars(project, pack, gsettings, settings.copyFiles, true)); @@ -1182,29 +1182,58 @@ } } -private string[] processVars(in Project project, in Package pack, in GeneratorSettings gsettings, string[] vars, bool are_paths = false) +private string[] processVars(bool glob = false)(in Project project, in Package pack, in GeneratorSettings gsettings, string[] vars, bool are_paths = false) { auto ret = appender!(string[])(); - processVars(ret, project, pack, gsettings, vars, are_paths); + processVars!glob(ret, project, pack, gsettings, vars, are_paths); return ret.data; - } -private void processVars(ref Appender!(string[]) dst, in Project project, in Package pack, in GeneratorSettings gsettings, string[] vars, bool are_paths = false) +private void processVars(bool glob = false)(ref Appender!(string[]) dst, in Project project, in Package pack, in GeneratorSettings gsettings, string[] vars, bool are_paths = false) { - foreach (var; vars) dst.put(processVars(var, project, pack, gsettings, are_paths)); + static if (glob) + alias process = processVarsWithGlob!(Project, Package); + else + alias process = processVars!(Project, Package); + foreach (var; vars) + dst.put(process(var, project, pack, gsettings, are_paths)); } private string processVars(Project, Package)(string var, in Project project, in Package pack, in GeneratorSettings gsettings, bool is_path) { var = var.expandVars!(varName => getVariable(varName, project, pack, gsettings)); - if (is_path) { - auto p = NativePath(var); - if (!p.absolute) { - return (pack.path ~ p).toNativeString(); - } else return p.toNativeString(); - } else return var; + if (!is_path) + return var; + auto p = NativePath(var); + if (!p.absolute) + return (pack.path ~ p).toNativeString(); + else + return p.toNativeString(); } +private string[] processVarsWithGlob(Project, Package)(string var, in Project project, in Package pack, in GeneratorSettings gsettings, bool is_path) +{ + assert(is_path, "can't glob something that isn't a path"); + string res = processVars(var, project, pack, gsettings, is_path); + // Find the unglobbed prefix and iterate from there. + size_t i = 0; + size_t sepIdx = 0; + loop: while (i < res.length) { + switch_: switch (res[i]) + { + case '*', '?', '[', '{': break loop; + case '/': sepIdx = i; goto default; + default: ++i; break switch_; + } + } + if (i == res.length) //no globbing found in the path + return [res]; + import std.path : globMatch; + import std.file : dirEntries, SpanMode; + return dirEntries(res[0 .. sepIdx], SpanMode.depth) + .map!(de => de.name) + .filter!(name => globMatch(name, res)) + .array; +} /// Expand variables using `$VAR_NAME` or `${VAR_NAME}` syntax. /// `$$` escapes itself and is expanded to a single `$`. private string expandVars(alias expandVar)(string s) diff --git a/test/.gitignore b/test/.gitignore index 77ea5b9..ff95cca 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -11,5 +11,6 @@ custom-unittest/custom-unittest path-subpackage-ref/test subpackage-ref/test +subpackage-common-with-sourcefile-globbing/mypackage* /test_registry diff --git a/test/subpackage-common-with-sourcefile-globbing.sh b/test/subpackage-common-with-sourcefile-globbing.sh new file mode 100755 index 0000000..1341acc --- /dev/null +++ b/test/subpackage-common-with-sourcefile-globbing.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +cd ${CURR_DIR}/subpackage-common-with-sourcefile-globbing +rm -rf .dub dub.selections.json +${DUB} build --compiler=${DC} :server -v +${DUB} build --compiler=${DC} :client -v +${DUB} build --compiler=${DC} :common -v diff --git a/test/subpackage-common-with-sourcefile-globbing/.no_build b/test/subpackage-common-with-sourcefile-globbing/.no_build new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/subpackage-common-with-sourcefile-globbing/.no_build diff --git a/test/subpackage-common-with-sourcefile-globbing/code/mypackage/client/app.d b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/client/app.d new file mode 100644 index 0000000..b44941f --- /dev/null +++ b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/client/app.d @@ -0,0 +1,3 @@ +import mypackage.client.extra; +import mypackage.common.blah; +void main() { foo(); blah(); } diff --git a/test/subpackage-common-with-sourcefile-globbing/code/mypackage/client/extra.d b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/client/extra.d new file mode 100644 index 0000000..16ada9b --- /dev/null +++ b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/client/extra.d @@ -0,0 +1,2 @@ +module mypackage.client.extra; +void foo() {} diff --git a/test/subpackage-common-with-sourcefile-globbing/code/mypackage/common/blah.d b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/common/blah.d new file mode 100644 index 0000000..7b4b17f --- /dev/null +++ b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/common/blah.d @@ -0,0 +1,2 @@ +module mypackage.common.blah; +void blah() {} diff --git a/test/subpackage-common-with-sourcefile-globbing/code/mypackage/server/app.d b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/server/app.d new file mode 100644 index 0000000..8912405 --- /dev/null +++ b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/server/app.d @@ -0,0 +1,3 @@ +import mypackage.server.extra; +import mypackage.common.blah; +void main() { foo(); blah(); } diff --git a/test/subpackage-common-with-sourcefile-globbing/code/mypackage/server/extra.d b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/server/extra.d new file mode 100644 index 0000000..07cc3ef --- /dev/null +++ b/test/subpackage-common-with-sourcefile-globbing/code/mypackage/server/extra.d @@ -0,0 +1,2 @@ +module mypackage.server.extra; +void foo() {} diff --git a/test/subpackage-common-with-sourcefile-globbing/dub.sdl b/test/subpackage-common-with-sourcefile-globbing/dub.sdl new file mode 100644 index 0000000..a659505 --- /dev/null +++ b/test/subpackage-common-with-sourcefile-globbing/dub.sdl @@ -0,0 +1,19 @@ +name "mypackage" +targetType "none" +subPackage { + name "server" + sourceFiles "code/mypackage/[sc][oe]*/*.d" + targetType "executable" +} +subPackage { + name "client" + sourceFiles "code/mypackage/client/*.d" + targetType "executable" + dependency "mypackage:common" version="*" +} +subPackage { + name "common" + sourceFiles "code/mypackage/common/*.d" + importPaths "code" + targetType "library" +}