Skip to content

Conversation

@gnawme
Copy link
Contributor

@gnawme gnawme commented Jul 7, 2020

Initial modernization of code base using clang-tidy and an innocuous subset of its modernize checks:

  • modernize-avoid-bind
  • modernize-avoid-c-arrays
  • modernize-concat-nested-namespaces
  • modernize-deprecated-headers
  • modernize-deprecated-ios-base-aliases
  • modernize-loop-convert
  • modernize-make-shared
  • modernize-make-unique
  • modernize-pass-by-value
  • modernize-raw-string-literal
  • modernize-redundant-void-arg
  • modernize-replace-auto-ptr
  • modernize-replace-random-shuffle
  • modernize-return-braced-init-list
  • modernize-shrink-to-fit
  • modernize-unary-static-assert
  • modernize-use-auto
  • modernize-use-bool-literals
  • modernize-use-default-member-init
  • modernize-use-emplace
  • modernize-use-equals-default
  • modernize-use-equals-delete
  • modernize-use-nodiscard
  • modernize-use-noexcept
  • modernize-use-nullptr
  • modernize-use-override
  • modernize-use-trailing-return-type
  • modernize-use-transparent-functors
  • modernize-use-uncaught-exceptions
  • modernize-use-using

@kunaltyagi
Copy link
Member

Could I request you to help integrate clang-tidy in the CI before adding the improvements to prevent a backslide later on?

@gnawme
Copy link
Contributor Author

gnawme commented Jul 7, 2020

Could I request you to help integrate clang-tidy in the CI before adding the improvements to prevent a backslide later on?

@kunaltyagi If there's a way to run clang-tidy as a last-stage check before merging, sure.

As something to run with each CI build, however, it makes CI much longer without adding much value. Policy at places I've worked is for the developer to run clang-tidy when they're getting close to being ready to merge.

@kunaltyagi
Copy link
Member

Does it take long to run clang-tidy? (How long did it take to run on PCL?)

@gnawme
Copy link
Contributor Author

gnawme commented Jul 7, 2020

Does it take long to run clang-tidy? (How long did it take to run on PCL?)

Try this:

  • Add set(CMAKE_EXPORT_COMPILE_COMMANDS ON) to CMakeLists.txt
  • Run cmake .
  • Make sure compile_commands.json is present.
  • Assuming you have clang-tidy installed, run (for example) run-clang-tidy -header-filter='.*' -checks=".*modernize-use-nullptr" -fix

@kunaltyagi
Copy link
Member

clang-tidy on my system takes 20 minutes, with a full compile (including cuda modules) requiring 45 minutes.

@PointCloudLibrary/maintainers What about trying GitHub actions for this?

@kunaltyagi kunaltyagi added the needs: feedback Specify why not closed/merged yet label Jul 7, 2020
@SergioRAgostinho
Copy link
Member

No opposition from my side.

@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from 2593283 to a042b05 Compare July 8, 2020 19:14
@kunaltyagi
Copy link
Member

@gnawme Could you please add a clang-tidy action to this PR on the lines of the format CI:

  • clone in a docker
  • run clang-format
  • diff to see if there's a regression
  • show diff else pass

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions

@gnawme
Copy link
Contributor Author

gnawme commented Jul 9, 2020

@gnawme Could you please add a clang-tidy action to this PR on the lines of the format CI:

  • clone in a docker
  • run clang-format
  • diff to see if there's a regression
  • show diff else pass

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions

@kunaltyagi Add this sequence to formatting.yaml? OK, I'll take a look.

@gnawme
Copy link
Contributor Author

gnawme commented Jul 9, 2020

@gnawme Could you please add a clang-tidy action to this PR on the lines of the format CI:

  • clone in a docker
  • run clang-format
  • diff to see if there's a regression
  • show diff else pass

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions

@kunaltyagi Add this sequence to formatting.yaml? OK, I'll take a look.

This will be in .ci/azure-pipelines/tidying.yaml; how do I test this?

jobs:
  - job: tidying
    displayName: Modernize C++
    pool:
      vmImage: 'ubuntu-latest'
    container: tdy
    steps:
      - checkout: self
        # find the commit hash on a quick non-forced update too
        fetchDepth: 10
      - script: run-clang-tidy -header-filter='.*' -checks='-*,modernize-deprecated-headers,modernize-redundant-void-arg,modernize-replace-random-shuffle,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nullptr,modernize-use-override,modernize-use-using' -fix
        displayName: 'Run clang-tidy'
      - script: git diff > formatting.patch
        displayName: 'Compute diff'
      - script: cat formatting.patch
        displayName: 'Show diff'
      - task: CopyFiles@2
        inputs:
          sourceFolder: '$(Build.SourcesDirectory)'
          contents: 'formatting.patch'
          targetFolder: '$(Build.ArtifactStagingDirectory)'
        displayName: 'Copy diff to staging directory'
      - task: PublishBuildArtifacts@1
        inputs:
          pathtoPublish: '$(Build.ArtifactStagingDirectory)'
          artifactName: formatting
        displayName: 'Publish diff'
      - script: "[ ! -s formatting.patch ]"
        displayName: 'Set job exit status'

@kunaltyagi
Copy link
Member

how do I test this?

I don't know. Does the file needs to be in master for this? @shrijitsingh99

@shrijitsingh99
Copy link
Contributor

shrijitsingh99 commented Jul 9, 2020

how do I test this?

Just setup Github Actions on your fork. That should work. Nothing to be done on PCL side to test.

Could I request you to help integrate clang-tidy in the CI before adding the improvements to prevent a backslide later on?

I would also recommend looking into #4004. The idea was to first integrate it into CMake or provide some tooling for running clang-tidy then integrate it. As I remember the blocker was CMake version since newer versions had tidy support.

Without providing tooling for contributors to run clang-tidy easily, adding a check to CI won't be that useful IMO.

@gnawme
Copy link
Contributor Author

gnawme commented Jul 9, 2020

I would also recommend looking into #4004. The idea was to first integrate it into CMake or provide some tooling for running clang-tidy then integrate it. As I remember the blocker was CMake version since newer versions had tidy support.

Older CMake versions are also blocking the transition to C++17 or later, since they don't recognize CMAKE_CXX_STANDARD 17. Are there plans to remedy that going forward?

Without providing tooling for contributors to run clang-tidy easily, adding a check to CI won't be that useful IMO.

Yes, clang-tidy was left as a developer task at places I worked that used clang-tidy. (There was a bash script in the repo's .ci directory that wasn't actually run by CI.)

@kunaltyagi I recommend that this initial modernization be a one-time task, to be revisited periodically. Backsliding will just have to be caught by reviewers.

@gnawme gnawme marked this pull request as ready for review July 9, 2020 21:26
@shrijitsingh99
Copy link
Contributor

Are there plans to remedy that going forward?

Have opened an issue #4004, we can continue the discussion there.

Yes, clang-tidy was left as a developer task at places I worked that used clang-tidy. (There was a bash script in the repo's .ci directory that wasn't actually run by CI.)

Yeah, for now at least we can also provide a bash script. Maybe using the commands you are currently running for clang-tidy.

@gnawme
Copy link
Contributor Author

gnawme commented Jul 12, 2020

@kunaltyagi once these changes are approved, I think the affected files could use a clang-format pass.

@kunaltyagi
Copy link
Member

I think the affected files could use a clang-format pass.

We've been rolling out clang-format bit by bit (since the patch can be monstrous as well has mess up the comments and some code). Which module do you think should be prioritised? PR by modifying the whitelist in .dev and running format 2 times would suffice though it might not get reviewed soon (GSoC pressure)

@gnawme
Copy link
Contributor Author

gnawme commented Jul 12, 2020

I think the affected files could use a clang-format pass.

We've been rolling out clang-format bit by bit (since the patch can be monstrous as well has mess up the comments and some code). Which module do you think should be prioritised? PR by modifying the whitelist in .dev and running format 2 times would suffice though it might not get reviewed soon (GSoC pressure)

These are the directories where the clang-tidy changes occurred in 1b90309b9:

  • common (2307)
  • features (6323)
  • filters (3102)
  • geometry (142)
  • io (11764)
  • kdtree (595)
  • keypoints (4043)
  • ml (5558)
  • octree (2316)
  • outofcore (2838)
  • people (871)
  • recognition (11812)
  • registration (8697)
  • sample_consensus (4882)
  • search (1320)
  • segmentation (7727)
  • stereo (1937)
  • surface (7418)
  • tools (789)
  • tracking (150)
  • visualization (6600)

Which will give most bang for the buck if they had clang-format run on them?

@kunaltyagi
Copy link
Member

Lines of code affected in each module would be a better indicator. You can get per directory stats (in alphabetical order) using:

ls -d ./* | xargs -n1 bash -c 'git diff --numstat master -- $@ | python -c "import fileinput as f; print(sum([int(line.strip()[0]) for line in f.input()]))"' {}

The largest one should be the priority

@SergioRAgostinho
Copy link
Member

SergioRAgostinho commented Jul 12, 2020

I would say following dependency graph should be top priority. The changes you make in the "base modules" are more likely to affect more parts of the code.

Edit: Here's the dep graph, for reference. Ignore the colors
pcl_dep_graph

@gnawme
Copy link
Contributor Author

gnawme commented Jul 12, 2020

I would say following dependency graph should be top priority. The changes you make in the "base modules" are more likely to affect more parts of the code.

@SergioRAgostinho Wow, your graph is a lot cleaner and simpler than the one produced by cmake --graphviz=graph. What did you use to produce it?

@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch 2 times, most recently from ff1dee6 to 3bc3aa5 Compare July 14, 2020 00:55
@gnawme
Copy link
Contributor Author

gnawme commented Jul 14, 2020

@kunaltyagi @SergioRAgostinho I ran clang-format on common, kdtree, and octree, net 1281 LOC changed (including clang-tidy changes). Shall I run clang-format on another module or two?

@SergioRAgostinho
Copy link
Member

I would say following dependency graph should be top priority. The changes you make in the "base modules" are more likely to affect more parts of the code.

@SergioRAgostinho Wow, your graph is a lot cleaner and simpler than the one produced by cmake --graphviz=graph. What did you use to produce it?

I didn't, @divmadan did :)

@kunaltyagi @SergioRAgostinho I ran clang-format on common, kdtree, and octree, net 1281 LOC changed (including clang-tidy changes). Shall I run clang-format on another module or two?

My preferred approach is to submit a PR per tool per module e.g. pass cmake tidy over common open PR, once merged enable cmake format for common, continue for other modules. We just had a PR of equivalent magnitude in LoC changes, a "simple find replace", and it was a nightmare to review.

@SergioRAgostinho
Copy link
Member

Split the PR.

@SergioRAgostinho SergioRAgostinho removed their request for review July 20, 2020 15:25
@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from d92d818 to c3194d4 Compare July 20, 2020 15:41
@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from c3194d4 to 245dc1d Compare July 20, 2020 21:06
@gnawme
Copy link
Contributor Author

gnawme commented Jul 20, 2020

Split the PR.

OK, opened #4283 to deal with empty destructors, reverted this PR to focus on the clang-tidy changes.

@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from f1c6bd8 to 251a484 Compare July 21, 2020 00:51
@gnawme gnawme requested a review from SergioRAgostinho July 21, 2020 17:21
Comment on lines 3 to 6
#include <stdlib.h> // NOLINT
#include <stdio.h> // NOLINT
#include <math.h> // NOLINT
#include <string.h> // NOLINT
Copy link
Member

Choose a reason for hiding this comment

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

I think there's a header-filter regex

@kunaltyagi kunaltyagi removed the needs: feedback Specify why not closed/merged yet label Jul 22, 2020
@kunaltyagi kunaltyagi added this to the pcl-1.12.0 milestone Jul 23, 2020
@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from 32c9514 to 085e65f Compare July 23, 2020 17:07
@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from 085e65f to 5d25b3c Compare August 5, 2020 01:56
@kunaltyagi kunaltyagi self-requested a review August 5, 2020 07:34
@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from 5d25b3c to 754e3fa Compare August 21, 2020 21:30
@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from 754e3fa to c449866 Compare September 1, 2020 19:57
@stale
Copy link

stale bot commented Oct 4, 2020

Marking this as stale due to 30 days of inactivity. Commenting or adding a new commit to the pull request will revert this.

@stale stale bot added the status: stale label Oct 4, 2020
Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Fixed clang-format violations

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Reverted to C++14 for older versions of CMake

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Test enabling C++17 when CMAKE_CXX_STANDARD 17 is not supported [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Test full(?) C++17 enable to see which CI builds fail [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Reverted to C++14, since CI dies with C++17

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added tags to exclude from clang-tidy [PL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Created initial clang-tidy GitHub action [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Created initial GitHub Action for clang-tidy [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Revised GitHub action, revised destructors per code review [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Reverted miscommunication [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Modernized code with clang-tidy [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Fixed clang-format violations

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Reverted to C++14 for older versions of CMake

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Test enabling C++17 when CMAKE_CXX_STANDARD 17 is not supported [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Test full(?) C++17 enable to see which CI builds fail [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Reverted to C++14, since CI dies with C++17

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added tags to exclude from clang-tidy [PL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Created initial clang-tidy GitHub action [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Created initial GitHub Action for clang-tidy [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Revised GitHub action, revised destructors per code review [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Reverted miscommunication [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Deleted empty virtual destructors [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Deleted another empty virtual destructor [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Made suggested changes to clang-tidy Action [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Restored clang-tidy bash script [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Fixed permissions on clang-tidy runner [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Modified Action to install clang-tidy [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added sudo, switched to use apt-get in Action [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Changed to run 'cmake .' to generate compile_commands.json [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Test adding compile_commands.json to repo [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Modified to install all clang tools [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Modified to install clang-10

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added explicit clang-tidy version [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Revised clang installer packages [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Revised to install minimal Boost and Eigen [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added VTK installation [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added full Boost install package [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Removed clang-tidy checks to .clang-format [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Made changes from code review [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Removed --line-filter [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Restored checks, since .clang-tidy is not being honored [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Changed to run clang-tidy check in a container [PCL-2731]

Co-authored-by: Shrijit Singh <shrijitsingh99@gmail.com>
Removed unnecessary installation commands since containerized [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Restored clang-tidy, clang-tools installation [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added -y to installation command [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added pyyaml installation [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added python-pip installation [PCL-2731]
Added git to installation [PCL-2731]
Added explicit branch checkout to Action
Inspected and revised destructors marked "empty" [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Added Ensenso to conform to Docker, split PR [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Qualified override to make Mojave build happy [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Found magic order for run-clang-tidy -config command [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Switched to installing latest clang tools [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Removed additional clang installs [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Specified clang-tools-10 explicitly [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Explicitly specify run-clang-tidy script [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>

Implemented exclusion filter, fixed file end [PCL-2731]

Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>
@gnawme gnawme force-pushed the norm.evangelista/PCL-2731-modernize-with-clang-tidy branch from c449866 to 16b956e Compare December 27, 2020 20:02
@stale stale bot removed the status: stale label Dec 27, 2020
Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>
Signed-off-by: Norm Evangelista <norm.evangelista@gmail.com>
@gnawme
Copy link
Contributor Author

gnawme commented Dec 28, 2020

Replaced by #4560, which is taking a phased approach to applying clang-tidy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: ABI break Meta-information for changelog generation needs: more work Specify why not closed/merged yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants