Skip to content

Commit

Permalink
Make the autopep8 clang-format targets quieter
Browse files Browse the repository at this point in the history
This makes our clang-format and autopep8 execution quieter. They will
now only print any files that they modified.
  • Loading branch information
bneradt authored and bneradt committed Jul 7, 2022
1 parent 33e34b9 commit c1cdcc7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
19 changes: 16 additions & 3 deletions tools/autopep8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,18 @@ function main() {
# Keep this list of Python extensions the same with the list of
# extensions searched for in the tools/git/pre-commit hook.
grep -E '\.py$|\.cli.ext$|\.test.ext$' ${files} > ${files_filtered}
# Prepend the filenames with "./" to make the modified file output consistent
# with the clang-format target output.
sed -i'.bak' 's:^:\./:' ${files_filtered}
rm -f ${files_filtered}.bak

echo "Running autopep8. This may take a minute."
# Efficiently retrieving modification timestamps in a platform
# independent way is challenging. We use find's -newer argument, which
# seems to be broadly supported. The following file is created and has a
# timestamp just before running clang-format. Any file with a timestamp
# after this we assume was modified by clang-format.
start_time_file=${tmp_dir}/format_start.$$
touch ${start_time_file}
autopep8 \
--ignore-local-config \
-i \
Expand All @@ -82,8 +92,11 @@ function main() {
--aggressive \
--aggressive \
$(cat ${files_filtered})
find $(cat ${files_filtered}) -newer ${start_time_file}

# The above will not catch the Python files in the metalink tests because
# they do not have extensions.
metalink_dir=${DIR}/plugins/experimental/metalink/test
autopep8 \
--ignore-local-config \
-i \
Expand All @@ -93,8 +106,8 @@ function main() {
--aggressive \
--aggressive \
--recursive \
${DIR}/plugins/experimental/metalink/test
echo "autopep8 completed."
${metalink_dir}
find ${metalink_dir} -newer ${start_time_file}
rm -rf ${tmp_dir}
deactivate
}
Expand Down
16 changes: 14 additions & 2 deletions tools/clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,29 @@ EOF
exit 1
else
[ ${just_install} -eq 1 ] && return
for file in $(find $DIR -iname \*.[ch] -o -iname \*.cc -o -iname \*.h.in); do

# Efficiently retrieving modification timestamps in a platform
# independent way is challenging. We use find's -newer argument, which
# seems to be broadly supported. The following file is created and has a
# timestamp just before running clang-format. Any file with a timestamp
# after this we assume was modified by clang-format.
start_time_file=/tmp/format_start.$$
touch ${start_time_file}

target_files=$(find $DIR -iname \*.[ch] -o -iname \*.cc -o -iname \*.h.in)
for file in ${target_files}; do
# The ink_autoconf.h and ink_autoconf.h.in files are generated files,
# so they do not need to be re-formatted by clang-format. Doing so
# results in make rebuilding all our files, so we skip formatting them
# here.
base_name=$(basename ${file})
[ ${base_name} = 'ink_autoconf.h.in' -o ${base_name} = 'ink_autoconf.h' ] && continue

echo $file
${FORMAT} -i $file
done

find ${target_files} -newer ${start_time_file}
rm ${start_time_file}
fi
}

Expand Down

0 comments on commit c1cdcc7

Please sign in to comment.