-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from espressif/refactor/add_clang_tidy
CI: Add Clang tidy
- Loading branch information
Showing
7 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import argparse | ||
import copy | ||
import json | ||
import typing | ||
|
||
|
||
def process(in_file: typing.TextIO, out_file: typing.TextIO, include_prefix_list: typing.List[str]) -> None: | ||
in_json = json.load(in_file) | ||
if len(in_json['runs']) != 1: | ||
raise NotImplementedError('Only 1 run is supported') | ||
in_results = in_json['runs'][0]['results'] | ||
out_results = [] | ||
for result in in_results: | ||
locations = result['locations'] | ||
if len(locations) != 1: | ||
raise NotImplementedError('Only 1 location is supported') | ||
artifact_location = locations[0]['physicalLocation']['artifactLocation'] | ||
uri = artifact_location['uri'] | ||
new_uri = None | ||
for include_prefix in include_prefix_list: | ||
if uri.startswith(include_prefix): | ||
new_uri = uri.replace(include_prefix, '') | ||
break | ||
if not new_uri: | ||
continue | ||
new_result = copy.deepcopy(result) | ||
new_result['locations'][0]['physicalLocation']['artifactLocation']['uri'] = new_uri | ||
out_results.append(new_result) | ||
|
||
out_json = copy.deepcopy(in_json) | ||
out_json['runs'][0]['results'] = out_results | ||
json.dump(out_json, out_file, indent=True) | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-o', '--output', type=argparse.FileType('w'), help='Output filtered SARIF file') | ||
parser.add_argument('--include-prefix', required=True, action='append', | ||
help='File prefix for source code to include in analysis') | ||
parser.add_argument('input_file', type=argparse.FileType('r'), help='Input SARIF file') | ||
args = parser.parse_args() | ||
process(args.input_file, args.output, args.include_prefix) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Run clang-tidy | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
name: Run clang-tidy | ||
runs-on: ubuntu-20.04 | ||
container: espressif/idf:latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
- name: Install libtinfo (esp-clang dependency) | ||
run: | | ||
export DEBIAN_FRONTEND=noninteractive | ||
apt update && apt-get install -y libtinfo5 | ||
- name: Install esp-clang | ||
run: | | ||
${IDF_PATH}/tools/idf_tools.py --non-interactive install esp-clang | ||
- name: Install clang-tidy-sarif | ||
run: | | ||
curl -sSL https://github.com/psastras/sarif-rs/releases/download/clang-tidy-sarif-v0.3.3/clang-tidy-sarif-x86_64-unknown-linux-gnu -o clang-tidy-sarif | ||
chmod +x clang-tidy-sarif | ||
- name: Install pyclang | ||
run: | | ||
. ${IDF_PATH}/export.sh | ||
pip install pyclang~=0.2.0 | ||
- name: Run code analysis | ||
shell: bash | ||
env: | ||
IDF_TOOLCHAIN: clang | ||
IDF_TARGET: esp32s3 | ||
working-directory: clang_tidy | ||
run: | | ||
. ${IDF_PATH}/export.sh | ||
idf.py reconfigure | ||
idf.py clang-check --include-paths $GITHUB_WORKSPACE --exclude-paths $PWD --run-clang-tidy-py run-clang-tidy | ||
cp warnings.txt ../ | ||
- name: Convert clang-tidy results into SARIF output | ||
run: | | ||
export PATH=$PWD:$PATH | ||
./clang-tidy-sarif -o results.sarif.raw warnings.txt | ||
python3 $GITHUB_WORKSPACE/.github/filter_sarif.py -o results.sarif --include-prefix ${GITHUB_WORKSPACE}/ results.sarif.raw | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
path: | | ||
warnings.txt | ||
results.sarif | ||
results.sarif.raw | ||
- name: Upload SARIF file | ||
uses: github/codeql-action/upload-sarif@v2 | ||
with: | ||
sarif_file: results.sarif | ||
category: clang-tidy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ dependencies.lock | |
**/managed_components/** | ||
.vscode/ | ||
doxygen/ | ||
warnings.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.5) | ||
include($ENV{IDF_PATH}/tools/cmake/version.cmake) | ||
|
||
# Specify components that will be checked with Clang tidy | ||
set(EXTRA_COMPONENT_DIRS | ||
../device/esp_tinyusb | ||
../host/class/cdc/esp_modem_usb_dte | ||
../host/class/cdc/usb_host_cdc_acm | ||
../host/class/cdc/usb_host_ch34x_vcp | ||
../host/class/cdc/usb_host_cp210x_vcp | ||
../host/class/cdc/usb_host_ftdi_vcp | ||
../host/class/cdc/usb_host_vcp | ||
../host/class/hid/usb_host_hid | ||
../host/class/msc/usb_host_msc | ||
../host/class/uvc/usb_host_uvc | ||
) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(clang_check) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ESP-USB Clang tidy | ||
|
||
This folder aims to store source files for Clang tidy CI job, which is run for this repository in the GitHub CI. |