|
1 | 1 | import os |
2 | 2 | import subprocess |
3 | | - |
4 | | -Dir = os.path.dirname(__file__) |
| 3 | +from tempfile import TemporaryDirectory |
5 | 4 |
|
6 | 5 |
|
7 | 6 | def main() -> str: |
8 | 7 | if subprocess.run(["cmake", "--version"]).returncode: |
9 | 8 | raise RuntimeError("Could not find cmake") |
10 | 9 |
|
11 | | - # get the compiler id and version |
12 | | - if subprocess.run( |
13 | | - ["cmake", "-S", Dir, "-B", os.path.join(Dir, "build")] |
14 | | - ).returncode: |
15 | | - raise RuntimeError( |
16 | | - "Could not find a C++ 20 compiler. Do you have a C++ 20 compiler installed?" |
17 | | - ) |
| 10 | + with TemporaryDirectory() as build_dir: |
| 11 | + # get the compiler id and version |
| 12 | + if subprocess.run( |
| 13 | + ["cmake", "-S", os.path.dirname(__file__), "-B", build_dir] |
| 14 | + ).returncode: |
| 15 | + raise RuntimeError( |
| 16 | + "Could not find a C++ 20 compiler. Do you have a C++ 20 compiler installed?" |
| 17 | + ) |
18 | 18 |
|
19 | | - # Get the compiler variables generated by the cmake file |
20 | | - with open(os.path.join(Dir, "build", "compiler_id.txt")) as f: |
21 | | - compiler_id_str = f.read().strip() |
22 | | - with open(os.path.join(Dir, "build", "compiler_version.txt")) as f: |
23 | | - compiler_version = f.read().strip().split(".", 1)[0] |
| 19 | + # Get the compiler variables generated by the cmake file |
| 20 | + with open(os.path.join(build_dir, "compiler_id.txt")) as f: |
| 21 | + compiler_id_str = f.read().strip() |
| 22 | + with open(os.path.join(build_dir, "compiler_version.txt")) as f: |
| 23 | + compiler_version = f.read().strip().split(".", 1)[0] |
24 | 24 |
|
25 | 25 | # convert the compiler id to an int so it can be used in a version number |
26 | 26 | compiler_id_int = 0 |
|
0 commit comments