blob: 7cb7397a22c8ab74fbbd509ac7cf22e96672cd49 [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
Georg Brandl1ca2e792011-03-05 20:51:24 +010023/* XXX Only unix build process has been tested */
Ned Deily5c4b0d02017-03-04 00:19:55 -050024#ifndef GITVERSION
25#define GITVERSION ""
Georg Brandl1ca2e792011-03-05 20:51:24 +010026#endif
Ned Deily5c4b0d02017-03-04 00:19:55 -050027#ifndef GITTAG
28#define GITTAG ""
Georg Brandl1ca2e792011-03-05 20:51:24 +010029#endif
Ned Deily5c4b0d02017-03-04 00:19:55 -050030#ifndef GITBRANCH
31#define GITBRANCH ""
Georg Brandl1ca2e792011-03-05 20:51:24 +010032#endif
33
Guido van Rossum2fff2e61997-01-20 18:34:26 +000034const char *
Thomas Woutersf3f33dc2000-07-21 06:00:07 +000035Py_GetBuildInfo(void)
Guido van Rossum2fff2e61997-01-20 18:34:26 +000036{
Ned Deily5c4b0d02017-03-04 00:19:55 -050037 static char buildinfo[50 + sizeof(GITVERSION) +
38 ((sizeof(GITTAG) > sizeof(GITBRANCH)) ?
39 sizeof(GITTAG) : sizeof(GITBRANCH))];
40 const char *revision = _Py_gitversion();
Antoine Pitrou7f14f0d2010-05-09 16:14:21 +000041 const char *sep = *revision ? ":" : "";
Ned Deily5c4b0d02017-03-04 00:19:55 -050042 const char *gitid = _Py_gitidentifier();
Miss Islington (bot)696a89f2021-10-20 10:41:35 -070043 if (!(*gitid)) {
44 gitid = "main";
45 }
Antoine Pitrou7f14f0d2010-05-09 16:14:21 +000046 PyOS_snprintf(buildinfo, sizeof(buildinfo),
Ned Deily5c4b0d02017-03-04 00:19:55 -050047 "%s%s%s, %.20s, %.9s", gitid, sep, revision,
Antoine Pitrou7f14f0d2010-05-09 16:14:21 +000048 DATE, TIME);
49 return buildinfo;
Guido van Rossum2fff2e61997-01-20 18:34:26 +000050}
Barry Warsawce3a9132005-12-19 14:43:44 +000051
52const char *
Ned Deily5c4b0d02017-03-04 00:19:55 -050053_Py_gitversion(void)
Georg Brandl1ca2e792011-03-05 20:51:24 +010054{
Ned Deily5c4b0d02017-03-04 00:19:55 -050055 return GITVERSION;
Georg Brandl1ca2e792011-03-05 20:51:24 +010056}
57
58const char *
Ned Deily5c4b0d02017-03-04 00:19:55 -050059_Py_gitidentifier(void)
Georg Brandl1ca2e792011-03-05 20:51:24 +010060{
Ned Deily5c4b0d02017-03-04 00:19:55 -050061 const char *gittag, *gitid;
62 gittag = GITTAG;
63 if ((*gittag) && strcmp(gittag, "undefined") != 0)
64 gitid = gittag;
Georg Brandl1ca2e792011-03-05 20:51:24 +010065 else
Ned Deily5c4b0d02017-03-04 00:19:55 -050066 gitid = GITBRANCH;
67 return gitid;
Georg Brandl1ca2e792011-03-05 20:51:24 +010068}