|
1 | 1 | importmath |
2 | 2 | importos.path |
3 | 3 | importsys |
| 4 | +importsysconfig |
4 | 5 | importtextwrap |
5 | 6 | fromtestimportsupport |
6 | 7 |
|
@@ -208,3 +209,87 @@ def clear_caches(): |
208 | 209 | pass |
209 | 210 | else: |
210 | 211 | fractions._hash_algorithm.cache_clear() |
| 212 | + |
| 213 | + |
| 214 | +defget_build_info(): |
| 215 | +# Get most important configure and build options as a list of strings. |
| 216 | +# Example: ['debug', 'ASAN+MSAN'] or ['release', 'LTO+PGO']. |
| 217 | + |
| 218 | +config_args=sysconfig.get_config_var('CONFIG_ARGS')or'' |
| 219 | +cflags=sysconfig.get_config_var('PY_CFLAGS')or'' |
| 220 | +cflags_nodist=sysconfig.get_config_var('PY_CFLAGS_NODIST')or'' |
| 221 | +ldflags_nodist=sysconfig.get_config_var('PY_LDFLAGS_NODIST')or'' |
| 222 | + |
| 223 | +build= [] |
| 224 | +ifhasattr(sys,'gettotalrefcount'): |
| 225 | +# --with-pydebug |
| 226 | +build.append('debug') |
| 227 | + |
| 228 | +if'-DNDEBUG'in (cflags+cflags_nodist): |
| 229 | +build.append('without_assert') |
| 230 | +else: |
| 231 | +build.append('release') |
| 232 | + |
| 233 | +if'--with-assertions'inconfig_args: |
| 234 | +build.append('with_assert') |
| 235 | +elif'-DNDEBUG'notin (cflags+cflags_nodist): |
| 236 | +build.append('with_assert') |
| 237 | + |
| 238 | +# --enable-framework=name |
| 239 | +framework=sysconfig.get_config_var('PYTHONFRAMEWORK') |
| 240 | +ifframework: |
| 241 | +build.append(f'framework={framework}') |
| 242 | + |
| 243 | +# --enable-shared |
| 244 | +shared=int(sysconfig.get_config_var('PY_ENABLE_SHARED')or'0') |
| 245 | +ifshared: |
| 246 | +build.append('shared') |
| 247 | + |
| 248 | +# --with-lto |
| 249 | +optimizations= [] |
| 250 | +if'-flto=thin'inldflags_nodist: |
| 251 | +optimizations.append('ThinLTO') |
| 252 | +elif'-flto'inldflags_nodist: |
| 253 | +optimizations.append('LTO') |
| 254 | + |
| 255 | +# --enable-optimizations |
| 256 | +pgo_options= ( |
| 257 | +# GCC |
| 258 | +'-fprofile-use', |
| 259 | +# clang: -fprofile-instr-use=code.profclangd |
| 260 | +'-fprofile-instr-use', |
| 261 | +# ICC |
| 262 | +"-prof-use", |
| 263 | + ) |
| 264 | +ifany(optionincflags_nodistforoptioninpgo_options): |
| 265 | +optimizations.append('PGO') |
| 266 | +ifoptimizations: |
| 267 | +build.append('+'.join(optimizations)) |
| 268 | + |
| 269 | +# --with-address-sanitizer |
| 270 | +sanitizers= [] |
| 271 | +ifsupport.check_sanitizer(address=True): |
| 272 | +sanitizers.append("ASAN") |
| 273 | +# --with-memory-sanitizer |
| 274 | +ifsupport.check_sanitizer(memory=True): |
| 275 | +sanitizers.append("MSAN") |
| 276 | +# --with-undefined-behavior-sanitizer |
| 277 | +ifsupport.check_sanitizer(ub=True): |
| 278 | +sanitizers.append("UBSAN") |
| 279 | +ifsanitizers: |
| 280 | +build.append('+'.join(sanitizers)) |
| 281 | + |
| 282 | +# --with-trace-refs |
| 283 | +ifhasattr(sys,'getobjects'): |
| 284 | +build.append("TraceRefs") |
| 285 | +# --enable-pystats |
| 286 | +ifhasattr(sys,'_stats_on'): |
| 287 | +build.append("pystats") |
| 288 | +# --with-valgrind |
| 289 | +ifsysconfig.get_config_var('WITH_VALGRIND'): |
| 290 | +build.append("valgrind") |
| 291 | +# --with-dtrace |
| 292 | +ifsysconfig.get_config_var('WITH_DTRACE'): |
| 293 | +build.append("dtrace") |
| 294 | + |
| 295 | +returnbuild |