SELinux Security Module development
 help / color / mirror / Atom feed
From: "Rahul Sandhu" <nvraxn@gmail.com>
To: "Stephen Smalley" <stephen.smalley.work@gmail.com>
Cc: <lautrbach@redhat.com>, <selinux@vger.kernel.org>
Subject: Re: [PATCH v3] treewide: add .clang-format configuration file
Date: Thu, 16 Oct 2025 23:05:55 +0100	[thread overview]
Message-ID: <DDK3662P8K9T.RXDV7DIQFPV1@gmail.com> (raw)
In-Reply-To: <CAEjxPJ5cMQb2DE37BnzrDQYars8eRfe4VSfN_4mwRQAhj2nW8w@mail.gmail.com>

On Tue Oct 7, 2025 at 2:21 PM BST, Stephen Smalley wrote:
> On Tue, Oct 7, 2025 at 6:47 AM Rahul Sandhu <nvraxn@gmail.com> wrote:
>>
>> Currently only an RFC.
>>
>> Add the .clang-format configuration file, taken from the Linux kernel
>> repository. We don't have any official style guidelines in tree at
>> present, which makes it a bit unclear how to format C code for new
>> contributors. As well as this, different parts of the codebase seem to
>> been formatted with different styles on occasion, so using an automatic
>> formatter should resolve this.
>>
>> As well as this, replace all the existing indent targets with format
>> targets. Commands used to find and replace those targets:
>>
>> git grep -l -E '(\.\./)*scripts/Lindent' | xargs sed -i -E 's@(\.\./)*scripts/Lindent@clang-format -i@g'
>> git grep -l 'indent' -- '*Makefile' | xargs sed -i 's/indent/format/g'
>>
>> Also add some empty format targets to Makefiles that previously were
>> missing an indent target so that `make format` does not error.
>>
>> A few other things to consider to do in the future:
>> 1. Reformat all existing code. I understand this is a big change, hence
>>    the RFC, but we may as well get all code formatted if we go down
>>    this route; afterall, it's not like this will cause any breaking
>>    changes.
>> 2. Possibly add a CI target to check that all code is formatted as per
>>    the new clang-format configuration? The options `--dry-run` as well
>>    as `-Werror` can be passed to clang-format for this.
>
> Yes please.

Should this be added in another patch? My concern is that CI will fail
should this be merged without formatting all code.

>
>>
>> Comments/feedback appreciated, thanks.
>>
>> Signed-off-by: Rahul Sandhu <nvraxn@gmail.com>
>> ---
>>
>> v2: remove linux kernel ForEachMacros and replace them with ours
>> v3: replace the indent target with the new format target. also remove any
>>     mention of `.editorconfig` from the commit message; those changes are
>>     better suited for another patch (they're small and self-contained enough
>>     that they're a smaller thing to merge).
>>
>>
>
>> diff --git a/mcstrans/Makefile b/mcstrans/Makefile
>> index b20279ab..28d8c7bc 100644
>> --- a/mcstrans/Makefile
>> +++ b/mcstrans/Makefile
>> @@ -21,4 +21,6 @@ clean:
>>
>>  relabel:
>>
>> +format:
>> +
>
> We should add targets for mcstrans/utils/*.c and mcstrans/src/*.[hc]

I wrote a simple check-format target in the Makefile:

# We shouldn't have any unformatted files in the repo without an explicit exception.
# Given that this is used with the `check-format` target, which does not modify any
# source files, merely checking if they're formatted properly, it's fine to rely on
# find to get all C source and header files.
CHECK_FORMAT_SOURCE_FILES := $(shell find $(SUBDIRS) -type f \( -name '*.c' -o -name '*.h' \))

check-format:
	clang-format --dry-run -Werror $(CHECK_FORMAT_SOURCE_FILES)

However, after running `make format` and `make check-format`, I noticed
a whole load of failures caused by a load of other missing targets. I'm
thinking that it may just be better off using that same find command to
get all c sources and headers, and have a single, global format target.
Afterall, in pushed code after we've formatted it all, I don't see any
reason that some code should be left unformatted (especially as we have
things such as the clang-format off comments for specific sub-sections
of code), and while working locally if someone wishes to format only a
specific globbed set of files, something like this should work fine:
clang-format -i src/*.c

Thoughts? Suggestions?

>
>> diff --git a/secilc/Makefile b/secilc/Makefile
>> index ef7bc8cd..2518933f 100644
>> --- a/secilc/Makefile
>> +++ b/secilc/Makefile
>> @@ -87,4 +87,6 @@ clean:
>>
>>  relabel:
>>
>> +format:
>> +
>
> Should add a target for secilc/*.c


  reply	other threads:[~2025-10-16 22:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-28 22:39 [RFC PATCH] treewide: add .clang-format configuration file Rahul Sandhu
2025-09-28 22:48 ` [RFC PATCH v2] " Rahul Sandhu
2025-10-06 16:52   ` Stephen Smalley
2025-10-07  6:35     ` Petr Lautrbach
2025-10-07 10:46       ` [PATCH v3] " Rahul Sandhu
2025-10-07 11:07         ` Rahul Sandhu
2025-10-07 13:24           ` Stephen Smalley
2025-10-07 13:21         ` Stephen Smalley
2025-10-16 22:05           ` Rahul Sandhu [this message]
2025-10-17 12:51             ` Stephen Smalley
2025-10-18  6:11               ` [RFC PATCH v4] " Rahul Sandhu
2025-10-20 13:23                 ` Stephen Smalley
2025-10-20 13:49                   ` Stephen Smalley
2025-10-20 14:07                     ` [PATCH v5] " Rahul Sandhu
2025-10-20 14:09                       ` [PATCH v6] " Rahul Sandhu
2025-10-20 14:55                         ` Stephen Smalley
2025-10-20 16:18                           ` When to apply `make format` to the entire tree Petr Lautrbach
2025-10-20 16:26                             ` Rahul Sandhu
2025-10-20 16:40                               ` Stephen Smalley
2025-10-21 13:49                           ` [PATCH v6] treewide: add .clang-format configuration file Stephen Smalley
2025-10-16 22:08           ` [PATCH v3] " Rahul Sandhu
2025-10-08 15:17     ` [RFC PATCH v2] " Kenton Groombridge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DDK3662P8K9T.RXDV7DIQFPV1@gmail.com \
    --to=nvraxn@gmail.com \
    --cc=lautrbach@redhat.com \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox