Skip to content

Resolve CMake File API source paths against the top-level source dir - #61

Open
mateusz-olczyk wants to merge 1 commit into
EngFlow:mainfrom
mateusz-olczyk:fix/cmake-project-relative-sources
Open

mateusz-olczyk wants to merge 1 commit into
EngFlow:mainfrom
mateusz-olczyk:fix/cmake-project-relative-sources

Conversation

@mateusz-olczyk

Copy link
Copy Markdown

The File API reports sources[].path relative to the top-level source directory (codemodel.paths.source, i.e. cmake -S) whenever the file is inside it, and absolute otherwise. extract_cmake passed those paths through unchanged, and reconstruct only rebases absolute paths onto <repo_root>.

This is fine when -S is the repo root, but when the CMake project lives in a subdirectory of the Bazel workspace (cmake -S sub/proj), TU keys came out as src/a.c instead of sub/proj/src/a.c. Those sources then looked missing on the CMake side and extra on the Bazel side, even though both builds compiled the same files. Only sources under the project dir were affected; sources outside it were already reported absolute and keyed correctly, so a target could show a mix of correct and bogus keys.

extract_cmake now makes source paths absolute against codemodel.paths.source (falling back to <repo_root> for replies without paths), in both the synthesized -c argument and the action inputs. Repo-relative keying then works as it already does for include directories. Out-of-tree absolute sources are unchanged.

A new extractor test covers a project configured from a subdirectory with one in-tree and one out-of-tree source; it fails without the fix. docs/REFERENCE-cmake.md notes that -S may be any directory under <repo_root>.

The File API reports `sources[].path` relative to the top-level source
directory (`codemodel.paths.source`, i.e. `cmake -S`) whenever the file
is inside it, and absolute otherwise. extract_cmake passed those paths
through unchanged, and reconstruct only rebases absolute paths onto
`<repo_root>`.

This is fine when `-S` is the repo root, but when the CMake project
lives in a subdirectory of the Bazel workspace (`cmake -S sub/proj`),
TU keys came out as `src/a.c` instead of `sub/proj/src/a.c`. Those
sources then looked missing on the CMake side and extra on the Bazel
side, even though both builds compiled the same files. Only sources
under the project dir were affected; sources outside it were already
reported absolute and keyed correctly, so a target could show a mix of
correct and bogus keys.

extract_cmake now makes source paths absolute against
`codemodel.paths.source` (falling back to `<repo_root>` for replies
without `paths`), in both the synthesized `-c` argument and the action
inputs. Repo-relative keying then works as it already does for include
directories. Out-of-tree absolute sources are unchanged.

A new extractor test covers a project configured from a subdirectory
with one in-tree and one out-of-tree source; it fails without the fix.
docs/REFERENCE-cmake.md notes that `-S` may be any directory under
`<repo_root>`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant