@@ -126,7 +126,7 @@ struct PackageDubVariables
126126/**
127127 * Reflects InitialDubVariables in the environment
128128 */
129- void setupBuildEnvironmentVariables (InitialDubVariables dubVars)
129+ void setupBuildEnvironmentVariables (const ref InitialDubVariables dubVars)
130130{
131131 import std.process ;
132132 static foreach (member; __traits (allMembers, InitialDubVariables))
@@ -166,7 +166,7 @@ InitialDubVariables getInitialDubVariablesFromArguments(DubArguments args, DubBu
166166 * Params:
167167 * root = The root project being parsed
168168 */
169- void setupEnvironmentVariablesForRootPackage (immutable BuildRequirements root)
169+ void setupEnvironmentVariablesForRootPackage (const ref BuildRequirements root)
170170{
171171 import std.process ;
172172 import std.conv :to;
@@ -186,7 +186,7 @@ void setupEnvironmentVariablesForRootPackage(immutable BuildRequirements root)
186186 * Params:
187187 * root = The root where <PKG>_PACKAGE_DIR will be started to be put on environment
188188 */
189- void setupEnvironmentVariablesForPackageTree (ProjectNode root)
189+ void setupEnvironmentVariablesForPackageTree (ref ProjectNode root) // It is const
190190{
191191 // /Path to a specific package that is part of the package's dependency graph. $ must be in uppercase letters without the semver string.
192192 // <PKG>_PACKAGE_DIR ;
@@ -202,7 +202,7 @@ void setupEnvironmentVariablesForPackageTree(ProjectNode root)
202202 * - DUB_TARGET_NAME
203203 * - DUB_MAIN_SOURCE_FILE
204204 */
205- PackageDubVariables getEnvironmentVariablesForPackage (const BuildConfiguration cfg)
205+ PackageDubVariables getEnvironmentVariablesForPackage (const ref BuildConfiguration cfg)
206206{
207207 import std.conv :to;
208208
@@ -224,7 +224,7 @@ PackageDubVariables getEnvironmentVariablesForPackage(const BuildConfiguration c
224224 * - DUB_TARGET_NAME
225225 * - DUB_MAIN_SOURCE_FILE
226226 */
227- void setupEnvironmentVariablesForPackage (const BuildConfiguration cfg)
227+ void setupEnvironmentVariablesForPackage (const ref BuildConfiguration cfg)
228228{
229229 PackageDubVariables pack = getEnvironmentVariablesForPackage(cfg);
230230 static foreach (mem; __traits (allMembers, PackageDubVariables))
@@ -275,15 +275,17 @@ string parseStringWithEnvironment(string str)
275275 string strVar = str[v.start+ 1 + bracketOffset.. v.end - bracketOffset];
276276 diffLength-= 1 + strVar.length + bracketOffset* 2 ; // $.length + (abcd).length {}.length (optionally)
277277
278+
278279 if (strVar.length == 0 ) // $
279280 continue ;
280- else if (! getEnvVariable(strVar))
281+ string envValue = getEnvVariable(strVar);
282+ if (! envValue.length)
281283 {
282284 variables = variables[0 .. i] ~ variables[i+ 1 .. $];
283285 i-- ;
284286 continue ;
285287 }
286- diffLength+= getEnvVariable (strVar) .length;
288+ diffLength+= envValue .length;
287289 }
288290 if (variables.length == 0 ) return str;
289291
@@ -369,25 +371,24 @@ BuildConfiguration parseEnvironmentForPreGenerate(BuildConfiguration cfg, out st
369371 */
370372BuildConfiguration parseEnvironment (BuildConfiguration cfg)
371373{
374+ import redub.command_generators.commons : attrIncludesUDA;
372375 redub.parsers.environment.setupEnvironmentVariablesForPackage(cfg);
373376 with (cfg)
374377 {
375- importDirectories = arrParseEnv(importDirectories);
376- sourcePaths = arrParseEnv(sourcePaths);
377- sourceFiles = arrParseEnv(sourceFiles);
378- libraries = arrParseEnv(libraries);
379- libraryPaths = arrParseEnv(libraryPaths);
380- dFlags = arrParseEnv(dFlags);
381- linkFlags = arrParseEnv(linkFlags );
382-
378+ static foreach (mem; __traits (allMembers, BuildConfiguration))
379+ {
380+ static if (
381+ ! attrIncludesUDA ! (absolutized, __traits(getAttributes, __traits(getMember, cfg, mem)))
382+ && is ( typeof (__traits(getMember, cfg, mem)) == string [])
383+ )
384+ __traits ( getMember , cfg, mem) = arrParseEnv(__traits(getMember, cfg, mem) );
385+ }
383386 if (cfg.commands.length > RedubCommands.postGenerate)
384387 cfg.commands[RedubCommands.postGenerate] = arrParseEnv(cfg.commands[RedubCommands.postGenerate]);
385388 if (cfg.commands.length > RedubCommands.preBuild)
386389 cfg.commands[RedubCommands.preBuild] = arrParseEnv(cfg.commands[RedubCommands.preBuild]);
387390 if (cfg.commands.length > RedubCommands.postBuild)
388391 cfg.commands[RedubCommands.postBuild] = arrParseEnv(cfg.commands[RedubCommands.postBuild]);
389- stringImportPaths = arrParseEnv(stringImportPaths);
390- filesToCopy = arrParseEnv(filesToCopy);
391392 }
392393 return cfg;
393394}
@@ -522,7 +523,21 @@ else
522523 string getEnvVariable (string key)
523524 {
524525 string * ret = key in redubEnv;
525- if (ret) return * ret;
526+ while (ret)
527+ {
528+ key = * ret;
529+ if (key.length == 0 )
530+ return null ;
531+ else if (key[0 ] != ' $' )
532+ return key;
533+ else
534+ {
535+ key = key[1 .. $];
536+ if (key.length > 1 && key[0 ] == ' {' && key[$- 1 ] == ' }' )
537+ key = key[1 .. $- 1 ];
538+ }
539+ ret = key in redubEnv;
540+ }
526541 return null ;
527542 }
528543 shared static this ()
0 commit comments