forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clang-format shell script (OSGeo#2732)
The clang-format shell script replaces the grass_indent.sh and grass_indent_ALL.sh scripts, which are both hereby removed.
- Loading branch information
Showing
3 changed files
with
74 additions
and
61 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/sh | ||
set -eu | ||
|
||
############################################################################### | ||
# Format source code according to GRASS GIS submitting rules | ||
# | ||
# Dependencies: | ||
# clang-format | ||
# (most easily available with e.g.: | ||
# `python -m pip install 'clang-format==15.0.6’`) | ||
# | ||
# Author(s): | ||
# Nicklas Larsson | ||
# | ||
# Usage: | ||
# If you have "clang-format" in PATH, execute for complete source formatting: | ||
# ./utils/grass_clang_format.sh | ||
# | ||
# Setting 'GRASS_CLANG_FORMAT' to explicitly set clang-format version: | ||
# GRASS_CLANG_FORMAT="clang-format-15" ./utils/grass_clang_format.sh | ||
# | ||
# It is also possible to format the content in a (one) given directory: | ||
# ./utils/grass_clang_format.sh ./lib/raster | ||
# | ||
# COPYRIGHT: (C) 2023 by the GRASS Development Team | ||
# | ||
# This program is free software under the GNU General Public | ||
# License (>=v2). Read the file COPYING that comes with GRASS | ||
# for details. | ||
# | ||
############################################################################### | ||
|
||
# Required clang-format version | ||
req_cf_v="15" | ||
|
||
# No need to continue if the .clang-format file isn't found | ||
if [ ! -f .clang-format ]; then | ||
echo "Error: could not find the .clang-format file. Is the GRASS source" | ||
echo " top directory your working directory?" | ||
exit 1 | ||
fi | ||
|
||
# If set, use env variable GRASS_CLANG_FORMAT for clang-format | ||
if [ -z ${GRASS_CLANG_FORMAT+x} ]; then | ||
fmt="clang-format" | ||
else | ||
fmt="${GRASS_CLANG_FORMAT}" | ||
fi | ||
|
||
if ! (${fmt} --version >/dev/null); then | ||
echo "clang-format not available." | ||
exit 1 | ||
fi | ||
|
||
clang_version_full=$(${fmt} --version) | ||
clang_version=$(echo "${clang_version_full}" | cut -f3 -d" " | cut -f1 -d".") | ||
if [ "${clang_version}" -lt "${req_cf_v}" ]; then | ||
echo "Error: ${clang_version_full}" | ||
echo " is used, but version ${req_cf_v} or newer is required." | ||
echo " Consider setting the global variable GRASS_CLANG_FORMAT to" | ||
echo " the clang-format version needed." | ||
exit 1 | ||
fi | ||
|
||
# One argument, a directory path is allowed | ||
if [ "$#" -eq 1 ] && [ -d "$1" ]; then | ||
dir="$1" | ||
else | ||
dir="." | ||
fi | ||
|
||
find "${dir}" -type f \ | ||
'(' -iname '*.c' -o -iname '*.cpp' -o -iname '*.h' -o -iname '*.hpp' ')' \ | ||
-exec "${fmt}" -i '{}' + |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.