Skip to content

Commit 9a0eeb2

Browse files
[nrf noup] Fix zap instalation for MacOs
Fix updating get_zap.py script, which ensure zap will work on the MacOs systems. Signed-off-by: Patryk Lipinski <patryk.lipinski@nordicsemi.no>
1 parent 1e9f9b2 commit 9a0eeb2

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

scripts/setup/nrfconnect/get_zap.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
2-
32
#
4-
# Copyright (c) 2023 Project CHIP Authors
3+
# Copyright (c) 2024 Project CHIP Authors
54
#
65
# Licensed under the Apache License, Version 2.0 (the "License");
76
# you may not use this file except in compliance with the License.
@@ -15,7 +14,7 @@
1514
# See the License for the specific language governing permissions and
1615
# limitations under the License.
1716
#
18-
17+
#
1918
# The script parses integrations/docker/images/chip-build/Dockerfile file
2019
# from the Matter repository and looks for ENV ZAP_VERSION= string to find
2120
# currently recommended ZAP version. After that the package matching this version
@@ -86,11 +85,11 @@ def download_recommended_zap_package(version, package_name, location):
8685
month = f'{int(splitted_version[1]):02d}'
8786
day = f'{int(splitted_version[2]):02d}'
8887
merged_version = f"{splitted_version[0]}.{month}.{day}"
89-
9088
url = f"https://github.com/project-chip/zap/releases/download/v{merged_version}-nightly/{package_name}.zip"
9189
print(f"Downloading {url} into {os.path.join(location, f'{package_name}.zip')}")
9290
wget.download(url, out=location)
9391
print("\n")
92+
9493
except Exception as e:
9594
raise RuntimeError("Invalid URL to download ZAP tool package {}".format(e))
9695

@@ -102,6 +101,7 @@ def clear_old_artifacts(location, overwrite):
102101
consent = input("The ZAP directory already exists in this location. Do you agree to overwrite it? Yes[y]/No[n]:")
103102
if consent.lower() != 'yes' and consent.lower() != 'y':
104103
raise RuntimeError("Couldn't download ZAP package, as the file already exists in this location.")
104+
105105
shutil.rmtree(location)
106106

107107

@@ -118,19 +118,27 @@ def set_executable(location, package_name, filename):
118118

119119

120120
def unzip_zap_package(location, package_name):
121+
package = location + f"/{package_name}.zip"
122+
destination = location + "/" + package_name
123+
121124
try:
122-
zip = ZipFile(os.path.join(location, f"{package_name}.zip"))
123-
zip.extractall(os.path.join(location, package_name))
124-
zip.close()
125+
if (platform.system() == 'Darwin'):
126+
subprocess.run(['unzip', package, '-d', destination], stdout = subprocess.PIPE)
127+
else:
128+
zip = ZipFile(os.path.join(location, f"{package_name}.zip"))
129+
zip.extractall(os.path.join(location, package_name))
130+
zip.close()
131+
125132
except Exception as e:
126133
raise RuntimeError("Encountered problem when trying to unzip the ZAP tool package. {}".format(e))
134+
127135
finally:
128136
remove_zip(location, package_name)
129137

130138

131139
def print_paths_warning(paths_to_print):
132-
messages = ["Please add the following location(s) to the system PATH:"] + paths_to_print
133140

141+
messages = ["Please add the following location(s) to the system PATH:"] + paths_to_print
134142
longest_message = max(messages, key=len)
135143

136144
for item in range(len(messages)):
@@ -160,6 +168,7 @@ def install_zap_package(version, location, overwrite):
160168
zap_cli_executable = 'zap-cli'
161169
else:
162170
raise RuntimeError(f"Couldn't find the proper ZAP tool package for the currently used operating system: {current_os}")
171+
163172
clear_old_artifacts(os.path.join(location, package), overwrite)
164173
download_recommended_zap_package(version, package, location)
165174
unzip_zap_package(location, package)
@@ -175,12 +184,9 @@ def install_zap_package(version, location, overwrite):
175184

176185

177186
def main():
178-
parser = argparse.ArgumentParser(
179-
description='Script helping to download the ZAP tool in the currently recommended revision.')
180-
parser.add_argument(
181-
"-l", "--location", help="Path to the location that should be used for storing ZAP tool package.", type=str, required=True)
182-
parser.add_argument(
183-
"-o", "--overwrite", help="Overwrite files without asking, in case they already exist in given location", action="store_true")
187+
parser = argparse.ArgumentParser(description='Script helping to download the ZAP tool in the currently recommended revision.')
188+
parser.add_argument("-l", "--location", help="Path to the location that should be used for storing ZAP tool package.", type=str, required=True)
189+
parser.add_argument("-o", "--overwrite", help="Overwrite files without asking, in case they already exist in given location", action="store_true")
184190
args = parser.parse_args()
185191

186192
location = os.path.abspath(args.location)
@@ -198,4 +204,5 @@ def main():
198204

199205

200206
if __name__ == '__main__':
207+
201208
main()

0 commit comments

Comments
 (0)