Commit b3627f9
authored
fix: emit absolute
* fix: emit absolute `-fprebuilt-module-path` so clangd resolves modules
src/build/flags.cppm was emitting a bare `-fprebuilt-module-path=pcm.cache`
(or `=gcm.cache`). This works for `mcpp build` because ninja runs commands
with cwd = `<projectRoot>/target/<triple>/<fp>/` so the relative path
resolves correctly. But the same flag is captured verbatim into
`compile_commands.json`, whose `directory` field is `plan.projectRoot`.
Per CDB spec, clangd does `cd <directory>` before resolving the args, so
it looks for `<projectRoot>/pcm.cache` — which doesn't exist. Effect:
`import` resolution silently fails in clangd ("module 'X' not found"),
even when `mcpp build` succeeds.
The other `-fmodule-file=` flags in the same block were already absolute
(escape_path-wrapped); this one was an oversight.
Fix: format the flag with `escape_path(plan.outputDir / traits.bmiDir)`.
Single line. ninja still works (absolute paths are cwd-independent), and
clangd now finds the BMI cache.
Regression test: tests/e2e/47_cdb_prebuilt_module_path_abs.sh creates a
fresh project, runs `mcpp build`, parses `compile_commands.json`, asserts
every `-fprebuilt-module-path=X`:
- is absolute (starts with `/` on POSIX or `<drive>:` on Windows)
- ends in `/pcm.cache` or `/gcm.cache`
- points to an existing directory
Pass-through for GCC-only flows that don't emit the flag at all.
* ci/test: un-escape ninja sequences in CDB args; harden e2e for Windows
First CI round revealed two layered issues exposed by the new e2e:
1. **The shipped CDB carries ninja-escape artefacts.** `flags.cppm`'s
`escape_path` ninja-escapes paths (`$ ` for space, `$:` for colon,
`$$` for literal `$`) so they survive embedding in ninja rule strings.
But the same escaped strings flow verbatim through `f.cxx` into
`compile_commands.json`, whose `arguments` array is exec'd by clangd
without any ninja involved. On Windows that makes `C:` appear as
`C$:` in CDB → clangd can't resolve the path. POSIX usually escaped
nothing in practice, hiding the bug; Windows drive letters always
trigger `$:`.
Fix in `compile_commands.cppm::split_flags`: same single pass now
splits tokens *and* unescapes the three ninja sequences. Splitting
was also broken for paths with a literal space (would've broken
`-isystem "/path with space/include"` mid-arg) — that's fixed
simultaneously since `$ ` is no longer a token separator.
2. **e2e test 47 needed Windows-friendly checks.** The original `[^"]+`
grep returned the raw JSON-escaped form (`\\Users\\...`) and the
`^[A-Za-z]:` regex didn't match `C$:`. Rewrote using `jq -r` (which
does JSON un-escape natively, preinstalled on all GHA runners) and:
- explicit ninja-escape sniff (`$:`, `$ `, `$$`)
- both POSIX and Windows-drive absolute-path checks
- basename check normalised against `\` / `/`
Net: CDB now contains plain paths in both runtimes, and the test fails
loudly if either layer regresses.
* test(e2e/47): strip trailing CR from jq output on git-bash/Windows
The Windows CI run reported:
FAIL: basename is not pcm.cache/gcm.cache: 'pcm.cache
'
The closing quote on the next line is the giveaway — the value carries a
trailing `\r`. `jq.exe` on git-bash emits CRLF; `mapfile -t` strips LF
but leaves CR, so every downstream comparison saw `pcm.cache$'\r'` and
failed. Trim with `${v%$'\r'}` per element.
The source-code fix (un-escape ninja sequences) is working — the value
itself is now a clean `C:\Users\...\pcm.cache`, no `$:` artefact.
* test(e2e/47): drop bash-4 `mapfile` for macOS bash 3.2 compat
Apple ships GPLv2-era bash 3.2 on macOS, which has no `mapfile` /
`readarray`. The previous round failed on ci-macos with:
line 31: mapfile: command not found
FAIL: 47_cdb_prebuilt_module_path_abs.sh (exit 127)
Replace `mapfile -t vals < <(jq …)` with `jq … > tmp.txt` followed by a
`while … read … done < tmp.txt`. Using input redirection (not a `|`
pipeline) keeps the loop in the current shell so `fail=1` propagates;
the temp file lives under $TMP and is cleaned up by the script's trap.
Empty-list signal now uses `[[ ! -s "$TMP/vals.txt" ]]` instead of array
length — same semantics, no bashism.-fprebuilt-module-path so clangd resolves modules (#77)1 parent 7f8d3e4 commit b3627f9
3 files changed
Lines changed: 137 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
41 | 55 | | |
42 | 56 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
53 | 79 | | |
| 80 | + | |
54 | 81 | | |
55 | 82 | | |
56 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
216 | 226 | | |
217 | 227 | | |
218 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
0 commit comments