Skip to content

Commit 9c44998

Browse files
committed
Update: Improved execution by changing from executeShell -> executeProcess thus halving number of processes
1 parent ed46216 commit 9c44998

File tree

11 files changed

+36
-38
lines changed

11 files changed

+36
-38
lines changed

source/redub/api.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ ProjectDetails[] buildProjectUniversal(ArgsDetails args)
449449
ProjectDetails[] ret;
450450
ArgsDetails other = args;
451451

452-
string lipoRun = "lipo -create ";
452+
string[] lipoRun = ["lipo", "-create"];
453453
string oldTargetName;
454454
foreach(arch; archs)
455455
{
@@ -460,15 +460,15 @@ ProjectDetails[] buildProjectUniversal(ArgsDetails args)
460460
d.tree.requirements.cfg.targetName~= "-"~arch;
461461
d = buildProject(d);
462462
ret~= d;
463-
lipoRun~= " " ~ d.getOutputFile();
463+
lipoRun~= d.getOutputFile();
464464
}
465465

466466
ret[0].tree.requirements.cfg.targetName = oldTargetName~"-osx-universal";
467-
lipoRun~= " -output "~ret[0].getOutputFile();
467+
lipoRun~= ["-output", ret[0].getOutputFile()];
468468
ret[0].tree.requirements.cfg.targetName = oldTargetName~"-"~archs[0];
469469

470470
vvlog(lipoRun);
471-
auto res = executeShell(lipoRun);
471+
auto res = execute(lipoRun, getRedubEnv);
472472
if(res.status)
473473
throw new BuildException(res.output);
474474

source/redub/buildapi.d

Lines changed: 1 addition & 1 deletion
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.2";
10+
enum RedubVersionOnly = "v1.26.3";
1111
///Redub vX.X.X
1212
enum RedubVersionShort = "Redub "~RedubVersionOnly;
1313
///Redub vX.X.X - Description

source/redub/building/utils.d

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import redub.buildapi;
33
public import redub.misc.shell;
44
import core.sys.posix.sys.ioctl;
55

6-
string getHighPriorityCmd()
6+
string[] getHighPriorityCmd(string[] compileFlags)
77
{
88
version(Posix)
99
{
10-
return "nice -n 0 ";
10+
import std.array;
11+
string[] ret = new string[compileFlags.length + 3];
12+
ret[0..3] = ["nice", "-n", "0"].staticArray;
13+
ret[3..$] = compileFlags;
14+
return ret;
1115
}
12-
else return "";
16+
return compileFlags;
1317
}
1418

1519
ProcessExec2 execCompiler(const BuildConfiguration cfg, Compiler compiler, string[] compileFlags, out string compilationCommands, bool hasHighPriority, out string cmdFile, const string[string] env)
@@ -27,7 +31,7 @@ ProcessExec2 execCompiler(const BuildConfiguration cfg, Compiler compiler, strin
2731
{
2832
cmdFile = createCommandFile(cfg, compileFlags, compilationCommands);
2933
compilationCommands = compilerBin ~ " "~compilationCommands;
30-
ProcessExec2 ret = executeShell2(compilerBin~ " @"~cmdFile, env, Config.none, size_t.max, cfg.workingDir);
34+
ProcessExec2 ret = executeProcess2([compilerBin, "@"~cmdFile], env, Config.none, size_t.max, cfg.workingDir);
3135

3236
version(Windows)
3337
{
@@ -37,11 +41,10 @@ ProcessExec2 execCompiler(const BuildConfiguration cfg, Compiler compiler, strin
3741
SetPriorityClass(ret.pipe.pid.osHandle, REALTIME_PRIORITY_CLASS);
3842
}
3943
}
40-
4144
return ret;
4245
}
4346
compilationCommands = escapeCompilationCommands(compilerBin, compileFlags);
44-
return executeShell2(getHighPriorityCmd ~ compilationCommands, env, Config.none, size_t.max, cfg.workingDir);
47+
return executeProcess2(cast(const(char)[][])getHighPriorityCmd(compileFlags), env, Config.none, size_t.max, cfg.workingDir);
4548
}
4649

4750

@@ -115,5 +118,5 @@ auto executeArchiver(const ThreadBuildData data, CompilingSession s, string main
115118

116119
putSourceFiles(cmd, null, [cacheDir], data.cfg.sourceFiles, data.cfg.excludeSourceFiles, ".o", ".obj");
117120

118-
return executeShell(escapeShellCommand(cmd), data.env);
121+
return execute(cmd, data.env);
119122
}

source/redub/extensions/update.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int updateMain(string[] args)
4747
}
4848
setLogLevel(update.vverbose ? LogLevel.vverbose : LogLevel.info);
4949

50-
int gitCode = executeShell("git --help").status;
50+
int gitCode = execute(["git", "--help"]).status;
5151
enum isNotGitRepo = 128;
5252
enum hasNoGitWindows = 9009;
5353
enum hasNoGitPosix = 127;
@@ -56,7 +56,7 @@ int updateMain(string[] args)
5656

5757
if(gitCode == 0 && !update.noPull)
5858
{
59-
auto ret = executeShell("git pull", null, Config.none, size_t.max, redubPath);
59+
auto ret = execute(["git", "pull"], null, Config.none, size_t.max, redubPath);
6060
gitCode = ret.status;
6161
if(gitCode != 0 && gitCode != isNotGitRepo)
6262
{

source/redub/misc/_7zip.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool extract7ZipToFolder(string zPath, string outputDirectory)
4747
chdir(outputDirectory);
4848
scope(exit)
4949
chdir(dir);
50-
auto res = executeShell(_7z ~ " x -y "~zPath);
50+
auto res = execute([_7z, "x", "-y",zPath]);
5151
if(res.status)
5252
error("Could not extract 7z '", zPath, "' to '", outputDirectory, "': ", res.output);
5353
return res.status == 0;

source/redub/misc/shell.d

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,21 @@ struct ProcessExec2
99
Appender!string output;
1010
}
1111

12-
ProcessExec2 executeShell2(scope const(char)[] command,
12+
ProcessExec2 executeProcess2(scope const(char)[][] command,
1313
const string[string] env = null,
1414
Config config = Config.none,
1515
size_t maxOutput = size_t.max,
16-
scope const(char)[] workDir = null,
17-
string shellPath = nativeShell)
16+
scope const(char)[] workDir = null)
1817
@safe
1918
{
20-
return executeImpl!pipeShell(command,
19+
return executeImpl!pipeProcess(command,
2120
env,
2221
config,
2322
maxOutput,
24-
workDir,
25-
shellPath);
23+
workDir);
2624
}
2725

28-
// Does the actual work for execute() and executeShell().
26+
// Does the actual work for execute() and executeProcess().
2927
private ProcessExec2 executeImpl(alias pipeFunc, Cmd, ExtraPipeFuncArgs...)(
3028
Cmd commandLine,
3129
const string[string] env = null,

source/redub/misc/unzip.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ bool extractTarGzToFolder(string tarGzPath, string outputDirectory)
5757
}
5858
info("Extracting ", tarGzPath, " to ", outputDirectory);
5959
std.file.mkdirRecurse(outputDirectory);
60-
auto res = executeShell("tar -xf "~tarGzPath~" -C "~outputDirectory);
60+
auto res = execute(["tar", "-xf", tarGzPath, "-C", outputDirectory]);
6161
if(res.status)
6262
error("Could not extract '",tarGzPath, "' to '", outputDirectory, "': ", res.output);
6363
return res.status == 0;

source/redub/tooling/archiver_identification.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ Archiver getArchiver(AcceptedArchiver archiver, const string[string] env)
5858
if(binPath)
5959
return Archiver(archiver, binPath.str);
6060
}
61-
string help = " --help";
62-
if(archiver == AcceptedArchiver.llvmLib || archiver == AcceptedArchiver.lib) help = " /help";
63-
auto res = executeShell(archiver~help, env);
61+
string help = "--help";
62+
if(archiver == AcceptedArchiver.llvmLib || archiver == AcceptedArchiver.lib) help = "/help";
63+
auto res = execute([archiver, help], env);
6464
if(res.status == 0)
6565
{
6666
Archiver arch = Archiver(archiver, findExecutable(archiver));

source/redub/tooling/compilers_inference.d

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void saveGlobalCompiler(string compilerPath, JSONValue compilersInfo, boo
2323

2424
CompilerBinary ret;
2525
string actualCompiler;
26-
auto res = executeShell(compilerPath~" --version", getRedubEnv());
26+
auto res = execute([compilerPath, "--version"], getRedubEnv());
2727
if(res.status)
2828
throw new Exception("saveGlobalCompiler was called in an inexistent compiler.");
2929
foreach(inf; isC ? cCompilersInference : dCompilersInference)
@@ -114,7 +114,7 @@ CompilerBinary inferCompiler(string compilerOrPath, string compilerAssumption, J
114114
* Params:
115115
* preferredCompiler = The compiler that the user may have specified.
116116
* actualCompiler = Actual compiler. If no compiler is found on the searchable list, the program will exit.
117-
* Returns: The output from executeShell. This will be processed for getting version information on the compiler.
117+
* Returns: The output from executeProcess. This will be processed for getting version information on the compiler.
118118
*/
119119
private string getActualCompilerToUse(string preferredCompiler, ref string actualCompiler, const string[] searchableCompilers, out bool isError)
120120
{
@@ -136,11 +136,9 @@ private string getActualCompilerToUse(string preferredCompiler, ref string actua
136136
else
137137
preferredTested = true;
138138

139-
string versionCommand = searchable;
140-
if(searchable.baseName.stripExtension != "cl")
141-
versionCommand~= " --version";
142-
143-
compVersionRes = executeShell(versionCommand, getRedubEnv());
139+
string[2] versionCommand = [searchable, "--version"];
140+
size_t args = searchable.baseName.stripExtension != "cl" ? 2 : 1;
141+
compVersionRes = execute(versionCommand[0..args], getRedubEnv());
144142
if(compVersionRes.status == 0)
145143
{
146144
actualCompiler = searchable;

source/redub/tooling/linker_identification.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ AcceptedLinker getDefaultLinker()
3838
{
3939
import std.process;
4040
import std.string;
41-
auto res = executeShell("ld -v");
41+
auto res = execute(["ld", "-v"]);
4242
if(res.status == 0)
4343
{
4444
if(res.output.startsWith("GNU ld"))

0 commit comments

Comments
 (0)