Skip to content

Commit ed46216

Browse files
committed
Update: Fixed Issue #59, improved envrionment parsing (a bit faster), better documentation, new test case,
1 parent 711a83a commit ed46216

File tree

11 files changed

+95
-45
lines changed

11 files changed

+95
-45
lines changed

source/redub/api.d

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ int createNewProject(string projectType, string single, string targetDirectory)
246246
projectName = single.length ? single.stripExtension : baseName(path);
247247
userName = getUserName();
248248
int returnCode = 0;
249-
string gitIgnore = "*.exe\n*.pdb\n*.o\n*.obj\n*.lst\n*.lnk\n.history\n.dub\ndocs.json\n__dummy.html\ndocs/\nbuild/\n/"~projectName;
249+
string gitIgnore = "*.exe\n*.pdb\n*.o\n*.obj\n*.lst\n*.lnk\n*.ilk\n.history\n.dub\ndocs.json\n__dummy.html\ndocs/\nbuild/\n/"~projectName;
250250
foreach(ext; [".so", ".dylib", ".dll", ".a", ".lib", "-test-*"])
251251
gitIgnore~= "\n" ~ projectName ~ ext;
252252
string appSource =
@@ -747,7 +747,7 @@ ProjectDetails resolveDependencies(
747747
);
748748

749749
CompilerBinary cBin = req.cfg.getCompiler(compiler);
750-
redub.parsers.environment.setupEnvironmentVariablesForRootPackage(cast(immutable)req);
750+
redub.parsers.environment.setupEnvironmentVariablesForRootPackage(req);
751751
if(cDetails.includeEnvironmentVariables)
752752
req.cfg = req.cfg.merge(redub.parsers.environment.parse());
753753

@@ -762,10 +762,7 @@ ProjectDetails resolveDependencies(
762762
redub.parsers.environment.setupEnvironmentVariablesForPackageTree(tree);
763763
///That now only happens at the last stage since some environment variables only finished the definition at that stage
764764
foreach(ProjectNode n; tree.collapse)
765-
n.requirements.cfg = redub.parsers.environment.parseEnvironment(n.requirements.cfg);
766-
767-
768-
765+
n.requirements.cfg = redub.parsers.environment.parseEnvironment(n.requirements.cfg); //Second pass on environment, important since now we have all projects available in the env
769766

770767
import redub.libs.colorize;
771768
import redub.package_searching.dub;

source/redub/buildapi.d

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import redub.package_searching.api;
77

88

99
///vX.X.X
10-
enum RedubVersionOnly = "v1.26.1";
10+
enum RedubVersionOnly = "v1.26.2";
1111
///Redub vX.X.X
1212
enum RedubVersionShort = "Redub "~RedubVersionOnly;
1313
///Redub vX.X.X - Description
@@ -127,8 +127,12 @@ TargetType targetFrom(string s)
127127
return ret;
128128
}
129129

130-
enum excludeRoot;
130+
///cacheExclude means that the value does not enter in the recipe file cache generation formula. That is good to reuse the project's output
131131
enum cacheExclude;
132+
///That means the same thing from cacheExclude, except it will only be excluded for the root project.
133+
enum excludeRoot;
134+
///Absolutized means that the strings have their environment value parsed inside the redub.parsers.automatic.postProcessBuildRequirements
135+
enum absolutized;
132136

133137
struct PluginExecution
134138
{
@@ -195,18 +199,18 @@ struct BuildConfiguration
195199
string name;
196200
string[] versions;
197201
string[] debugVersions;
198-
string[] importDirectories;
199-
string[] libraryPaths;
200-
string[] stringImportPaths;
202+
@absolutized string[] importDirectories;
203+
@absolutized string[] libraryPaths;
204+
@absolutized string[] stringImportPaths;
201205
string[] libraries;
202206
string[] frameworks;
203207
string[] linkFlags;
204208
string[] dFlags;
205-
string[] sourcePaths;
206-
string[] sourceFiles;
207-
string[] excludeSourceFiles;
209+
@absolutized string[] sourcePaths;
210+
@absolutized string[] sourceFiles;
211+
@absolutized string[] excludeSourceFiles;
208212
string[] extraDependencyFiles;
209-
string[] filesToCopy;
213+
@absolutized string[] filesToCopy;
210214
string[][] commands;
211215
PluginExecution[] preBuildPlugins;
212216
string workingDir;

source/redub/building/cache.d

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,6 @@ ubyte[] hashFunction(const ubyte[] input, ref ubyte[8] output)
197197
return output;
198198
}
199199

200-
bool attrIncludesUDA(LookType, Attribs...)()
201-
{
202-
bool hasFound = false;
203-
static foreach (value; Attribs)
204-
static if (is(typeof(value) == LookType) || is(LookType == value))
205-
hasFound = true;
206-
return hasFound;
207-
}
208-
209200
/**
210201
*
211202
* Params:

source/redub/command_generators/commons.d

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,15 @@ void setSpanModeAsBreadth(bool breadth)
418418
atomicStore(usingBreadth, breadth);
419419
}
420420

421+
bool attrIncludesUDA(LookType, Attribs...)()
422+
{
423+
bool hasFound = false;
424+
static foreach (value; Attribs)
425+
static if (is(typeof(value) == LookType) || is(LookType == value))
426+
hasFound = true;
427+
return hasFound;
428+
}
429+
421430
auto dirEntriesBreadth(string inputPath)
422431
{
423432
import std.file;

source/redub/parsers/automatic.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ BuildRequirements postProcessBuildRequirements(BuildRequirements req, BuildConfi
110110
req.cfg.flags|= BuildConfigurationFlags.outputsDeps;
111111

112112
partiallyFinishBuildRequirements(req, pending); ///Merge need to happen after partial finish, since other configuration will be merged
113-
req.cfg = redub.parsers.environment.parseEnvironment(req.cfg);
113+
req.cfg = redub.parsers.environment.parseEnvironment(req.cfg); //First pass in env parsing
114114
return req;
115115
}
116116

@@ -149,8 +149,9 @@ private void partiallyFinishBuildRequirements(ref BuildRequirements req, BuildCo
149149
{
150150
foreach(ref string dir; *arr)
151151
{
152-
import redub.command_generators.commons : escapePath;
153-
if(!isAbsolute(dir))
152+
import redub.parsers.environment;
153+
dir = parseStringWithEnvironment(dir);
154+
if(!isAbsolute(dir))
154155
dir = redub.misc.path.buildNormalizedPath(req.cfg.workingDir, dir);
155156
}
156157
}

source/redub/parsers/environment.d

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
370372
BuildConfiguration 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()

tests/env/.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
*.exe
2+
*.pdb
3+
*.o
4+
*.obj
5+
*.lst
6+
*.lnk
7+
*.ilk
8+
.history
9+
.dub
10+
docs.json
11+
__dummy.html
12+
docs/
13+
build/
14+
/env
15+
env.so
16+
env.dylib
17+
env.dll
18+
env.a
19+
env.lib
20+
env-test-*

tests/env/dub.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "env",
3+
"stringImportPaths": ["$LOL"]
4+
}

tests/env/repro.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set LOL=%CD%\simport
2+
echo LOL variable set to %LOL%
3+
redub -v -f

tests/env/simport/main.inl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
void main()
2+
{
3+
import std;
4+
writeln("Everything OK.");
5+
}

0 commit comments

Comments
 (0)