Skip to content

Commit f9be944

Browse files
committed
gh-100086: Add build details to sys.version
Add more build details about how Python was configured in sys.version, like "debug" or "release" build. Build details and related configure option: * "debug": --with-pydebug, "release" otherwise * "+assert": --with-assertions * "+tracerefs": --with-trace-refs * "+pystats": --enable-pystats * "asan": --with-address-sanitizer * "msan": --with-memory-sanitizer * "ubsan": --with-undefined-behavior-sanitizer * "lto+pgo": --with-lto --enable-optimizations * "framework": --enable-framework * "shared": --enable-shared
1 parent 68e4129 commit f9be944

File tree

6 files changed

+155
-3
lines changed

6 files changed

+155
-3
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ sys
323323
with contributions from Gregory P. Smith [Google] and Mark Shannon
324324
in :gh:`96123`.)
325325

326+
* Add more build details about how Python was configured in
327+
:data:`sys.version`, like "debug" or "release" build.
328+
(Contributed by Victor Stinner in :gh:`100086`.)
329+
326330

327331
Optimizations
328332
=============

Makefile.pre.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ PY_CORE_CFLAGS= $(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE
123123
PY_CORE_LDFLAGS=$(PY_LDFLAGS) $(PY_LDFLAGS_NODIST)
124124
# Strict or non-strict aliasing flags used to compile dtoa.c, see above
125125
CFLAGS_ALIASING=@CFLAGS_ALIASING@
126-
126+
# String describing the Python build used by sys.version (ex: "debug build")
127+
PY_BUILD_STR=@PY_BUILD_STR@
127128

128129
# Machine-dependent subdirectories
129130
MACHDEP= @MACHDEP@
@@ -1245,6 +1246,7 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
12451246
-DGITVERSION="\"`LC_ALL=C $(GITVERSION)`\"" \
12461247
-DGITTAG="\"`LC_ALL=C $(GITTAG)`\"" \
12471248
-DGITBRANCH="\"`LC_ALL=C $(GITBRANCH)`\"" \
1249+
-DPY_BUILD_STR="\"$(PY_BUILD_STR)\"" \
12481250
-o $@ $(srcdir)/Modules/getbuildinfo.c
12491251

12501252
Modules/getpath.o: $(srcdir)/Modules/getpath.c Python/frozen_modules/getpath.h Makefile $(PYTHON_HEADERS)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add more build details about how Python was configured in :data:`sys.version`,
2+
like "debug" or "release" build. Patch by Victor Stinner.

Modules/getbuildinfo.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
#ifndef GITBRANCH
3131
#define GITBRANCH ""
3232
#endif
33+
#ifndef PY_BUILD_STR
34+
// On Windows, only provide basic info
35+
# ifdef Py_DEBUG
36+
# define PY_BUILD_STR "debug build"
37+
# else
38+
# define PY_BUILD_STR "release build"
39+
# endif
40+
#endif
3341

3442
static int initialized = 0;
3543
static char buildinfo[50 + sizeof(GITVERSION) +
@@ -50,8 +58,9 @@ Py_GetBuildInfo(void)
5058
gitid = "main";
5159
}
5260
PyOS_snprintf(buildinfo, sizeof(buildinfo),
53-
"%s%s%s, %.20s, %.9s", gitid, sep, revision,
54-
DATE, TIME);
61+
"%s%s%s, %.20s, %.9s, %s",
62+
gitid, sep, revision, DATE, TIME,
63+
PY_BUILD_STR);
5564
return buildinfo;
5665
}
5766

configure

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3093,12 +3093,15 @@ case $ac_sys_system/$ac_sys_release in
30933093
;;
30943094
esac
30953095

3096+
SANITIZERS=""
3097+
30963098
AC_MSG_CHECKING(for --with-address-sanitizer)
30973099
AC_ARG_WITH(address_sanitizer,
30983100
AS_HELP_STRING([--with-address-sanitizer],
30993101
[enable AddressSanitizer memory error detector, 'asan' (default is no)]),
31003102
[
31013103
AC_MSG_RESULT($withval)
3104+
SANITIZERS="$SANITIZERS asan"
31023105
BASECFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASECFLAGS"
31033106
LDFLAGS="-fsanitize=address $LDFLAGS"
31043107
# ASan works by controlling memory allocation, our own malloc interferes.
@@ -3113,6 +3116,7 @@ AC_ARG_WITH(memory_sanitizer,
31133116
[
31143117
AC_MSG_RESULT($withval)
31153118
AX_CHECK_COMPILE_FLAG([-fsanitize=memory],[
3119+
SANITIZERS="$SANITIZERS msan"
31163120
BASECFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer $BASECFLAGS"
31173121
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 $LDFLAGS"
31183122
],[AC_MSG_ERROR([The selected compiler doesn't support memory sanitizer])])
@@ -3127,6 +3131,7 @@ AC_ARG_WITH(undefined_behavior_sanitizer,
31273131
[enable UndefinedBehaviorSanitizer undefined behaviour detector, 'ubsan' (default is no)]),
31283132
[
31293133
AC_MSG_RESULT($withval)
3134+
SANITIZERS="$SANITIZERS ubsan"
31303135
BASECFLAGS="-fsanitize=undefined $BASECFLAGS"
31313136
LDFLAGS="-fsanitize=undefined $LDFLAGS"
31323137
with_ubsan="yes"
@@ -3136,6 +3141,10 @@ AC_MSG_RESULT(no)
31363141
with_ubsan="no"
31373142
])
31383143

3144+
# strip leading space
3145+
SANITIZERS=$(echo $SANITIZERS | sed 's/^ //')
3146+
3147+
31393148
# Set info about shared libraries.
31403149
AC_SUBST(SHLIB_SUFFIX)
31413150
AC_SUBST(LDSHARED)
@@ -7374,6 +7383,64 @@ PY_STDLIB_MOD([xxlimited_35], [test "$with_trace_refs" = "no"], [test "$ac_cv_fu
73747383
# substitute multiline block, must come after last PY_STDLIB_MOD()
73757384
AC_SUBST([MODULE_BLOCK])
73767385

7386+
7387+
# String describing the Python build used by sys.version (ex: "debug build")
7388+
# Short string containing most important configure options.
7389+
# Examples:
7390+
# - "debug+tracerefs build"
7391+
# - "release+assert shared build"
7392+
# - "release lto+pgo build"
7393+
AC_SUBST(PY_BUILD_STR)
7394+
if test "$Py_DEBUG" = 'true' ; then
7395+
PY_BUILD_STR="debug"
7396+
else
7397+
PY_BUILD_STR="release"
7398+
if test "$assertions" = 'true'; then
7399+
PY_BUILD_STR="$PY_BUILD_STR+assert"
7400+
fi
7401+
fi
7402+
if test "$with_trace_refs" = "yes"; then
7403+
PY_BUILD_STR="$PY_BUILD_STR+tracerefs"
7404+
fi
7405+
if test "$enable_pystats" = "yes"; then
7406+
PY_BUILD_STR="$PY_BUILD_STR+pystats"
7407+
fi
7408+
if test -n "${SANITIZERS}"; then
7409+
PY_BUILD_STR="$PY_BUILD_STR $SANITIZERS"
7410+
fi
7411+
if test "$Py_LTO" = 'true' ; then
7412+
LTO_BUILD_STR="lto"
7413+
if test "$Py_LTO_POLICY" = 'thin' ; then
7414+
LTO_BUILD_STR="lto=thin"
7415+
fi
7416+
else
7417+
LTO_BUILD_STR=""
7418+
fi
7419+
if test "$Py_OPT" = 'true' ; then
7420+
PGO_BUILD_STR="pgo"
7421+
else
7422+
PGO_BUILD_STR=""
7423+
fi
7424+
if test -n "${LTO_BUILD_STR}"; then
7425+
if test -n "${PGO_BUILD_STR}"; then
7426+
PY_BUILD_STR="$PY_BUILD_STR $LTO_BUILD_STR+$PGO_BUILD_STR"
7427+
else
7428+
PY_BUILD_STR="$PY_BUILD_STR $LTO_BUILD_STR"
7429+
fi
7430+
else
7431+
if test -n "${PGO_BUILD_STR}"; then
7432+
PY_BUILD_STR="$PY_BUILD_STR $PGO_BUILD_STR"
7433+
fi
7434+
fi
7435+
if test "$enable_framework"; then
7436+
PY_BUILD_STR="$PY_BUILD_STR framework"
7437+
fi
7438+
if test "$PY_ENABLE_SHARED" = 1; then
7439+
PY_BUILD_STR="$PY_BUILD_STR shared"
7440+
fi
7441+
PY_BUILD_STR="$PY_BUILD_STR build"
7442+
7443+
73777444
# generate output files
73787445
AC_CONFIG_FILES(Makefile.pre Misc/python.pc Misc/python-embed.pc Misc/python-config.sh)
73797446
AC_CONFIG_FILES([Modules/Setup.bootstrap Modules/Setup.stdlib])

0 commit comments

Comments
 (0)