Skip to content

Commit 3a5508e

Browse files
committed
Port build identification from default branch.
1 parent 93512f2 commit 3a5508e

File tree

6 files changed

+120
-5
lines changed

6 files changed

+120
-5
lines changed

Include/pythonrun.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
114114
PyAPI_FUNC(const char *) _Py_svnversion(void);
115115
PyAPI_FUNC(const char *) Py_SubversionRevision(void);
116116
PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
117+
PyAPI_FUNC(const char *) _Py_hgidentifier(void);
118+
PyAPI_FUNC(const char *) _Py_hgversion(void);
117119

118120
/* Internal -- various one-time initializations */
119121
PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);

Makefile.pre.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ LINKCC= @LINKCC@
3535
AR= @AR@
3636
RANLIB= @RANLIB@
3737
SVNVERSION= @SVNVERSION@
38+
HGVERSION= @HGVERSION@
39+
HGTAG= @HGTAG@
40+
HGBRANCH= @HGBRANCH@
3841

3942
GNULD= @GNULD@
4043

@@ -522,7 +525,12 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
522525
$(SIGNAL_OBJS) \
523526
$(MODOBJS) \
524527
$(srcdir)/Modules/getbuildinfo.c
525-
$(CC) -c $(PY_CFLAGS) -DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" -o $@ $(srcdir)/Modules/getbuildinfo.c
528+
$(CC) -c $(PY_CFLAGS) \
529+
-DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" \
530+
-DHGVERSION="\"`LC_ALL=C $(HGVERSION)`\"" \
531+
-DHGTAG="\"`LC_ALL=C $(HGTAG)`\"" \
532+
-DHGBRANCH="\"`LC_ALL=C $(HGBRANCH)`\"" \
533+
-o $@ $(srcdir)/Modules/getbuildinfo.c
526534

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

Modules/getbuildinfo.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,28 @@
2828
#define SVNVERSION "$WCRANGE$$WCMODS?M:$"
2929
#endif
3030

31+
/* XXX Only unix build process has been tested */
32+
#ifndef HGVERSION
33+
#define HGVERSION ""
34+
#endif
35+
#ifndef HGTAG
36+
#define HGTAG ""
37+
#endif
38+
#ifndef HGBRANCH
39+
#define HGBRANCH ""
40+
#endif
41+
3142
const char *
3243
Py_GetBuildInfo(void)
3344
{
3445
static char buildinfo[50];
35-
const char *revision = Py_SubversionRevision();
46+
const char *revision = _Py_hgversion();
3647
const char *sep = *revision ? ":" : "";
37-
const char *branch = Py_SubversionShortBranch();
48+
const char *hgid = _Py_hgidentifier();
49+
if (!(*hgid))
50+
hgid = "default";
3851
PyOS_snprintf(buildinfo, sizeof(buildinfo),
39-
"%s%s%s, %.20s, %.9s", branch, sep, revision,
52+
"%s%s%s, %.20s, %.9s", hgid, sep, revision,
4053
DATE, TIME);
4154
return buildinfo;
4255
}
@@ -50,3 +63,21 @@ _Py_svnversion(void)
5063
return svnversion; /* it was interpolated, or passed on command line */
5164
return "Unversioned directory";
5265
}
66+
67+
const char *
68+
_Py_hgversion(void)
69+
{
70+
return HGVERSION;
71+
}
72+
73+
const char *
74+
_Py_hgidentifier(void)
75+
{
76+
const char *hgtag, *hgid;
77+
hgtag = HGTAG;
78+
if ((*hgtag) && strcmp(hgtag, "tip") != 0)
79+
hgid = hgtag;
80+
else
81+
hgid = HGBRANCH;
82+
return hgid;
83+
}

Python/sysmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,9 @@ _PySys_Init(void)
14621462
SET_SYS_FROM_STRING("subversion",
14631463
Py_BuildValue("(ssz)", "CPython", branch,
14641464
svn_revision));
1465+
SET_SYS_FROM_STRING("_mercurial",
1466+
Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
1467+
_Py_hgversion()));
14651468
SET_SYS_FROM_STRING("dont_write_bytecode",
14661469
PyBool_FromLong(Py_DontWriteBytecodeFlag));
14671470
SET_SYS_FROM_STRING("api_version",

configure

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 88568 .
2+
# From configure.in Revision.
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.68 for python 2.7.
55
#
@@ -643,6 +643,10 @@ LN
643643
INSTALL_DATA
644644
INSTALL_SCRIPT
645645
INSTALL_PROGRAM
646+
HAS_HG
647+
HGBRANCH
648+
HGTAG
649+
HGVERSION
646650
SVNVERSION
647651
ARFLAGS
648652
AR
@@ -5169,6 +5173,58 @@ else
51695173
SVNVERSION="echo Unversioned directory"
51705174
fi
51715175
5176+
5177+
5178+
5179+
# Extract the first word of "hg", so it can be a program name with args.
5180+
set dummy hg; ac_word=$2
5181+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
5182+
$as_echo_n "checking for $ac_word... " >&6; }
5183+
if ${ac_cv_prog_HAS_HG+:} false; then :
5184+
$as_echo_n "(cached) " >&6
5185+
else
5186+
if test -n "$HAS_HG"; then
5187+
ac_cv_prog_HAS_HG="$HAS_HG" # Let the user override the test.
5188+
else
5189+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
5190+
for as_dir in $PATH
5191+
do
5192+
IFS=$as_save_IFS
5193+
test -z "$as_dir" && as_dir=.
5194+
for ac_exec_ext in '' $ac_executable_extensions; do
5195+
if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
5196+
ac_cv_prog_HAS_HG="found"
5197+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
5198+
break 2
5199+
fi
5200+
done
5201+
done
5202+
IFS=$as_save_IFS
5203+
5204+
test -z "$ac_cv_prog_HAS_HG" && ac_cv_prog_HAS_HG="not-found"
5205+
fi
5206+
fi
5207+
HAS_HG=$ac_cv_prog_HAS_HG
5208+
if test -n "$HAS_HG"; then
5209+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAS_HG" >&5
5210+
$as_echo "$HAS_HG" >&6; }
5211+
else
5212+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
5213+
$as_echo "no" >&6; }
5214+
fi
5215+
5216+
5217+
if test $HAS_HG = found
5218+
then
5219+
HGVERSION="hg id -i \$(srcdir)"
5220+
HGTAG="hg id -t \$(srcdir)"
5221+
HGBRANCH="hg id -b \$(srcdir)"
5222+
else
5223+
HGVERSION=""
5224+
HGTAG=""
5225+
HGBRANCH=""
5226+
fi
5227+
51725228
case $MACHDEP in
51735229
bsdos*|hp*|HP*)
51745230
# install -d does not work on BSDI or HP-UX

configure.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,21 @@ else
853853
SVNVERSION="echo Unversioned directory"
854854
fi
855855

856+
AC_SUBST(HGVERSION)
857+
AC_SUBST(HGTAG)
858+
AC_SUBST(HGBRANCH)
859+
AC_CHECK_PROG(HAS_HG, hg, found, not-found)
860+
if test $HAS_HG = found
861+
then
862+
HGVERSION="hg id -i \$(srcdir)"
863+
HGTAG="hg id -t \$(srcdir)"
864+
HGBRANCH="hg id -b \$(srcdir)"
865+
else
866+
HGVERSION=""
867+
HGTAG=""
868+
HGBRANCH=""
869+
fi
870+
856871
case $MACHDEP in
857872
bsdos*|hp*|HP*)
858873
# install -d does not work on BSDI or HP-UX

0 commit comments

Comments
 (0)