1 #ifndef Py_BUILD_CORE_BUILTIN
2 # define Py_BUILD_CORE_MODULE 1
3 #endif
4
5 #include "Python.h"
6 #include "pycore_pylifecycle.h" // _Py_gitidentifier()
7
8 #ifndef DONT_HAVE_STDIO_H
9 #include <stdio.h>
10 #endif
11
12 #ifndef DATE
13 #ifdef __DATE__
14 #define DATE __DATE__
15 #else
16 #define DATE "xx/xx/xx"
17 #endif
18 #endif
19
20 #ifndef TIME
21 #ifdef __TIME__
22 #define TIME __TIME__
23 #else
24 #define TIME "xx:xx:xx"
25 #endif
26 #endif
27
28 /* XXX Only unix build process has been tested */
29 #ifndef GITVERSION
30 #define GITVERSION ""
31 #endif
32 #ifndef GITTAG
33 #define GITTAG ""
34 #endif
35 #ifndef GITBRANCH
36 #define GITBRANCH ""
37 #endif
38
39 static int initialized = 0;
40 static char buildinfo[50 + sizeof(GITVERSION) +
41 ((sizeof(GITTAG) > sizeof(GITBRANCH)) ?
42 sizeof(GITTAG) : sizeof(GITBRANCH))];
43
44 const char *
Py_GetBuildInfo(void)45 Py_GetBuildInfo(void)
46 {
47 if (initialized) {
48 return buildinfo;
49 }
50 initialized = 1;
51 const char *revision = _Py_gitversion();
52 const char *sep = *revision ? ":" : "";
53 const char *gitid = _Py_gitidentifier();
54 if (!(*gitid)) {
55 gitid = "main";
56 }
57 PyOS_snprintf(buildinfo, sizeof(buildinfo),
58 "%s%s%s, %.20s, %.9s", gitid, sep, revision,
59 DATE, TIME);
60 return buildinfo;
61 }
62
63 const char *
_Py_gitversion(void)64 _Py_gitversion(void)
65 {
66 return GITVERSION;
67 }
68
69 const char *
_Py_gitidentifier(void)70 _Py_gitidentifier(void)
71 {
72 const char *gittag, *gitid;
73 gittag = GITTAG;
74 if ((*gittag) && strcmp(gittag, "undefined") != 0)
75 gitid = gittag;
76 else
77 gitid = GITBRANCH;
78 return gitid;
79 }
80