toggle quoted messageShow quoted text
I could not figure out how to download uncrustify tool from the provided link. 99% of the people are just going to want to install the tool, not be a developer of the fork. We should have some simple instructions on how to download the tool.
The link points to something git web view looking Azure DevOps page and talks about this Nuget thing I know nothing about. I ran out of time and had to give up trying to download the tool.
Good information in this thread on code style.
Some of the topics apply to uncrustify and some are out of scope for what uncrustify can fix on its own.
I would like to focus on a date to convert all source code in edk2 repo using the uncrustify tool and to capture the other code style topics into their own thread andbugzillas.
I would like to propose a conversion date for uncrustify immediately after the edk2-stable202111 release on 2021-11-26.
I have been working with Michael Kubacki on a build comparison tool that verifies that the build generate the same obj/lib/dll/efi/fv/fd files before and after the uncrustify changes. We would run and publish the results from this tool before committing the changes.
We need TianoCore community approval of the following:
- Approve format of C source generated by the uncrustify.
- Approve uncrustify changes right after edk2-stable-202111 release.
- Extend code freeze until these changes are committed.
- Require use of uncrustify tool before submitting patch review emails or PRs.
- The required version would be a formally released version from the fork maintained by Michael Kubacki until the changes can be upstreamed.
- Add EDK II CI check to verify that all PRs submitted exactly match uncrustified version. Reject PRs that do not match exactly.
- Implement a git hook available that would automatically run uncristufy before committing changes to a local branch of an edk2 repo.
On Oct 7, 2021, at 1:43 PM, Marvin Häuser <mhaeuser@...> wrote:
I'll just reply to both mails at once :)
On 07/10/2021 19:36, Andrew Fish wrote:
On Oct 7, 2021, at 1:19 PM, Michael D Kinney <michael.d.kinney@...> wrote:
Some comments below.
From:firstname.lastname@example.org<email@example.com> On Behalf Of Marvin Häuser
Sent: Thursday, October 7, 2021 11:31 AM
To: Leif Lindholm <leif@...>;firstname.lastname@example.org;mikuback@...
Cc:rebecca@...; Michael Kubacki <Michael.Kubacki@...>; Bret Barkelew <Bret.Barkelew@...>;
Kinney, Michael D <michael.d.kinney@...>
Subject: Re: [edk2-devel] Progress on getting Uncrustify working for EDK2?
+1, but while you're at it, can we have arguments not align to the
Status = Test (
... but to the next natural indentation level?
Status = Test (
Basically no IDE I have seen supports EDK II's style, and I wouldn't be
keen on writing known-broken style to then rely on Uncrustify to fix it.
I also have heard some controversy regarding casts off-list, where some
prefer no spaces after casts to stress the evaluation order, and some
prefer spaces to have clearer visuals (as a cast *ideally* would be
something rare that requires good justification). Just throwing that out
For things unrelated to autoformat (so semi-offtopic) but still relevant
to the coding spec:
1. Allow STATIC functions (if the debugging concerns are still relevant,
there could be another level of indirection, like RELEASE_STATIC)?
Thanks! I'd keep STATIC actually just for the sake of not doing no-op changes that do not really do anything and for consistency with CONST, but whatever works really.
2. Allow variable assignments on definition (basically non-static CONST
variables are banned...)?
Are referring to use of pre-initialized CONST variables declared within
a function? I think Bret brought this topic up when implementing some
unit tests and the suggestion to pass ECCC was to promote them to
pre-initialized CONST global variables.
The challenges we have seen in the past with pre-initialized variables within
a function is that they can cause compilers to inject use of memcpy() calls,
especially if the variable being initialized on the stack is a structure.
These cause build breaks today.
This issue is independent of CONST. I’m not sure a coding style tool is smart enough to catch this generically? You need an understanding of C types to know if the local variable assignment is going to trigger a memcpy().
What I’ve seen in the real world is the firmware compiles with -Os or LTO to fit int he ROM for DEBUG and RELEASE, and the optimizer optimizes away the call to memcpy. Then if you try to build NOOPT (or over ride the compiler flags on an individual driver/lib) you fail to link as only the NOOPT build injects the memcpy.
Thus I think the best way to enforce this rule is to compile a project NOOPT. I’m trying to remember are there flags to built to tell it to compile and skip the FD construction? Maybe we should advocate platforms add a NOOPT build target that just compiles the code, but does not create the FD?
I know there were stability concerns with intrinsics in the past, but memcpy() is in the standard, and the rest remained stable to my knowledge. Maybe it's time to fix the issues at the root? Works for us:
Good point. This would make the rule moot. So maybe just removing the requirement would be the easiest long term fix.
Other embedded projects I know of do this too, and as you point out the compilers keep these APIs standard for folks the provide their own runtimes.
3. Allow variable declarations at any scope (I had some nasty shadowing
bugs before, probably prohibit shadowing with warnings)?
By shadowing do you mean the declaration of the same variable name in
multiple scoped within the same function?
4. Require that exactly all function declarations and all function
definitions with no prior declaration must be documented (first
direction is enforcing docs, second is prohibiting doc duplication, I've
seen them go out-of-sync plenty of times)?
I agree that this can reduce duplication and sync issues. The uncrustify
tool being discussed here could not help clean this up or enforce this
type of rule. It is a good topic, but may need to be split out into its
The latter bunch would not require any autoformat rules or reformatation
of existing code, but would be target only new submissions in my
Thanks for your efforts!
Am 07.10.2021 um 12:48 schrieb Leif Lindholm:
Apologies, I've owed you a response (promised off-list) for a while
First, let me say I hugely appreciate this effort. Apart from aligning
the codebase(s), this will reduce manual reviewing effort
substantially, as well as cutting down on number of rework cycles for
Looking at the changes to (well, the comments in) uncrustify, this
seems to be constrained to:
- Newline after '(' for multi-line function calls.
- Dealing with "(("/"))" for DEBUG macros.
- Function pointer typedefs:
- closing parentheses indentation
I don't think I've made any secret over the years that I am not a
massive fan of the EDK2 coding style in general. So I think for any
of its quirks that are substantial enough that they require not just
custom configuration but actual new function added to existing code
conformance tools, this would be an excellent point to sanitise the
coding style instead.
Taking these in order:
Newline after '('
I think we already reached a level of flexibility around this, where
we don't actually enforce this (or single argument per
line). Personally, I'd be happy to update the coding style as
DEBUG macro parentheses
How does uncrustify treat DEBUG macros without this modification?
Do we start getting everything turned into multi-level indented
multi-line statements without this change?
Function pointer typedefs:
I don't see that function pointer typedefs need to rigidly follow the
same pattern as the declaration of functions implementing them. Could
we update the coding style (if needed) instead?
On Mon, Aug 16, 2021 at 16:00:38 -0400, Michael Kubacki wrote:
That said, I have also finished a CI plugin to run Uncrustify that should be
ready soon to initially deploy in Project Mu. Before doing so, I am trying
to settle on an initial configuration file that less strictly but more
reliably formats the code than in the examples in those branches. For
example, remove heuristics that when run against the same set of code
multiple times can produce different results. An example would be a rule
that reformats code because it exceeds a specified column width on one run
but on the next run that reformatted code triggers a different rule to
further align the code and so on. At least initially, some rules might be
tweaked in a more conservative approach that can be tightened in the future.
Once this configuration file is ready, we will baseline Project Mu code as
an example and turn on the plugin. The CI plugin runs Uncrustify against
modified files and if there's any changes, indicating a formatting
deviation, the diff chunks are saved in a log so they can be viewed as a
I am making progress on the updated config file and I should be able to post
a "uncrustify_poc_3" branch soon with the results.
Regarding indentation, Marvin is right that Uncrustify cannot support edk2
indentation style out-of-box. Some changes are made in that fork to handle
the formatting. At this point, it can handle the indentation in the cases
I've seen. Uncrustify does potentially give us the ability to massively
deploy changes across the codebase in case a decision were made to change
On 8/16/2021 3:39 PM, Marvin Häuser wrote:
I think even Uncrustify has issues with the EDK II indentation style.
You might want to check the UEFI Talkbox Discord server, I had a brief
chat with Michael about it there. I don't think realistically any tool
supports EDK II's indentation style however, so I'd propose it is
changed. This could be for new submissions only, or actually the entire
codebase could be reformatted at once with a good tool setup. While this
screws with git blame, the (to my understanding) decided on CRLF -> LF
change does that anyway, so at least two evils could be dealt with in
one go really.
On 16/08/2021 21:34, Rebecca Cran wrote:
cc devel@ .
On 8/16/21 1:33 PM, Rebecca Cran wrote:
I noticed a message on Twitter about an idea of using Uncrustify
for EDK2 instead of the ECC tool, and came across https://www.mail-
I was wondering if there's been any progress on it that I could
Michael Kubacki: in that message, you said:
"I'm planning to put up a branch that we can use as a reference
for a conversation around uncrustify in the next couple of
Did you end up creating that branch, and if so could you provide
a link to it please?