Skip to content

[libc++][lit] Atomically update the persistent cache #66538

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
Sep 18, 2023
Merged
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
8 changes: 7 additions & 1 deletion libcxx/utils/libcxx/test/dsl.py
Original file line number Diff line number Diff line change
@@ -69,8 +69,14 @@ def f(config, *args, **kwargs):
if cacheKey not in cache:
cache[cacheKey] = function(config, *args, **kwargs)
# Update the persistent cache so it knows about the new key
with open(persistentCache, "wb") as cacheFile:
# We write to a PID-suffixed file and rename the result to
# ensure that the cache is not corrupted when running the test
# suite with multiple shards. Since this file is in the same
# directory as the destination, os.replace() will be atomic.
unique_suffix = ".tmp." + str(os.getpid())
with open(persistentCache + unique_suffix, "wb") as cacheFile:
pickle.dump(cache, cacheFile)
os.replace(persistentCache + unique_suffix, persistentCache)
return cache[cacheKey]

return f