Skip to content

Commit 6beb2d5

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 6beb2d5

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

scripts/setup/nrfconnect/get_zap.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#!/usr/bin/env python3
21

2+
#!/usr/bin/env python3
33
#
4-
# Copyright (c) 2023 Project CHIP Authors
4+
# Copyright (c) 2024 Project CHIP Authors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -14,8 +14,8 @@
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
17-
#
1817

18+
#
1919
# The script parses integrations/docker/images/chip-build/Dockerfile file
2020
# from the Matter repository and looks for ENV ZAP_VERSION= string to find
2121
# currently recommended ZAP version. After that the package matching this version
@@ -86,11 +86,11 @@ def download_recommended_zap_package(version, package_name, location):
8686
month = f'{int(splitted_version[1]):02d}'
8787
day = f'{int(splitted_version[2]):02d}'
8888
merged_version = f"{splitted_version[0]}.{month}.{day}"
89-
9089
url = f"https://github.com/project-chip/zap/releases/download/v{merged_version}-nightly/{package_name}.zip"
9190
print(f"Downloading {url} into {os.path.join(location, f'{package_name}.zip')}")
9291
wget.download(url, out=location)
9392
print("\n")
93+
9494
except Exception as e:
9595
raise RuntimeError("Invalid URL to download ZAP tool package {}".format(e))
9696

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

107108

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

119120

120121
def unzip_zap_package(location, package_name):
122+
package = location + f"/{package_name}.zip"
123+
destination = location + "/" + package_name
124+
121125
try:
122-
zip = ZipFile(os.path.join(location, f"{package_name}.zip"))
123-
zip.extractall(os.path.join(location, package_name))
124-
zip.close()
126+
if (platform.system() == 'Darwin'):
127+
subprocess.run(['unzip', package, '-d', destination], stdout = subprocess.PIPE)
128+
else:
129+
zip = ZipFile(os.path.join(location, f"{package_name}.zip"))
130+
zip.extractall(os.path.join(location, package_name))
131+
zip.close()
132+
125133
except Exception as e:
126134
raise RuntimeError("Encountered problem when trying to unzip the ZAP tool package. {}".format(e))
135+
127136
finally:
128137
remove_zip(location, package_name)
129138

130139

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

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

136145
for item in range(len(messages)):
@@ -160,6 +169,7 @@ def install_zap_package(version, location, overwrite):
160169
zap_cli_executable = 'zap-cli'
161170
else:
162171
raise RuntimeError(f"Couldn't find the proper ZAP tool package for the currently used operating system: {current_os}")
172+
163173
clear_old_artifacts(os.path.join(location, package), overwrite)
164174
download_recommended_zap_package(version, package, location)
165175
unzip_zap_package(location, package)
@@ -175,12 +185,9 @@ def install_zap_package(version, location, overwrite):
175185

176186

177187
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")
188+
parser = argparse.ArgumentParser(description='Script helping to download the ZAP tool in the currently recommended revision.')
189+
parser.add_argument("-l", "--location", help="Path to the location that should be used for storing ZAP tool package.", type=str, required=True)
190+
parser.add_argument("-o", "--overwrite", help="Overwrite files without asking, in case they already exist in given location", action="store_true")
184191
args = parser.parse_args()
185192

186193
location = os.path.abspath(args.location)
@@ -198,4 +205,5 @@ def main():
198205

199206

200207
if __name__ == '__main__':
208+
201209
main()

0 commit comments

Comments
 (0)