RFR: 8352645: Add tool support to check order of includes
Magnus Ihse Bursie
ihse at openjdk.org
Tue Mar 25 14:59:28 UTC 2025
On Sun, 23 Mar 2025 21:14:47 GMT, Doug Simon <dnsimon at openjdk.org> wrote:
> This PR adds `bin/sort_includes.py`, a python3 script to check that blocks of include statements in C++ files are sorted alphabetically and that there's at least one blank line between user and sys includes (as per the [style guide](https://github.com/openjdk/jdk/blob/master/doc/hotspot-style.md#source-files)).
> This script can also update files with unsorted includes. The second commit in this PR shows the result of running:
>
> python3 ./bin/sort_includes.py ./src/hotspot
>
> To prevent an include being reordered, put at least one non-space character after the closing `"` or `>`. See `src/hotspot/share/adlc/archDesc.cpp` for an example.
>
> Assuming this PR is integrated, jcheck could be updated to use it to ensure include statements remain sorted.
Interesting! Thank you for creating automation for keeping the code up to the code standard.
You wrote the script using python. We have intentionally not been using python before, to avoid dragging in yet another dependency. I realize this is a free-standing script and a python dependency is still not required for building, but I still would like to see it avoided.
Did you consider writing the tool in Java? Or rather, could you be convinced to convert it to Java? With the source code launch mechanism, it is just as simple to run as a python script. Also, there is some kind of optics about it as well, where we actually use Java for developing the JDK.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24180#issuecomment-2751551897
More information about the build-dev
mailing list