From 290654f7d9d36439a3801b64a182153013de42fe Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sun, 4 Dec 2022 09:12:25 -0800 Subject: [PATCH] Allow emscripten-releases-tags/aliases to work be used without SDK deps 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 --- emsdk.py | 22 ++++++++++++++++------ test/test.py | 6 ++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/emsdk.py b/emsdk.py index df57423a4d..36ae8a6b4b 100644 --- a/emsdk.py +++ b/emsdk.py @@ -2323,11 +2323,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 @@ -2817,8 +2823,12 @@ def expand_sdk_name(name, activating): elif '-fastcomp' in fullname: fullname = fullname.replace('-fastcomp', '') backend = 'fastcomp' - 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, '') + sdk_prefix = 'sdk-' + if name.startswith('releases-') or name.endswith('-base'): + sdk_prefix = '' releases_info = load_releases_info()['releases'] release_hash = get_release_hash(version, releases_info) if release_hash: @@ -2830,7 +2840,7 @@ def expand_sdk_name(name, activating): backend = 'upstream' else: backend = 'fastcomp' - full_name = '%sreleases-%s-%s-64bit' % (sdk, backend, release_hash) + full_name = '%sreleases-%s-%s-64bit' % (sdk_prefix, backend, release_hash) print("Resolving SDK version '%s' to '%s'" % (version, full_name)) return full_name @@ -2839,7 +2849,7 @@ def expand_sdk_name(name, activating): backend = 'upstream' global extra_release_tag extra_release_tag = version - return '%sreleases-%s-%s-64bit' % (sdk, backend, version) + return '%sreleases-%s-%s-64bit' % (sdk_prefix, backend, version) return name diff --git a/test/test.py b/test/test.py index f9766d0c22..459cb22b0b 100755 --- a/test/test.py +++ b/test/test.py @@ -286,6 +286,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-upstream-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-upstream-13e29bd55185e3c12802bc090b4507901856b2ba-64bit'")