Skip to content

Commit

Permalink
buildsys: embed the current git commit id(or tag) to ctags binary
Browse files Browse the repository at this point in the history
If configure is used for building and building is done in
a git repository, git commit id is embedded to ctags
executable (as before). The id can be seen in the output
of `ctags --version' or in __TAG_PROGRAM_VERSION pseudo tag
in a tags file.

If ctags built on a platform where configure is not used,
the id is set to 0. If ctags at the outside of a git repository,
the id is set to 0.

This feature will be used in regression test I'm designing now.

For tagged version, embed the tag instead of commit id.
Suggested by @k-takata.

Signed-off-by: Masatake YAMATO <[email protected]>
  • Loading branch information
masatake committed Dec 15, 2015
1 parent 13419d4 commit c409ec9
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mkinstalldirs
perf.data*
readtags
readtags.exe
repoinfo.h
respmvc
stamp-h1
STDERR.*
Expand Down
15 changes: 15 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,28 @@ ctags_CPPFLAGS = -I. -I$(srcdir) -I$(srcdir)/main
ctags_CPPFLAGS+= $(DEBUG_CPPFLAGS)
ctags_CPPFLAGS+= $(FNMATCH_CPPFLAGS)
ctags_CPPFLAGS+= $(REGCOMP_CPPFLAGS)
ctags_CPPFLAGS+= -DHAVE_REPOINFO_H

ctags_CFLAGS = -g -O2
ctags_CFLAGS += $(EXTRA_CFLAGS)
ctags_CFLAGS += $(WARNING_CFLAGS)
ctags_CFLAGS += $(COVERAGE_CFLAGS)
ctags_CFLAGS += $(CGCC_CFLAGS)

nodist_ctags_SOURCES = $(REPOINFO_HEADS)
BUILT_SOURCES = $(REPOINFO_HEADS)
CLEANFILES = $(REPOINFO_HEADS)
$(REPOINFO_OBJS): $(REPOINFO_SRCS) $(REPOINFO_HEADS)
if BUILD_IN_GIT_REPO
GEN_REPOINFO = $(srcdir)/misc/gen-repoinfo
$(REPOINFO_HEADS): $(srcdir)/.git/*
$(GEN_REPOINFO) > $@
endif
if !BUILD_IN_GIT_REPO
$(REPOINFO_HEADS):
echo 0 > $@
endif

OPTLIB2C = $(srcdir)/misc/optlib2c
.ctags.c: $(OPTLIB2C)
$(OPTLIB2C) $< > $@
Expand Down
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,19 @@ fi

# Checks for operating environment
# --------------------------------
in_git_repo=no
AC_MSG_CHECKING(building in a git repository)
if test -f "${srcdir}/.git/HEAD"; then
in_git_repo=yes
fi
AC_MSG_RESULT(${in_git_repo})

AC_CHECK_PROGS([GIT], [git])
if ! test "${GIT+set}" = "set"; then
in_git_repo=no
fi
AM_CONDITIONAL([BUILD_IN_GIT_REPO], [test "x${in_git_repo}" = "xyes"])


# Check for temporary directory
AC_MSG_CHECKING(directory to use for temporary files)
Expand Down
5 changes: 5 additions & 0 deletions main/ctags.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#define PROGRAM_COPYRIGHT "Copyright (C) 2015"
#define AUTHOR_NAME "Universal Ctags Team"

/*
* Constant
*/
extern const char* ctags_repoinfo;

#endif /* CTAGS_MAIN_CTAGS_H */

/* vi:set tabstop=4 shiftwidth=4: */
9 changes: 3 additions & 6 deletions main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static void addPseudoTags (void)
{
char format [11];
const char *formatComment = "unknown format";
char commit_id [8] = "";
const char* repoinfo;

sprintf (format, "%u", Option.tagFileFormat);

Expand All @@ -187,11 +187,8 @@ static void addPseudoTags (void)
writePseudoTag ("TAG_PROGRAM_AUTHOR", AUTHOR_NAME, "", NULL);
writePseudoTag ("TAG_PROGRAM_NAME", PROGRAM_NAME, "Derived from Exuberant Ctags", NULL);
writePseudoTag ("TAG_PROGRAM_URL", PROGRAM_URL, "official site", NULL);

#if defined(CTAGS_COMMIT_ID) && CTAGS_COMMIT_ID != 0
snprintf (commit_id, sizeof (commit_id), "%.7x", CTAGS_COMMIT_ID);
#endif
writePseudoTag ("TAG_PROGRAM_VERSION", PROGRAM_VERSION, commit_id, NULL);
repoinfo = ctags_repoinfo? ctags_repoinfo: "";
writePseudoTag ("TAG_PROGRAM_VERSION", PROGRAM_VERSION, repoinfo, NULL);

#ifdef HAVE_ICONV
if (Option.outputEncoding)
Expand Down
17 changes: 8 additions & 9 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,15 +1188,14 @@ static void processListFieldsOption(const char *const option __unused__,

static void printProgramIdentification (void)
{
printf (
#if defined(CTAGS_COMMIT_ID) && CTAGS_COMMIT_ID != 0
"%s %s(%.7x), %s %s\n",
PROGRAM_NAME, PROGRAM_VERSION, CTAGS_COMMIT_ID,
#else
"%s %s, %s %s\n",
PROGRAM_NAME, PROGRAM_VERSION,
#endif
PROGRAM_COPYRIGHT, AUTHOR_NAME);
if (ctags_repoinfo)
printf ("%s %s(%s), %s %s\n",
PROGRAM_NAME, PROGRAM_VERSION, ctags_repoinfo,
PROGRAM_COPYRIGHT, AUTHOR_NAME);
else
printf ("%s %s, %s %s\n",
PROGRAM_NAME, PROGRAM_VERSION,
PROGRAM_COPYRIGHT, AUTHOR_NAME);
printf ("Universal Ctags is derived from Exuberant Ctags.\n");
printf ("Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert\n");

Expand Down
8 changes: 8 additions & 0 deletions main/repoinfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "general.h"
#include "ctags.h"
#ifdef HAVE_REPOINFO_H
#include "main/repoinfo.h"
#else
#define CTAGS_REPOINFO ((char*)0)
#endif
const char* ctags_repoinfo = CTAGS_REPOINFO;
4 changes: 4 additions & 0 deletions misc/gen-repoinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
rinfo=`git describe --tag --exact-match HEAD 2> /dev/null || git rev-parse --short HEAD`
echo "#define CTAGS_REPOINFO \"${rinfo}\""

14 changes: 13 additions & 1 deletion source.mak
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Shared macros

# REPOINFO_HEADS is included from REPOINFO_SRCS
# only when the building environment has ability
# to generate the header file.
# REPOINFO_OBJS is always linked to ctags executable.
REPOINFO_HEADS = main/repoinfo.h
REPOINFO_SRCS = main/repoinfo.c
REPOINFO_OBJS = $(REPOINFO_SRCS:.c=.$(OBJEXT))

MAIN_HEADS = \
main/args.h \
main/ctags.h \
Expand Down Expand Up @@ -51,7 +59,11 @@ MAIN_SRCS = \
main/sort.c \
main/strlist.c \
main/vstring.c \
main/xtag.c
main/xtag.c \
\
$(REPOINFO_SRCS) \
\
$(NULL)

include makefiles/translator_input.mak
TRANSLATED_SRCS = $(TRANSLATOR_INPUT:.ctags=.c)
Expand Down
1 change: 1 addition & 0 deletions win32/ctags_vs2013.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">TurnOffAllWarnings</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">TurnOffAllWarnings</WarningLevel>
</ClCompile>
<ClCompile Include="..\main\repoinfo.c" />
<ClCompile Include="..\parsers\rst.c" />
<ClCompile Include="..\parsers\r.c" />
<ClCompile Include="..\parsers\rexx.c" />
Expand Down
3 changes: 3 additions & 0 deletions win32/ctags_vs2013.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@
<ClCompile Include="..\main\xtag.c">
<Filter>Source Files\Main</Filter>
</ClCompile>
<ClCompile Include="..\main\repoinfo.c">
<Filter>Source Files\Main</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\main\e_msoft.h">
Expand Down

0 comments on commit c409ec9

Please sign in to comment.