gtest: Install the run_with_tmp script for convenience

This makes it possible for other tests to utilize the script.

Change-Id: I1bb6100e4018bad020817d569294704e267c2776
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/meson.build b/src/meson.build
index 6ff400d..0b6be99 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -147,4 +147,13 @@
     description: 'C++ helper utilities',
     version: meson.project_version(),
     requires: stdplus_gtest_reqs)
+
+  install_data(
+    'run_with_tmp',
+    install_mode: 'rwxr-xr-x',
+    install_dir: get_option('bindir'))
+
+  meson.override_find_program('run_with_tmp', files('run_with_tmp'))
 endif
+
+run_with_tmp = find_program('run_with_tmp', native: true)
diff --git a/src/run_with_tmp b/src/run_with_tmp
new file mode 100755
index 0000000..8b8895a
--- /dev/null
+++ b/src/run_with_tmp
@@ -0,0 +1,14 @@
+#!/bin/bash
+TMPDIR="$(mktemp -d --tmpdir "${TMPTMPL-tmp.XXXXXXXXXX}")" || exit
+rmtmp() {
+  if [ -n "${TMP_DEBUG-}" ]; then
+    echo "Removing TMPDIR=$TMPDIR" >&2
+  fi
+  rm -rf -- "$TMPDIR"
+}
+trap rmtmp EXIT
+export TMPDIR
+if [ -n "${TMP_DEBUG-}" ]; then
+  echo "Exec $* with TMPDIR=$TMPDIR" >&2
+fi
+"$@"