Skip to content

Commit

Permalink
Merge pull request #3594 from masatake/output-versioning
Browse files Browse the repository at this point in the history
main: output versioning and shorten output mode for --version
  • Loading branch information
masatake committed Dec 14, 2022
2 parents ebc90c2 + 0a2c667 commit 2fd9b0c
Show file tree
Hide file tree
Showing 30 changed files with 132 additions and 82 deletions.
1 change: 1 addition & 0 deletions Tmain/extras-field-for-pseudo-tags.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ run_ctags()
--pseudo-tags=-TAG_PROGRAM_VERSION \
--pseudo-tags=-TAG_PROC_CWD \
--pseudo-tags=-TAG_PARSER_VERSION \
--pseudo-tags=-TAG_OUTPUT_VERSION \
$@ \
-o - input.c
}
Expand Down
1 change: 1 addition & 0 deletions Tmain/input-encoding-option.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if ${CTAGS} --quiet --options=NONE --list-features | grep -q iconv; then
--pseudo-tags=-TAG_FIELD_DESCRIPTION \
--pseudo-tags=-TAG_ROLE_DESCRIPTION \
--pseudo-tags=-TAG_PARSER_VERSION \
--pseudo-tags=-TAG_OUTPUT_VERSION \
--input-encoding=utf-8 --input-encoding-java=shift_jis --input-encoding-javascript=euc-jp \
-o ${BUILDDIR}/tags \
input.js input.java ; then
Expand Down
17 changes: 8 additions & 9 deletions Tmain/interactive-mode.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,42 @@ is_feature_available ${CTAGS} interactive
# It seems that the output format is slightly different between libjansson versions
s()
{
sed -e s/':"'/': "'/g
sed -e s/':"'/': "'/g | jdropver
}

CTAGS="$CTAGS --options=NONE"
NV="--pseudo-tags=-TAG_PROGRAM_VERSION"

echo identification message on startup
echo =======================================
${CTAGS} --_interactive $NV < /dev/null |s
${CTAGS} --_interactive < /dev/null |s

echo
echo error on invalid command
echo =======================================
echo '{"command":"foobar"}' | ${CTAGS} --_interactive $NV |s
echo '{"command":"foobar"}' | ${CTAGS} --_interactive |s

echo
echo error on missing arguments
echo =======================================
echo '{"command":"generate-tags"}' | ${CTAGS} --_interactive $NV |s
echo '{"command":"generate-tags"}' | ${CTAGS} --_interactive |s

echo
echo error on invalid file
echo =======================================
echo '{"command":"generate-tags", "filename":"test.foo"}' | ${CTAGS} --_interactive $NV |s
echo '{"command":"generate-tags", "filename":"test.foo"}' | ${CTAGS} --_interactive |s

echo
echo generate tags from file
echo =======================================
echo '{"command":"generate-tags", "filename":"test.rb"}' | ${CTAGS} --_interactive $NV |s
echo '{"command":"generate-tags", "filename":"test.rb"}' | ${CTAGS} --_interactive |s

echo
echo process multiple commands
echo =======================================
(
echo '{"command":"generate-tags", "filename":"test.rb"}'
echo '{"command":"generate-tags", "filename":"test.c"}'
) | ${CTAGS} --_interactive $NV |s
) | ${CTAGS} --_interactive |s

echo
echo generate tags from data
Expand All @@ -54,4 +53,4 @@ size=$(filesize test.rb)
(
echo '{"command":"generate-tags", "filename":"foobar.rb", "size":'$size'}'
cat test.rb
) | ${CTAGS} --_interactive $NV |s
) | ${CTAGS} --_interactive |s
2 changes: 1 addition & 1 deletion Tmain/interactive-notice-output.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CTAGS=$1
# It seems that the output format is slightly different between libjansson versions
s()
{
sed -e s/':"'/': "'/g
sed -e s/':"'/': "'/g | jdropver
}

if is_feature_available ${CTAGS} json; then
Expand Down
5 changes: 2 additions & 3 deletions Tmain/interactive-option-write-to-file.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ is_feature_available ${CTAGS} interactive
# It seems that the output format is slightly different between libjansson versions
s()
{
sed -e s/':"'/': "'/g
sed -e s/':"'/': "'/g | jdropver
}

O=/tmp/ctags-tmain-$$.txt

echo '{"command":"generate-tags", "filename":"test.rb"}' | ${CTAGS} --quiet --options=NONE --_interactive -o ${O} \
--pseudo-tags=-TAG_PROGRAM_VERSION |s
echo '{"command":"generate-tags", "filename":"test.rb"}' | ${CTAGS} --quiet --options=NONE --_interactive -o ${O} |s

rm -f ${O}
1 change: 1 addition & 0 deletions Tmain/json-output-format.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if is_feature_available "${CTAGS}" json; then
run_with_format json --languages=+man --fields="*"-T --extras='*'
} | cat \
| grep -v TAG_PROGRAM_VERSION \
| grep -v TAG_OUTPUT_VERSION \
| grep -v TAG_OUTPUT_FILESEP \
| grep -v TAG_PROC_CWD
fi
1 change: 1 addition & 0 deletions Tmain/list-pseudo-tags.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TAG_KIND_SEPARATOR off the separators used in kinds
TAG_OUTPUT_EXCMD on the excmd: number, pattern, mixed, or combine
TAG_OUTPUT_FILESEP on the separator used in file name (slash or backslash)
TAG_OUTPUT_MODE on the output mode: u-ctags or e-ctags
TAG_OUTPUT_VERSION on the version of the output interface (current.age)
TAG_PARSER_VERSION on the version of the parser (current.age)
TAG_PATTERN_LENGTH_LIMIT on the limit of pattern length
TAG_PROC_CWD on the current working directory of the tags generator
Expand Down
3 changes: 2 additions & 1 deletion Tmain/output-encoding-option.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ if ${CTAGS} --quiet --options=NONE --list-features | grep -q iconv; then
check_encoding euc-jp
if ${CTAGS} --quiet --options=NONE \
--pseudo-tags=-TAG_PROC_CWD \
--pseudo-tags=-TAG_PROGRAM_VERSION \
--pseudo-tags=-TAG_PROGRAM_VERSION \
--pseudo-tags=-TAG_KIND_DESCRIPTION \
--pseudo-tags=-TAG_FIELD_DESCRIPTION \
--pseudo-tags=-TAG_EXTRA_DESCRIPTION \
--pseudo-tags=-TAG_ROLE_DESCRIPTION \
--pseudo-tags=-TAG_PARSER_VERSION \
--pseudo-tags=-TAG_OUTPUT_VERSION \
--output-encoding=shift_jis --input-encoding=utf-8 --input-encoding-javascript=euc-jp \
-o ${BUILDDIR}/tags \
input.js input.java ; then
Expand Down
1 change: 1 addition & 0 deletions Tmain/ptag-kind-sep.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ ${CTAGS} --quiet --options=NONE -o - \
--pseudo-tags=-TAG_EXTRA_DESCRIPTION \
--pseudo-tags=-TAG_ROLE_DESCRIPTION \
--pseudo-tags=-TAG_PARSER_VERSION \
--pseudo-tags=-TAG_OUTPUT_VERSION \
input.php
9 changes: 5 additions & 4 deletions Tmain/sandbox-crash.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ is_feature_available ${CTAGS} '!' gcov
{
echo '{"command":"generate-tags", "filename":"input.ctst", "size": 1}'
echo 'P'
} | $CTAGS --quiet --options=NONE --language-force=CTagsSelfTest --_interactive=sandbox \
--pseudo-tags=-TAG_PROGRAM_VERSION

exit $?
} | $CTAGS --quiet --options=NONE --language-force=CTagsSelfTest --_interactive=sandbox > /tmp/ctags-Tmain-$$
r=$?
jdropver < /tmp/ctags-Tmain-$$
rm /tmp/ctags-Tmain-$$
exit $r
9 changes: 5 additions & 4 deletions Tmain/sandbox-default-req.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ is_feature_available ${CTAGS} '!' gcov
echo '{"command":"generate-tags", "filename":"input.c", "size": -1}'
echo '{"command":"generate-tags", "filename":"input.el", "size": 16}'
echo '(defun foo () 0)'
} | $CTAGS --quiet --options=NONE --_interactive=sandbox \
--pseudo-tags=-TAG_PROGRAM_VERSION

exit $?
} | $CTAGS --quiet --options=NONE --_interactive=sandbox > /tmp/ctags-Tmain-$$
r=$?
jdropver < /tmp/ctags-Tmain-$$
rm /tmp/ctags-Tmain-$$
exit $r
9 changes: 5 additions & 4 deletions Tmain/sandbox-no-eager-guessing.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ is_feature_available ${CTAGS} '!' gcov
{
echo '{"command":"generate-tags", "filename":"input.unknown", "size": 44}'
echo '/* -*- c -*- */ int main(void) { return 0; }'
} | $CTAGS --quiet --options=NONE --_interactive=sandbox \
--pseudo-tags=-TAG_PROGRAM_VERSION

exit $?
} | $CTAGS --quiet --options=NONE --_interactive=sandbox > /tmp/ctags-Tmain-$$
r=$?
jdropver < /tmp/ctags-Tmain-$$
rm /tmp/ctags-Tmain-$$
exit $r
1 change: 0 additions & 1 deletion Tmain/sandbox-version.d/exit-expected.txt

This file was deleted.

22 changes: 0 additions & 22 deletions Tmain/sandbox-version.d/run.sh

This file was deleted.

Empty file.
3 changes: 0 additions & 3 deletions Tmain/sandbox-version.d/stdout-expected.txt

This file was deleted.

9 changes: 5 additions & 4 deletions Tmain/sandbox-with-eager-guessing.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ is_feature_available ${CTAGS} '!' gcov
{
echo '{"command":"generate-tags", "filename":"input.unknown", "size": 44}'
echo '/* -*- c -*- */ int main(void) { return 0; }'
} | $CTAGS --quiet --options=NONE -G --_interactive=sandbox \
--pseudo-tags=-TAG_PROGRAM_VERSION

exit $?
} | $CTAGS --quiet --options=NONE -G --_interactive=sandbox > /tmp/ctags-Tmain-$$
r=$?
jdropver < /tmp/ctags-Tmain-$$
rm /tmp/ctags-Tmain-$$
exit $r
9 changes: 5 additions & 4 deletions Tmain/sandbox.d/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ is_feature_available ${CTAGS} '!' gcov
{
echo '{"command":"generate-tags", "filename":"input.c", "size": 28}'
echo 'int main(void) { return 0; }'
} | $CTAGS --quiet --options=NONE --_interactive=sandbox \
--pseudo-tags=-TAG_PROGRAM_VERSION

exit $?
} | $CTAGS --quiet --options=NONE --_interactive=sandbox > /tmp/ctags-Tmain-$$
r=$?
jdropver < /tmp/ctags-Tmain-$$
rm /tmp/ctags-Tmain-$$
exit $r
5 changes: 5 additions & 0 deletions Tmain/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,8 @@ check_encoding()
fi
skip "iconv doesn't know about the encoding: $1"
}

jdropver()
{
sed -e 's/, "version": "5.9.0"//'
}
12 changes: 12 additions & 0 deletions docs/man/ctags-client-tools.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ for using notable ones.
``TAG_OUTPUT_MODE`` (new in Universal Ctags)
TBW

``TAG_OUTPUT_VERSION`` (new in Universal Ctags 6.0)
Indicates the language-common interface version of the output::

!_TAG_OUTPUT_VERSION {current}.{age} /.../

The public interface includes common fields, common extras,
pseudo tags.

The maintainer of Universal Ctags may update the numbers,
"{current}" and "{age}" in the same manner as explained
in ``TAG_PARSER_VERSION``.

``TAG_PARSER_VERSION`` (new in Universal Ctags 6.0)
Indicates the interface version of the parser::

Expand Down
2 changes: 1 addition & 1 deletion docs/man/ctags-json-output.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ For an example, the value for ``pattern`` field of ctags takes a string or a boo
VERSIONS
--------

Cnages since "0.0"
Change since "0.0"
~~~~~~~~~~~~~~~~~~

* New key ``kindName`` for ``TAG_ROLE_DESCRIPTION`` pseudo tag
Expand Down
8 changes: 5 additions & 3 deletions docs/man/ctags.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1327,11 +1327,13 @@ Miscellaneous Options
``-V``
Equivalent to ``--verbose``.

``--version[=<language>]``
``--version[=<language>|NONE]``
Prints a version identifier for ctags to standard
output, and then exits. This is guaranteed to always contain the string
"Universal Ctags". See also the description for ``TAG_PROGRAM_VERSION`` in
:ref:`ctags-client-tools(7) <ctags-client-tools(7)>`.
"Universal Ctags". See also the description for ``TAG_PROGRAM_VERSION``
and ``TAG_OUTPUT_VERSION`` in :ref:`ctags-client-tools(7) <ctags-client-tools(7)>`.

If ``NONE`` is given, prints the version identifier in a simplified way.

If *<language>* is given, print the version identifier for the parser
for *<language>*. See also the description for ``TAG_PARSER_VERSION`` in
Expand Down
26 changes: 23 additions & 3 deletions main/ctags.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
of ctags or readtags commands, increment VERSION.
Removing a parameter of a parser is part of incompatible change
for the CLI.
When OUTPUT_VERSOIN_AGE set to 0, increment VERSION. Set REVISION
When OUTPUT_VERSION_AGE set to 0, increment VERSION. Set REVISION
and PATCH to 0.
For changing setting versionAge member of a parser, increment
VERSION. Set REVISION and PATCH to 0.
Expand All @@ -30,8 +30,8 @@
For uppper compatible changes for the CLI,
increment REVISION.
Adding a new parameter to a parser is an uppper compatible change.
When incrementing OUTPUT_VERSOIN_CURRENT but not setting
OUTPUT_VERSOIN_AGE to 0, increment REVISION.
When incrementing OUTPUT_VERSION_CURRENT but not setting
OUTPUT_VERSION_AGE to 0, increment REVISION.
For changing increment versionCurrent member of a parser but not
setting versionAge to 0, increment REVISION.
When changing REVISION, set PATCH to 0.
Expand All @@ -48,6 +48,26 @@
#define PROGRAM_COPYRIGHT "Copyright (C) 2015-2022"
#define AUTHOR_NAME "Universal Ctags Team"

/* The concept of CURRENT and AGE is taken from libtool.
* However, we deleted REVISION in libtool when importing
* the concept of versioning from libtool.
*
* If common fields, common extras, pseudo tags have been added,
* removed or changed since last release, increment CURRENT.
* If they have been added since last release, increment AGE.
* If they have been removed since last release, set AGE to 0
*
* From the command line of ctags, you can see the version
* information with --version and --version=NONE.
*
* In the tags file, !_TAGS_OUTPUT_VERSION shows the the version.
*
* Chaning for the command line interface, and implementation changes
* like bug fixes don't affect the CURRENT an AGE.
*/
#define OUTPUT_VERSION_CURRENT 0
#define OUTPUT_VERSION_AGE 0

/*
* Constant
*/
Expand Down
12 changes: 1 addition & 11 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include "options_p.h"
#include "optscript.h"
#include "parse_p.h"
#include "ptag_p.h"
#include "read_p.h"
#include "routines_p.h"
#include "stats_p.h"
Expand Down Expand Up @@ -416,16 +415,7 @@ void interactiveLoop (cookedArgs *args CTAGS_ATTR_UNUSED, void *user)
char buffer[1024];
json_t *request;

if (isPtagEnabled(PTAG_PROGRAM_NAME))
{
if (isPtagEnabled(PTAG_PROGRAM_VERSION))
fputs ("{\"_type\": \"program\", \"name\": \"" PROGRAM_NAME "\", \"version\": \"" PROGRAM_VERSION "\"}\n", stdout);
else
fputs ("{\"_type\": \"program\", \"name\": \"" PROGRAM_NAME "\"}\n", stdout);
}
else if (isPtagEnabled(PTAG_PROGRAM_VERSION))
fputs ("{\"_type\": \"program\", \"version\": \"" PROGRAM_VERSION "\"}\n", stdout);

fputs ("{\"_type\": \"program\", \"name\": \"" PROGRAM_NAME "\", \"version\": \"" PROGRAM_VERSION "\"}\n", stdout);
fflush (stdout);

while (fgets (buffer, sizeof(buffer), stdin))
Expand Down
10 changes: 10 additions & 0 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,8 @@ static void printProgramIdentification (void)

printf (" Compiled: %s, %s\n", __DATE__, __TIME__);
printf (" URL: %s\n", PROGRAM_URL);
printf (" Output version: %d.%d\n",
OUTPUT_VERSION_CURRENT, OUTPUT_VERSION_AGE);

printFeatureList ();
}
Expand Down Expand Up @@ -2685,6 +2687,14 @@ static void processVersionOption (
{
if (parameter == NULL || *parameter == '\0')
printProgramIdentification ();
else if (strcmp (parameter, RSV_NONE) == 0)
{
printf("ctags: %s\n", PROGRAM_VERSION);
if (! ((ctags_repoinfo == NULL)
|| (strcmp (ctags_repoinfo, PROGRAM_VERSION) == 0)))
printf("repoinfo: %s\n", ctags_repoinfo);
printf("output: %d.%d\n", OUTPUT_VERSION_CURRENT, OUTPUT_VERSION_AGE);
}
else
{
langType language = getNamedLanguage (parameter, 0);
Expand Down
Loading

0 comments on commit 2fd9b0c

Please sign in to comment.