externalsrc: avoid race in temporary git index file

Use a unique tempfile as the temporary git index file when determining
the git hash of the source tree. A fixed filename was obviously causing
races (with the git index.lock file) under oe-selftest where multiple
bitbake instances were run against the same source tree at the same
time.

(From OE-Core rev: f81c641022c26a9b89fac769e0f2889eaec5d32f)

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Markus Lehtonen
2016-04-05 16:21:49 +03:00
committed by Richard Purdie
parent f4f1d206f4
commit 43071a0d67

View File

@@ -130,21 +130,22 @@ python externalsrc_compile_prefunc() {
def srctree_hash_files(d): def srctree_hash_files(d):
import shutil import shutil
import subprocess import subprocess
import tempfile
s_dir = d.getVar('EXTERNALSRC', True) s_dir = d.getVar('EXTERNALSRC', True)
git_dir = os.path.join(s_dir, '.git') git_dir = os.path.join(s_dir, '.git')
oe_index_file = os.path.join(git_dir, 'oe-devtool-index')
oe_hash_file = os.path.join(git_dir, 'oe-devtool-tree-sha1') oe_hash_file = os.path.join(git_dir, 'oe-devtool-tree-sha1')
ret = " " ret = " "
if os.path.exists(git_dir): if os.path.exists(git_dir):
# Clone index with tempfile.NamedTemporaryFile(dir=git_dir, prefix='oe-devtool-index') as tmp_index:
shutil.copy2(os.path.join(git_dir, 'index'), oe_index_file) # Clone index
# Update our custom index shutil.copy2(os.path.join(git_dir, 'index'), tmp_index.name)
env = os.environ.copy() # Update our custom index
env['GIT_INDEX_FILE'] = oe_index_file env = os.environ.copy()
subprocess.check_output(['git', 'add', '.'], cwd=s_dir, env=env) env['GIT_INDEX_FILE'] = tmp_index.name
sha1 = subprocess.check_output(['git', 'write-tree'], cwd=s_dir, env=env) subprocess.check_output(['git', 'add', '.'], cwd=s_dir, env=env)
sha1 = subprocess.check_output(['git', 'write-tree'], cwd=s_dir, env=env)
with open(oe_hash_file, 'w') as fobj: with open(oe_hash_file, 'w') as fobj:
fobj.write(sha1) fobj.write(sha1)
ret = oe_hash_file + ':True' ret = oe_hash_file + ':True'