Commit 41155cc7 authored by George Nash's avatar George Nash Committed by Kishen Maloor

Add clang-format tool to the CI build

This adds the clang-format tool to the CI build. This enables
catching formating errors on from contributers that have not
installed the pre-commit hook.

This change was integrated into the same build as the doxygen
build script.  This was done to reduce the number of CI build
pipelines needed to pass the build.

Copyright block added to the build_doc.sh script. The scripts
also print out some blocks of text to indicate there run status
making it easer to instantly see the results of the build
output.

The new script added to the .gitignore if it is found in the
top of the project  incase users want to use it localy on
their own computers. Similar to the reason the _clang-format
file is in the ignore file.
Signed-off-by: George Nash's avatarGeorge Nash <george.nash@intel.com>
parent 03943d6a
Pipeline #416 passed with stage
in 7 minutes and 17 seconds
......@@ -72,6 +72,7 @@ port/openthread/output
*.gcno
.clang-format
_clang-format
whitespace_commit_checker.sh
port/linux/platformtest
port/linux/storage_test
port/linux/apitest
......
......@@ -68,10 +68,15 @@ Android_build:
- cd port/android
- make DYNAMIC=1 TCP=1 IPV4=1 SECURE=1 PKI=1 CLOUD=1 JAVA=1 DEBUG=0
run_doxygen:
whitespace_and_doxygen:
stage: build
before_script:
- apt update && apt -y install make autoconf doxygen
- apt update && apt -y install make autoconf doxygen clang-format
script:
- clang-format --version
- doxygen --version
- cp tools/_clang-format _clang-format
- cp tools/whitespace_commit_checker.sh whitespace_commit_checker.sh
- ./whitespace_commit_checker.sh
- cd tools
- ./build_doc.sh
#! /bin/bash
# Copyright (c) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
echo "***********************************************************************"
echo "RUNNING Doxygen code documentation tool"
echo "***********************************************************************"
echo "doxygen doxygen.ini"
if doxygen doxygen.ini ;
then
[ ! -s Doxygen.log ]
if [ $? -eq 0 ]
then
echo "***********************************************************************"
echo "API documentation looks good!"
echo "***********************************************************************"
exit 0
else
cat Doxygen.log
echo "***********************************************************************"
echo "ERRORS found in the API documentation."
echo "***********************************************************************"
exit 1
fi
else
......
#! /bin/bash
# Copyright (c) 2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# function to check for C/C++ file based on suffix
function isC() {
if [[ ($1 == *.c) || ($1 == *.C) || ($1 == *.cc) ]]; then
return 0
elif [[ ($1 == *.cpp) || ($1 == *.cxx) || ($1 == *.c++) || ($1 == *.CPP) ]]; then
return 0
elif [[ ($1 == *.h) || ($1 == *.hpp) ]]; then
return 0
fi
return 1
}
# trap will increment the 'failures' variable each time a one of the commands
# from this script returns failure. The diff command should return failure
# every time the output from clang-format is different than the input file.
failures=0
trap 'failures=$((failures+1))' ERR
echo "***********************************************************************"
echo "RUNNING clang-format tool against committed code"
echo "***********************************************************************"
filelist=`git diff --name-only HEAD HEAD~1`
for f in $filelist; do
if isC $f; then
echo "Running clang-format on ${f}"
echo ""
# the '-' at the end of the diff will cause the diff command to use the
# output from clang-format as part of the diff input.
clang-format -style=file ${f} | diff -u --color=auto ${f} -
fi
done
if (( failures == 0)); then
echo "***********************************************************************"
echo "GOOD formating."
echo "***********************************************************************"
exit 0;
else
# A list of files that actually had white space issues was not kept this will
# just print all of the C/C++ files. Even if the user runs a command on a file
# that does not need to be change it will leave the file unchanged.
echo "***********************************************************************"
echo "Found $failures file(s) with BAD formating!"
echo ""
echo "Please update the files formating."
echo ""
echo "This can be done automatically by running the following commands from"
echo "the top directory of iotivity-lite project"
echo ""
echo " cp tools/_clang-format _clang-format"
for f in $filelist; do
if isC $f; then
echo " clang-format -style=file -i ${f}"
fi
done
echo ""
echo "The format tool can be added to git's pre-commit hook using the"
echo "following command"
echo ""
echo " cp tools/_clang-format _clang-format"
echo " cp tools/pre-commit .git/hooks/pre-commit"
echo ""
echo "Reference the tools/README file for more information about setting up"
echo "and using the clang-format tool for formatting contributed code."
echo "***********************************************************************"
exit 1
fi
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment