MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / check_sanity

Function check_sanity

tools/shared.py:377–447  ·  view source on GitHub ↗

Check that basic stuff we need (Node.js, and Clang and LLVM) exists. The test runner always does this check (through |force|). emcc does this less frequently, only when ${EM_CONFIG}_sanity does not exist or is older than EM_CONFIG (so, we re-check sanity when the settings are changed). We al

(force=False, quiet=False)

Source from the content-addressed store, hash-verified

375
376@ToolchainProfiler.profile()
377def check_sanity(force=False, quiet=False):
378 """Check that basic stuff we need (Node.js, and Clang and LLVM) exists.
379
380 The test runner always does this check (through |force|). emcc does this less
381 frequently, only when ${EM_CONFIG}_sanity does not exist or is older than
382 EM_CONFIG (so, we re-check sanity when the settings are changed). We also
383 re-check sanity and clear the cache when the version changes.
384 """
385 if not force and utils.get_env_bool('EMCC_SKIP_SANITY_CHECK'):
386 return
387
388 # We set EMCC_SKIP_SANITY_CHECK so that any subprocesses that we launch will
389 # not re-run the tests.
390 os.environ['EMCC_SKIP_SANITY_CHECK'] = '1'
391
392 # In DEBUG mode we perform the sanity checks even when
393 # early return due to the file being up-to-date.
394 if DEBUG:
395 force = True
396
397 if config.FROZEN_CACHE:
398 if force:
399 perform_sanity_checks(quiet)
400 return
401
402 if utils.get_env_bool('EM_IGNORE_SANITY'):
403 perform_sanity_checks(quiet)
404 return
405
406 expected = generate_sanity()
407
408 sanity_file = cache.get_path('sanity.txt')
409
410 def sanity_is_correct():
411 sanity_data = None
412 # We can't simply check for the existence of sanity_file and then read from
413 # it here because we don't hold the cache lock yet and some other process
414 # could clear the cache between checking for, and reading from, the file.
415 with contextlib.suppress(Exception):
416 sanity_data = utils.read_file(sanity_file)
417 if sanity_data == expected:
418 logger.debug(f'sanity file up-to-date: {sanity_file}')
419 # Even if the sanity file is up-to-date we still run the checks
420 # when force is set.
421 if force:
422 perform_sanity_checks(quiet)
423 return True # all is well
424 return False
425
426 if sanity_is_correct():
427 # Early return without taking the cache lock
428 return
429
430 with cache.lock('sanity'):
431 # Check again once the cache lock as acquired
432 if sanity_is_correct():
433 return
434

Callers

nothing calls this directly

Calls 8

perform_sanity_checksFunction · 0.85
generate_sanityFunction · 0.85
sanity_is_correctFunction · 0.85
get_pathMethod · 0.80
existsMethod · 0.80
write_fileMethod · 0.80
lockMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected