From b5fbf819137895ffd82af12bbff9d8da7229297e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szablowski?= Date: Thu, 6 Jul 2023 15:07:27 +0200 Subject: [PATCH] [nrf noup] Fix generate zap sript on windows Usage of generate.py script is not possible on windows due to fcntl package available onlu on unix pyhton packages using I/O control on descriptor file is not needed on windows. This change enhance script to use fcntl on non-window system. --- scripts/tools/zap/generate.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/tools/zap/generate.py b/scripts/tools/zap/generate.py index a4d36a7cbc..f3fceac2cf 100755 --- a/scripts/tools/zap/generate.py +++ b/scripts/tools/zap/generate.py @@ -16,7 +16,7 @@ # import argparse -import fcntl +import platform import json import os import shutil @@ -30,6 +30,13 @@ from zap_execution import ZapTool +def isWindows(): + return platform.system() == "Windows" + +# fcntl is not supported on widows platfrom due to lack of necessity of I/O control on file descriptor +if not isWindows(): + import fcntl + @dataclass class CmdLineArgs: @@ -287,16 +294,17 @@ def __init__(self, path): self.lock_file = None def __enter__(self): - if not self.lock_file_path: + # fcntl is not supported on widows platfrom due to lack of necessity of I/O control on file descriptor + if not self.lock_file_path or isWindows(): return - self.lock_file = open(self.lock_file_path, 'wb') fcntl.lockf(self.lock_file, fcntl.LOCK_EX) + def __exit__(self, *args): - if not self.lock_file: + # fcntl is not supported on widows platfrom due to lack of necessity of I/O control on file descriptor + if not self.lock_file or isWindows(): return - fcntl.lockf(self.lock_file, fcntl.LOCK_UN) self.lock_file.close() self.lock_file = None