(self)
| 283 | internal_settings: set[str] = set() |
| 284 | |
| 285 | def __init__(self): |
| 286 | self.attrs.clear() |
| 287 | self.legacy_settings.clear() |
| 288 | self.defaults.clear() |
| 289 | self.alt_names.clear() |
| 290 | self.internal_settings.clear() |
| 291 | self.allowed_settings.clear() |
| 292 | |
| 293 | # Load the JS defaults into python. |
| 294 | def read_js_settings(filename, attrs): |
| 295 | settings = utils.read_file(filename) |
| 296 | # Use a bunch of regexs to convert the file from JS to python |
| 297 | # TODO(sbc): This is kind hacky and we should probably convert |
| 298 | # this file in format that python can read directly (since we |
| 299 | # no longer read this file from JS at all). |
| 300 | settings = settings.replace('//', '#') |
| 301 | settings = re.sub(r'var ([\w\d]+)', r'attrs["\1"]', settings) |
| 302 | settings = re.sub(r'=\s+false\s*;', '= False', settings) |
| 303 | settings = re.sub(r'=\s+true\s*;', '= True', settings) |
| 304 | exec(settings, {'attrs': attrs}) |
| 305 | |
| 306 | internal_attrs = {} |
| 307 | read_js_settings(path_from_root('src/settings.js'), self.attrs) |
| 308 | read_js_settings(path_from_root('src/settings_internal.js'), internal_attrs) |
| 309 | self.attrs.update(internal_attrs) |
| 310 | self.infer_types() |
| 311 | |
| 312 | strict_override = utils.get_env_bool('EMCC_STRICT') |
| 313 | |
| 314 | # Special handling for LEGACY_SETTINGS. See src/setting.js for more |
| 315 | # details |
| 316 | for legacy in LEGACY_SETTINGS: |
| 317 | if len(legacy) == 2: |
| 318 | name, new_name = legacy |
| 319 | self.legacy_settings[name] = (None, 'setting renamed to ' + new_name) |
| 320 | self.alt_names[name] = new_name |
| 321 | self.alt_names[new_name] = name |
| 322 | default_value = self.attrs[new_name] |
| 323 | else: |
| 324 | name, fixed_values, err = legacy |
| 325 | self.legacy_settings[name] = (fixed_values, err) |
| 326 | default_value = fixed_values[0] |
| 327 | assert name not in self.attrs, 'legacy setting (%s) cannot also be a regular setting' % name |
| 328 | if not strict_override: |
| 329 | self.attrs[name] = default_value |
| 330 | |
| 331 | self.internal_settings.update(internal_attrs.keys()) |
| 332 | # Stash a deep copy of all settings in self.defaults. This allows us to detect which settings |
| 333 | # have local mods. |
| 334 | self.defaults.update(copy.deepcopy(self.attrs)) |
| 335 | |
| 336 | if strict_override: |
| 337 | self.attrs['STRICT'] = strict_override |
| 338 | |
| 339 | def infer_types(self): |
| 340 | for key, value in self.attrs.items(): |
nothing calls this directly
no test coverage detected