Write shaderCache.bin next to the executable instead of CWD#1670
Merged
bghgary merged 4 commits intoBabylonJS:masterfrom Apr 22, 2026
Merged
Write shaderCache.bin next to the executable instead of CWD#1670bghgary merged 4 commits intoBabylonJS:masterfrom
bghgary merged 4 commits intoBabylonJS:masterfrom
Conversation
ShaderCache.SaveAndLoad was writing 'shaderCache.bin' to the current working directory, which polluted whatever directory the test happened to run from (e.g. the repo root if someone launched UnitTests.exe directly). Switch to std::filesystem::temp_directory_path() and remove the file after the round-trip so the test leaves no trace. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the ShaderCache unit test to avoid writing shaderCache.bin into the user’s current working directory by moving the artifact to the OS temp directory and attempting to delete it after the round-trip.
Changes:
- Switch shader cache file location from CWD to
std::filesystem::temp_directory_path(). - Add a best-effort cleanup via
std::filesystem::remove(..., std::error_code&).
- Use temp_directory_path(error_code) to avoid filesystem_error throws. - Add per-run unique suffix so concurrent UnitTests.exe invocations don't collide on the shared temp filename. - Assert streams opened successfully before Save/Load. - Check the result of std::filesystem::remove so silent cleanup failures don't leave artifacts behind. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replaces the temp_directory_path()+unique-suffix approach with a new GetExecutableDirectory() helper (Win32 GetModuleFileNameW, Apple _NSGetExecutablePath, Linux /proc/self/exe) declared in App.h and implemented per-platform. Collisions between concurrent runs are not possible (each CMake build has its own UnitTests.exe), and artifacts land alongside the build output rather than in the user's current directory or system temp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bkaradzic-microsoft
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ShaderCache.SaveAndLoadwritesshaderCache.binto the current working directory:When
UnitTests.exeis launched from anywhere that isn't the build output directory (e.g. the repo root), the file lands in that directory and is never cleaned up. A unit test should not leave artifacts in the user's working directory.Fix
Write the file next to the executable instead. Added a
GetExecutableDirectory()helper declared inApp.hand implemented per-platform:GetModuleFileNameW(nullptr, ...)_NSGetExecutablePath+std::filesystem::canonicalstd::filesystem::canonical("/proc/self/exe")The test now uses
GetExecutableDirectory() / "shaderCache.bin", asserts each stream opened successfully, and asserts on the result ofstd::filesystem::removeso silent cleanup failures are visible.No collisions between concurrent runs are possible (each CMake build has its own
UnitTests.exe), and artifacts land alongside the build output rather than in the user's current directory or system temp.Testing
Ran
UnitTests.exe --gtest_filter="ShaderCache.*"from the repo root: test passes, noshaderCache.binleft behind at the repo root or next to the executable.[Created by Copilot on behalf of @bghgary]