Skip to content

Commit 470dcff

Browse files
committed
Update:
- Improved error messages - Performance on the environment parsing (no useless lock) - Improved warning for when running redub
1 parent 1cd6fa4 commit 470dcff

File tree

5 files changed

+53
-19
lines changed

5 files changed

+53
-19
lines changed

source/app.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ int runMain(string[] args, string[] runArgs)
119119
ProjectDetails d = resolveDependencies(args);
120120
if(!d.tree || d.usesExternalErrorCode)
121121
return d.getReturnCode;
122+
if(d.tree.name == "redub")
123+
warnTitle("Attempt to build and run redub with redub: ", "For building redub with redub, use the command 'redub update' which already outputs an optimized build");
122124
d = buildProject(d);
123125
if(!d.tree || d.usesExternalErrorCode)
124126
return d.getReturnCode;
125127
if(d.tree.requirements.cfg.targetType != TargetType.executable)
126128
return 1;
129+
127130
if(d.tree.name == "redub")
128-
{
129-
warnTitle("Attempt to build and run redub with redub: ", "For building redub with redub, use the command 'redub update' which already outputs an optimized build");
130131
return 0;
131-
}
132132
return executeProgram(d.tree, runArgs);
133133
}
134134

source/redub/package_searching/downloader.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ string getDownloadLink(string packageName, string repo, SemVer requirement, out
3737
if(requirement.isInvalid)
3838
{
3939
if(!repo)
40-
throw new Exception("Can't have invalid requirement '"~requirement.toString~"' and have no 'repo' information.");
40+
throw new Exception("Can't have invalid requirement '"~requirement.toString~"' and have no 'repository' information.
41+
\nExample of repository with branch usage: \"redub\": {\"version\": \"~master\", \"repository\": \"git+https://github.com/MrcSnm/redub.git\"}");
4142
actualVer = requirement;
4243
return getGitDownloadLink(packageName, repo, requirement.toString);
4344
}

source/redub/parsers/base.d

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,34 @@ void addExtraDependencyFiles(ref BuildRequirements req, JSONStringArray files, P
7171
void addFilesToCopy(ref BuildRequirements req, JSONStringArray files, ParseConfig c){req.cfg.filesToCopy = req.cfg.filesToCopy.append(files);}
7272
void addPreGenerateCommands(ref BuildRequirements req, JSONStringArray cmds, ParseConfig c)
7373
{
74-
import hipjson;
74+
if(req.cfg.commands.length <= RedubCommands.preGenerate)
75+
req.cfg.commands.length = RedubCommands.preGenerate + 1;
76+
req.cfg.commands[RedubCommands.preGenerate] = req.cfg.commands[RedubCommands.preGenerate].append(cmds);
77+
}
78+
79+
void runPreGenerateCommands(ParseConfig c, ref BuildRequirements req)
80+
{
81+
import redub.parsers.environment;
82+
string[string] outRedubEnv;
83+
req.cfg = parseEnvironmentForPreGenerate(req.cfg, outRedubEnv);
7584
import redub.parsers.environment;
7685
if(c.preGenerateRun)
7786
{
7887
infos("Pre-gen ", "Running commands for ", c.extra.requiredBy);
79-
foreach(JSONValue cmd; cmds.save)
88+
foreach(string cmd; req.cfg.preGenerateCommands)
8089
{
8190
import std.process;
8291
import std.stdio;
8392
import std.conv:to;
8493

8594
if(hasLogLevel(LogLevel.verbose))
86-
vlog("Executing: ", executeShell("echo "~cmd.str, getRedubEnv, Config.none, size_t.max, c.workingDir).output, " at dir ", c.workingDir);
95+
vlog("Executing: ", executeShell("echo "~cmd, outRedubEnv, Config.none, size_t.max, c.workingDir).output, " at dir ", c.workingDir);
8796

88-
auto status = wait(spawnShell(cmd.str, stdin, stdout, stderr, getRedubEnv, Config.none, c.workingDir));
97+
auto status = wait(spawnShell(cmd, stdin, stdout, stderr, outRedubEnv, Config.none, c.workingDir));
8998
if(status)
90-
throw new Exception("preGenerateCommand '"~cmd.str~"' exited with code "~status.to!string);
99+
throw new Exception("preGenerateCommand '"~cmd~"' exited with code "~status.to!string);
91100
}
92101
}
93-
if(req.cfg.commands.length <= RedubCommands.preGenerate)
94-
req.cfg.commands.length = RedubCommands.preGenerate + 1;
95-
req.cfg.commands[RedubCommands.preGenerate] = req.cfg.commands[RedubCommands.preGenerate].append(cmds);
96102
}
97103
void addPostGenerateCommands(ref BuildRequirements req, JSONStringArray cmds, ParseConfig c)
98104
{

source/redub/parsers/environment.d

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void setupEnvironmentVariablesForPackageTree(ProjectNode root)
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 ;
193193
foreach(ProjectNode mem; root.collapse)
194-
setEnvVariable(asPackageVariable(mem.name)~"_PACKAGE_DIR", mem.requirements.cfg.workingDir.forceTrailingDirSeparator);
194+
setEnvVariableNoLock(asPackageVariable(mem.name)~"_PACKAGE_DIR", mem.requirements.cfg.workingDir.forceTrailingDirSeparator);
195195
}
196196

197197
/**
@@ -226,14 +226,12 @@ PackageDubVariables getEnvironmentVariablesForPackage(const BuildConfiguration c
226226
*/
227227
void setupEnvironmentVariablesForPackage(const BuildConfiguration cfg)
228228
{
229-
import std.process;
230229
PackageDubVariables pack = getEnvironmentVariablesForPackage(cfg);
231230
static foreach(mem; __traits(allMembers, PackageDubVariables))
232-
setEnvVariable(mem, __traits(getMember, pack, mem));
231+
setEnvVariableNoLock(mem, __traits(getMember, pack, mem));
233232
}
234233
string parseStringWithEnvironment(string str)
235234
{
236-
import std.process;
237235
import std.exception;
238236
import std.string;
239237
import std.ascii:isAlphaNum;
@@ -338,7 +336,29 @@ unittest
338336
parseStringWithEnvironment(`C:\Users\Marcelo\Documents\D\test\sokol-d\${SOKOL_D_PACKAGE_DIR}\src\sokol\c\sokol_log.c`) ==
339337
`C:\Users\Marcelo\Documents\D\test\sokol-d\test\src\sokol\c\sokol_log.c`
340338
);
339+
}
341340

341+
/**
342+
* cfg = Config to parse environment inside the preGenerateCommands
343+
* outEnv = Output environment to be used for the preGenerateCommands
344+
*/
345+
BuildConfiguration parseEnvironmentForPreGenerate(BuildConfiguration cfg, out string[string] outEnv)
346+
{
347+
//In this part it does need to lock since it runs on parallel.
348+
PackageDubVariables pack = getEnvironmentVariablesForPackage(cfg);
349+
lockEnv();
350+
scope(exit)
351+
unlockEnv();
352+
static foreach(mem; __traits(allMembers, PackageDubVariables))
353+
setEnvVariableNoLock(mem, __traits(getMember, pack, mem));
354+
outEnv = getRedubEnv();
355+
redub.parsers.environment.setupEnvironmentVariablesForPackage(cfg);
356+
with(cfg)
357+
{
358+
if(cfg.commands.length > RedubCommands.preGenerate)
359+
cfg.commands[RedubCommands.preGenerate] = arrParseEnv(cfg.commands[RedubCommands.preGenerate]);
360+
}
361+
return cfg;
342362
}
343363

344364
/**
@@ -360,8 +380,6 @@ BuildConfiguration parseEnvironment(BuildConfiguration cfg)
360380
dFlags = arrParseEnv(dFlags);
361381
linkFlags = arrParseEnv(linkFlags);
362382

363-
if(cfg.commands.length > RedubCommands.preGenerate)
364-
cfg.commands[RedubCommands.preGenerate] = arrParseEnv(cfg.commands[RedubCommands.preGenerate]);
365383
if(cfg.commands.length > RedubCommands.postGenerate)
366384
cfg.commands[RedubCommands.postGenerate] = arrParseEnv(cfg.commands[RedubCommands.postGenerate]);
367385
if(cfg.commands.length > RedubCommands.preBuild)
@@ -447,7 +465,9 @@ version(AsLibrary) //Library version will use environment instead of redubEnv si
447465
* key =
448466
* value =
449467
*/
468+
450469
void setEnvVariable(string key, string value){environment[key] = value;}
470+
alias setEnvVariableNoLock = setEnvVariable;
451471
/**
452472
* Gets the environment as a string[string] to be used inside a function
453473
* Returns:
@@ -478,6 +498,8 @@ version(AsLibrary) //Library version will use environment instead of redubEnv si
478498
}
479499
return null;
480500
}
501+
void lockEnv(){}
502+
alias unlockEnv = lockEnv;
481503
}
482504
else
483505
{
@@ -491,7 +513,12 @@ else
491513
redubEnv[key] = value;
492514
}
493515
}
516+
517+
void setEnvVariableNoLock(string key, string value){redubEnv[key] = value;}
494518
string[string] getRedubEnv(){return redubEnv;}
519+
520+
void lockEnv(){envMutex.lock();}
521+
void unlockEnv(){envMutex.unlock();}
495522
string getEnvVariable(string key)
496523
{
497524
string* ret = key in redubEnv;

source/redub/parsers/json.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ BuildRequirements parse(JSONValue json, ParseConfig cfg, out BuildConfiguration
486486
runHandlers(requirementsRun, buildRequirements, cfg, json, false, unusedKeys, pending);
487487

488488
if(cfg.firstRun && unusedKeys.length) warn("Unused Keys -> ", unusedKeys);
489-
489+
runPreGenerateCommands(cfg, buildRequirements);
490490
return buildRequirements;
491491
}
492492

0 commit comments

Comments
 (0)