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

feat(lint): Add files for clang tidy and license check #37

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-License-Identifier: Apache-2.0
---
Checks: "*, \
-abseil-*, \
-cert-env33-c, \
-cert-err58-cpp, \
-clang-diagnostic-padded, \
-clang-analyzer-deadcode.DeadStores, \
-cppcoreguidelines-avoid-magic-numbers, \
-cppcoreguidelines-pro-bounds-constant-array-index, \
-cppcoreguidelines-pro-bounds-pointer-arithmetic, \
-cppcoreguidelines-pro-type-reinterpret-cast, \
-cppcoreguidelines-no-malloc, \
-cppcoreguidelines-owning-memory, \
-cppcoreguidelines-macro-usage, \
-cppcoreguidelines-pro-type-vararg, \
-cppcoreguidelines-pro-bounds-array-to-pointer-decay, \
-fuchsia-overloaded-operator, \
-fuchsia-default-arguments, \
-fuchsia-multiple-inheritance, \
-fuchsia-default-arguments-calls, \
-fuchsia-trailing-return, \
-fuchsia-default-arguments-declarations, \
-fuchsia-statically-constructed-objects, \
-google-runtime-references, \
-google-runtime-int, \
-google-explicit-constructor, \
-hicpp-no-malloc, \
-hicpp-vararg, \
-hicpp-invalid-access-moved, \
-hicpp-no-array-decay, \
-hicpp-signed-bitwise, \
-llvm-header-guard, \
-modernize-use-trailing-return-type, \
-misc-definitions-in-headers, \
-misc-unused-alias-decls, \
-modernize-concat-nested-namespaces, \
-modernize-raw-string-literal, \
-readability-magic-numbers"
HeaderFilterRegex: ""
...
13 changes: 13 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
header:
license:
spdx-id: Apache-2.0
copyright-owner: Apache Software Foundation

paths-ignore:
- 'dist'
- 'licenses'
- '**/*.md'
- 'LICENSE'
- 'NOTICE'

comment: on-failure
58 changes: 58 additions & 0 deletions scripts/run-clang-tidy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python
# SPDX-License-Identifier: Apache-2.0

# Run clang-tidy recursively and parallel on directory
# Usage: run-clang-tidy sourcedir builddir excludedirs extensions
# extensions and excludedirs are specified as comma-separated
# string without dot, e.g. 'c,cpp'
# e.g. run-clang-tidy . build test,other c,cpp file

import os, sys, subprocess, multiprocessing
manager = multiprocessing.Manager()
failedfiles = manager.list()

# Get absolute current path and remove trailing seperators
currentdir = os.path.realpath(os.getcwd()).rstrip(os.sep)
print("Arguments: " + str(sys.argv))
# Get absolute source dir after removing leading and trailing seperators from input.
sourcedir = currentdir + sys.argv[1].lstrip(os.sep).rstrip(os.sep)
print("Source directory: " + sourcedir)
builddir = sourcedir + os.sep + sys.argv[2].rstrip(os.sep)
print("Build directory: " + builddir)
# Split exclude dirs into a tuple
excludedirs = tuple([(sourcedir + os.sep + s).rstrip(os.sep) for s in sys.argv[3].split(',')])
# If the build directory is not the same as the source directory, exclude it
if not sourcedir == builddir:
excludedirs = excludedirs + (builddir,)
print("Exclude directories: " + str(excludedirs))
# Split extensions into a tuple
extensions = tuple([("." + s) for s in sys.argv[4].split(',')])
print("Extensions: " + str(extensions))

def runclangtidy(filepath):
print("Checking: " + filepath)
proc = subprocess.Popen("clang-tidy --quiet -p=" + builddir + " " + filepath, shell=True)
if proc.wait() != 0:
failedfiles.append(filepath)

def collectfiles(dir, exclude, exts):
collectedfiles = []
for root, dirs, files in os.walk(dir):
for file in files:
filepath = root + os.sep + file
if (len(exclude) == 0 or not filepath.startswith(exclude)) and filepath.endswith(exts):
collectedfiles.append(filepath)
return collectedfiles

# Define the pool AFTER the global variables and subprocess function because multiprocessing
# has stricter requirements on member ordering
# See: https://stackoverflow.com/questions/41385708/multiprocessing-example-giving-attributeerror
pool = multiprocessing.Pool()
pool.map(runclangtidy, collectfiles(sourcedir, excludedirs, extensions))
pool.close()
pool.join()
if len(failedfiles) > 0:
print("Errors in " + len(failedfiles) + " files")
sys.exit(1)
print("No errors found")
sys.exit(0)
1 change: 1 addition & 0 deletions scripts/setup-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ sudo --preserve-env apt install -y \
ccache \
ninja-build \
checkinstall \
clang-tidy \
git \
wget \
libprotobuf-dev \
Expand Down