|
105 | 105 | "check_warnings", "check_no_resource_warning", "EnvironmentVarGuard", |
106 | 106 | "run_with_locale", "swap_item", |
107 | 107 | "swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict", |
108 | | - "run_with_tz", "PGO", |
| 108 | + "run_with_tz", "PGO", "missing_compiler_executable", |
109 | 109 | ] |
110 | 110 |
|
111 | 111 | class Error(Exception): |
@@ -2491,3 +2491,28 @@ def __del__(self): |
2491 | 2491 | # The sequence should be deallocated just after the end of iterating |
2492 | 2492 | gc_collect() |
2493 | 2493 | test.assertTrue(done) |
| 2494 | + |
| 2495 | + |
| 2496 | +def missing_compiler_executable(cmd_names=[]): |
| 2497 | + """Check if the compiler components used to build the interpreter exist. |
| 2498 | +
|
| 2499 | + Check for the existence of the compiler executables whose names are listed |
| 2500 | + in 'cmd_names' or all the compiler executables when 'cmd_names' is empty |
| 2501 | + and return the first missing executable or None when none is found |
| 2502 | + missing. |
| 2503 | +
|
| 2504 | + """ |
| 2505 | + from distutils import ccompiler, sysconfig, spawn |
| 2506 | + compiler = ccompiler.new_compiler() |
| 2507 | + sysconfig.customize_compiler(compiler) |
| 2508 | + for name in compiler.executables: |
| 2509 | + if cmd_names and name not in cmd_names: |
| 2510 | + continue |
| 2511 | + cmd = getattr(compiler, name) |
| 2512 | + if cmd_names: |
| 2513 | + assert cmd is not None, \ |
| 2514 | + "the '%s' executable is not configured" % name |
| 2515 | + elif cmd is None: |
| 2516 | + continue |
| 2517 | + if spawn.find_executable(cmd[0]) is None: |
| 2518 | + return cmd[0] |
0 commit comments