Skip to content

Fix false positive writability check on cache directory #23049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -15412,3 +15412,25 @@ def test_rust_integration_basics(self):
return 0;
}''')
self.do_runf('main.cpp', 'Hello from rust!', emcc_args=[lib])

@crossplatform
def test_create_cache_directory(self):
if config.FROZEN_CACHE:
self.skipTest("test doesn't work with frozen cache")

# Test that the cache directory (including parent directories) is
# created on demand.
with env_modify({'EM_CACHE': os.path.abspath('foo/bar')}):
self.run_process([EMCC, '-c', test_file('hello_world.c')])
self.assertExists('foo/bar/sysroot_install.stamp')

if not WINDOWS:
# Test that we generate a nice error when we cannot create the cache
# because it is in a read-only location.
# For some reason this doesn't work on windows, at least not in CI.
os.mkdir('rodir')
os.chmod('rodir', 0o444)
self.assertFalse(os.access('rodir', os.W_OK))
with env_modify({'EM_CACHE': os.path.abspath('rodir/foo')}):
err = self.expect_fail([EMCC, '-c', test_file('hello_world.c')])
self.assertContained('emcc: error: unable to create cache directory', err)
8 changes: 4 additions & 4 deletions tools/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ def lock(reason):
def ensure():
ensure_setup()
if not os.path.isdir(cachedir):
parent_dir = os.path.dirname(cachedir)
if not is_writable(parent_dir):
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)')
utils.safe_ensure_dirs(cachedir)
try:
utils.safe_ensure_dirs(cachedir)
except Exception as e:
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)')


def erase():
Expand Down
Loading