import os # CFGDIR is the directory containing this file, set by tools/config.py. _root = os.environ["CFGDIR"] LLVM_ROOT = os.path.normpath(os.path.join(_root, "..", "bin")) BINARYEN_ROOT = os.path.normpath(os.path.join(_root, "..")) NODE_JS = "@NODE@" # The shipped cache is root-owned. Seed a per-user cache with symlinks to # those files so emcc can read the prebuilt libraries and write new ones # without EM_CACHE. sanity.txt must be a real file: a mismatch makes emcc # delete the cache (tools/shared.py generate_sanity). if not os.environ.get("EM_CACHE"): _system = os.path.join(_root, "cache") _base = os.environ.get("XDG_CACHE_HOME") or os.path.join(os.path.expanduser("~"), ".cache") _user = os.path.join(_base, "emscripten") _version = open(os.path.join(_root, "emscripten-version.txt"), encoding="utf-8").read().strip().strip('"') _identity = f"{_version}|{os.path.normcase(LLVM_ROOT)}" _stamp = os.path.join(_user, ".seed-stamp") try: _current = open(_stamp, encoding="utf-8").read().strip() except FileNotFoundError: _current = None if _current != _identity: def _seed(src, dst): os.makedirs(dst, exist_ok=True) with os.scandir(src) as it: for entry in it: if entry.name in ("cache.lock", "sanity.txt", ".seed-stamp"): continue dest = os.path.join(dst, entry.name) if entry.is_dir(follow_symlinks=False): _seed(entry.path, dest) elif not os.path.lexists(dest): try: os.symlink(entry.path, dest) except FileExistsError: pass _seed(_system, _user) _sanity = os.path.join(_user, "sanity.txt") if os.path.islink(_sanity): os.remove(_sanity) with open(_sanity, "w", encoding="utf-8") as fh: fh.write(_identity + "\n") with open(_stamp, "w", encoding="utf-8") as fh: fh.write(_identity + "\n") CACHE = _user