Skip to content

Commit 13039c8

Browse files
committed
Merge build identification to 3.2 branch.
2 parents 80d3610 + 8256242 commit 13039c8

File tree

8 files changed

+128
-7
lines changed

8 files changed

+128
-7
lines changed

Include/pythonrun.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
182182
PyAPI_FUNC(const char *) _Py_svnversion(void);
183183
PyAPI_FUNC(const char *) Py_SubversionRevision(void);
184184
PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
185+
PyAPI_FUNC(const char *) _Py_hgidentifier(void);
186+
PyAPI_FUNC(const char *) _Py_hgversion(void);
185187
#endif
186188

187189
/* Internal -- various one-time initializations */

Lib/platform.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,9 @@ def _sys_version(sys_version=None):
13921392
name = 'CPython'
13931393
builddate = builddate + ' ' + buildtime
13941394

1395-
if hasattr(sys, 'subversion'):
1395+
if hasattr(sys, '_mercurial'):
1396+
_, branch, revision = sys._mercurial
1397+
elif hasattr(sys, 'subversion'):
13961398
# sys.subversion was added in Python 2.5
13971399
_, branch, revision = sys.subversion
13981400
else:

Lib/test/test_platform.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ def test_processor(self):
5757
def setUp(self):
5858
self.save_version = sys.version
5959
self.save_subversion = sys.subversion
60+
self.save_mercurial = sys._mercurial
6061
self.save_platform = sys.platform
6162

6263
def tearDown(self):
6364
sys.version = self.save_version
6465
sys.subversion = self.save_subversion
66+
sys._mercurial = self.save_mercurial
6567
sys.platform = self.save_platform
6668

6769
def test_sys_version(self):
@@ -109,10 +111,12 @@ def test_sys_version(self):
109111
sys_versions.items():
110112
sys.version = version_tag
111113
if subversion is None:
114+
if hasattr(sys, "_mercurial"):
115+
del sys._mercurial
112116
if hasattr(sys, "subversion"):
113117
del sys.subversion
114118
else:
115-
sys.subversion = subversion
119+
sys._mercurial = subversion
116120
if sys_platform is not None:
117121
sys.platform = sys_platform
118122
self.assertEqual(platform.python_implementation(), info[0])

Makefile.pre.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ RANLIB= @RANLIB@
3737
SVNVERSION= @SVNVERSION@
3838
SOABI= @SOABI@
3939
LDVERSION= @LDVERSION@
40+
HGVERSION= @HGVERSION@
41+
HGTAG= @HGTAG@
42+
HGBRANCH= @HGBRANCH@
4043

4144
GNULD= @GNULD@
4245

@@ -552,7 +555,12 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
552555
$(SIGNAL_OBJS) \
553556
$(MODOBJS) \
554557
$(srcdir)/Modules/getbuildinfo.c
555-
$(CC) -c $(PY_CORE_CFLAGS) -DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" -o $@ $(srcdir)/Modules/getbuildinfo.c
558+
$(CC) -c $(PY_CORE_CFLAGS) \
559+
-DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" \
560+
-DHGVERSION="\"`LC_ALL=C $(HGVERSION)`\"" \
561+
-DHGTAG="\"`LC_ALL=C $(HGTAG)`\"" \
562+
-DHGBRANCH="\"`LC_ALL=C $(HGBRANCH)`\"" \
563+
-o $@ $(srcdir)/Modules/getbuildinfo.c
556564

557565
Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
558566
$(CC) -c $(PY_CORE_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
@@ -1600,6 +1600,9 @@ _PySys_Init(void)
16001600
SET_SYS_FROM_STRING("subversion",
16011601
Py_BuildValue("(sss)", "CPython", branch,
16021602
svn_revision));
1603+
SET_SYS_FROM_STRING("_mercurial",
1604+
Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
1605+
_Py_hgversion()));
16031606
SET_SYS_FROM_STRING("dont_write_bytecode",
16041607
PyBool_FromLong(Py_DontWriteBytecodeFlag));
16051608
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: 88430 .
2+
# From configure.in Revision.
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.68 for python 3.2.
55
#
@@ -644,6 +644,10 @@ LN
644644
INSTALL_DATA
645645
INSTALL_SCRIPT
646646
INSTALL_PROGRAM
647+
HAS_HG
648+
HGBRANCH
649+
HGTAG
650+
HGVERSION
647651
SVNVERSION
648652
ARFLAGS
649653
AR
@@ -5166,6 +5170,58 @@ else
51665170
SVNVERSION="echo Unversioned directory"
51675171
fi
51685172
5173+
5174+
5175+
5176+
# Extract the first word of "hg", so it can be a program name with args.
5177+
set dummy hg; ac_word=$2
5178+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
5179+
$as_echo_n "checking for $ac_word... " >&6; }
5180+
if ${ac_cv_prog_HAS_HG+:} false; then :
5181+
$as_echo_n "(cached) " >&6
5182+
else
5183+
if test -n "$HAS_HG"; then
5184+
ac_cv_prog_HAS_HG="$HAS_HG" # Let the user override the test.
5185+
else
5186+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
5187+
for as_dir in $PATH
5188+
do
5189+
IFS=$as_save_IFS
5190+
test -z "$as_dir" && as_dir=.
5191+
for ac_exec_ext in '' $ac_executable_extensions; do
5192+
if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
5193+
ac_cv_prog_HAS_HG="found"
5194+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
5195+
break 2
5196+
fi
5197+
done
5198+
done
5199+
IFS=$as_save_IFS
5200+
5201+
test -z "$ac_cv_prog_HAS_HG" && ac_cv_prog_HAS_HG="not-found"
5202+
fi
5203+
fi
5204+
HAS_HG=$ac_cv_prog_HAS_HG
5205+
if test -n "$HAS_HG"; then
5206+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAS_HG" >&5
5207+
$as_echo "$HAS_HG" >&6; }
5208+
else
5209+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
5210+
$as_echo "no" >&6; }
5211+
fi
5212+
5213+
5214+
if test $HAS_HG = found
5215+
then
5216+
HGVERSION="hg id -i \$(srcdir)"
5217+
HGTAG="hg id -t \$(srcdir)"
5218+
HGBRANCH="hg id -b \$(srcdir)"
5219+
else
5220+
HGVERSION=""
5221+
HGTAG=""
5222+
HGBRANCH=""
5223+
fi
5224+
51695225
case $MACHDEP in
51705226
bsdos*|hp*|HP*)
51715227
# 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
@@ -817,6 +817,21 @@ else
817817
SVNVERSION="echo Unversioned directory"
818818
fi
819819

820+
AC_SUBST(HGVERSION)
821+
AC_SUBST(HGTAG)
822+
AC_SUBST(HGBRANCH)
823+
AC_CHECK_PROG(HAS_HG, hg, found, not-found)
824+
if test $HAS_HG = found
825+
then
826+
HGVERSION="hg id -i \$(srcdir)"
827+
HGTAG="hg id -t \$(srcdir)"
828+
HGBRANCH="hg id -b \$(srcdir)"
829+
else
830+
HGVERSION=""
831+
HGTAG=""
832+
HGBRANCH=""
833+
fi
834+
820835
case $MACHDEP in
821836
bsdos*|hp*|HP*)
822837
# install -d does not work on BSDI or HP-UX

0 commit comments

Comments
 (0)