Skip to content

Commit b30f912

Browse files
authored
Use certifi certs for buck download (#10095)
### Summary Depending on how Python is installed and managed, it is common for certificates to not be installed out of box on Macs. This can cause the download of buck2 as part of the build process to fail with a certificate error. While the ultimate solution for this is for the user to install certs in their environment, we can smooth this over a bit for build by pointing urllib at the certifi package certs, which we install as part of install_requirements. ### Test plan I worked with @nil-is-all to verify that this fix allowed him to build and install ExecuTorch from a clean environment. Without this change, he was seeing cert failure errors during buck download.
1 parent 65d931e commit b30f912

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

tools/cmake/resolve_buck.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import os
1111
import platform
12+
import ssl
1213
import stat
1314
import sys
1415
import urllib.request
@@ -18,6 +19,7 @@
1819
from typing import Union
1920

2021
import buck_util
22+
import certifi
2123
import zstd
2224

2325
"""
@@ -179,26 +181,23 @@ def resolve_buck2(args: argparse.Namespace) -> Union[str, int]:
179181
if os.path.isfile(buck2_local_path):
180182
return buck2_local_path
181183

182-
buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{target_buck_version}/{buck_info.archive_name}"
184+
buck2_archive_url = f"https://github.com/facebook/buck2/releases/download/{target_buck_version}/{buck_info.archive_name}"
183185

184-
try:
185-
print(f"Downloading buck2 from {buck2_archive_url}...", file=sys.stderr)
186-
archive_file, _ = urllib.request.urlretrieve(buck2_archive_url)
186+
print(f"Downloading buck2 from {buck2_archive_url}...", file=sys.stderr)
187+
ssl_context = ssl.create_default_context(cafile=certifi.where())
187188

188-
# Extract and chmod.
189-
with open(archive_file, "rb") as f:
190-
data = f.read()
191-
decompressed_bytes = zstd.decompress(data)
189+
with urllib.request.urlopen(buck2_archive_url, context=ssl_context) as request:
190+
# Extract and chmod.
191+
data = request.read()
192+
decompressed_bytes = zstd.decompress(data)
192193

193-
with open(buck2_local_path, "wb") as f:
194-
f.write(decompressed_bytes)
194+
with open(buck2_local_path, "wb") as f:
195+
f.write(decompressed_bytes)
195196

196-
file_stat = os.stat(buck2_local_path)
197-
os.chmod(buck2_local_path, file_stat.st_mode | stat.S_IEXEC)
198-
finally:
199-
os.remove(archive_file)
197+
file_stat = os.stat(buck2_local_path)
198+
os.chmod(buck2_local_path, file_stat.st_mode | stat.S_IEXEC)
200199

201-
return buck2_local_path
200+
return buck2_local_path
202201

203202

204203
def main():

0 commit comments

Comments
 (0)