commit 6aa577238c2023223aff7c97be917b03457e9a49
parent 42c0f415a04631022eb9a77a8b33890247d224ec
Author: Richard Ipsum <richardipsum@vx21.xyz>
Date:   Sun, 15 Mar 2020 15:17:08 +0000
Set env var SRCDIR
Diffstat:
3 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/tyarn.1 b/tyarn.1
@@ -81,6 +81,8 @@ step they are a match for.
 .PP
 Scenarios are executed in a temporary directory, the environment
 variable DATADIR is set to the path of this temporary directory.
+The environment variable SRCDIR is set to the path of the working
+directory tyarn is executed from.
 .SH OPTIONS
 .TP
 .BR \-C
diff --git a/tyarn.c b/tyarn.c
@@ -657,6 +657,21 @@ static int tyarn_mkdir(lua_State *L)
     return 2;
 }
 
+static int tyarn_getcwd(lua_State *L)
+{
+    char *path = getcwd(NULL, 0);
+
+    if (path == NULL) {
+        lua_pushnil(L);
+        lua_pushstring(L, strerror(errno));
+        return 2;
+    }
+
+    lua_pushstring(L, path);
+    free(path);
+    return 1;
+}
+
 static const struct luaL_Reg tyarn_functions[] = {
     {"exec", tyarn_exec},
     {"mkdtemp", tyarn_mkdtemp},
@@ -671,6 +686,7 @@ static const struct luaL_Reg tyarn_functions[] = {
     {"help", tyarn_help},
     {"path_exists", tyarn_path_exists},
     {"mkdir", tyarn_mkdir},
+    {"getcwd", tyarn_getcwd},
     {NULL, NULL}
 };
 
diff --git a/tyarn.lua.in b/tyarn.lua.in
@@ -327,6 +327,7 @@ function run_step(scenario_dir, datadir, implementations, scenario_key, step, sh
     env = cleanenv()
     shell_script_lines = {}
     env['DATADIR'] = datadir
+    env['SRCDIR'] = tyarn.getcwd()
     debug(string.format("Run step %s", step))
 
     step_impl, step_captures = find_matching_implementation(implementations, step)