Skip to content

Commit

Permalink
New CI job: clang-tidy (#389)
Browse files Browse the repository at this point in the history
* clang-tidy CI job

* Updated the path to Brew installations

* Pick the right Xcode version

* Docs: Updated the Xcode version and the Homebrew path
  • Loading branch information
mikekazakov authored Sep 20, 2024
1 parent 256ead1 commit dbdf1fd
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 23 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
matrix:
configuration: ["Debug", "Release", "ASAN", "UBSAN"]
steps:
- name: Select latest Xcode
- name: Select the Xcode version
run: "sudo xcode-select -s /Applications/Xcode_$XC_VERSION.app"
- uses: actions/checkout@v4
- name: Build and run unit tests
Expand All @@ -34,9 +34,9 @@ jobs:
integration-tests:
runs-on: macos-14
steps:
- name: Select latest Xcode
- name: Select the Xcode version
run: "sudo xcode-select -s /Applications/Xcode_$XC_VERSION.app"
- name: Install deps
- name: Install the dependencies
run: |
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
sudo rm -rf /Library/Frameworks/Python.framework/
Expand All @@ -63,7 +63,7 @@ jobs:
clang-format:
runs-on: macos-14
steps:
- name: Install deps
- name: Install the dependencies
run: |
brew update
brew install clang-format
Expand All @@ -72,12 +72,26 @@ jobs:
run: "cd Scripts && ./run_clang_format.sh --check"


clang-tidy:
runs-on: macos-14
steps:
- name: Select the Xcode version
run: "sudo xcode-select -s /Applications/Xcode_$XC_VERSION.app"
- name: Install the dependencies
run: |
brew update
brew install llvm jq
- uses: actions/checkout@v4
- name: Run clang-tidy
run: "cd Scripts && ./run_clang_tidy.sh --check"


build-unsigned:
runs-on: macos-14
steps:
- name: Select latest Xcode
- name: Select the Xcode version
run: "sudo xcode-select -s /Applications/Xcode_$XC_VERSION.app"
- name: Install deps
- name: Install the dependencies
run: |
brew install create-dmg pandoc basictex
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Docs/Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To minimize internet bandwidth, you can opt to fetch only the latest version wit
`git clone https://github.com/mikekazakov/nimble-commander --depth=1`

## Compiling the Project
After obtaining the source code, you'll need Xcode 15.4 to open and compile the project. Navigate to the `NimbleCommander.xcodeproj` folder within the source code and open it using either the Xcode GUI or the command line with:
After obtaining the source code, you'll need Xcode 16.0 to open and compile the project. Navigate to the `NimbleCommander.xcodeproj` folder within the source code and open it using either the Xcode GUI or the command line with:
`open nimble-commander/Source/NimbleCommander/NimbleCommander.xcodeproj`

![](schema.png)
Expand Down
6 changes: 3 additions & 3 deletions Scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ Rules from `Source/.clang-format` are used in the process.
## `run_clang_tidy.sh`
Executes `clang-tidy` against all source files in the `Source` directory, updating them in-place if necessary.
`xcodebuild`, `xcpretty` and `jq` must be available in the environment in order for this script to run.
`clang-tidy` must be installed via Brew and is expected to be located at `/usr/local/opt/llvm/bin/`.
`clang-tidy` must be installed via Brew and is expected to be located at `/opt/homebrew/opt/llvm/bin/`.
Rules from `Source/.clang-tidy` are used in the process.
It's recommended to execute `run_clang_format.sh` afterwards.

## Dependencies installation:
* xcodebuild:
* XCode: https://download.developer.apple.com/Developer_Tools/Xcode_15.1/Xcode_15.1.xip
* Or just build tools: https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_15.1/Command_Line_Tools_for_Xcode_15.1.dmg
* XCode: https://download.developer.apple.com/Developer_Tools/Xcode_16/Xcode_16.xip
* Or just build tools: https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_16/Command_Line_Tools_for_Xcode_16.dmg
* [xcpretty](https://github.com/xcpretty/xcpretty): `gem install xcpretty`
* [clang-format](https://clang.llvm.org/docs/ClangFormat.html): `brew install clang-format`
* [clang-tidy](https://clang.llvm.org/extra/clang-tidy/): `brew install llvm`
Expand Down
59 changes: 46 additions & 13 deletions Scripts/run_clang_tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if ! [ -x "$(command -v xcpretty)" ] ; then
exit -1
fi

if ! [ -x "$(command -v /usr/local/opt/llvm/bin/clang-tidy)" ] ; then
if ! [ -x "$(command -v /opt/homebrew/opt/llvm/bin/clang-tidy)" ] ; then
echo 'clang-tidy is not found, aborting. Do brew install llvm.'
exit -1
fi
Expand All @@ -22,14 +22,21 @@ fi
export LC_CTYPE=en_US.UTF-8

# Tools from LLVM
RUNTIDY=/usr/local/opt/llvm/bin/run-clang-tidy
TIDY=/usr/local/opt/llvm/bin/clang-tidy
APPLY=/usr/local/opt/llvm/bin/clang-apply-replacements
RUNTIDY=/opt/homebrew/opt/llvm/bin/run-clang-tidy
TIDY=/opt/homebrew/opt/llvm/bin/clang-tidy
APPLY=/opt/homebrew/opt/llvm/bin/clang-apply-replacements

# Get current directory
SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT_DIR=$(cd "$SCRIPTS_DIR/.." && pwd)

# Check if --check flag is provided
check_mode=0
if [ "$1" = "--check" ]; then
echo "Dry run - only checking the clang-tidy rules"
check_mode=1
fi

# Allocate a dir for build artifacts
BUILD_DIR="${SCRIPTS_DIR}/run_clang_tidy.tmp"
mkdir -p "${BUILD_DIR}"
Expand Down Expand Up @@ -78,13 +85,39 @@ for target in ${targets[@]}; do
rm "compile_commands-${target}.json"
done

# Log file to capture the output of run-clang-tidy
LOG_FILE="${BUILD_DIR}/run-clang-tidy.log"

# Run clang-tidy in parallel via run-clang-tidy
${RUNTIDY} \
-p ${SCRIPTS_DIR} \
-clang-tidy-binary ${TIDY} \
-clang-apply-replacements-binary ${APPLY} \
-j $(sysctl -n hw.activecpu) \
-use-color 1 \
-fix \
-format \
"${ROOT_DIR}/Source/.*"
if [ $check_mode -eq 1 ]; then
echo "Running in check mode. No fixes will be applied."
${RUNTIDY} \
-p ${SCRIPTS_DIR} \
-clang-tidy-binary ${TIDY} \
-clang-apply-replacements-binary ${APPLY} \
-j $(sysctl -n hw.activecpu) \
-use-color 1 \
"${ROOT_DIR}/Source/.*" 2>&1 | tee ${LOG_FILE}
else
echo "Running in fix mode. Fixes will be applied."
${RUNTIDY} \
-p ${SCRIPTS_DIR} \
-clang-tidy-binary ${TIDY} \
-clang-apply-replacements-binary ${APPLY} \
-j $(sysctl -n hw.activecpu) \
-use-color 1 \
-fix \
-format \
"${ROOT_DIR}/Source/.*" 2>&1 | tee ${LOG_FILE}
fi

# Exit with non-zero if in check mode and any issues were found
if [ $check_mode -eq 1 ]; then
if grep -q "warning:" ${LOG_FILE} || grep -q "error:" ${LOG_FILE}; then
echo "Clang-tidy check failed. Please run Scripts/run_clang_tidy.sh before submitting your code."
exit 1
else
echo "Clang-tidy check passed."
exit 0
fi
fi

0 comments on commit dbdf1fd

Please sign in to comment.