diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-06-04 15:17:33 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-06-04 20:46:45 +0000 |
commit | b64e8e721fd9117af585151b93a18fec1c285059 (patch) | |
tree | 8964bbdc8b4070f99e12b0bf480afa7f8a1705ab /util/cmake | |
parent | 63f2b8c7a885a84fc8f240ec8e4ac88c3a3c6e64 (diff) |
Fix special_case_handler to handle git add prev_CMakeLists.txt better
When using run_pro2cmake.py, it spawns multiple instances of
pro2cmake.py.
If more than 1 of the instances need to git add prev_CMakeLists.txt at
the same time, git add might fail due to the acquired index.lock.
The cleaner solution would be to use a file lock as a mutex, but that
requires an external pypi package.
Use a poor man solution of retrying the git add with a time delay for a
finite amount of times.
Change-Id: I2031f6e29ae499526cb4f1753e4387e7f4fab0ab
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'util/cmake')
-rw-r--r-- | util/cmake/special_case_helper.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/util/cmake/special_case_helper.py b/util/cmake/special_case_helper.py index 57b91b6cb1..1cb25ac1e2 100644 --- a/util/cmake/special_case_helper.py +++ b/util/cmake/special_case_helper.py @@ -87,6 +87,7 @@ import re import os import subprocess import filecmp +import time from shutil import copyfile from shutil import rmtree @@ -142,7 +143,7 @@ def check_if_git_in_path() -> bool: return False -def run_process_quiet(args_string: str, debug=False) -> None: +def run_process_quiet(args_string: str, debug=False) -> bool: if debug: print('Running command: "{}\"'.format(args_string)) args_list = args_string.split() @@ -153,6 +154,8 @@ def run_process_quiet(args_string: str, debug=False) -> None: # an error for us. if 'git merge' not in args_string: print('Error while running: "{}"\n{}'.format(args_string, e.stdout)) + return False + return True def does_file_have_conflict_markers(file_path: str, debug=False) -> bool: @@ -289,7 +292,28 @@ class SpecialCaseHandler(object): # merge result, save the new "clean" file for future # regenerations. copyfile_log(self.generated_file_path, self.prev_file_path, debug=self.debug) - run_process_quiet("git add {}".format(self.prev_file_path), debug=self.debug) + + # Attempt to git add until we succeed. It can fail when + # run_pro2cmake executes pro2cmake in multiple threads, and git + # has acquired the index lock. + success = False + failed_once = False + i = 0 + while not success and i < 20: + success = run_process_quiet("git add {}".format(self.prev_file_path), + debug=self.debug) + if not success: + failed_once = True + i += 1 + time.sleep(0.1) + + if failed_once and not success: + print('Retrying git add, the index.lock was probably acquired.') + if failed_once and success: + print('git add succeeded.') + elif failed_once and not success: + print('git add failed. Make sure to git add {} yourself.'.format( + self.prev_file_path)) def handle_special_cases_helper(self) -> bool: """ |