Skip to content

Conversation

@chiphogg
Copy link
Member

This gives us the most important portion of #255. In fact, it's even
better than what we originally suggested, which was a blocking checkbox
in code review. This solution uses bazel query to get the
authoritative set of headers included in our main targets, //au and
//au:io. It compares them to the CMake target au, which encompasses
both of these targets.

The script returns an exit code of 0 if the headers are an exact
match, and 1 otherwise. If any files differ, it prints out the list
of every file that is found in only bazel or only CMake.

A good way to test this is to run:

check-cmake-headers && echo $?

This should print 0 on the last line. Then, if we edit
au/code/au/CMakeLists.txt, and change the name of one of the files
(say, prepend asdf), we should see the discrepancy printed out, and
the printed exit code should change to 1.

A future PR will add a GitHub action to call this script and gate PRs on
its result.

This gives us the most important portion of #255.  In fact, it's even
better than what we originally suggested, which was a blocking checkbox
in code review.  This solution uses `bazel query` to get the
authoritative set of headers included in our main targets, `//au` and
`//au:io`.  It compares them to the CMake target `au`, which encompasses
both of these targets.

The script returns an exit code of `0` if the headers are an exact
match, and `1` otherwise.  If any files differ, it prints out the list
of every file that is found in only bazel or only CMake.

A good way to test this is to run:

```sh
check-cmake-headers && echo $?
```

This should print `0` on the last line.  Then, if we edit
`au/code/au/CMakeLists.txt`, and _change the name_ of one of the files
(say, prepend `asdf`), we should see the discrepancy printed out, and
the printed exit code should change to `1`.

A future PR will add a GitHub action to call this script and gate PRs on
its result.
@chiphogg chiphogg added the release notes: 🔨 tooling PR for the Tooling section of release notes label Jan 19, 2025
We'll revert this commit before landing this PR.
@chiphogg chiphogg requested a review from a team as a code owner January 19, 2025 20:32
If the gating jobs fail, then that means that this script works!
@chiphogg chiphogg removed the request for review from a team January 19, 2025 20:35
@chiphogg
Copy link
Member Author

For proof that the script will actually work in CI, see this passed build for 1805ffa (which temporarily made it gating), and this failed build for 82e6727 (which intentionally created an error condition).

subprocess.run(
[
"cmake",
"-S",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to lean towards long arguments when using scripts to make them more self documenting. Not being a regular cmake user I have no idea what -B and -S do. Well, I have have a decent guess as to -S.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, cmake --help didn't seem to suggest a long-form alternative!

Usage

  cmake [options] <path-to-source>
  cmake [options] <path-to-existing-build>
  cmake [options] -S <path-to-source> -B <path-to-build>

Specify a source directory to (re-)generate a build system for it in the
current working directory.  Specify an existing build directory to
re-generate its build system.

Options
  -S <path-to-source>          = Explicitly specify a source directory.
  -B <path-to-build>           = Explicitly specify a build directory.
  -C <initial-cache>           = Pre-load a script to populate the cache.
  -D <var>[:<type>]=<value>    = Create or update a cmake cache entry.
  -U <globbing_expr>           = Remove matching entries from CMake cache.
...

Anyway, I don't know them from memory either, but this command was basically pasted from our installation instructions. I've added a link here in a comment; thanks for pointing it out!

@chiphogg chiphogg merged commit 40b3226 into main Jan 21, 2025
14 checks passed
@chiphogg chiphogg deleted the chiphogg/check-cmake-headers#255 branch January 21, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes: 🔨 tooling PR for the Tooling section of release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants