Repository navigation
Conversation
Merge Python/getcompiler.c, Python/getcopyright.c, Python/getplatform.c and Python/getversion.c into Modules/getbuildinfo.c. Add Tools/build/generate_getbuildinfo.py to auto-generate a new Module/getbuildinfo.h header file which contains build information strings.
|
This PR is a draft. I didn't investigate Windows support yet. I didn't try cross-compilation, it may break. |
|
This change may fix the regression described by @itamaro: #158608 (comment). |
|
|
|
Ok, I fixed the out-of-tree build (used by the Ubuntu CI for example). |
It's only needed in the Python script. Python.h defines PY_VERSION (via patchlevel.h).
|
Example of auto-generated // Header file auto-generated by Tools/build/generate_getbuildinfo.py
#define DATE "Oct 7 2026"
#define TIME "05:35:34"
#define COMPILER "[GCC 16.2.1 20260819 (Red Hat 16.2.1-2)]"
#define PLATFORM "linux"
#define GITBRANCH "getbuildinfo"
#define GITTAG "heads/getbuildinfo"
#define GITVERSION "22d1a6b7c1e"
#define GIT_IDENTIFIER "heads/getbuildinfo"
#define BUILDINFO "heads/getbuildinfo:22d1a6b7c1e, Oct 7 2026, 05:35:34"
#define GET_VERSION "3.16.0a0 (heads/getbuildinfo:22d1a6b7c1e, Oct 7 2026, 05:35:34) [GCC 16.2.1 20260819 (Red Hat 16.2.1-2)]" |
|
Ah, the "WASI / build and test" job does cross-compile! Running the Later, running |
|
With the help of @zware, I managed to update the PCbuild project, to build Programs_getcompiler.c and generate Modules\getbuildinfo.h on Windows. |
|
Aha, test_freeze_simple_script() of test_tools fails on Ubuntu / build and test (ubuntu-26.04-arm) with: |
It's just missing quotes: I fixed it. |
* Use argparse for command line parsing. * Run _getcompiler if --compiler option is omitted. * Rename getbuildinfo.h variables.
|
See also #144124 which adds |
Add the script name as prefix to all logged messages.
|
🤖 New build scheduled with the buildbot fleet by @vstinner for commit ebaadbc 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158951%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
Adjust also getbuildinfo.h indentation
|
🤖 New build scheduled with the buildbot fleet by @vstinner for commit 8431d21 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158951%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
|
Logs of truncated Clang versions on buildbots:
Note: |
|
Windows also does cross-compilation, and presumably you're running the generator using whichever host Python is available, which means there's 0% guarantee it'll be the same as the target. I'd also be very disappointed if generating the build info invalidates the cleanness of version control - if everything is committed, it should show as clean, and overwriting Is there a real reason to rework this into a script rather than just avoiding the fixed-length arrays? Between some external commands and the C preprocessor, this should be straightforward. |
On Windows, the I didn't think about cross-compilation on Windows. On Unix, running
I didn't get your remark on version control:
To me, it seems cleaner to have the |
|
I created https://discuss.python.org/t/generate-modules-getbuildinfo-h-when-building-python-to-get-build-information-statically/109401 to discuss this build change. |
|
I wasn't sure if On Windows, the |
Which are optional, and if the generated files are present, it shouldn't run. (From one of the buildbots):
This command line bothers me, there seems to be some very easy ways to inject extra commands here if you control the branch name or compiler name (and as we know, some compiler names can be a bit silly). I'd rather see the values passed as environment variables to avoid any risk I haven't dug through the change yet to figure it out, but it's worth being aware that our release builds don't always run the two PGO builds on the same machine. We do the instrumented build first, maybe start a new machine to run the profile, and then start another new machine to merge the profile. This involves copying |
The Windows clang build bot now shows (https://buildbot.python.org/?#/builders/2269/builds/34/steps/3/logs/stdio) 1 vs https://buildbot.python.org/#/builders/2269/builds/17/steps/3/logs/stdio Quote from #157368
which the associated PRs #154210 and #154553 "masked away" on main (and hence the buildbot stayed green). 3rd party code relying on being able to parse the Also, I'd miss the MSC CRT version ... Footnotes
|
|
I also share @zooba's concern regarding cross-compiling on Windows in case of Arm: 1 vs https://github.com/python/cpython/actions/runs/37815471280/job/113442970056 Footnotes
|
Add Tools/build/generate_getbuildinfo.py to generate a new Module/getbuildinfo.h header file which contains build information strings. It replaces C code which generates these strings at runtime.
Merge Python/getcompiler.c, Python/getcopyright.c, Python/getplatform.c and Python/getversion.c into Modules/getbuildinfo.c.
Truncate long Clang version string to just keep "Clang x.y.z" or "Apple Clang x.y.z".
COMPILER and _Py_COMPILER macros no longer contain surrounding square brackets.
Add _getcompiler project to the Visual Studio solution.
Modules/getbuildinfo.cto build strings at build time, instead of runtime #158948