diff --git a/tools/autopep8.sh b/tools/autopep8.sh index 44e6f1ac1a9..e489627a914 100755 --- a/tools/autopep8.sh +++ b/tools/autopep8.sh @@ -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 \ @@ -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 \ @@ -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 } diff --git a/tools/clang-format.sh b/tools/clang-format.sh index c85a5965c4c..eb142b6b95f 100755 --- a/tools/clang-format.sh +++ b/tools/clang-format.sh @@ -87,7 +87,17 @@ 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=$(mktemp -t clang-format-start-time.XXXXXXXXXX) + 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 @@ -95,9 +105,11 @@ EOF 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 }