add svn_runner module

This commit is contained in:
Josh Holtrop 2020-01-07 15:59:31 -05:00
parent bb20d3bf38
commit 8b85b70ea9
4 changed files with 56 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
/Build/
/.rscons* /.rscons*
/build/
/svi

10
Rsconscript Normal file
View File

@ -0,0 +1,10 @@
configure do
check_d_compiler
end
build do
Environment.new do |env|
env["D_IMPORT_PATH"] << "src"
env.Program("svi", glob("src/**/*.d"))
end
end

8
src/main.d Normal file
View File

@ -0,0 +1,8 @@
import svn_runner;
import std.stdio;
int main(string[] args)
{
auto r = run_svn(["ls", "https://vcs.gentex.com/svn/embedded_sw"]);
return 0;
}

36
src/svn_runner.d Normal file
View File

@ -0,0 +1,36 @@
import std.process;
import std.stdio;
struct Result
{
int status;
char[] stdout;
char[] stderr;
}
private File nullfd()
{
return File("/dev/null", "r");
}
Result run_svn(string[] args)
{
string[] command = ["svn", "--non-interactive", "--no-auth-cache"] ~ args;
auto stdout_pipe = pipe();
auto stderr_pipe = pipe();
auto pid = spawnProcess(command, nullfd(), stdout_pipe.writeEnd,
stderr_pipe.writeEnd);
char[] stdout;
char[] stderr;
char[] buf;
while (stdout_pipe.readEnd.readln(buf))
{
stdout ~= buf;
}
while (stderr_pipe.readEnd.readln(buf))
{
stderr ~= buf;
}
int status = wait(pid);
return Result(status, stdout, stderr);
}