Skip to content

Commit

Permalink
Add GitHub action for IWYU
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhashiniNaik committed Dec 24, 2024
1 parent ec25295 commit 5e33071
Show file tree
Hide file tree
Showing 4 changed files with 647 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .github/problem-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "iwyu-matcher",
"pattern": [
{
"regexp": "^(.*):(\\d+):(\\d+):\\s*(.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
}
]
}
42 changes: 37 additions & 5 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,49 @@ jobs:
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.22.x'


- name: Install GCC 11.4.0 and GCOV
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update
sudo apt-get install -y gcc-11=11.4.0-1ubuntu1~22.04 g++-11=11.4.0-1ubuntu1~22.04
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-11 100
- name: Install LCOV 1.14
run: |
wget https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz
tar -xvzf lcov-1.14.tar.gz
cd lcov-1.14
sudo make install
# - name: Install GCC 11 and GCOV from PPA
# run: |
# sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
# sudo apt-get update
# sudo apt-get install -y gcc-11 g++-11

# - name: Install LCOV from GitHub
# run: |
# wget https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz
# tar -xvzf lcov-1.14.tar.gz
# cd lcov-1.14
# sudo make install

- name: Test
# Execute tests defined by the CMake configuration.
run: |
cmake -B cmake-build-unit-tests -S executables/unitTest -DBUILD_UNIT_TESTS=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
cmake --build cmake-build-unit-tests -j4
ctest --test-dir cmake-build-unit-tests -j4
- name: Install lcov
run: sudo apt install lcov

- name: Log tool versions
run: |
gcc --version
gcov --version
lcov --version
# no-external command excludes the system libraries in the root directory
- name: Capture code coverage
run: |
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: IWYU Analysis

on: [push, pull_request, workflow_dispatch]


jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.22.x'

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install python dependencies
run: |
python -m pip install --upgrade pip
- name: Install iwyu
run: |
sudo apt-get update
sudo apt-get install -y iwyu
- name: Register problem matcher
run: echo "::add-matcher::./.github/problem-matcher.json"

- name: Export CXXFLAGS

#Since Clang 17 is installed in usr/bin, it will search for built-ins in /usr/lib/clang/17/include.
#The purpose of this step is to help the clang toolchain used by IWYU to locate the correct system
#header directories.

run: |
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON executables/referenceApp
export CXXFLAGS="-isystem /usr/lib/llvm-17/lib/clang/17/include/"
echo "done exporting"
python3 iwyu_tool.py -p compile_commands.json 2>&1 > iwyu_output.txt | tee iwyu_output.txt
echo "Output in iwyu_output.txt"
- name: Print IWYU output
run: cat iwyu_output.txt

- name: Unregister problem matcher
if: always()
run: echo "::remove-matcher owner=iwyu-matcher::"

- name: Upload IWYU output
uses: actions/upload-artifact@v4
with:
name: iwyu_output
path: iwyu_output.txt
Loading

0 comments on commit 5e33071

Please sign in to comment.