From 2954a73c1c8438110a6b7f690c5b33b5cf605716 Mon Sep 17 00:00:00 2001
From: Marc Bonnici <marc.bonnici@arm.com>
Date: Thu, 18 Jan 2018 13:18:27 +0000
Subject: [PATCH] Target: Generate a new tmp directory when creating shutils

Previously the same temporary directory was used which caused issues
with concurrent runs interfering with each other.
---
 devlib/target.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/devlib/target.py b/devlib/target.py
index f2b92a2..9653ed3 100644
--- a/devlib/target.py
+++ b/devlib/target.py
@@ -656,7 +656,8 @@ class Target(object):
 
     def _setup_shutils(self):
         shutils_ifile = os.path.join(PACKAGE_BIN_DIRECTORY, 'scripts', 'shutils.in')
-        shutils_ofile = os.path.join(tempfile.gettempdir(), 'shutils')
+        tmp_dir = tempfile.mkdtemp()
+        shutils_ofile = os.path.join(tmp_dir, 'shutils')
         shell_path = '/bin/sh'
         if self.os == 'android':
             shell_path = '/system/bin/sh'
@@ -669,6 +670,7 @@ class Target(object):
                 ofile.write(line)
         self._shutils = self.install(shutils_ofile)
         os.remove(shutils_ofile)
+        os.rmdir(tmp_dir)
 
     def _execute_util(self, command, timeout=None, check_exit_code=True, as_root=False):
         command = '{} {}'.format(self.shutils, command)