fix(os): save_dir/config_dir/cache_dir follow the platform, not just macOS

They were the macOS layout on every platform - the comment above them even said
"macOS/BSD layout" - so a game built on Linux wrote its saves to
~/Library/Application Support, a directory that means nothing there. Naming the
right directory is the entire reason a program calls these instead of joining a
path itself.

  macOS   save/config  ~/Library/Application Support/<app>
          cache        ~/Library/Caches/<app>
  Linux   save         $XDG_DATA_HOME   or ~/.local/share/<app>
          config       $XDG_CONFIG_HOME or ~/.config/<app>
          cache        $XDG_CACHE_HOME  or ~/.cache/<app>

macOS is unchanged to the byte, deliberately. save_dir and config_dir stay the
same directory there: Apple's home for a config file that is not an
NSUserDefaults plist is Application Support too, and a shipped game's settings
must not move out from under it. On Linux XDG separates the two and so does this.
An XDG variable that is set but EMPTY falls back to the default, which is what
the spec says and what an exported-but-unset variable looks like from a shell.

uname is read once and remembered rather than per call, because save_dir is
called on every save.

Verified on both branches. macOS by running it; the Linux branch by building the
probe's IR with the cached platform flag pinned, which exercises the emitted XDG
code exactly - unset, set, and set-but-empty all resolve as the spec says. The
suite's own case asserts the HOST's convention, so a macOS box covers the Apple
branch and CI covers XDG.

This is a backend change, so selfhost/ludicc.seed.ll is reseeded with it: the
bootstrap fixpoint (gen2 == gen3) and the C-free rebuild from the seed both pass.
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-11 19:46:47 +03:00
parent c069459343
commit 6bcb5f4ae1
7 changed files with 14780 additions and 14546 deletions

View file

@ -11,7 +11,14 @@ ns: Os
member: cache_dir
---
The per-user directory for an application's disposable cache — regenerable data the system may clear under disk pressure. On macOS this is under <code>~/Library/Caches/</code>. Never store anything here you cannot recreate.
The per-user directory for an application's disposable cache — regenerable data the system may clear under disk pressure. Never store anything here you cannot recreate.
| | |
| --- | --- |
| macOS | <code>~/Library/Caches/&lt;app&gt;</code> |
| Linux | <code>$XDG_CACHE_HOME/&lt;app&gt;</code>, or <code>~/.cache/&lt;app&gt;</code> |
An XDG variable that is set but empty falls back to the default, as the spec requires.
Parameters:
- `app` — the application name (used as the folder name)

View file

@ -11,7 +11,14 @@ ns: Os
member: config_dir
---
The per-user directory where an application should store configuration, named for the app. On macOS this resolves under <code>~/Library/Application Support/</code> (the platform keeps config and saves together there).
The per-user directory where an application should store configuration, named for the app.
| | |
| --- | --- |
| macOS | <code>~/Library/Application Support/&lt;app&gt;</code> |
| Linux | <code>$XDG_CONFIG_HOME/&lt;app&gt;</code>, or <code>~/.config/&lt;app&gt;</code> |
On macOS this is the same directory as <a href="os-save_dir"><code>save_dir</code></a> — the platform keeps config and saves together, and Apple's home for a config file that is not an <code>NSUserDefaults</code> plist is Application Support. On Linux XDG separates the two. An XDG variable that is set but empty falls back to the default, as the spec requires.
Parameters:
- `app` — the application name (used as the folder name)

View file

@ -11,7 +11,16 @@ ns: Os
member: save_dir
---
The per-user directory where an application should store save files, named for the app. On macOS this is under <code>~/Library/Application Support/</code>. The path is returned as a string; creating the directory and reading/writing files is the filesystem library's job (see the <a href="os-config_dir"><code>config_dir</code></a>/<a href="os-cache_dir"><code>cache_dir</code></a> companions).
The per-user directory where an application should store save files, named for the app. Which directory that is, is the platform's decision, not the program's:
| | |
| --- | --- |
| macOS | <code>~/Library/Application Support/&lt;app&gt;</code> |
| Linux | <code>$XDG_DATA_HOME/&lt;app&gt;</code>, or <code>~/.local/share/&lt;app&gt;</code> |
An XDG variable that is set but empty falls back to the default, as the spec requires. The path is returned as a string; creating the directory and reading/writing files is the filesystem library's job (see the <a href="os-config_dir"><code>config_dir</code></a>/<a href="os-cache_dir"><code>cache_dir</code></a> companions).
On macOS <code>save_dir</code> and <code>config_dir</code> are the same directory — Apple's home for a config file that is not an <code>NSUserDefaults</code> plist is Application Support too. On Linux XDG separates them, and so does this.
Parameters:
- `app` — the application name (used as the folder name)