blob: ac5188126cdc253fe08f4c516d10d525271d133e [file] [log] [blame]
Tim Peters22a51ef2001-12-04 01:11:32 +00001#include "Python.h"
Guido van Rossum49bff651997-05-20 22:40:26 +00002
Guido van Rossumff7e83d1999-08-27 20:39:37 +00003#ifndef DONT_HAVE_STDIO_H
Guido van Rossum2fff2e61997-01-20 18:34:26 +00004#include <stdio.h>
Guido van Rossumff7e83d1999-08-27 20:39:37 +00005#endif
Guido van Rossum2fff2e61997-01-20 18:34:26 +00006
7#ifndef DATE
8#ifdef __DATE__
9#define DATE __DATE__
10#else
11#define DATE "xx/xx/xx"
12#endif
13#endif
14
15#ifndef TIME
16#ifdef __TIME__
17#define TIME __TIME__
18#else
19#define TIME "xx:xx:xx"
20#endif
21#endif
22
Guido van Rossumcd16bf62007-06-13 18:07:49 +000023/* on unix, SVNVERSION is passed on the command line.
24 * on Windows, the string is interpolated using
25 * subwcrev.exe
26 */
27#ifndef SVNVERSION
Martin v. Löwisd078e402006-01-18 09:13:51 +000028#define SVNVERSION "$WCRANGE$$WCMODS?M:$"
Guido van Rossumcd16bf62007-06-13 18:07:49 +000029#endif
30
Georg Brandl1ca2e792011-03-05 20:51:24 +010031/* 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
Guido van Rossum2fff2e61997-01-20 18:34:26 +000042const char *
Thomas Woutersf3f33dc2000-07-21 06:00:07 +000043Py_GetBuildInfo(void)
Guido van Rossum2fff2e61997-01-20 18:34:26 +000044{
Antoine Pitrou7983d332011-03-09 12:34:41 +010045 static char buildinfo[50 + sizeof HGVERSION +
46 ((sizeof HGTAG > sizeof HGBRANCH) ?
47 sizeof HGTAG : sizeof HGBRANCH)];
Georg Brandl1ca2e792011-03-05 20:51:24 +010048 const char *revision = _Py_hgversion();
Antoine Pitrou7f14f0d2010-05-09 16:14:21 +000049 const char *sep = *revision ? ":" : "";
Georg Brandl1ca2e792011-03-05 20:51:24 +010050 const char *hgid = _Py_hgidentifier();
51 if (!(*hgid))
52 hgid = "default";
Antoine Pitrou7f14f0d2010-05-09 16:14:21 +000053 PyOS_snprintf(buildinfo, sizeof(buildinfo),
Georg Brandl1ca2e792011-03-05 20:51:24 +010054 "%s%s%s, %.20s, %.9s", hgid, sep, revision,
Antoine Pitrou7f14f0d2010-05-09 16:14:21 +000055 DATE, TIME);
56 return buildinfo;
Guido van Rossum2fff2e61997-01-20 18:34:26 +000057}
Barry Warsawce3a9132005-12-19 14:43:44 +000058
59const char *
Martin v. Löwis43b57802006-01-05 23:38:54 +000060_Py_svnversion(void)
Barry Warsawce3a9132005-12-19 14:43:44 +000061{
Antoine Pitrou7f14f0d2010-05-09 16:14:21 +000062 /* the following string can be modified by subwcrev.exe */
63 static const char svnversion[] = SVNVERSION;
64 if (svnversion[0] != '$')
65 return svnversion; /* it was interpolated, or passed on command line */
66 return "Unversioned directory";
Barry Warsawce3a9132005-12-19 14:43:44 +000067}
Georg Brandl1ca2e792011-03-05 20:51:24 +010068
69const char *
70_Py_hgversion(void)
71{
72 return HGVERSION;
73}
74
75const char *
76_Py_hgidentifier(void)
77{
78 const char *hgtag, *hgid;
79 hgtag = HGTAG;
80 if ((*hgtag) && strcmp(hgtag, "tip") != 0)
81 hgid = hgtag;
82 else
83 hgid = HGBRANCH;
84 return hgid;
85}