Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-format] always use a line per constructor initialiser for longer lines #16962

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

phunkyfish
Copy link
Contributor

Description

Ensures for longer lines that this occurs:

MyClass::CMyClass(bool bBoolArg,
                  int iIntegerArg,
                  const std::string& strSomeText,
                  const std::shared_ptr<CMyOtherClass>& myOtherClass)
  : m_bBoolArg(bBoolArg),
    m_iIntegerArg(iIntegerArg),
    m_strSomeText(strSomeText),
    m_myOtherClass(myOtherClass)
{
}

But never this:

MyClass::CMyClass(bool bBoolArg,
                  int iIntegerArg,
                  const std::string& strSomeText,
                  const std::shared_ptr<CMyOtherClass>& myOtherClass)
  : m_bBoolArg(bBoolArg), m_iIntegerArg(iIntegerArg), m_strSomeText(strSomeText)
{
}

I.e. if a constructor lines is longer than .clang-format column limit then there will always be one initialiser per line.

This change does not effect constructor lines short than the .clang-format column limit.

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

Copy link
Member

@Paxxi Paxxi left a comment

Choose a reason for hiding this comment

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

I'm a bit worried that using such a new option could lead to a lot of churn on constructor formatting depending on the version of clang-format.
Either we accept that and go ahead or we don't use it. If someone has submitted a clang-formatted PR we should never request formatting changes because they used the wrong clang-format version imo.

@ksooo
Copy link
Member

ksooo commented Nov 25, 2019

If someone has submitted a clang-formatted PR we should never request formatting changes because they used the wrong clang-format version imo.

Why not? We also require them to use other tools with at least a certain version. I don't see a difference to minimal required SDK version, for example.

@Paxxi
Copy link
Member

Paxxi commented Nov 25, 2019

Linux distros are slow to add newer versions so it could make it a hassle to install the correct version. Is v9 available in any version of Ubuntu right now?

One of the main values with clang-format imo is that it lowers the bar to contribute. If you use the tool your PR should pass formatting guidelines.

Copy link
Member

@Rechi Rechi left a comment

Choose a reason for hiding this comment

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

  • The documentation mentioning clang-format has to be updated that at least version 9 is required.
  • The server running git-clang-format for the whole PR and per commit during a PR build has to be updated.

@Paxxi
Copy link
Member

Paxxi commented Nov 25, 2019

Looking at https://packages.ubuntu.com/search?suite=default&section=all&arch=any&keywords=clang-format&searchon=names it appears that clang-format 9 isn't available in Ubuntu yet. If that's correct it's not feasible to require that they install or have it installed already unless we provide it in our apt repo.

@fritsch
Copy link
Member

fritsch commented Nov 25, 2019

@Paxxi
Copy link
Member

Paxxi commented Nov 25, 2019

Oh, I read the (devel) as it not being released yet, sorry about that 😄

@fritsch
Copy link
Member

fritsch commented Nov 25, 2019

You are right never the less. Many are on 18.04 LTS and will stay there until 20.04

@phunkyfish
Copy link
Contributor Author

phunkyfish commented Nov 25, 2019

If you run clang-format using the above .clang-format but are using clang-format 8 does it give an error or ignore the option?

I.e. can anyone using clang-format 8 check this?

@phunkyfish
Copy link
Contributor Author

As 20.04 is out soon maybe this can be revisited soon.

@phunkyfish phunkyfish added the PR Cleanup: Merge Candidate Candidate for merging after PR cleanup label Mar 9, 2020
@phunkyfish
Copy link
Contributor Author

Ubuntu should be ok now:

Package clang-format-9
bionic (18.04LTS) (devel): Tool to format C/C++/Obj-C code [universe]
1:9-2~ubuntu18.04.2 [security]: amd64 i386
bionic-updates (devel): Tool to format C/C++/Obj-C code [universe]
1:9-2~ubuntu18.04.2: amd64 arm64 armhf i386 ppc64el s390x
eoan (19.10) (devel): Tool to format C/C++/Obj-C code [universe]
1:9-2: amd64 arm64 armhf i386 ppc64el s390x
focal (devel): Tool to format C/C++/Obj-C code [universe]
1:9.0.1-12: amd64 arm64 armhf i386 ppc64el s390x

@Rechi where and how would I update this on this on the server running git-clang-format for PRs?

@Rechi
Copy link
Member

Rechi commented Apr 19, 2020

You are missing Ubuntu Xenial and also the correct package for checking versions is clang-format instead of clang-format-.

@phunkyfish
Copy link
Contributor Author

You are missing Ubuntu Xenial and also the correct package for checking versions is clang-format instead of clang-format-.

Ok, then maybe this waits for kodi 20. I don't follow the mention of clang-format-. Did I miss something?

@DaveTBlake
Copy link
Member

This seems to have got forgotten, and clearly isn't happening in v19 code, so bump to v20 and @phunkyfish please pursue it for that.

@DaveTBlake DaveTBlake added this to the N* 20.0 Alpha 1 milestone Feb 7, 2021
@phunkyfish
Copy link
Contributor Author

Will do. Thanks @DaveTBlake

@jenkins4kodi jenkins4kodi added the Rebase needed PR that does not apply/merge cleanly to current base branch label Oct 4, 2022
@phunkyfish phunkyfish force-pushed the clang-format-init branch 2 times, most recently from f5a2f8d to 8ce846c Compare October 4, 2022 21:32
@phunkyfish phunkyfish force-pushed the clang-format-init branch 2 times, most recently from 05d98d4 to be7fb43 Compare October 4, 2022 21:43
@jenkins4kodi jenkins4kodi removed the Rebase needed PR that does not apply/merge cleanly to current base branch label Oct 4, 2022
@phunkyfish
Copy link
Contributor Author

Jenkins build this please

Comment on lines 11 to 23
execute_process(COMMAND clang-format --version ERROR_QUIET OUTPUT_VARIABLE CLANG_FORMAT_VERSION_OUTPUT)
string(REGEX MATCH "([0-9]+)\\..*" CLANG_FORMAT_VERSION ${CLANG_FORMAT_VERSION_OUTPUT})
if(CLANG_FORMAT_VERSION VERSION_LESS_EQUAL "9.0.0")
message(WARNING "clang-format must be at least version 9.0 and the version installed is ${CLANG_FORMAT_VERSION}")
set(CLANG_FORMAT_FOUND OFF)
endif()

Copy link
Contributor

Choose a reason for hiding this comment

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

Can i suggest the following

#.rst:
# FindClangFormat
# ----------
# Finds clang-format

find_program(CLANG_FORMAT_EXECUTABLE clang-format)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ClangFormat REQUIRED_VARS CLANG_FORMAT_EXECUTABLE)

if(CLANGFORMAT_FOUND)

  set(CLANGFORMAT_MINVERSION "9.0")

  execute_process(COMMAND clang-format --version ERROR_QUIET OUTPUT_VARIABLE CLANG_FORMAT_VERSION_OUTPUT)
  string(REGEX MATCH "([0-9]+)\\..*" CLANG_FORMAT_VERSION ${CLANG_FORMAT_VERSION_OUTPUT})
  if(CLANG_FORMAT_VERSION VERSION_LESS_EQUAL ${CLANGFORMAT_MINVERSION})
    message(WARNING "clang-format must be at least version ${CLANGFORMAT_MINVERSION}. The version found is ${CLANG_FORMAT_VERSION}")
    set(CLANGFORMAT_FOUND OFF CACHE BOOL "" FORCE)
    set(CLANG_FORMAT_EXECUTABLE "CLANG_FORMAT_EXECUTABLE-NOTFOUND" CACHE STRING "" FORCE)
  endif()
endif()

mark_as_advanced(CLANG_FORMAT_EXECUTABLE)

We only do the version check if clang-format is found. We extract the version number to s single variable (for if/when it needs to be updated).
It also sets the cache variable for CLANGFORMAT_FOUND and CLANG_FORMAT_EXECUTABLE to false/notfound

Copy link
Member

@Rechi Rechi left a comment

Choose a reason for hiding this comment

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

Version hacking in the find module is wrong.
Use the correct CMake way for checking versions.

@fuzzard
Copy link
Contributor

fuzzard commented Oct 7, 2022

I dont really understand what you're asking for here @Rechi

find_program calls do not have any understanding of versioning, and do not make version info available.
Clang-format doesnt provide *ConfigVersion.cmake files to retrieve any version info, there is no pkg-config data provided either.

What exactly is the "Correct Cmake way" for this?

@Rechi
Copy link
Member

Rechi commented Oct 16, 2022

Read the documentation of find_package and FindPackageHandleStandardArgs and how those two commands interact. There is no need to touch the find module.

There is also one dependency of Kodi with a minimum version requirement, where it is done correct.

@phunkyfish
Copy link
Contributor Author

Which dependency?

@fuzzard fuzzard removed this from the Omega 21.0 Alpha 2 milestone May 10, 2023
@fuzzard fuzzard removed the v21 Omega label May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement non-breaking change which improves existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet