-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
47 lines (36 loc) · 1.42 KB
/
setup.py
File metadata and controls
47 lines (36 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import subprocess
import os
from setuptools import setup
MajorVersion = "4"
# verify cmake is installed
if subprocess.run(["cmake", "--version"]).returncode:
raise RuntimeError(
"Could not find cmake command. cmake is required to get compiler version."
)
# get the compiler id and version
if subprocess.run(
["cmake", "-S", "get_compiler", "-B", "get_compiler/build"]
).returncode:
raise RuntimeError(
"Could not find a C++ 20 compiler. Do you have a C++ 20 compiler installed?"
)
# Get the compiler variables generated by the cmake file
with open("get_compiler/build/compiler_id.txt") as f:
compiler_id_str = f.read().strip()
with open("get_compiler/build/compiler_version.txt") as f:
compiler_version = f.read().strip().split(".", 1)[0]
# convert the compiler id to an int so it can be used in a version number
compiler_id_int = 0
for b in compiler_id_str.encode("utf-8"):
compiler_id_int <<= 8
compiler_id_int += b
# combine the compiler id and compiler version into a version number
version = f"{MajorVersion}.{compiler_id_int}.{compiler_version}"
# write the python file
os.makedirs("src", exist_ok=True)
with open("src/amulet_compiler_version.py", "w") as f:
f.write(f'compiler_id = "{compiler_id_str}"\n')
f.write(f'compiler_version = "{compiler_version}"\n')
f.write(f'__version__ = "{version}"\n')
# run setup with the generated or default version
setup(version=version)