diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-06-01 18:50:04 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-06-01 18:50:04 -0400 |
commit | 13822c77b8c06bba522a40fdccd9e0c8e6f7d547 (patch) | |
tree | 552f3864d72f1610f28619fc45a80c990a3e7c8b | |
parent | 8fc1017d809c69943f0257902e4e408fc7b47cb9 (diff) | |
download | dm-13822c77b8c06bba522a40fdccd9e0c8e6f7d547.tar.gz |
Interpolation of environment variables
-rw-r--r-- | source/app.d | 4 | ||||
-rw-r--r-- | source/util.d | 32 |
2 files changed, 36 insertions, 0 deletions
diff --git a/source/app.d b/source/app.d index 4344492..3252c62 100644 --- a/source/app.d +++ b/source/app.d @@ -9,6 +9,7 @@ import std.range : enumerate; import conda; import merge; import session; +import util; int main(string[] args) { @@ -115,6 +116,9 @@ int main(string[] args) { string testdir = buildPath(output_dir, "testdir"); testable_t[] pkgs = testable_packages(conda, session.conda_requirements, session.test_filter_git_orgs); + // Allow use of environment variables in test program argument list + session.test_args = interpolate(conda.env, session.test_args); + foreach (i, pkg; pkgs.enumerate(0)) { string tmpenv = format("%04d_%s", i, session.delivery); if(conda.run("create -n " ~ tmpenv ~ " --clone " ~ session.delivery)) { diff --git a/source/util.d b/source/util.d index 101645a..1d0abf1 100644 --- a/source/util.d +++ b/source/util.d @@ -202,6 +202,38 @@ string expander(string[string] aa, string name, char delim = '$') { } +string interpolate(string[string]aa, string str, char delim = '$') { + import std.ascii; + string s = str.dup; + ulong[] needles = indexOfAll(s, delim); + string[] found; + + foreach (needle; needles) { + string tmp = ""; + for (ulong i = needle; i < s.length; i++) { + if (s[i] == delim) continue; + else if (s[i] == '{' || s[i] == '}') + continue; + else if (!s[i].isAlphaNum && s[i] != '_' ) + break; + tmp ~= s[i]; + } + found ~= tmp; + } + + foreach (match; found) { + foreach (pair; aa.byPair) { + if (pair.key != match) + continue; + s = s.replace(delim ~ pair.key, pair.value) + .replace(format("%c{%s}", delim, pair.key), pair.value); + } + } + + return s; +} + + string short_version(string vrs) { string tmp = vrs.dup; tmp = tmp.replace(".", ""); |