From 87f21d2c68900ea4ccc6e20a9a3c941fafa9f94a Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Wed, 15 Feb 2023 09:52:42 +0900 Subject: [PATCH] Fix make_etags failure on Mac. Previously make_etags always ran make_ctags -e when make_etags was executed. However, because non-Exuberant ctags on Mac does not support -e option (and also on other platforms including old Linux), ctags failed. To avoid the failure change make_ctags so that if non-Exuberant ctags is used and ctags -e option is requested, run etags command instead. If etags command does not exist, make_ctags will fail. Also refactor make_ctags and tweak make_etags to emit proper usage message. Author: Fujii Masao Reviewed-by: Tatsuo Ishii Discussion: https://www.postgresql.org/message-id/369c13b9-8b0f-d6f9-58fc-61258ec8f713%40oss.nttdata.com --- src/tools/make_ctags | 38 +++++++++++++++++++++++++++----------- src/tools/make_etags | 8 +++++++- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/tools/make_ctags b/src/tools/make_ctags index 102881667b610..aa7d7b573f09f 100755 --- a/src/tools/make_ctags +++ b/src/tools/make_ctags @@ -9,15 +9,19 @@ then echo $usage exit 1 fi -MODE= +EMACS_MODE= NO_SYMLINK= +IS_EXUBERANT= +PROG="ctags" +TAGS_OPT="-a -f" TAGS_FILE="tags" +FLAGS= +IGNORE_IDENTIFIES= while [ $# -gt 0 ] do if [ $1 = "-e" ] - then MODE="-e" - TAGS_FILE="TAGS" + then EMACS_MODE="Y" elif [ $1 = "-n" ] then NO_SYMLINK="Y" else @@ -27,15 +31,24 @@ do shift done -command -v ctags >/dev/null || \ +if [ ! "$EMACS_MODE" ] +then (command -v ctags >/dev/null) || \ { echo "'ctags' program not found" 1>&2; exit 1; } +fi -trap "ret=$?; rm -rf /tmp/$$; exit $ret" 0 1 2 3 15 -rm -f ./$TAGS_FILE - -IS_EXUBERANT="" ctags --version 2>&1 | grep Exuberant && IS_EXUBERANT="Y" +if [ "$EMACS_MODE" ] +then TAGS_FILE="TAGS" + if [ "$IS_EXUBERANT" ] + then PROG="ctags -e" + else (command -v etags >/dev/null) || \ + { echo "neither 'etags' nor exuberant 'ctags' program not found" 1>&2; exit 1; } + PROG="etags" + TAGS_OPT="-a -o" + fi +fi + # List of kinds supported by Exuberant Ctags 5.8 # generated by ctags --list-kinds # --c-kinds was called --c-types before 2003 @@ -56,20 +69,23 @@ ctags --version 2>&1 | grep Exuberant && IS_EXUBERANT="Y" if [ "$IS_EXUBERANT" ] then FLAGS="--c-kinds=+dfmstuv" -else FLAGS="-dt" +elif [ ! "$EMACS_MODE" ] +then FLAGS="-dt" fi # Use -I option to ignore a macro if [ "$IS_EXUBERANT" ] then IGNORE_IDENTIFIES="-I pg_node_attr+" -else IGNORE_IDENTIFIES= fi +trap "ret=$?; rm -rf /tmp/$$; exit $ret" 0 1 2 3 15 +rm -f ./$TAGS_FILE + # this is outputting the tags into the file 'tags', and appending find `pwd`/ \( -name tmp_install -prune -o -name tmp_check -prune \) \ -o \( -name "*.[chly]" -o -iname "*makefile*" -o -name "*.mk" -o -name "*.in" \ -o -name "*.sql" -o -name "*.p[lm]" \) -type f -print | - xargs ctags $MODE -a -f $TAGS_FILE "$FLAGS" "$IGNORE_IDENTIFIES" + xargs $PROG $TAGS_OPT $TAGS_FILE $FLAGS $IGNORE_IDENTIFIES # Exuberant tags has a header that we cannot sort in with the other entries # so we skip the sort step diff --git a/src/tools/make_etags b/src/tools/make_etags index afc57e3e89268..7e51bb4c4e2e7 100755 --- a/src/tools/make_etags +++ b/src/tools/make_etags @@ -1,5 +1,11 @@ #!/bin/sh -# src/tools/make_etags + +# src/tools/make_etags [-n] + +if [ $# -gt 1 ] || ( [ $# -eq 1 ] && [ $1 != "-n" ] ) +then echo "Usage: $0 [-n]" + exit 1 +fi cdir=`dirname $0` dir=`(cd $cdir && pwd)`