-
Notifications
You must be signed in to change notification settings - Fork 841
/
preconfigure.py
executable file
·156 lines (138 loc) · 4.88 KB
/
preconfigure.py
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
#!/usr/bin/env python3
## \file preconfigure.py
# \brief An preconfigure script for setting up the build environment
# \author T. Albring and F. Poli
# \version 8.1.0 "Harrier"
#
# SU2 Project Website: https://su2code.github.io
#
# The SU2 Project is maintained by the SU2 Foundation
# (http://su2foundation.org)
#
# Copyright 2012-2024, SU2 Contributors (cf. AUTHORS.md)
#
# SU2 is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# SU2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with SU2. If not, see <http://www.gnu.org/licenses/>.
import sys, os, subprocess, shutil, urllib.request, zipfile
from pathlib import Path
sys.path.append(sys.path[0] + os.path.sep + "meson_scripts")
from init import init_submodules
from init import remove_file
def build_ninja():
# If we are on windows, we don't need to compile ninja, we just download the executable
if os.name == "nt":
ninja_exe_url = "https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-win.zip"
# Try to execute ninja, if it fails, download .exe from github
try:
subprocess.run(
[sys.path[0] + os.path.sep + "ninja.exe", "--version"],
stdout=subprocess.PIPE,
)
except OSError:
print("Downloading ninja ... ")
try:
urllib.request.urlretrieve(ninja_exe_url, "ninja-win.zip")
except:
print(e)
print("Download of ninja executable failed.")
print("Get archive at " + ninja_exe_url)
print("extract ninja.exe in the source code root folder.")
print("Run meson.py again.")
sys.exit(1)
zipf = zipfile.ZipFile(sys.path[0] + os.path.sep + "ninja-win.zip")
zipf.extractall(sys.path[0])
remove_file(sys.path[0] + os.path.sep + "ninja-win.zip")
else:
ninjapath = sys.path[0] + os.path.sep + "externals" + os.path.sep + "ninja"
try:
subprocess.run(
[sys.path[0] + os.path.sep + "ninja", "--version"],
stdout=subprocess.PIPE,
)
except OSError:
print("ninja executable not found. Building ...")
subprocess.run(["python3", "configure.py", "--bootstrap"], cwd=ninjapath)
shutil.copy(ninjapath + os.path.sep + "ninja", ".")
def run(
own_meson=False,
own_codi=True,
own_medi=True,
own_opdi=True,
own_mpp=True,
own_cool=True,
own_mel=True,
own_mlpcpp=True,
):
# Set up the build environment, i.e. clone or download submodules
init_submodules(
method="auto",
own_meson=own_meson,
own_codi=own_codi,
own_medi=own_medi,
own_opdi=own_opdi,
own_mpp=own_mpp,
own_cool=own_cool,
own_mel=own_mel,
own_mlpcpp=own_mlpcpp,
)
if own_meson:
# Build ninja if it cannot be found
build_ninja()
# Leave a timestamp
Path("su2preconfig.timestamp").touch()
if __name__ == "__main__":
if sys.version_info[0] < 3:
raise Exception("Script must be run using Python 3")
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--with-own-meson",
help="download own copies of Meson and Ninja",
action="store_true",
)
parser.add_argument(
"--no-codi", help="do not download own copy of CoDiPack", action="store_false"
)
parser.add_argument(
"--no-medi", help="do not download own copy of MeDiPack", action="store_false"
)
parser.add_argument(
"--no-opdi", help="do not download own copy of OpDiLib", action="store_false"
)
parser.add_argument(
"--no-mpp", help="do not download own copy of Mutationpp", action="store_false"
)
parser.add_argument(
"--no-coolprop",
help="do not download own copy of CoolProp",
action="store_false",
)
parser.add_argument(
"--no-mel", help="do not download own copy of MEL", action="store_false"
)
parser.add_argument(
"--no-mlpcpp",
help="do not download copy of MLpCpp",
action="store_false",
)
args = parser.parse_args()
run(
own_meson=args.with_own_meson,
own_codi=args.no_codi,
own_medi=args.no_medi,
own_opdi=args.no_opdi,
own_mpp=args.no_mpp,
own_cool=args.no_coolprop,
own_mel=args.no_mel,
own_mlpcpp=args.no_mlpcpp,
)