Commit cb89fe1
Write shaderCache.bin next to the executable instead of CWD (#1670)
## Problem
`ShaderCache.SaveAndLoad` writes `shaderCache.bin` to the current
working directory:
```cpp
static const char* shaderCacheFileName = "shaderCache.bin";
std::ofstream stream(shaderCacheFileName, std::ios::binary);
```
When `UnitTests.exe` is 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 in `App.h` and implemented
per-platform:
- **Win32** — `GetModuleFileNameW(nullptr, ...)`
- **Apple** — `_NSGetExecutablePath` + `std::filesystem::canonical`
- **X11/Linux** — `std::filesystem::canonical("/proc/self/exe")`
The test now uses `GetExecutableDirectory() / "shaderCache.bin"`,
asserts each stream opened successfully, and asserts on the result of
`std::filesystem::remove` so 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, no `shaderCache.bin` left behind at the repo root or next
to the executable.
[Created by Copilot on behalf of @bghgary]
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent fb416e3 commit cb89fe1
5 files changed
Lines changed: 48 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
4 | 18 | | |
5 | 19 | | |
6 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
10 | 21 | | |
11 | 22 | | |
12 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
19 | 24 | | |
20 | 25 | | |
21 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
79 | | - | |
| 82 | + | |
| 83 | + | |
80 | 84 | | |
81 | 85 | | |
82 | | - | |
| 86 | + | |
| 87 | + | |
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
86 | 91 | | |
87 | | - | |
| 92 | + | |
| 93 | + | |
88 | 94 | | |
89 | 95 | | |
90 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
91 | 101 | | |
92 | 102 | | |
93 | 103 | | |
| |||
0 commit comments