forked from ESCOMP/FMS_interface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildlib
executable file
·103 lines (82 loc) · 3.44 KB
/
buildlib
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
#!/usr/bin/env python3
import os, sys
_CIMEROOT = os.environ.get("CIMEROOT")
if _CIMEROOT is None:
raise SystemExit("ERROR: must set CIMEROOT environment variable")
_LIBDIR = os.path.join(_CIMEROOT, "scripts", "Tools")
sys.path.append(_LIBDIR)
from standard_script_setup import *
from CIME.utils import copyifnewer, run_bld_cmd_ensure_logging
from CIME.case import Case
from CIME.build import get_standard_makefile_args
import glob
logger = logging.getLogger(__name__)
def parse_command_line(args, description):
###############################################################################
parser = argparse.ArgumentParser(
usage="""\n{0} [--debug]
OR
{0} --verbose
OR
{0} --help
\033[1mEXAMPLES:\033[0m
\033[1;32m# Run \033[0m
> {0}
""".format(
os.path.basename(args[0])
),
description=description,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
CIME.utils.setup_standard_logging_options(parser)
parser.add_argument("buildroot", help="build path root")
parser.add_argument("installpath", help="install path ")
parser.add_argument(
"caseroot", nargs="?", default=os.getcwd(), help="Case directory to build"
)
args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)
return args.buildroot, args.installpath, args.caseroot
def buildlib(bldroot, installpath, case):
###############################################################################
print(f"fms bldroot is {bldroot} installpath is {installpath}")
srcroot = case.get_value("SRCROOT")
caseroot = case.get_value("CASEROOT")
fms_dir = os.path.join(srcroot, "libraries", "FMS")
fpfile = os.path.join(bldroot, "Filepath")
if not os.path.isfile(fpfile):
filepath = []
for _dir in glob.iglob(os.path.join(fms_dir, "src", "*")):
if os.path.isdir(_dir) and not "cime_config" in _dir:
filepath.append(os.path.join(fms_dir, _dir))
with open(os.path.join(bldroot, "Filepath"), "w") as fd:
for path in filepath:
fd.write(path + "\n")
# Tell mkSrcfiles to ignore files beginning in test_
os.environ["mkSrcfiles_skip_prefix"] = "test_"
gmake_opts = "-f {} ".format(os.path.join(fms_dir, "Makefile.cesm"))
gmake_opts += " -C {} ".format(bldroot)
gmake_opts += "CASEROOT={} ".format(caseroot)
gmake_opts += 'USER_INCLDIR="'\
f'-I{os.path.join(fms_dir, "src", "include")} '\
f'-I{os.path.join(fms_dir, "src", "fms2_io", "include")} '\
f'-I{os.path.join(fms_dir, "src", "mpp", "include")} '\
f'-I{os.path.join(fms_dir, "src", "diag_manager", "include")} '\
f'-I{os.path.join(fms_dir, "src", "string_utils", "include")} '\
f'-I{os.path.join(bldroot, "FMS")} '\
'"'
gmake_opts += " COMPLIB=libfms.a "
gmake_opts += get_standard_makefile_args(case)
gmake_cmd = case.get_value("GMAKE")
# This runs the FMS build
cmd = "{} {}".format(gmake_cmd, gmake_opts)
run_bld_cmd_ensure_logging(cmd, logger)
del os.environ["mkSrcfiles_skip_prefix"]
libfms = os.path.join(bldroot, "libfms.a")
if os.path.exists(libfms):
copyifnewer(libfms, case.get_value("LIBROOT"))
def _main(argv, documentation):
bldroot, installpath, caseroot = parse_command_line(argv, documentation)
with Case(caseroot) as case:
buildlib(bldroot, installpath, case)
if __name__ == "__main__":
_main(sys.argv, __doc__)