industrial_ci
industrial_ci copied to clipboard
Clang Format blacklist directories/packages?
In one of my repositories I have sub-modules that get pulled in from third party repositories that I would like to blacklist from the clang format check. Is it possible to blacklist or whitelist packages for the clang-format test. If not would the maintainers be supportive of adding this feature, I would be happy add this feature?
At the moment there is no blacklist/whitelist option for the clang format check. Perhaps you can disable submodules cloning for a specific job.
If not would the maintainers be supportive of adding this feature, I would be happy add this feature?
Of course! The file selection happens around here.
I could imaging to implement some wildcard matching against "file", but I haven't found a nice solution yet.
I have something working providing package/directory name. The example below would exclude file that contain any directory in the path that is listed int TEST_BLACKLIST.
TEST_BLACKLIST=stomp,industrial_core
CLANG_PKGS=$((echo "$TEST_BLACKLIST" | tr ' ;,' '\n') | tr '\n' ' ')
if [ -n "$CLANG_PKGS" ]; then
IFS=' ' read -r -a CLANG_PKGS <<< "$CLANG_PKGS"
fi
PRUNE=""
CNT=0
for i in "${CLANG_PKGS[@]}"
do
if [[ $CNT -eq 0 ]]; then
PRUNE="-name $i"
else
PRUNE="$PRUNE -o -name $i"
fi
let CNT+=1
done
# Run clang-format
if [[ $CNT -eq 0 ]]; then
find . -type f -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\|hxx\)' -exec clang-format -style=file -i {} \;
else
find . -type d \( $PRUNE \) -prune -o -type f -regex '.*\.\(cpp\|hpp\|cc\|cxx\|h\|hxx\)' -exec clang-format -style=file -i {} \;
fi
Roughly based on your solution I came up with this:
exclude=()
for p in $CLANG_FORMAT_EXCLUDE; do exclude+=(-and -not -path "$path/$p"); done
find "$path"/* -iregex '.*\.\(cpp\|hpp\|cc\|cxx\|h\|hxx\)' "${exclude[@]}"
- avoids
tr
, because we do not use this elsewhere -> split only by spaces - allows blacklisting individual files
- uses relative file names (in target repository)
- Example:
CLANG_FORMAT_EXCLUDE="stomp/* industrial_core/*"
Even better.
@ipa-mdl I tested the code you provided and the for p in $CLANG_FORMAT_EXCLUDE; do exclude+=(-and -not -path "$path/$p"); done
does not search sub-directories.
@Levi-Armstrong: Please elaborate on what you tried and what did not work. I gave it a try with https://github.com/ros-industrial/industrial_moveit and it worked as expected:
CLANG_FORMAT_EXCLUDE="stomp_moveit/src/utils/* constrained_ik/include/constrained_ik/*"
path=/tmp/industrial_moveit
git clone --depth 1 https://github.com/ros-industrial/industrial_moveit.git "$path"
exclude=()
for p in $CLANG_FORMAT_EXCLUDE; do exclude+=(-and -not -path "$path/$p"); done
find "$path"/* -iregex '.*\.\(cpp\|hpp\|cc\|cxx\|h\|hxx\)' "${exclude[@]}"
rm -rf "$path"
@ipa-mdl I must have had a error because running your script everything worked. Thank you for taking a look.
@ipa-mdl Is there plans to incorporate your functionality into industrial_ci?
@ipa-mdl Is there plans to incorporate your functionality into industrial_ci?
I don't have time to work on this, but pull requests are welcome :)