From dd60179dfd89606ee476bd419a9b5e89742a36b0 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 16 Jan 2013 16:40:54 +0100
Subject: [PATCH] run-in-tempdir: Improve speed

By creating symlinks instead of actually creating files we still get the
benefits of using a temporary directory, but the preparation is about
three times as fast. Test used:

$ time bash -c 'for ((i=0; i < 100; ++i)); do
    autotools/run-in-tempdir true; done'

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Bernardo Dal Seno <bdalseno@google.com>
---
 autotools/run-in-tempdir | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/autotools/run-in-tempdir b/autotools/run-in-tempdir
index 3c1a79ba5..0f4bbe0cb 100755
--- a/autotools/run-in-tempdir
+++ b/autotools/run-in-tempdir
@@ -8,19 +8,27 @@ set -e
 tmpdir=$(mktemp -d -t gntbuild.XXXXXXXX)
 trap "rm -rf $tmpdir" EXIT
 
-# fully copy items
-cp -r autotools daemons scripts lib tools qa $tmpdir
+linkcopy() {
+  cp -L -s -r "$@"
+}
+
+dirs=( autotools daemons scripts lib tools qa )
 
 if [[ -z "$COPY_DOC" ]]; then
   mkdir $tmpdir/doc
   ln -s $PWD/doc/examples $tmpdir/doc
 else
   # Building documentation requires all files
-  cp -r doc $tmpdir
+  dirs+=( doc )
 fi
 
+# Create symlinks
+for i in ${dirs[@]}; do
+  linkcopy $PWD/$i $tmpdir
+done
+
 mkdir $tmpdir/test/
-cp -r test/py $tmpdir/test/py
+linkcopy $PWD/test/py $tmpdir/test/py
 ln -s $PWD/test/data $tmpdir/test
 ln -s $PWD/test/hs $tmpdir/test
 
-- 
GitLab