Skip to content

Commit 07a319b

Browse files
committed
Remove automatic fallback to $HOME/.emscripten_cache. NFC
Putting the cache in the $HOME directory is not a great idea since its a location that is shared by any/all versions of emscripten. If anyone really wants to use that location they can do so via the config file setting `CACHE` or via the environment variable `EMCC_CACHE`.
1 parent 282d3a8 commit 07a319b

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ See docs/process.md for more on how version tagging works.
2424
passing non-trivially-copyable destrination parameter to `memcpy`,
2525
`memset` and similar functions for which it is a documented undefined
2626
behavior (#22798). See https://github.com/llvm/llvm-project/pull/111434
27+
- The automatic fallback to `$HOME/.emscripten_cache` when the emscripten
28+
directory is read-only was removed. This automatic behaviour could cause
29+
confusion. Anyone who really wants to use `$HOME/.emscripten_cache` can
30+
still do so either via an environment variable (`EMCC_CACHE`) or via a config
31+
file setting `CACHE`.
2732

2833
3.1.70 - 10/25/24
2934
-----------------

tools/cache.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@
2323
cachelock_name = None
2424

2525

26+
def is_writable(path):
27+
return os.access(path, os.W_OK)
28+
29+
2630
def acquire_cache_lock(reason):
2731
global acquired_count
2832
if config.FROZEN_CACHE:
2933
# Raise an exception here rather than exit_with_error since in practice this
3034
# should never happen
3135
raise Exception('Attempt to lock the cache but FROZEN_CACHE is set')
3236

37+
if not is_writable(cachedir):
38+
utils.exit_with_error(f'cache directory "{cachedir}" is not writable while accessing cache for: {reason} (see https://emscripten.org/docs/tools_reference/emcc.html for info on setting the cache directory)')
39+
3340
if acquired_count == 0:
3441
logger.debug(f'PID {os.getpid()} acquiring multiprocess file lock to Emscripten cache at {cachedir}')
3542
assert 'EM_CACHE_IS_LOCKED' not in os.environ, f'attempt to lock the cache while a parent process is holding the lock ({reason})'
@@ -67,7 +74,11 @@ def lock(reason):
6774

6875
def ensure():
6976
ensure_setup()
70-
utils.safe_ensure_dirs(cachedir)
77+
if not os.path.isdir(cachedir):
78+
parent_dir = os.path.dirname(cachedir)
79+
if not is_writable(parent_dir):
80+
utils.exit_with_error('unable to create cache directory "{cachdir}": parent directory not writable (see https://emscripten.org/docs/tools_reference/emcc.html for info on setting the cache directory)')
81+
utils.safe_ensure_dirs(cachedir)
7182

7283

7384
def erase():

tools/config.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ def fix_js_engine(old, new):
5555
return new
5656

5757

58-
def root_is_writable():
59-
return os.access(__rootpath__, os.W_OK)
60-
61-
6258
def normalize_config_settings():
6359
global CACHE, PORTS, LLVM_ADD_VERSION, CLANG_ADD_VERSION, CLOSURE_COMPILER
6460
global NODE_JS, NODE_JS_TEST, V8_ENGINE, JS_ENGINES, SPIDERMONKEY_ENGINE, WASM_ENGINES
@@ -80,16 +76,7 @@ def normalize_config_settings():
8076
WASM_ENGINES = [listify(engine) for engine in WASM_ENGINES]
8177
CLOSURE_COMPILER = listify(CLOSURE_COMPILER)
8278
if not CACHE:
83-
if FROZEN_CACHE or root_is_writable():
84-
CACHE = path_from_root('cache')
85-
else:
86-
# Use the legacy method of putting the cache in the user's home directory
87-
# if the emscripten root is not writable.
88-
# This is useful mostly for read-only installation and perhaps could
89-
# be removed in the future since such installations should probably be
90-
# setting a specific cache location.
91-
logger.debug('Using home-directory for emscripten cache due to read-only root')
92-
CACHE = os.path.expanduser(os.path.join('~', '.emscripten_cache'))
79+
CACHE = path_from_root('cache')
9380
if not PORTS:
9481
PORTS = os.path.join(CACHE, 'ports')
9582

@@ -276,10 +263,6 @@ def find_config_file():
276263
if os.path.isfile(user_home_config):
277264
return user_home_config
278265

279-
# No config file found. Return the default location.
280-
if not root_is_writable():
281-
return user_home_config
282-
283266
return embedded_config
284267

285268

0 commit comments

Comments
 (0)