Coverage Report

Created: 2025-07-04 06:49

/src/cpython/Modules/getbuildinfo.c
Line
Count
Source (jump to first uncovered line)
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
16
#define DATE __DATE__
15
#else
16
#define DATE "Jan 01 1970"
17
#endif
18
#endif
19
20
#ifndef TIME
21
#ifdef __TIME__
22
16
#define TIME __TIME__
23
#else
24
#define TIME "00:00:00"
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 *
45
Py_GetBuildInfo(void)
46
16
{
47
16
    if (initialized) {
48
0
        return buildinfo;
49
0
    }
50
16
    initialized = 1;
51
16
    const char *revision = _Py_gitversion();
52
16
    const char *sep = *revision ? ":" : "";
53
16
    const char *gitid = _Py_gitidentifier();
54
16
    if (!(*gitid)) {
55
0
        gitid = "main";
56
0
    }
57
16
    PyOS_snprintf(buildinfo, sizeof(buildinfo),
58
16
                  "%s%s%s, %.20s, %.9s", gitid, sep, revision,
59
16
                  DATE, TIME);
60
16
    return buildinfo;
61
16
}
62
63
const char *
64
_Py_gitversion(void)
65
32
{
66
32
    return GITVERSION;
67
32
}
68
69
const char *
70
_Py_gitidentifier(void)
71
32
{
72
32
    const char *gittag, *gitid;
73
32
    gittag = GITTAG;
74
32
    if ((*gittag) && strcmp(gittag, "undefined") != 0)
75
32
        gitid = gittag;
76
0
    else
77
0
        gitid = GITBRANCH;
78
32
    return gitid;
79
32
}