-
Notifications
You must be signed in to change notification settings - Fork 8
/
build_programs.py
executable file
·123 lines (112 loc) · 3.16 KB
/
build_programs.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
import argparse
import subprocess
import sys
import textwrap
from pathlib import Path
from modflow_devtools.ostags import get_modflow_ostag
DEFAULT_RETRIES = 3
DPRECISION_EXES = ["mf2005", "mflgr", "mfnwt", "mfusg"]
def get_fc() -> str:
"""Determine Intel Fortran compiler to use based on the current platform."""
return "ifort"
def get_cc() -> str:
"""Determine Intel C compiler to use based on the current platform."""
if sys.platform.startswith("linux"):
return "icc"
elif sys.platform.startswith("win"):
return "icl"
elif sys.platform.startswith("darwin"):
return "icc"
raise ValueError(f"platform {sys.platform!r} not supported")
def run_cmd(args) -> bool:
success = False
for idx in range(DEFAULT_RETRIES):
p = subprocess.run(args)
if p.returncode == 0:
success = True
break
print(f"{args[0]} run {idx + 1}/{DEFAULT_RETRIES} failed...rerunning")
return success
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog=f"Build MODFLOW-related binaries and metadata files",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=textwrap.dedent(
"""\
Build MODFLOW-related executables, shared libraries and metadata files with pymake.
"""
),
)
parser.add_argument(
"-k",
"--keep",
action=argparse.BooleanOptionalAction,
help="Whether to keep (not recreate) existing binaries",
)
parser.add_argument(
"-p",
"--path",
required=False,
default=get_modflow_ostag(),
help="Path to create built binaries and metadata files",
)
parser.add_argument(
"-r",
"--retries",
type=int,
required=False,
default=DEFAULT_RETRIES,
help="Number of times to retry a failed build",
)
args = parser.parse_args()
keep = bool(args.keep)
path = Path(args.path)
path.mkdir(parents=True, exist_ok=True)
zip_path = Path(path).with_suffix(".zip")
dp_exes = ",".join(DPRECISION_EXES)
retries = args.retries
fc = get_fc()
cc = get_cc()
assert run_cmd(
[
"make-program",
":",
"--appdir",
path,
"-fc",
fc,
"-cc",
cc,
"--zip",
f"{path}.zip",
]
+ (["--keep"] if keep else [])
), "could not build default precision binaries"
assert run_cmd(
[
"make-program",
dp_exes,
"--appdir",
path,
"--double",
"--keep",
"-fc",
fc,
"-cc",
cc,
"--zip",
str(zip_path),
]
), f"could not build double precision binaries: {dp_exes}"
assert run_cmd(
[
"make-code-json",
"-ad",
str(path),
"--verbose",
"--zip",
str(zip_path)
]
), "could not make code.json"
assert zip_path.is_file(), "could not build distribution zipfile"
print(f"created distribution zipfile: {zip_path}")