From 2f41d9740ce4765707936475c1c8d6d2eeef7f2f Mon Sep 17 00:00:00 2001 From: Ralf Wildenhues Date: Sat, 26 Sep 2009 10:48:45 +0200 Subject: [PATCH] Fixups and tests for cscope functionality. It seems cscope is not able to take into account relative file names of included cscope.files files, but it is able to canonicalize file names containing '../' sequences. This patch makes the cscope references relative again, and fixes some corner cases. * .gitignore: Ignore files generated by `make cscope'. * NEWS: Reword a bit. * THANKS: Update. * automake.in (handle_tags): Use $(am__cd). Provide default empty rule for the `cscope' target, for empty sources. * lib/am/tags.am (cscopelist): Construct relative path to files in $(srcdir) if $(srcdir) is relative. [TOPDIR_P] (cscope): Do not depend on cscope-clean. Only invoke $(CSCOPE) if cscope.files is nonemtpy. (clean-cscope): Rename from ... (cscopeclean): ... this. (cscope.files): Depend on clean-cscope. (distclean-tags) [!TOPDIR_P]: No need to remove cscope files here. * tests/cscope.test, tests/cscope2.test, tests/cscope3.test: New tests. * tests/Makefile.am: Adjust. Signed-off-by: Ralf Wildenhues --- .gitignore | 4 ++ ChangeLog | 25 ++++++++ Makefile.in | 30 +++++---- NEWS | 2 +- THANKS | 1 + automake.in | 4 +- doc/Makefile.in | 13 ++-- lib/Automake/Makefile.in | 15 +++-- lib/Automake/tests/Makefile.in | 2 +- lib/Makefile.in | 15 +++-- lib/am/Makefile.in | 2 +- lib/am/tags.am | 28 +++++---- m4/Makefile.in | 2 +- tests/Makefile.am | 3 + tests/Makefile.in | 5 +- tests/cscope.test | 108 +++++++++++++++++++++++++++++++++ tests/cscope2.test | 36 +++++++++++ tests/cscope3.test | 41 +++++++++++++ 18 files changed, 288 insertions(+), 48 deletions(-) create mode 100755 tests/cscope.test create mode 100755 tests/cscope2.test create mode 100755 tests/cscope3.test diff --git a/.gitignore b/.gitignore index 81e5a98ef..716ef8b30 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,9 @@ config.log config.status config.status.lineno configure.lineno +cscope.files +cscope.in.out +cscope.out +cscope.po.out tags TAGS diff --git a/ChangeLog b/ChangeLog index f72ad9ea0..e425420a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2009-09-26 Ralf Wildenhues + + Fixups and tests for cscope functionality. + It seems cscope is not able to take into account relative + file names of included cscope.files files, but it is able to + canonicalize file names containing '../' sequences. + This patch makes the cscope references relative again, and + fixes some corner cases. + * NEWS: Reword a bit. + * THANKS: Update. + * automake.in (handle_tags): Use $(am__cd). Provide default + empty rule for the `cscope' target, for empty sources. + * lib/am/tags.am (cscopelist): Construct relative path to files + in $(srcdir) if $(srcdir) is relative. + [TOPDIR_P] (cscope): Do not depend on cscope-clean. Only invoke + $(CSCOPE) if cscope.files is nonemtpy. + (clean-cscope): Rename from ... + (cscopeclean): ... this. + (cscope.files): Depend on clean-cscope. + (distclean-tags) [!TOPDIR_P]: No need to remove cscope files + here. + * tests/cscope.test, tests/cscope2.test, tests/cscope3.test: New + tests. + * tests/Makefile.am: Adjust. + 2009-09-25 Debarshi Ray New target to generate cscope database. diff --git a/Makefile.in b/Makefile.in index b1ab663d9..2e1b41293 100644 --- a/Makefile.in +++ b/Makefile.in @@ -442,7 +442,7 @@ ctags-recursive: done cscopelist-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) @@ -507,28 +507,32 @@ GTAGS: && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" -cscope: cscopeclean cscope.files - $(CSCOPE) -b -q $(CSCOPEFLAGS) $(AM_CSCOPEFLAGS) \ - -i cscope.files $(CSCOPE_ARGS) +cscope: cscope.files + test ! -s cscope.files \ + || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) -cscopeclean: +clean-cscope: -rm -f cscope.files -cscope.files: cscopelist-recursive cscopelist +cscope.files: clean-cscope cscopelist-recursive cscopelist cscopelist: cscopelist-recursive $(HEADERS) $(SOURCES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ for i in $$list; do \ - if test -f "$$i"; \ - then echo \"$(subdir)/$$i\"; \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ else \ - echo \"$(abs_srcdir)/$$i\"; \ + echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ - cscope.po.out cscope.files + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + -rm -f cscope.out cscope.in.out cscope.po.out cscope.files distdir: $(DISTFILES) $(am__remove_distdir) @@ -822,8 +826,8 @@ uninstall-am: uninstall-binSCRIPTS install-exec-am install-strip tags-recursive uninstall-am .PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ - all all-am am--refresh check check-am clean clean-generic \ - cscope cscopeclean cscopelist cscopelist-recursive ctags \ + all all-am am--refresh check check-am clean clean-cscope \ + clean-generic cscope cscopelist cscopelist-recursive ctags \ ctags-recursive dist dist-all dist-bzip2 dist-gzip dist-hook \ dist-lzma dist-shar dist-tarZ dist-xz dist-zip distcheck \ distclean distclean-generic distclean-tags distcleancheck \ diff --git a/NEWS b/NEWS index 4c63fa971..ef608da39 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New in 1.11.0a: * New targets: - - New `cscope' target (builds cscope database). + - New `cscope' target to build a cscope database for the source tree. Bugs fixed in 1.11.0a: diff --git a/THANKS b/THANKS index 7b8664a23..54615bec5 100644 --- a/THANKS +++ b/THANKS @@ -64,6 +64,7 @@ danbp danpb@nospam.postmaster.co.uk Daniel Jacobowitz drow@false.org Daniel Kahn Gillmor dkg@fifthhorseman.net Daniel Richard G. danielg@teragram.com +Debarshi Ray rishi@gnu.org Dave Brolley brolley@redhat.com Dave Morrison dave@bnl.gov David A. Swierczek swiercze@mr.med.ge.com diff --git a/automake.in b/automake.in index b0a8951bf..84ed8bc73 100755 --- a/automake.in +++ b/automake.in @@ -3753,7 +3753,7 @@ sub handle_tags . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n" # Never fail here if a subdir fails; it # isn't important. - . "\t test \"\$\$subdir\" = . || (cd \$\$subdir" + . "\t test \"\$\$subdir\" = . || (\$(am__cd) \$\$subdir" . " && \$(MAKE) \$(AM_MAKEFLAGS) cscopelist); \\\n" . "\tdone\n"); push (@cscope_deps, 'cscopelist-recursive'); @@ -3799,7 +3799,7 @@ sub handle_tags $output_rules .= "tags: TAGS\nTAGS:\n\n"; # Ditto ctags and cscope. $output_rules .= "ctags: CTAGS\nCTAGS:\n\n"; - $output_rules .= "cscopelist:\n\n"; + $output_rules .= "cscope cscopelist:\n\n"; } } diff --git a/doc/Makefile.in b/doc/Makefile.in index f39bbed19..8b776607d 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -535,17 +535,20 @@ GTAGS: cscopelist: $(HEADERS) $(SOURCES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ for i in $$list; do \ - if test -f "$$i"; \ - then echo \"$(subdir)/$$i\"; \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ else \ - echo \"$(abs_srcdir)/$$i\"; \ + echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ - cscope.po.out cscope.files + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(DISTFILES) @list='$(MANS)'; if test -n "$$list"; then \ diff --git a/lib/Automake/Makefile.in b/lib/Automake/Makefile.in index 65d23b557..db148df69 100644 --- a/lib/Automake/Makefile.in +++ b/lib/Automake/Makefile.in @@ -389,7 +389,7 @@ ctags-recursive: done cscopelist-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) @@ -456,17 +456,20 @@ GTAGS: cscopelist: cscopelist-recursive $(HEADERS) $(SOURCES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ for i in $$list; do \ - if test -f "$$i"; \ - then echo \"$(subdir)/$$i\"; \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ else \ - echo \"$(abs_srcdir)/$$i\"; \ + echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ - cscope.po.out cscope.files + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ diff --git a/lib/Automake/tests/Makefile.in b/lib/Automake/tests/Makefile.in index e217e3fee..7bc886fb2 100644 --- a/lib/Automake/tests/Makefile.in +++ b/lib/Automake/tests/Makefile.in @@ -274,7 +274,7 @@ TAGS: ctags: CTAGS CTAGS: -cscopelist: +cscope cscopelist: # To be appended to the command running the test. Handle the stdout diff --git a/lib/Makefile.in b/lib/Makefile.in index 27fc1e291..78564c99b 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -364,7 +364,7 @@ ctags-recursive: done cscopelist-recursive: list='$(SUBDIRS)'; for subdir in $$list; do \ - test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) cscopelist); \ done ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) @@ -431,17 +431,20 @@ GTAGS: cscopelist: cscopelist-recursive $(HEADERS) $(SOURCES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ for i in $$list; do \ - if test -f "$$i"; \ - then echo \"$(subdir)/$$i\"; \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ else \ - echo \"$(abs_srcdir)/$$i\"; \ + echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ - cscope.po.out cscope.files + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ diff --git a/lib/am/Makefile.in b/lib/am/Makefile.in index 616237b94..4189f297d 100644 --- a/lib/am/Makefile.in +++ b/lib/am/Makefile.in @@ -269,7 +269,7 @@ TAGS: ctags: CTAGS CTAGS: -cscopelist: +cscope cscopelist: distdir: $(DISTFILES) diff --git a/lib/am/tags.am b/lib/am/tags.am index 142748bed..7fa75c951 100644 --- a/lib/am/tags.am +++ b/lib/am/tags.am @@ -141,28 +141,32 @@ GTAGS: if %?TOPDIR_P% CSCOPE = cscope -.PHONY: cscope cscopeclean +.PHONY: cscope clean-cscope AM_RECURSIVE_TARGETS += cscope -cscope: cscopeclean cscope.files - $(CSCOPE) -b -q $(CSCOPEFLAGS) $(AM_CSCOPEFLAGS) \ - -i cscope.files $(CSCOPE_ARGS) +cscope: cscope.files + test ! -s cscope.files \ + || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) -cscopeclean: +clean-cscope: -rm -f cscope.files -cscope.files: %CSCOPEDIRS% cscopelist +cscope.files: clean-cscope %CSCOPEDIRS% cscopelist endif %?TOPDIR_P% .PHONY: cscopelist cscopelist: %CSCOPEDIRS% $(HEADERS) $(SOURCES) $(LISP) list='$(SOURCES) $(HEADERS) $(LISP)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ for i in $$list; do \ - if test -f "$$i"; \ - then echo \"$(subdir)/$$i\"; \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ else \ - echo \"$(abs_srcdir)/$$i\"; \ + echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files @@ -174,5 +178,7 @@ cscopelist: %CSCOPEDIRS% $(HEADERS) $(SOURCES) $(LISP) .PHONY distclean-am: distclean-tags distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags cscope.out cscope.in.out \ - cscope.po.out cscope.files + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +if %?TOPDIR_P% + -rm -f cscope.out cscope.in.out cscope.po.out cscope.files +endif %?TOPDIR_P% diff --git a/m4/Makefile.in b/m4/Makefile.in index a7edbd362..0c7bf7d5e 100644 --- a/m4/Makefile.in +++ b/m4/Makefile.in @@ -266,7 +266,7 @@ TAGS: ctags: CTAGS CTAGS: -cscopelist: +cscope cscopelist: distdir: $(DISTFILES) diff --git a/tests/Makefile.am b/tests/Makefile.am index 62529a6b5..e97468984 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -208,6 +208,9 @@ confsub.test \ confvar.test \ confvar2.test \ copy.test \ +cscope.test \ +cscope2.test \ +cscope3.test \ ctarget1.test \ cxx.test \ cxx2.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 9cd1666cf..9e9fb97c6 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -442,6 +442,9 @@ confsub.test \ confvar.test \ confvar2.test \ copy.test \ +cscope.test \ +cscope2.test \ +cscope3.test \ ctarget1.test \ cxx.test \ cxx2.test \ @@ -1020,7 +1023,7 @@ TAGS: ctags: CTAGS CTAGS: -cscopelist: +cscope cscopelist: # To be appended to the command running the test. Handle the stdout diff --git a/tests/cscope.test b/tests/cscope.test new file mode 100755 index 000000000..5beee5b27 --- /dev/null +++ b/tests/cscope.test @@ -0,0 +1,108 @@ +#! /bin/sh +# Copyright (C) 2009 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test cscope functionality. + +required= +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_CONFIG_FILES([sub/Makefile]) +AC_PROG_CC +AC_PROG_CXX +AC_PROG_FC +AM_PROG_GCJ +AM_PATH_LISPDIR +AC_OUTPUT +END + +mkdir sub sub/subsub + +cat >Makefile.am <<'END' +SUBDIRS = sub +bin_PROGRAMS = foo +foo_SOURCES = foo.c bar.cpp baz.f90 +lisp_LISP = foo.el +EXTRA_DIST = foo.el +END + +cat >sub/Makefile.am <<'END' +bin_PROGRAMS = bar +bar_SOURCES = subsub/dist.c +nodist_bar_SOURCES = subsub/gen.c +subsub/gen.c: + $(MKDIR_P) subsub + echo 'int generated_subsub () { return 0; }' > $@ +CLEANFILES = subsub/gen.c +END + +echo 'int foo_func () { return 0; }' > foo.c +echo 'int main () { return 0; }' > bar.cpp +cat > baz.f90 <<'END' + subroutine baz + end +END +: >foo.el +echo 'int main () { return 0; }' > sub/subsub/dist.c + +$ACLOCAL +$AUTOCONF +$AUTOMAKE --add-missing + +mkdir build +cd build +../configure || Exit 77 + +$MAKE -n cscope + +: ${CSCOPE=cscope} +( $CSCOPE --version ) >/dev/null 2>&1 || Exit 77 + +$MAKE cscope 2>stderr +cat stderr >&2 +grep 'cannot find file' stderr && Exit 1 + +test -f cscope.files +$FGREP foo.c cscope.files +$FGREP bar.cpp cscope.files +$FGREP sub/subsub/dist.c cscope.files +$FGREP sub/subsub/gen.c cscope.files + +cp cscope.files cscope.files1 +$MAKE cscope +diff cscope.files cscope.files1 + +$MAKE distclean +test ! -f cscope.files +test ! -f cscope.out +test ! -f cscope.in.out +test ! -f cscope.po.out + + +`pwd`/../configure || Exit 77 + +$MAKE cscope 2>stderr +cat stderr >&2 +grep 'cannot find file' stderr && Exit 1 +$MAKE distclean + +cd .. +./configure +$MAKE distcheck + +: diff --git a/tests/cscope2.test b/tests/cscope2.test new file mode 100755 index 000000000..801457f31 --- /dev/null +++ b/tests/cscope2.test @@ -0,0 +1,36 @@ +#! /bin/sh +# Copyright (C) 2009 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# The `cscope' target should not fail if there are no sources. + +required= +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_OUTPUT +END +: >Makefile.am + +$ACLOCAL +$AUTOCONF +$AUTOMAKE + +./configure +$MAKE cscope + +: diff --git a/tests/cscope3.test b/tests/cscope3.test new file mode 100755 index 000000000..04e85c3d9 --- /dev/null +++ b/tests/cscope3.test @@ -0,0 +1,41 @@ +#! /bin/sh +# Copyright (C) 2009 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# The `cscope' target should not fail if there are no sources in a subdir. +# In practice this means `cscope' should not be invoked if cscope.files +# is empty. + +required=cscope +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_CONFIG_FILES([sub/Makefile]) +AC_OUTPUT +END +mkdir sub +echo 'SUBDIRS = sub' >Makefile.am +: >sub/Makefile.am + +$ACLOCAL +$AUTOCONF +$AUTOMAKE + +./configure +$MAKE cscope + +: -- 2.47.2