From a3bdc2c2a5dbb6fd7f7f655f6970f7559dca0497 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Sun, 18 Dec 2005 22:46:35 +0000 Subject: [PATCH] Handle a couple of use cases discussed in python-dev w.r.t. calculating the Subversion revision number. First, in an svn export, there will be no .svn directory, so use an in-file $Revision$ keyword string with the keyword chrome stripped off. Also, use $(srcdir) in the Makefile.pre.in to handle the case where Python is build outside the source tree. --- Makefile.pre.in | 15 ++++++++------- Modules/getbuildinfo.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/Makefile.pre.in b/Makefile.pre.in index 0ce2afa685b..020c86ed39c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -349,12 +349,9 @@ buildno: $(PARSER_OBJS) \ $(SIGNAL_OBJS) \ $(MODOBJS) \ $(srcdir)/Modules/getbuildinfo.c - if test -d .svn; then \ - svnversion . >buildno; \ - elif test -f buildno; then \ - expr `cat buildno` + 1 >buildno1; \ - mv -f buildno1 buildno; \ - else echo 1 >buildno; fi + if test -d $(srcdir)/.svn; then \ + svnversion $(srcdir) >buildno; \ + fi # Build static library # avoid long command lines, same as LIBRARY_OBJS @@ -446,7 +443,11 @@ Modules/Setup: $(srcdir)/Modules/Setup.dist # Special rules for object files Modules/getbuildinfo.o: $(srcdir)/Modules/getbuildinfo.c buildno - $(CC) -c $(PY_CFLAGS) -DBUILD=\"`cat buildno`\" -o $@ $(srcdir)/Modules/getbuildinfo.c + if test -f buildno; then \ + $(CC) -c $(PY_CFLAGS) -DBUILD=\"`cat buildno`\" -o $@ $(srcdir)/Modules/getbuildinfo.c ;\ + else \ + $(CC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/getbuildinfo.c ;\ + fi Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile $(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \ diff --git a/Modules/getbuildinfo.c b/Modules/getbuildinfo.c index 8b1ca22f3ab..446340badbf 100644 --- a/Modules/getbuildinfo.c +++ b/Modules/getbuildinfo.c @@ -21,20 +21,38 @@ #endif #ifndef BUILD -#define BUILD "0" +#define BUILD "$Revision$" #endif +const char * +Py_GetBuildNumber(void) +{ + static char buildno[20]; + static int buildno_okay; + + if (!buildno_okay) { + char *build = BUILD; + int len = strlen(build); + + if (len > 13 && + !strncmp(build, "$Revision: ", 11) && + !strcmp(build + len - 2, " $")) + { + memcpy(buildno, build + 11, len - 13); + } + else { + memcpy(buildno, build, 19); + } + buildno_okay = 1; + } + return buildno; +} + const char * Py_GetBuildInfo(void) { static char buildinfo[50]; PyOS_snprintf(buildinfo, sizeof(buildinfo), - "%s, %.20s, %.9s", BUILD, DATE, TIME); + "#%s, %.20s, %.9s", Py_GetBuildNumber(), DATE, TIME); return buildinfo; } - -const char * -Py_GetBuildNumber(void) -{ - return BUILD; -}