Skip to content

Commit 7c65e19

Browse files
committed
Fix false positive writability check on cache directory
We were incorrectly reporting non-existent parent directories as non-writable. This was broken in emscripten-core#22801.
1 parent 5643c26 commit 7c65e19

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

test/test_other.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15400,3 +15400,18 @@ def test_rust_integration_basics(self):
1540015400
return 0;
1540115401
}''')
1540215402
self.do_runf('main.cpp', 'Hello from rust!', emcc_args=[lib])
15403+
15404+
@crossplatform
15405+
def test_create_cache_directory(self):
15406+
# Test that cache directory (including parents directories) is
15407+
# created on demand.
15408+
with env_modify({'EM_CACHE': os.path.abspath('foo/bar')}):
15409+
self.run_process([EMCC, '-c', test_file('hello_world.c')])
15410+
self.assertExists('foo/bar/sysroot_install.stamp')
15411+
15412+
# Test that we generate a nice error when we cannot create the cache
15413+
# because it is in a read-only location.
15414+
self.assertFalse(os.access('/', os.W_OK))
15415+
with env_modify({'EM_CACHE': '/foo'}):
15416+
err = self.expect_fail([EMCC, '-c', test_file('hello_world.c')])
15417+
self.assertContained('emcc: error: unable to create cache directory "/foo"', err)

tools/cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ def lock(reason):
7575
def ensure():
7676
ensure_setup()
7777
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(f'unable to create cache directory "{cachedir}": 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)
78+
try:
79+
utils.safe_ensure_dirs(cachedir)
80+
except Exception as e:
81+
utils.exit_with_error(f'unable to create cache directory "{cachedir}": {e} (see https://emscripten.org/docs/tools_reference/emcc.html for info on setting the cache directory)')
8282

8383

8484
def erase():

0 commit comments

Comments
 (0)