Take a map of users settings {NAME: VALUE} and apply them to the global settings object.
()
| 737 | |
| 738 | |
| 739 | def apply_user_settings(): |
| 740 | """Take a map of users settings {NAME: VALUE} and apply them to the global settings object.""" |
| 741 | # Stash a copy of all available incoming APIs before the user can potentially override it |
| 742 | settings.ALL_INCOMING_MODULE_JS_API = settings.INCOMING_MODULE_JS_API + settings.EXTRA_INCOMING_JS_API |
| 743 | |
| 744 | for key, value in user_settings.items(): |
| 745 | if key in settings.internal_settings: |
| 746 | exit_with_error('%s is an internal setting and cannot be set from command line', key) |
| 747 | |
| 748 | # map legacy settings which have aliases to the new names |
| 749 | # but keep the original key so errors are correctly reported via the `setattr` below |
| 750 | user_key = key |
| 751 | if key in settings.legacy_settings and key in settings.alt_names: |
| 752 | key = settings.alt_names[key] |
| 753 | |
| 754 | # In those settings fields that represent amount of memory, translate suffixes to multiples of 1024. |
| 755 | if key in MEM_SIZE_SETTINGS: |
| 756 | value = str(expand_byte_size_suffixes(value)) |
| 757 | |
| 758 | filename = None |
| 759 | if value and value[0] == '@': |
| 760 | filename = value.removeprefix('@') |
| 761 | if not os.path.isfile(filename): |
| 762 | exit_with_error('%s: file not found parsing argument: %s=%s' % (filename, key, value)) |
| 763 | value = read_file(filename).strip() |
| 764 | else: |
| 765 | value = value.replace('\\', '\\\\') |
| 766 | |
| 767 | expected_type = settings.types.get(key) |
| 768 | |
| 769 | if filename and expected_type == list and value.strip()[0] != '[': |
| 770 | # Prefer simpler one-line-per value parser |
| 771 | value = parse_symbol_list_file(value) |
| 772 | else: |
| 773 | try: |
| 774 | value = parse_value(value, expected_type) |
| 775 | except Exception as e: |
| 776 | exit_with_error(f'error parsing "-s" setting "{key}={value}": {e}') |
| 777 | |
| 778 | setattr(settings, user_key, value) |
| 779 | |
| 780 | if key == 'EXPORTED_FUNCTIONS': |
| 781 | # used for warnings in emscripten.py |
| 782 | settings.USER_EXPORTS = settings.EXPORTED_FUNCTIONS.copy() |
| 783 | |
| 784 | if key == 'JSPI': |
| 785 | settings.ASYNCIFY = 2 |
| 786 | if key == 'JSPI_IMPORTS': |
| 787 | settings.ASYNCIFY_IMPORTS = value |
| 788 | if key == 'JSPI_EXPORTS': |
| 789 | settings.ASYNCIFY_EXPORTS = value |
| 790 | |
| 791 | |
| 792 | def normalize_boolean_setting(name, value): |
no test coverage detected