industrial_ci icon indicating copy to clipboard operation
industrial_ci copied to clipboard

Clang Format blacklist directories/packages?

Open Levi-Armstrong opened this issue 5 years ago • 9 comments

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?

Levi-Armstrong avatar Dec 17 '18 13:12 Levi-Armstrong

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.

mathias-luedtke avatar Dec 17 '18 16:12 mathias-luedtke

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

Levi-Armstrong avatar Dec 18 '18 01:12 Levi-Armstrong

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/*"

mathias-luedtke avatar Dec 18 '18 09:12 mathias-luedtke

Even better.

Levi-Armstrong avatar Dec 18 '18 12:12 Levi-Armstrong

@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 avatar Jan 18 '19 03:01 Levi-Armstrong

@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"

mathias-luedtke avatar Jan 21 '19 23:01 mathias-luedtke

@ipa-mdl I must have had a error because running your script everything worked. Thank you for taking a look.

Levi-Armstrong avatar Jan 26 '19 04:01 Levi-Armstrong

@ipa-mdl Is there plans to incorporate your functionality into industrial_ci?

Levi-Armstrong avatar Jul 14 '19 03:07 Levi-Armstrong

@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 :)

mathias-luedtke avatar Jul 14 '19 08:07 mathias-luedtke