|
5 | 5 |
|
6 | 6 | from __future__ import print_function |
7 | 7 |
|
| 8 | +import functools |
8 | 9 | import os |
9 | 10 | import subprocess |
10 | 11 | import shutil |
@@ -79,7 +80,31 @@ def env_var_options_to_cmake_options(): |
79 | 80 | return cmake_options |
80 | 81 |
|
81 | 82 |
|
| 83 | +@functools.cache |
| 84 | +def check_cmake(): |
| 85 | + try: |
| 86 | + subprocess.run(("cmake", ), check=True, stdout=subprocess.PIPE, |
| 87 | + stderr=subprocess.PIPE, timeout=60) |
| 88 | + except subprocess.CalledProcessError as e: |
| 89 | + msg = ("llvmlite needs working CMake tools to build. There was an " |
| 90 | + "issue when performing a test run of the 'cmake' binary.\n" |
| 91 | + f"STDOUT: {e.stdout.decode('UTF-8')}\n" |
| 92 | + f"STDERR: {e.stderr.decode('UTF-8')}\n" |
| 93 | + "See the traceback for details.") |
| 94 | + raise RuntimeError(msg) from e |
| 95 | + except FileNotFoundError as e: |
| 96 | + msg = ("llvmlite needs CMake tools to build. It appears that the " |
| 97 | + "'cmake' tool is either not installed or not found on the path. " |
| 98 | + "Please add CMake tools to the build environment and path, they " |
| 99 | + "are available from many package managers.") |
| 100 | + raise FileNotFoundError(msg) from e |
| 101 | + # Timeout etc not handled, there's little advice that can be given and the |
| 102 | + # traceback is self explanatory. |
| 103 | + |
| 104 | + |
82 | 105 | def try_cmake(cmake_dir, build_dir, generator, arch=None, toolkit=None): |
| 106 | + # first check that CMake tools are present and run ok. |
| 107 | + check_cmake() |
83 | 108 | old_dir = os.getcwd() |
84 | 109 | args = ['cmake', '-G', generator] |
85 | 110 | if arch is not None: |
|
0 commit comments