mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
7b8f675bfd
- Change formatting standard to Cpp11. Main difference is not having the space between two closing >> for nested templates. We don't choose c++14, because older versions of clang-format (version 9 and earlier) don't know this value yet, and it doesn't make a difference in the formatting. - Apply clang-format to all (non generated) internal source files. - Manually fix some code sections (clang-format on/off) and c-strings - Exclude some embedded external files with very different formatting (gtest/gmock) - Add script to format all source files Change-Id: Ic6cea41575ad6e37c9e136dbce176b0d505dc44d
54 lines
1.4 KiB
Bash
Executable File
54 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Format all source files in the project.
|
|
#
|
|
# Set CLANG_FORMAT_CMD environment variable to specify executable used (default: `clang-format`).
|
|
|
|
set -e
|
|
|
|
################################################################################
|
|
# Configuration
|
|
|
|
# folders to search
|
|
FOLDERS="
|
|
include
|
|
internal
|
|
examples
|
|
"
|
|
|
|
# paths to ignore
|
|
EXCLUDE_PATHS="
|
|
internal/ceres/gtest/*
|
|
internal/ceres/gmock/*
|
|
internal/ceres/gmock_gtest_all.cc
|
|
internal/ceres/gmock_main.cc
|
|
internal/ceres/generated/*
|
|
internal/ceres/generated_bundle_adjustment_tests/*
|
|
internal/ceres/schur_eliminator.cc
|
|
internal/ceres/partitioned_matrix_view.cc
|
|
internal/ceres/schur_templates.cc
|
|
"
|
|
|
|
################################################################################
|
|
# Implementation
|
|
|
|
# directory of this script and the repository root
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
REPO_DIR="$SCRIPT_DIR/.."
|
|
|
|
# set default for CLANG_FORMAT_CMD
|
|
CLANG_FORMAT_CMD=${CLANG_FORMAT_CMD:-clang-format}
|
|
echo "Formatting with $CLANG_FORMAT_CMD (`$CLANG_FORMAT_CMD --version`)"
|
|
|
|
# prepare arguments to exclude ignored paths
|
|
EXCLUDE_ARGS=""
|
|
for p in $EXCLUDE_PATHS; do
|
|
EXCLUDE_ARGS="-not -path */$p $EXCLUDE_ARGS"
|
|
done
|
|
|
|
# for each folder, format header and source dirs
|
|
for d in $FOLDERS; do
|
|
d="$REPO_DIR/$d"
|
|
find "$d" \( -name "*.h" -or -name "*.cc" \) $EXCLUDE_ARGS | xargs $CLANG_FORMAT_CMD -verbose -i
|
|
done
|