run-in-tempdir: Improve speed
authorMichael Hanselmann <hansmi@google.com>
Wed, 16 Jan 2013 15:40:54 +0000 (16:40 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 16 Jan 2013 17:01:26 +0000 (18:01 +0100)
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

index 3c1a79b..0f4bbe0 100755 (executable)
@@ -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