Skip to content

Commit fe09a54

Browse files
committed
Merge build identification to default branch.
2 parents f874deb + 13039c8 commit fe09a54

File tree

8 files changed

+659
-495
lines changed

8 files changed

+659
-495
lines changed

Include/pythonrun.h

+2
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

+3-1
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,9 @@ def _sys_version(sys_version=None):
13111311
name = 'CPython'
13121312
builddate = builddate + ' ' + buildtime
13131313

1314-
if hasattr(sys, 'subversion'):
1314+
if hasattr(sys, '_mercurial'):
1315+
_, branch, revision = sys._mercurial
1316+
elif hasattr(sys, 'subversion'):
13151317
# sys.subversion was added in Python 2.5
13161318
_, branch, revision = sys.subversion
13171319
else:

Lib/test/test_platform.py

+5-1
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

+9-1
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

+34-3
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

+3
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,9 @@ _PySys_Init(void)
15991599
SET_SYS_FROM_STRING("subversion",
16001600
Py_BuildValue("(sss)", "CPython", branch,
16011601
svn_revision));
1602+
SET_SYS_FROM_STRING("_mercurial",
1603+
Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
1604+
_Py_hgversion()));
16021605
SET_SYS_FROM_STRING("dont_write_bytecode",
16031606
PyBool_FromLong(Py_DontWriteBytecodeFlag));
16041607
SET_SYS_FROM_STRING("api_version",

0 commit comments

Comments
 (0)