Skip to content

Conversation

@gxalpha
Copy link
Member

@gxalpha gxalpha commented Dec 5, 2025

Description

Creates a gersemi extension that sorts the elements in target_sources alphabetically (and also removes duplicates). This uses case-sensitive sorting as bd2024e does.
The minimum version of gersemi for these extensions is 0.20 as per BlankSpruce/gersemi@4b21bf5, which is below our current minimum of 0.21.

Motivation and Context

Sorting of these lists comes up every so often in PR reviews (see e.g. bd2024e or #12735 (comment)). Having it get sorted automatically (and enforced by CI) should make things easier.

In theory, this could be extended to other lists like target_link_libraries as well, but from what it looks like, those are usually sorted manually based on other criteria (internal OBS:: libraries first, etc)

How Has This Been Tested?

Ran the check (./build-aux/run-gersemi -c) and saw many badly formatted files. Ran the formatter (./build-aux/run-gersemi) and the files changed (to what is in this PR). Ran the check again and had no more badly formatted files.

Types of changes

  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Creates a gersemi extension that sorts the elements in target_sources
alphabetically (and also removes duplicates). This uses case-sensitive
sorting as [1] does.
The minimum version of gersemi for these extensions is 0.20 as per [2],
which is below our current minimum of 0.21.

[1]: bd2024e
[2]: BlankSpruce/gersemi@4b21bf5
@gxalpha gxalpha requested a review from PatTheMav December 5, 2025 23:19
@gxalpha gxalpha added the CI label Dec 5, 2025
local -a source_files=($@)
local file
local -a command=(${formatter} -c --no-cache ${source_files})
local -a command=(${formatter} -c --no-cache ${source_files} --extensions ./build-aux/gersemi-sort.py)
Copy link
Member

Choose a reason for hiding this comment

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

This breaks at least two fundamental aspects of the script:

  • The script can be run from any working directory and will pick up a sane selection of matching source files from it
  • The script can be run from any working directory with an explicit list of files

E.g. you can switch to plugins/aja and just run run-gersemi (run-clang, etc.) from there, and it will pick up all source files and format/check them. And you can also just run run-gersemi <some obs checkout>/plugins/aja/CMakeLists.txt and it will work.

That is by design. So you cannot use a relative path to resolve the extension and use a different path to introduce it to gersemi.

Copy link
Member

Choose a reason for hiding this comment

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

This should be packaged as a proper Python module, just like the example code.

# Exclude modified Flatpak files
# Exclude modified Flatpak and gersemi files
build-aux/flatpak-github-action-modified-*
build-aux/__pycache__
Copy link
Member

Choose a reason for hiding this comment

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

This seems unnecessary if we would package the extension as a proper PyPi package and install it into Homebrew's Python site-packages (as we probably should).

@gxalpha
Copy link
Member Author

gxalpha commented Jan 8, 2026

I'll close this until I can get the proper solution to work.

@gxalpha gxalpha closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants