-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathcheck_meson_build.py
More file actions
184 lines (166 loc) · 6.04 KB
/
Copy pathcheck_meson_build.py
File metadata and controls
184 lines (166 loc) · 6.04 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import subprocess
import json
import os
import os.path
import platform
import sys
# For simple terminal colors
class bcolors:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKCYAN = "\033[96m"
OKGREEN = "\033[92m"
WARNING = "\033[93m"
FAIL = "\033[91m"
ENDC = "\033[0m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
# Bail with error
def bail():
print(
f"\n{bcolors.FAIL}There seem to be some issues. Please fix before trying to build!{bcolors.ENDC}"
)
sys.exit(1)
# Run meson introspect and get the key buildoptions as JSON
result = subprocess.run(
["meson", "introspect", "build", "--buildoptions"], stdout=subprocess.PIPE
)
# Process the JSON
vars = json.loads(result.stdout)
# Which variables do we want to see?
grab = ["prefix", "libdir", "bindir"]
ourvars = {}
# Grab the important values
for var in vars:
if var["name"] in grab:
ourvars[var["name"]] = var["value"]
# Show the values for prefix and libdir
print("\nPRESTO's meson build directory currently has:")
print(f" prefix = {ourvars['prefix']}")
print(f" bindir = {ourvars['bindir']}")
print(f" libdir = {ourvars['libdir']}\n")
libinstall = os.path.join(ourvars["prefix"], ourvars["libdir"])
bininstall = os.path.join(ourvars["prefix"], ourvars["bindir"])
# Now show the user what they should be setting
print(
f"Checking for {bcolors.BOLD}PRESTO{bcolors.ENDC} as an environment variable:",
end="",
)
presto = os.environ.get("PRESTO")
if presto is None:
print(f" {bcolors.OKBLUE}no (optional){bcolors.ENDC}")
print(
" PRESTO is no longer required: the installed tools find their data in"
)
print(
" <prefix>/share/presto. Setting it (to this source directory) still"
)
print(" works as an override, e.g. for running from an uninstalled tree:")
print(f" export PRESTO={os.getcwd()}")
else:
print(f" {bcolors.OKGREEN}yes{bcolors.ENDC}")
if os.getcwd() != os.path.realpath(presto):
print(
f"\n {bcolors.WARNING}WARNING:{bcolors.ENDC} PRESTO is set, but not to the current directory!"
)
print(
f"Checking for {bcolors.BOLD}TEMPO2{bcolors.ENDC} as an environment variable:",
end="",
)
tempo2 = os.environ.get("TEMPO2")
if tempo2 is None:
print(f" {bcolors.FAIL}no{bcolors.ENDC}")
print(
f"\n {bcolors.WARNING}WARNING:{bcolors.ENDC} TEMPO2 environment variable is not set!"
)
print(" It is only needed for polyco generation (e.g. prepfold -timing).")
print(" conda-forge's tempo2 package sets it automatically; for a source")
print(" build, point it at the tempo2 runtime directory.")
else:
print(f" {bcolors.OKGREEN}yes{bcolors.ENDC}")
path = os.environ.get("PATH")
path = path.split(":") if path is not None else []
path = [x.rstrip("/") for x in path]
dlpath = "DYLD_LIBRARY_PATH" if platform.system() == "Darwin" else "LD_LIBRARY_PATH"
# These sanity checks only apply when PRESTO is set as an override
if presto is not None:
chk = os.path.join(presto, "bin")
if chk != bininstall:
print("Is $PRESTO/bin in PATH? (it shouldn't be):", end="")
if chk in path:
print(f" {bcolors.FAIL}yes{bcolors.ENDC}")
print(
f"\n {bcolors.WARNING}WARNING:{bcolors.ENDC} $PRESTO/bin should probably not be in your PATH!"
)
bail()
else:
print(f" {bcolors.OKGREEN}no{bcolors.ENDC}")
chk = os.path.join(presto, "lib")
if chk != libinstall:
print(f"Is $PRESTO/lib in {dlpath}? (it shouldn't be):", end="")
if chk in path:
print(f" {bcolors.FAIL}yes{bcolors.ENDC}")
print(
f"\n {bcolors.WARNING}WARNING:{bcolors.ENDC} $PRESTO/lib should probably not be in your {dlpath}!"
)
bail()
else:
print(f" {bcolors.OKGREEN}no{bcolors.ENDC}")
print(f"Is {bcolors.BOLD}{bininstall}{bcolors.ENDC} in PATH? (it should be):", end="")
if bininstall not in path:
print(f" {bcolors.FAIL}no{bcolors.ENDC}")
print(f"\n {bcolors.WARNING}WARNING:{bcolors.ENDC} {bininstall} is not in PATH!")
print(
f" That may cause issues with linking if {bininstall} is not a standard binary directory."
)
print(" You can ensure that it is used by setting PATH using something like:")
print(f" export PATH={bininstall}:$PATH")
bail()
else:
print(f" {bcolors.OKGREEN}yes{bcolors.ENDC}")
print(
f"Is {bcolors.BOLD}{libinstall}{bcolors.ENDC} in LIBRARY_PATH? (it probably should be)",
end="",
)
libpath = os.environ.get("LIBRARY_PATH")
libpath = libpath.split(":") if libpath is not None else []
libpath = [x.rstrip("/") for x in libpath]
if libinstall not in libpath:
print(f" {bcolors.FAIL}no{bcolors.ENDC}")
print(
f"\n {bcolors.WARNING}WARNING:{bcolors.ENDC} {libinstall} is not in LIBRARY_PATH!"
)
print(
f" That may cause link issues if {libinstall} is not a standard library directory."
)
print(
" You can ensure that it is used by setting LIBRARY_PATH using something like:"
)
print(f" export LIBRARY_PATH={libinstall}:$LIBRARY_PATH")
bail()
else:
print(f" {bcolors.OKGREEN}yes{bcolors.ENDC}")
print(
f"Is {bcolors.BOLD}{libinstall}{bcolors.ENDC} in {dlpath}? (it probably should be)",
end="",
)
ldlibpath = os.environ.get(dlpath)
ldlibpath = ldlibpath.split(":") if ldlibpath is not None else []
ldlibpath = [x.rstrip("/") for x in ldlibpath]
if libinstall not in ldlibpath:
print(f" {bcolors.FAIL}no{bcolors.ENDC}")
print(
f"\n {bcolors.WARNING}WARNING:{bcolors.ENDC} {libinstall} is not in {dlpath}!"
)
print(
f" That may cause runtime issues if {libinstall} is not a standard library directory."
)
print(f" You can ensure that it is used by setting {dlpath} using something like:")
print(f" export {dlpath}={libinstall}:${dlpath}")
bail()
else:
print(f" {bcolors.OKGREEN}yes{bcolors.ENDC}")
print(
f"\n{bcolors.OKGREEN}Everything looks good! Let's try to build:{bcolors.ENDC}\n"
" meson compile -C build\n meson install -C build"
)