Skip to content

Commit

Permalink
Allow emscripten-releases-tags/aliases to work be used without SDK deps
Browse files Browse the repository at this point in the history
This change means that aliases such as `latest` and `3.10.2` can be
used to install jsut the emscipten-releases packages and not the full
SDK with all the dependencies.

This allows uses who do not want to install dependencies such as node,
python or java to still use this package.

These packages were already available to install on their own via
their full names such as:

```
$ ./emsdk install releases-upstream-48ce0b44015d0182fc8c27aa9fbc0a4474b55982-64bi
```

Now these base packages can also be install via:

```
$ ./emsdk install latest-base
```

Fixes: #1142
  • Loading branch information
sbc100 committed Jan 30, 2023
1 parent 6305e91 commit bcd05f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
26 changes: 19 additions & 7 deletions emsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2110,11 +2110,17 @@ def load_file_index_list(filename):
def load_releases_info():
if not hasattr(load_releases_info, 'cached_info'):
try:
text = open(sdk_path('emscripten-releases-tags.json'), 'r').read()
load_releases_info.cached_info = json.loads(text)
with open(sdk_path('emscripten-releases-tags.json')) as f:
text = f.read()
info = json.loads(text)
except Exception as e:
print('Error parsing emscripten-releases-tags.json!')
exit_with_error(str(e))
for key, value in dict(info['aliases']).items():
info['aliases'][key + '-base'] = value + '-base'
for key, value in dict(info['releases']).items():
info['releases'][key + '-base'] = value + '-base'
load_releases_info.cached_info = info

return load_releases_info.cached_info

Expand Down Expand Up @@ -2589,20 +2595,25 @@ def expand_sdk_name(name, activating):
# sdk-x.y.z-64bit
# TODO: support short notation for old builds too?
fullname = name
version = fullname.replace('sdk-', '').replace('releases-', '').replace('-64bit', '').replace('tag-', '')
sdk = 'sdk-' if not name.startswith('releases-') else ''
version = fullname
for pattern in ('sdk-', 'releases-', '-64bit', 'tag-', '-base'):
version = version.replace(pattern, '')
if name.startswith('releases-') or name.endswith('-base'):
sdk_prefix = ''
else:
sdk_prefix = 'sdk-'
releases_info = load_releases_info()['releases']
release_hash = get_release_hash(version, releases_info)
if release_hash:
# Known release hash
full_name = '%sreleases-%s-64bit' % (sdk, release_hash)
full_name = '%sreleases-%s-64bit' % (sdk_prefix, release_hash)
print("Resolving SDK version '%s' to '%s'" % (version, full_name))
return full_name

if len(version) == 40:
global extra_release_tag
extra_release_tag = version
return '%sreleases-%s-64bit' % (sdk, version)
return '%sreleases-%s-64bit' % (sdk_prefix, version)

return name

Expand Down Expand Up @@ -2848,7 +2859,8 @@ def installed_sdk_text(name):
releases_versions = sorted(load_releases_versions(), key=version_key, reverse=True)
releases_info = load_releases_info()['releases']
for ver in releases_versions:
print(' %s %s' % (ver, installed_sdk_text('sdk-releases-%s-64bit' % get_release_hash(ver, releases_info))))
if not ver.endswith('-base'):
print(' %s %s' % (ver, installed_sdk_text('sdk-releases-%s-64bit' % get_release_hash(ver, releases_info))))
print()

# Use array to work around the lack of being able to mutate from enclosing
Expand Down
6 changes: 6 additions & 0 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ def test_install_tool(self):
# Test that its possible to install emscripten as tool instead of SDK
checked_call_with_output(emsdk + ' install releases-77b065ace39e6ab21446e13f92897f956c80476a', unexpected='Installing SDK')

def test_install_alias(self):
# 3.1.18 is 49d45744895c7d7e28acd94a385d7ee361653b4a
run_emsdk('install 3.1.18-base')
checked_call_with_output(emsdk + ' install install 3.1.18-base', unexpected='Installing SDK')
checked_call_with_output(emsdk + ' install install releases-upstream-49d45744895c7d7e28acd94a385d7ee361653b4a', unexpected='already downloaded, skipping', unexpected='Downloading:')

def test_activate_missing(self):
run_emsdk('install latest')
failing_call_with_output(emsdk + ' activate 2.0.1', expected="error: tool is not installed and therefore cannot be activated: 'releases-13e29bd55185e3c12802bc090b4507901856b2ba-64bit'")
Expand Down

0 comments on commit bcd05f7

Please sign in to comment.