Skip to content

Commit

Permalink
Merge pull request #93 from k-okada/clang
Browse files Browse the repository at this point in the history
support catkin_lint and clang-format tests in travis.yml
  • Loading branch information
k-okada authored Apr 22, 2019
2 parents 8874d17 + 66980a2 commit 69ee207
Show file tree
Hide file tree
Showing 36 changed files with 3,276 additions and 2,664 deletions.
66 changes: 66 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
BasedOnStyle: Google
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 2
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: true
BinPackParameters: true
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerBinding: false
PointerBindsToType: true
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 60
PenaltyBreakString: 100
PenaltyBreakFirstLessLess: 1000
PenaltyExcessCharacter: 1000
PenaltyReturnTypeOnItsOwnLine: 70
SpacesBeforeTrailingComments: 2
Cpp11BracedListStyle: false
Standard: Auto
IndentWidth: 2
TabWidth: 2
UseTab: Never
IndentFunctionDeclarationAfterType: false
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
SortIncludes: false
SpaceAfterCStyleCast: false

# Configure each individual brace in BraceWrapping
BreakBeforeBraces: Custom

# Control of individual brace wrapping cases
BraceWrapping: {
AfterClass: 'true'
AfterControlStatement: 'true'
AfterEnum : 'true'
AfterFunction : 'true'
AfterNamespace : 'true'
AfterStruct : 'true'
AfterUnion : 'true'
BeforeCatch : 'true'
BeforeElse : 'true'
IndentBraces : 'false'
}
...
50 changes: 50 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
Checks: '-*,
performance-*,
llvm-namespace-comment,
modernize-redundant-void-arg,
modernize-use-nullptr,
modernize-use-default,
modernize-use-override,
modernize-loop-convert,
readability-named-parameter,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-simplify-boolean-expr,
readability-container-size-empty,
readability-identifier-naming,
'
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
CheckOptions:
- key: llvm-namespace-comment.ShortNamespaceLines
value: '10'
- key: llvm-namespace-comment.SpacesBeforeComments
value: '2'
- key: readability-braces-around-statements.ShortStatementLines
value: '2'
# type names
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.UnionCase
value: CamelCase
# method names
- key: readability-identifier-naming.MethodCase
value: camelBack
# variable names
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.ClassMemberSuffix
value: '_'
# const static or global variables are UPPER_CASE
- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.StaticConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.ClassConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.GlobalVariableCase
value: UPPER_CASE
...
172 changes: 119 additions & 53 deletions .travis.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,131 @@ function travis_time_end {
set -x
}

function setup {
travis_time_start setup.before_install
#before_install:
# Install ROS
sudo sh -c "echo \"deb http://packages.ros.org/ros-shadow-fixed/ubuntu `lsb_release -cs` main\" > /etc/apt/sources.list.d/ros-latest.list"
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-get update -qq
# Install ROS
sudo apt-get install -y -q python-catkin-pkg python-catkin-tools python-rosdep python-wstool python-rosinstall-generator ros-$ROS_DISTRO-catkin
source /opt/ros/$ROS_DISTRO/setup.bash
# Setup for rosdep
sudo rosdep init
rosdep update
travis_time_end

travis_time_start setup.install
#install:
mkdir -p ~/catkin_ws/src

# Add the package under test to the workspace.
cd ~/catkin_ws/src
ln -s $CI_SOURCE_PATH . # Link the repo we are testing to the new workspace

# Install all dependencies, using wstool and rosdep.
# wstool looks for a ROSINSTALL_FILE defined in before_install.
travis_time_end

travis_time_start setup.before_script
#before_script:
# source dependencies: install using wstool.
cd ~/catkin_ws/src
wstool init
#if [[ -f $ROSINSTALL_FILE ]] ; then wstool merge $ROSINSTALL_FILE ; fi
if [ "$OPENCV_VERSION" == 3 ]; then rosinstall_generator image_pipeline --upstream >> .rosinstall.opencv3; fi # need to recompile image_proc
if [ "$OPENCV_VERSION" == 3 ]; then rosinstall_generator compressed_image_transport --upstream >> .rosinstall.opencv3; fi # need to recompile compressed_image_transport
if [ "$OPENCV_VERSION" == 3 ]; then rosinstall_generator vision_opencv --upstream >> .rosinstall.opencv3; fi # need to recompile visoin_opencv
if [ "$OPENCV_VERSION" == 3 ]; then wstool merge .rosinstall.opencv3; fi # need to recompile visoin_opencv
wstool up
wstool info
if [ "$OPENCV_VERSION" == 3 ]; then sed -i 's@libopencv-dev@opencv3@' */*/package.xml ; fi


# package depdencies: install using rosdep.
cd ~/catkin_ws
rosdep install -q -y --from-paths src --ignore-src --rosdistro $ROS_DISTRO
travis_time_end
}

function build {
travis_time_start build.script
source /opt/ros/$ROS_DISTRO/setup.bash
cd ~/catkin_ws
catkin build -p1 -j1 --no-status
travis_time_end
}

function run_test {
travis_time_start run_test.script
source /opt/ros/$ROS_DISTRO/setup.bash
cd ~/catkin_ws
catkin run_tests -p1 -j1 --no-status opencv_apps --no-deps
catkin_test_results --verbose build || catkin_test_results --all build
travis_time_end
}

function build_install {
travis_time_start build_install.script
source /opt/ros/$ROS_DISTRO/setup.bash
cd ~/catkin_ws
catkin clean -b --yes || catkin clean -b -a
catkin config --install
catkin build -p1 -j1 --no-status
travis_time_end
}

travis_time_start apt.before_install
apt-get update -qq && apt-get install -y -q wget sudo lsb-release gnupg # for docker
# set DEBIAN_FRONTEND=noninteractive
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections

travis_time_start setup.before_install
#before_install:
# Install ROS
sudo sh -c "echo \"deb http://packages.ros.org/ros-shadow-fixed/ubuntu `lsb_release -cs` main\" > /etc/apt/sources.list.d/ros-latest.list"
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-get update -qq
# Install ROS
sudo apt-get install -y -q python-catkin-pkg python-catkin-tools python-rosdep python-wstool python-rosinstall-generator ros-$ROS_DISTRO-catkin
source /opt/ros/$ROS_DISTRO/setup.bash
# Setup for rosdep
sudo rosdep init
rosdep update
travis_time_end

travis_time_start setup.install
#install:
mkdir -p ~/catkin_ws/src
if [ $TEST == "catkin_lint" ]; then

# Add the package under test to the workspace.
cd ~/catkin_ws/src
ln -s $CI_SOURCE_PATH . # Link the repo we are testing to the new workspace
travis_time_start catkin_lint.script
apt-get install -y -q python-pip
pip install catkin_lint rosdep
rosdep init
rosdep update
travis_time_end
ROS_DISTRO=melodic catkin_lint --resolve-env --strict $CI_SOURCE_PATH

# Install all dependencies, using wstool and rosdep.
# wstool looks for a ROSINSTALL_FILE defined in before_install.
travis_time_end

travis_time_start setup.before_script
#before_script:
# source dependencies: install using wstool.
cd ~/catkin_ws/src
wstool init
#if [[ -f $ROSINSTALL_FILE ]] ; then wstool merge $ROSINSTALL_FILE ; fi
if [ $OPENCV_VERSION == 3 ]; then rosinstall_generator image_pipeline --upstream >> .rosinstall.opencv3; fi # need to recompile image_proc
if [ $OPENCV_VERSION == 3 ]; then rosinstall_generator compressed_image_transport --upstream >> .rosinstall.opencv3; fi # need to recompile compressed_image_transport
if [ $OPENCV_VERSION == 3 ]; then rosinstall_generator vision_opencv --upstream >> .rosinstall.opencv3; fi # need to recompile visoin_opencv
if [ $OPENCV_VERSION == 3 ]; then wstool merge .rosinstall.opencv3; fi # need to recompile visoin_opencv
wstool up
wstool info
if [ $OPENCV_VERSION == 3 ]; then sed -i 's@libopencv-dev@opencv3@' */*/package.xml ; fi


# package depdencies: install using rosdep.
cd ~/catkin_ws
rosdep install -q -y --from-paths src --ignore-src --rosdistro $ROS_DISTRO
travis_time_end
elif [ $TEST == "clang-format" ]; then

# Compile and test.
#script:
travis_time_start setup.script
source /opt/ros/$ROS_DISTRO/setup.bash
cd ~/catkin_ws
catkin build -p1 -j1 --no-status
catkin run_tests -p1 -j1 --no-status opencv_apps --no-deps
catkin_test_results --verbose build || catkin_test_results --all build
catkin clean -b --yes || catkin clean -b -a
catkin config --install
catkin build -p1 -j1 --no-status
travis_time_end
travis_time_start clang_format.script
apt-get install -y -q clang-format-3.9 git
find $CI_SOURCE_PATH -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs clang-format-3.9 -i -style=file
travis_time_end
git -C $CI_SOURCE_PATH --no-pager diff
git -C $CI_SOURCE_PATH diff-index --quiet HEAD -- .

elif [ $TEST == "clang-tidy" ]; then

setup

travis_time_start clang_tidy.script
apt-get install -y -q clang-tidy clang-tools
cd ~/catkin_ws
catkin config --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
travis_time_end

build

travis_time_start clang_tidy.script
for file in $(find ~/catkin_ws/build -name compile_commands.json) ; do
run-clang-tidy -fix -p $(dirname $file)
done
travis_time_end
git -C $CI_SOURCE_PATH --no-pager diff
git -C $CI_SOURCE_PATH diff-index --quiet HEAD -- .

else
# Compile and test.
setup
build
run_test
build_install
fi
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ sudo: required
dist: trusty
language: generic
env:
- TEST=catkin_lint DOCKER_IMAGE=ubuntu:bionic
- TEST=clang-format DOCKER_IMAGE=ubuntu:bionic
- TEST=clang-tidy ROS_DISTRO=melodic DOCKER_IMAGE=ubuntu:bionic
- ROS_DISTRO=hydro DOCKER_IMAGE=ubuntu:precise
- OPENCV_VERSION=2 ROS_DISTRO=indigo DOCKER_IMAGE=ubuntu:trusty
- OPENCV_VERSION=3 ROS_DISTRO=indigo DOCKER_IMAGE=ubuntu:trusty
Expand All @@ -12,7 +15,7 @@ script:
- export CI_SOURCE_PATH=$(pwd)
- export REPOSITORY_NAME=${PWD##*/}
- echo "Testing branch $TRAVIS_BRANCH of $REPOSITORY_NAME"
- docker run --rm -i -v $CI_SOURCE_PATH:$CI_SOURCE_PATH -e "CI_SOURCE_PATH=$CI_SOURCE_PATH" -e "HOME=$HOME" -e "ROS_DISTRO=$ROS_DISTRO" -e "OPENCV_VERSION=$OPENCV_VERSION" -t $DOCKER_IMAGE sh -c "cd $CI_SOURCE_PATH; ./.travis.sh"
- docker run --rm -i -v $CI_SOURCE_PATH:$CI_SOURCE_PATH -e "CI_SOURCE_PATH=$CI_SOURCE_PATH" -e "HOME=$HOME" -e "ROS_DISTRO=$ROS_DISTRO" -e "OPENCV_VERSION=$OPENCV_VERSION" -e "TEST=$TEST" -t $DOCKER_IMAGE sh -c "cd $CI_SOURCE_PATH; /bin/bash .travis.sh"

after_failure:
- find ${HOME}/.ros/test_results -type f -exec echo "== {} ==" \; -exec cat {} \;
Expand Down
23 changes: 20 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
cmake_minimum_required(VERSION 2.8.3)
project(opencv_apps)

find_package(catkin REQUIRED COMPONENTS cv_bridge dynamic_reconfigure message_generation image_transport nodelet roscpp sensor_msgs)
## https://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake
if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)
message(STATUS "C++11 activated.")
add_definitions("-std=gnu++11")
elseif(GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
message(WARNING "C++0x activated. If you get any errors update to a compiler which fully supports C++11")
add_definitions("-std=gnu++0x")
else ()
message(FATAL_ERROR "C++11 needed. Therefore a gcc compiler with a version higher than 4.3 is needed.")
endif()
else(CMAKE_COMPILER_IS_GNUCXX)
add_definitions("-std=c++0x")
endif(CMAKE_COMPILER_IS_GNUCXX)

find_package(catkin REQUIRED COMPONENTS cv_bridge dynamic_reconfigure message_generation image_transport nodelet roscpp sensor_msgs std_msgs std_srvs)

find_package(OpenCV REQUIRED)
message(STATUS "OpenCV VERSION: ${OpenCV_VERSION}")
Expand Down Expand Up @@ -99,7 +115,7 @@ generate_messages(
std_msgs
)

catkin_package(CATKIN_DEPENDS std_msgs
catkin_package(CATKIN_DEPENDS message_runtime sensor_msgs std_msgs
# DEPENDS OpenCV
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
Expand Down Expand Up @@ -351,7 +367,8 @@ install(DIRECTORY launch test scripts

## test
if(CATKIN_ENABLE_TESTING)
find_package(catkin REQUIRED COMPONENTS rostest roslaunch)
find_package(rostest REQUIRED)
find_package(roslaunch REQUIRED)
if(roslaunch_VERSION VERSION_LESS "1.11.1")
message(WARNING "roslaunch_add_file check fails with unsupported doc attributes ${roslaunch_VERSION}")
else()
Expand Down
18 changes: 0 additions & 18 deletions cfg/HSIColorFilter.cfg

This file was deleted.

Loading

0 comments on commit 69ee207

Please sign in to comment.