Skip to content

Commit 5d1c39d

Browse files
authored
Use curl to download files on macOS (emscripten-core#21525)
1 parent 18ff548 commit 5d1c39d

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

tools/ports/__init__.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
import glob
1111
import importlib.util
1212
import sys
13+
import subprocess
1314
from typing import Set
15+
from urllib.request import urlopen
16+
1417
from tools import cache
1518
from tools import config
1619
from tools import shared
1720
from tools import system_libs
1821
from tools import utils
1922
from tools.settings import settings
20-
2123
from tools.toolchain_profiler import ToolchainProfiler
2224

2325
ports = []
@@ -297,27 +299,14 @@ def retrieve():
297299
# retrieve from remote server
298300
logger.info(f'retrieving port: {name} from {url}')
299301

300-
# Attempt to use the `requests` module rather `urllib`.
301-
# The main difference here is that `requests` will use the `certifi`
302-
# certificate chain whereas `urllib` will use the system openssl
303-
# certificate chain, which can be out-of-date on some macOS systems.
304-
# TODO(sbc): Perhaps we can remove this at some point when we no
305-
# longer support such out-of-date systems.
306-
try:
307-
import requests
308-
try:
309-
response = requests.get(url)
310-
data = response.content
311-
except requests.exceptions.InvalidSchema:
312-
# requests does not support 'file://' protocol and raises InvalidSchema
313-
pass
314-
except ImportError:
315-
pass
316-
317-
# If we don't have `requests` or if we got InvalidSchema then fall
318-
# back to `urllib`.
319-
if not data:
320-
from urllib.request import urlopen
302+
if utils.MACOS:
303+
# Use `curl` over `urllib` on macOS to avoid issues with
304+
# certificate verification.
305+
# https://stackoverflow.com/questions/40684543/how-to-make-python-use-ca-certificates-from-mac-os-truststore
306+
# Unlike on Windows or Linux, curl is guaranteed to always be
307+
# available on macOS.
308+
data = subprocess.check_output(['curl', '-sSL', url])
309+
else:
321310
f = urlopen(url)
322311
data = f.read()
323312

0 commit comments

Comments
 (0)