-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cmake-format-all.sh script + friendlier xargs usage (#3470)
* Fix calling xargs on OSX * Fix cmake-format-all.sh script * Design ci/cmake-format-all.sh and ci/check-cmake-format.sh to be consistent with the clang ones
- Loading branch information
Showing
4 changed files
with
71 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
|
||
if ! command -v cmake-format &>/dev/null; then | ||
echo "pip install cmake-format and try again" | ||
set -e | ||
|
||
if [[ ! -z $(git status --untracked-files=no --porcelain) ]]; then | ||
echo "Unable to run script: working directory not clean (see git status)" | ||
exit 1 | ||
fi | ||
REPO_ROOT=$(git rev-parse --show-toplevel) | ||
cd "${REPO_ROOT}" | ||
find "${REPO_ROOT}" -iwholename "${REPO_ROOT}/nano/*/CMakeLists.txt" -o -iwholename "${REPO_ROOT}/CMakeLists.txt" -o -iwholename "${REPO_ROOT}/coverage/CMakeLists.txt" | xargs cmake-format --check &>.cmake_format_check | ||
if [[ $(wc -l .cmake_format_check | cut -f1 -d ' ') != 0 ]]; then | ||
echo | ||
echo "Code formatting differs from expected - please run \n\t'bash ci/cmake-format-all.sh'" | ||
RET=1 | ||
|
||
source "$(dirname "$BASH_SOURCE")/common.sh" | ||
|
||
"$REPO_ROOT/ci/cmake-format-all.sh" | ||
|
||
if [[ ! -z $(git status --untracked-files=no --porcelain) ]]; then | ||
echo "CMake formatting differs from expected - please run ci/cmake-format-all.sh" | ||
git diff | ||
git reset --hard HEAD > /dev/null | ||
exit 1 | ||
fi | ||
rm -fr .cmake_format_check | ||
exit ${RET-0} | ||
|
||
echo "cmake-format passed" | ||
exit 0 |
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
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,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
is_cmake_format_usable() | ||
{ | ||
if [[ $(builtin type -p $1) ]]; then | ||
local output=$($1 --version) | ||
if [[ $output =~ ^(.)*$2(.)*$ ]]; then | ||
echo "0" | ||
else | ||
echo $output | ||
fi | ||
else | ||
echo "1" | ||
fi | ||
} | ||
|
||
CMAKE_FORMAT="" | ||
CMAKE_FORMAT_VERSION="0.6.13" | ||
|
||
cmake_format_attempts=("cmake-format") | ||
|
||
for itr in ${cmake_format_attempts[@]}; do | ||
result=$(is_cmake_format_usable $itr $CMAKE_FORMAT_VERSION) | ||
if [[ $result == "0" ]]; then | ||
CMAKE_FORMAT=$itr | ||
break | ||
elif [[ $result == "1" ]]; then | ||
continue | ||
else | ||
echo "Detected '$itr' with version '$result' " \ | ||
"(different than '$CMAKE_FORMAT_VERSION'), skipping it." | ||
fi | ||
done | ||
|
||
if [[ -z $CMAKE_FORMAT ]]; then | ||
echo "No 'cmake-format' of version '$CMAKE_FORMAT_VERSION' could be detected in your PATH." \ | ||
"Try pip/pip3 install cmake-format. Or try up/down-grading if you installed it differently." | ||
exit 1 | ||
fi | ||
|
||
echo "Using '$CMAKE_FORMAT' version '$CMAKE_FORMAT_VERSION'" |