From 8b85b70ea9d2553172f2438f212a8ea106fcffa9 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 7 Jan 2020 15:59:31 -0500 Subject: [PATCH] add svn_runner module --- .gitignore | 3 ++- Rsconscript | 10 ++++++++++ src/main.d | 8 ++++++++ src/svn_runner.d | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 Rsconscript create mode 100644 src/main.d create mode 100644 src/svn_runner.d diff --git a/.gitignore b/.gitignore index 7d0ba35..d9c5846 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -/Build/ /.rscons* +/build/ +/svi diff --git a/Rsconscript b/Rsconscript new file mode 100644 index 0000000..ce049e8 --- /dev/null +++ b/Rsconscript @@ -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 diff --git a/src/main.d b/src/main.d new file mode 100644 index 0000000..f7f5b70 --- /dev/null +++ b/src/main.d @@ -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; +} diff --git a/src/svn_runner.d b/src/svn_runner.d new file mode 100644 index 0000000..6043fff --- /dev/null +++ b/src/svn_runner.d @@ -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); +}