Skip to content

Commit d42c740

Browse files
authored
Switch to .xz by default for SDK downloads (#1281)
This is a bit of a hack but I can't think of another way to do it. Basically when downloading SDKs, we first try the new `.xz` extension. If that fails, we fall back to the old `.tbz2`. Both these first two download attempts we run in "silent" mode. If both of them fail we re-run the original request in non-silent mode so that the error message will always contain the original `.xz` extension. See #1235
1 parent 93360d3 commit d42c740

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

emsdk.py

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ def get_download_target(url, dstpath, filename_prefix=''):
672672

673673
# On success, returns the filename on the disk pointing to the destination file that was produced
674674
# On failure, returns None.
675-
def download_file(url, dstpath, download_even_if_exists=False, filename_prefix=''):
675+
def download_file(url, dstpath, download_even_if_exists=False,
676+
filename_prefix='', silent=False):
676677
debug_print('download_file(url=' + url + ', dstpath=' + dstpath + ')')
677678
file_name = get_download_target(url, dstpath, filename_prefix)
678679

@@ -717,9 +718,10 @@ def download_file(url, dstpath, download_even_if_exists=False, filename_prefix='
717718
print(']')
718719
sys.stdout.flush()
719720
except Exception as e:
720-
errlog("Error: Downloading URL '" + url + "': " + str(e))
721-
if "SSL: CERTIFICATE_VERIFY_FAILED" in str(e) or "urlopen error unknown url type: https" in str(e):
722-
errlog("Warning: Possibly SSL/TLS issue. Update or install Python SSL root certificates (2048-bit or greater) supplied in Python folder or https://pypi.org/project/certifi/ and try again.")
721+
if not silent:
722+
errlog("Error: Downloading URL '" + url + "': " + str(e))
723+
if "SSL: CERTIFICATE_VERIFY_FAILED" in str(e) or "urlopen error unknown url type: https" in str(e):
724+
errlog("Warning: Possibly SSL/TLS issue. Update or install Python SSL root certificates (2048-bit or greater) supplied in Python folder or https://pypi.org/project/certifi/ and try again.")
723725
rmfile(file_name)
724726
return None
725727
except KeyboardInterrupt:
@@ -1407,18 +1409,36 @@ def download_and_extract(archive, dest_dir, filename_prefix='', clobber=True):
14071409
debug_print('download_and_extract(archive=' + archive + ', dest_dir=' + dest_dir + ')')
14081410

14091411
url = urljoin(emsdk_packages_url, archive)
1410-
download_target = get_download_target(url, download_dir, filename_prefix)
14111412

1412-
received_download_target = download_file(url, download_dir, not KEEP_DOWNLOADS, filename_prefix)
1413-
if not received_download_target:
1413+
def try_download(url, silent=False):
1414+
return download_file(url, download_dir, not KEEP_DOWNLOADS,
1415+
filename_prefix, silent=silent)
1416+
1417+
# Special hack for the wasm-binaries we transitioned from `.bzip2` to
1418+
# `.xz`, but we can't tell from the version/url which one to use, so
1419+
# try one and then fall back to the other.
1420+
success = False
1421+
if 'wasm-binaries' in archive and os.path.splitext(archive)[1] == '.xz':
1422+
success = try_download(url, silent=True)
1423+
if not success:
1424+
alt_url = url.replace('.tar.xz', '.tbz2')
1425+
success = try_download(alt_url, silent=True)
1426+
if success:
1427+
url = alt_url
1428+
1429+
if not success:
1430+
success = try_download(url)
1431+
1432+
if not success:
14141433
return False
1415-
assert received_download_target == download_target
14161434

14171435
# Remove the old directory, since we have some SDKs that install into the
14181436
# same directory. If we didn't do this contents of the previous install
14191437
# could remain.
14201438
if clobber:
14211439
remove_tree(dest_dir)
1440+
1441+
download_target = get_download_target(url, download_dir, filename_prefix)
14221442
if archive.endswith('.zip'):
14231443
return unzip(download_target, dest_dir)
14241444
else:
@@ -2071,17 +2091,29 @@ def get_emscripten_releases_tot():
20712091
arch = ''
20722092
if ARCH == 'arm64':
20732093
arch = '-arm64'
2074-
for release in recent_releases:
2075-
url = emscripten_releases_download_url_template % (
2094+
2095+
def make_url(ext):
2096+
return emscripten_releases_download_url_template % (
20762097
os_name(),
20772098
release,
20782099
arch,
2079-
'tbz2' if not WINDOWS else 'zip'
2100+
ext,
20802101
)
2102+
2103+
for release in recent_releases:
2104+
make_url('tbz2' if not WINDOWS else 'zip')
20812105
try:
2082-
urlopen(url)
2106+
urlopen(make_url('tar.xz' if not WINDOWS else 'zip'))
20832107
except:
2084-
continue
2108+
if not WINDOWS:
2109+
# Try the old `.tbz2` name
2110+
# TODO:remove this once tot builds are all using xz
2111+
try:
2112+
urlopen(make_url('tbz2'))
2113+
except:
2114+
continue
2115+
else:
2116+
continue
20852117
return release
20862118
exit_with_error('failed to find build of any recent emsdk revision')
20872119

emsdk_manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"version": "%releases-tag%",
3535
"bitness": 64,
3636
"arch": "x86_64",
37-
"linux_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/%releases-tag%/wasm-binaries.tbz2",
38-
"macos_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/mac/%releases-tag%/wasm-binaries.tbz2",
37+
"linux_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/%releases-tag%/wasm-binaries.tar.xz",
38+
"macos_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/mac/%releases-tag%/wasm-binaries.tar.xz",
3939
"windows_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/win/%releases-tag%/wasm-binaries.zip",
4040
"download_prefix": "%releases-tag%-",
4141
"install_path": "upstream",
@@ -48,8 +48,8 @@
4848
"version": "%releases-tag%",
4949
"bitness": 64,
5050
"arch": "arm64",
51-
"macos_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/mac/%releases-tag%/wasm-binaries-arm64.tbz2",
52-
"linux_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/%releases-tag%/wasm-binaries-arm64.tbz2",
51+
"macos_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/mac/%releases-tag%/wasm-binaries-arm64.tar.xz",
52+
"linux_url": "https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/%releases-tag%/wasm-binaries-arm64.tar.xz",
5353
"download_prefix": "%releases-tag%-",
5454
"install_path": "upstream",
5555
"activated_path": "%installation_dir%/emscripten",

0 commit comments

Comments
 (0)