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