Skip to content
Snippets Groups Projects

Add uncrustify script

Merged Simon Praetorius requested to merge feature/uncrustify into main
2 unresolved threads

This is an alternative to !3 (closed)

Merge request reports

Pipeline #70838 passed

Pipeline passed for 53c1e501 on feature/uncrustify

Merged by Simon PraetoriusSimon Praetorius 10 months ago (May 19, 2024 10:18am UTC)

Loading

Pipeline #70839 passed

Pipeline passed for 94e059b6 on main

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
113 117 Concepts::BindableToElement<LA, typename TestLocalView::Element> &&
114 118 Concepts::BindableToLocalViews<LA, TestLocalView, TrialLocalView> &&
115 119 Concepts::BindableToOutsideLocalViews<LA, TestLocalView, TrialLocalView> &&
116 requires(LA la, typename TestLocalView::GridView::Intersection is, Archetypes::Matrix (&localMatrix)[2][2], Archetypes::LocalPattern (&localPattern)[2][2])
120 requires(LA la, typename TestLocalView::GridView::Intersection is, Archetypes::Matrix localMatrix[2][2], Archetypes::LocalPattern localPattern[2][2])
    • See !11 (comment 137215) for an example where different uncrustify versions lead to a problem. The incompatibility revealed there:

      Foo (...)
        : Foo (...) // Mind the space before (...) introduced by new uncrustify
      {}

      which is removed by newer versions

      Foo (...)
        : Foo(...) // No extra space here in old uncrustify
      {}
      Edited by Carsten Gräser
    • Oh, this is problematic. Even if we would remove the CI check, still if someone touches the file with a different uncrustify version as it was saved before, it would change the formatting. If uncrustify is included in the editor, it is hard to enforce a violation of the rules.

      What we could do is to enforce a specific uncrustify version. That must be the same as in the gitlab ci. Then there would be no change.

      Or we remove the CI check and just document the formatting rules. But this will probably lead to inconsistent formatting soon.

    • Are we sure that this is not "simply" a bug in uncrustify? Then the recommendation would be to use a version of uncrustify that is "new enough".

      IMO the whole automatic formatting thing doesn't make much sense without the CI check.

    • As written in the other MR (or in Matrix), in each uncrustify version the formatting (and the options database) changes. In the example above, I would say we want the "newer version", because function calls should not have a space between function name and brackets, but function declaration should. (By the current configuration)

      Edited by Simon Praetorius
    • Note that we have currently uncrustify 0.72 installed in our docker images. This is the "old" version.

    • We could fix the uncrustify version to use and update the docker image (or install a newer version in another base image, e.g. the ubuntu 24.04). I don't know whether there is a flag or special comment to ensure that the right uncrustify version is used with the provided options file.

    • I'm sorry, the versions have been mixed up in my comment. It's the new version, that adds the space.

    • I will try to adapt the options file. I have just removed/renamed any unknown option in the version-specific cfg files. Maybe there is a new option added that works similar to the old version. Also, there is an --update-config flat in uncrustify. Maybe the brings an existing cfg file to the new version? I have to try this out

    • We may update the container used by the CI, but then people will have the same problem when they use an older version locally. The simplest solution is to use a version compatible to what most people use. Currently the CI uses Debian 11 (oldstable). I just tried Debian 12 (stable). This gives the same result.

      It would be nice if all of you try make fix-format. If it does not modify anything (in particular if it does not add the space before ( in : Assembler(...)) for all of you, we can stick with the current version. Personally I now know how to easily switch the used version and am happy to use whatever works for the majority.

    • > uncrustify --version
      Uncrustify-0.78.1_f
      diff --git a/dune/assembler/defaultglobalassembler.hh b/dune/assembler/defaultglobalassembler.hh
      index 8ba28f1..47cf739 100644
      --- a/dune/assembler/defaultglobalassembler.hh
      +++ b/dune/assembler/defaultglobalassembler.hh
      @@ -48,7 +48,7 @@ public:
         {}
       
         Assembler (const RowBasis& rowBasis) requires std::same_as<RowBasis, ColBasis>
      -    : Assembler(rowBasis, rowBasis)
      +    : Assembler (rowBasis, rowBasis)
         {}
       
         // ....
    • I don't think this incompatibility issue will be as big a problem in practice as it may sound here. Possibly a problem, yes, but not a big one.

      IMO the uncrustify version used by CI is the official one that defines the "correct" formatting. If people use a different version locally then they may have to fix formatting differences manually. The git diff run by CI tells them exactly what needs fixing. In a given MR, formatting differences can only occur in files touched by that MR (i.e., few) [0]

      [0] unless, of course, if you run make fix-formatting on the entire repo. That you cannot do, but in my experience that's an inconvenience but not a serious problem.

    • IMO the uncrustify version used by CI is the official one that defines the "correct" formatting. If people use a different version locally then they may have to fix formatting differences manually.

      I agree, that we should declare this the official version. However, adjusting the code manually seems to be tedious compared to make fix-format, but for me using an older version of uncrustify is fine.

    • @christi With this version you will also run into trouble. Would either manual reformatting or using uncrustify via a container be an option for you?

    • It is also very easy to compile uncrustify yourself, the git repo has release tags and this is what I am using (in combination with debians update-alternatives tool for managing symbolic links

    • Please register or sign in to reply
  • In order to make sure that everyone uses the correct uncrustify version, we could

    1. make a cmake version check.
    2. only use the uncrustify-0.72.cfg config file and not the one without a version number.
    3. Add a comment in the top of the file that this cfg files is for uncrustify version 0.72 only.
  • Please register or sign in to reply
    Loading