Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3bdc2c

Browse files
committed
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.
1 parent d24499d commit a3bdc2c

2 files changed

Lines changed: 34 additions & 15 deletions

File tree

Makefile.pre.in

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,9 @@ buildno: $(PARSER_OBJS) \
349349
$(SIGNAL_OBJS) \
350350
$(MODOBJS) \
351351
$(srcdir)/Modules/getbuildinfo.c
352-
if test -d .svn; then \
353-
svnversion . >buildno; \
354-
elif test -f buildno; then \
355-
expr `cat buildno` + 1 >buildno1; \
356-
mv -f buildno1 buildno; \
357-
else echo 1 >buildno; fi
352+
if test -d $(srcdir)/.svn; then \
353+
svnversion $(srcdir) >buildno; \
354+
fi
358355

359356
# Build static library
360357
# avoid long command lines, same as LIBRARY_OBJS
@@ -446,7 +443,11 @@ Modules/Setup: $(srcdir)/Modules/Setup.dist
446443
# Special rules for object files
447444

448445
Modules/getbuildinfo.o: $(srcdir)/Modules/getbuildinfo.c buildno
449-
$(CC) -c $(PY_CFLAGS) -DBUILD=\"`cat buildno`\" -o $@ $(srcdir)/Modules/getbuildinfo.c
446+
if test -f buildno; then \
447+
$(CC) -c $(PY_CFLAGS) -DBUILD=\"`cat buildno`\" -o $@ $(srcdir)/Modules/getbuildinfo.c ;\
448+
else \
449+
$(CC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/getbuildinfo.c ;\
450+
fi
450451

451452
Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
452453
$(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \

Modules/getbuildinfo.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,38 @@
2121
#endif
2222

2323
#ifndef BUILD
24-
#define BUILD "0"
24+
#define BUILD "$Revision$"
2525
#endif
2626

2727
const char *
28-
Py_GetBuildInfo(void)
28+
Py_GetBuildNumber(void)
2929
{
30-
static char buildinfo[50];
31-
PyOS_snprintf(buildinfo, sizeof(buildinfo),
32-
"%s, %.20s, %.9s", BUILD, DATE, TIME);
33-
return buildinfo;
30+
static char buildno[20];
31+
static int buildno_okay;
32+
33+
if (!buildno_okay) {
34+
char *build = BUILD;
35+
int len = strlen(build);
36+
37+
if (len > 13 &&
38+
!strncmp(build, "$Revision: ", 11) &&
39+
!strcmp(build + len - 2, " $"))
40+
{
41+
memcpy(buildno, build + 11, len - 13);
42+
}
43+
else {
44+
memcpy(buildno, build, 19);
45+
}
46+
buildno_okay = 1;
47+
}
48+
return buildno;
3449
}
3550

3651
const char *
37-
Py_GetBuildNumber(void)
52+
Py_GetBuildInfo(void)
3853
{
39-
return BUILD;
54+
static char buildinfo[50];
55+
PyOS_snprintf(buildinfo, sizeof(buildinfo),
56+
"#%s, %.20s, %.9s", Py_GetBuildNumber(), DATE, TIME);
57+
return buildinfo;
4058
}

0 commit comments

Comments
 (0)