Skip to content

Commit

Permalink
.github: add iwyu workflow
Browse files Browse the repository at this point in the history
iwyu is short for "include what you use". this workflow is added to
identify missing "#include" and extraneous "#include" in C++ source
files.

This workflow is triggered when a pull request is created targetting
the "master" branch. It uses the clang-include-cleaner tool provided
by clang-tools package to analyze all the ".cc" and ".hh" source files.

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov committed Apr 22, 2024
1 parent 4279483 commit c296c89
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/iwyu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: iwyu

on:
push:
branches:
- master
pull_request:
branches:
- master

env:
CLANG_VERSION: 19
BUILD_TYPE: RelWithDebInfo
BUILD_DIR: build
CLEANER_OUTPUT_PATH: build/clang-include-cleaner.log

permissions: {}

jobs:
clang-include-cleaner:
name: "Analyze #includes in source files"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Add scylla-ppa repo
env:
scylla_ppa_key: 6B2BFD3660EF3F5B
# "add-apt-repository ppa:scylladb/ppa" does not work, as jammy is not built in this ppa repo,
# so, let's use xenial instead. it is the latest version provided by ppa:scylladb/ppa
run: |
gpg_home=$(mktemp -d)
gpg --homedir $gpg_home --no-default-keyring --keyring ppa.key --keyserver keyserver.ubuntu.com --recv-key $scylla_ppa_key
sudo gpg --homedir $gpg_home --keyring ppa.key --export --output /etc/apt/trusted.gpg.d/ubuntu-scylladb-ppa.gpg $scylla_ppa_key
echo "deb http://ppa.launchpadcontent.net/scylladb/ppa/ubuntu xenial main" | sudo tee -a /etc/apt/sources.list.d/scylla-ppa.list
- name: Install clang-tools
run: |
sudo apt-get install -y curl
curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc >/dev/null
echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" | sudo tee -a /etc/apt/sources.list.d/llvm.list
sudo apt-get update
sudo apt-get install -y clang-tools-$CLANG_VERSION
- name: Install more build dependencies
run: |
# - do not install java dependencies, which is not only not necessary,
# and they include "python", which is not EOL and not available.
# - replace "scylla-libthrift010" with "libthrift-dev". because
# scylla-libthrift010 : Depends: libssl1.0.0 (>= 1.0.1) but it is not installable
# - we don't perform tests, so minio is not necessary.
sed -i.orig \
-e '/tools\/.*\/install-dependencies.sh/d' \
-e 's/scylla-libthrift010-dev/libthrift-dev/' \
-e 's/(minio_download_jobs)/(true)/' \
./install-dependencies.sh
sudo ./install-dependencies.sh
mv ./install-dependencies.sh{.orig,}
- name: Generate compilation database
run: |
cmake \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-G Ninja \
-B $BUILD_DIR \
-S .
- name: clang-include-cleaner
run: |
# TODO: run multi-threaded
find $PWD -name "*.cc" -o -name ".hh" | \
xargs -t -n 1 \
clang-include-cleaner-$CLANG_VERSION --print=changes -p $BUILD_DIR > $CLEANER_OUTPUT_PATH 2>&1
- uses: actions/upload-artifact@v4
with:
name: Logs (clang-include-cleaner)
path: "./${{ env.CLEANER_OUTPUT_PATH }}"

0 comments on commit c296c89

Please sign in to comment.