Skip to content

Commit fb72066

Browse files
[scripts][zap] Add Windows support for ZAP generate and download scripts (#35598)
Signed-off-by: marius-alex-tache <marius.tache@nxp.com>
1 parent bb2c574 commit fb72066

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

scripts/tools/zap/generate.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#
1717

1818
import argparse
19-
import fcntl
2019
import json
2120
import os
2221
import shutil
@@ -338,16 +337,30 @@ def __enter__(self):
338337
return
339338

340339
self.lock_file = open(self.lock_file_path, 'wb')
341-
fcntl.lockf(self.lock_file, fcntl.LOCK_EX)
340+
self._lock()
342341

343342
def __exit__(self, *args):
344343
if not self.lock_file:
345344
return
346345

347-
fcntl.lockf(self.lock_file, fcntl.LOCK_UN)
346+
self._unlock()
348347
self.lock_file.close()
349348
self.lock_file = None
350349

350+
def _lock(self):
351+
if sys.platform == 'linux' or sys.platform == 'darwin':
352+
import fcntl
353+
fcntl.lockf(self.lock_file, fcntl.LOCK_EX)
354+
else:
355+
print(f"Warning: lock does nothing on {sys.platform} platform")
356+
357+
def _unlock(self):
358+
if sys.platform == 'linux' or sys.platform == 'darwin':
359+
import fcntl
360+
fcntl.lockf(self.lock_file, fcntl.LOCK_UN)
361+
else:
362+
print(f"Warning: unlock does nothing on {sys.platform} platform")
363+
351364

352365
def main():
353366
checkPythonVersion()

scripts/tools/zap/zap_download.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,21 @@ def _SetupReleaseZap(install_directory: str, zap_version: str):
106106

107107
if sys.platform == 'linux':
108108
zap_platform = 'linux'
109+
arch = os.uname().machine
109110
elif sys.platform == 'darwin':
110111
zap_platform = 'mac'
112+
arch = os.uname().machine
113+
elif sys.platform == 'win32':
114+
zap_platform = 'win'
115+
# os.uname is not implemented on Windows, so use an alternative instead.
116+
import platform
117+
arch = platform.uname().machine
111118
else:
112119
raise Exception('Unknown platform - do not know what zip file to download.')
113120

114-
arch = os.uname().machine
115121
if arch == 'arm64':
116122
zap_arch = 'arm64'
117-
elif arch == 'x86_64':
123+
elif arch == 'x86_64' or arch == 'AMD64':
118124
zap_arch = 'x64'
119125
else:
120126
raise Exception(f'Unknown architecture "${arch}" - do not know what zip file to download.')
@@ -228,17 +234,21 @@ def main(log_level: str, sdk_root: str, extract_root: str, zap_version: Optional
228234

229235
install_directory = os.path.join(extract_root, f"zap-{zap_version}")
230236

237+
export_cmd = "export"
238+
if sys.platform == 'win32':
239+
export_cmd = "set"
240+
231241
if zap == DownloadType.SOURCE:
232242
install_directory = install_directory + "-src"
233243
_SetupSourceZap(install_directory, zap_version)
234244

235245
# Make sure the results can be used in scripts
236-
print(f"export ZAP_DEVELOPMENT_PATH={shlex.quote(install_directory)}")
246+
print(f"{export_cmd} ZAP_DEVELOPMENT_PATH={shlex.quote(install_directory)}")
237247
else:
238248
_SetupReleaseZap(install_directory, zap_version)
239249

240250
# Make sure the results can be used in scripts
241-
print(f"export ZAP_INSTALL_PATH={shlex.quote(install_directory)}")
251+
print(f"{export_cmd} ZAP_INSTALL_PATH={shlex.quote(install_directory)}")
242252

243253

244254
if __name__ == '__main__':

0 commit comments

Comments
 (0)