From 9e471b614300d57b55e64e1bf74e6aef52910a7b Mon Sep 17 00:00:00 2001 From: bigA2021 Date: Tue, 20 Jul 2021 04:35:26 -0700 Subject: [PATCH] fix hcs fail issue Signed-off-by: bigA2021 --- tools/hc-gen/build_hcs.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tools/hc-gen/build_hcs.py b/tools/hc-gen/build_hcs.py index 4543cb3fd..d67bbd240 100755 --- a/tools/hc-gen/build_hcs.py +++ b/tools/hc-gen/build_hcs.py @@ -31,6 +31,7 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +import fcntl import os import sys import argparse @@ -38,6 +39,31 @@ import platform import subprocess import time +_LOCK_FILE_NAME = "._lock" +_BUILD_DIR = 'build' +_LOCK_FILE = '' + + +def lock(): + global _LOCK_FILE + global _BUILD_DIR + global _LOCK_FILE_NAME + if not os.path.exists(_BUILD_DIR): + os.mkdir(_BUILD_DIR) + lock_file = os.path.join(_BUILD_DIR, _LOCK_FILE_NAME) + if not os.path.exists(lock_file): + with open(lock_file, 'w') as l_file: + l_file.write("lock") + l_file.close + print('hc-gen lock file ' + lock_file) + _LOCK_FILE = open(lock_file, 'r') + fcntl.flock(_LOCK_FILE.fileno(), fcntl.LOCK_EX) + + +def unlock(): + global _LOCK_FILE + _LOCK_FILE.close() + def exec_command(cmd): process = subprocess.Popen(cmd) @@ -57,14 +83,20 @@ def prepare(current_dir): def main(argv): + lock() current_dir = os.path.split(os.path.realpath(__file__))[0] hc_gen = os.path.join(current_dir, 'build', 'hc-gen') - build_hcs_cmd = [hc_gen] + argv[1:] + host_hc_gen = argv[1] + if (os.path.exists(host_hc_gen)): + build_hcs_cmd = argv[1:] + else: + prepare(current_dir) + build_hcs_cmd = [hc_gen] + argv[1:] prepare(current_dir) exec_command(build_hcs_cmd) - + unlock() if __name__ == '__main__': sys.exit(main(sys.argv)) -- Gitee