-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildlib
executable file
·93 lines (72 loc) · 3.21 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
#!/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):
###############################################################################
srcroot = case.get_value("SRCROOT")
caseroot = case.get_value("CASEROOT")
socrates_dir = os.path.join(srcroot,"libraries","SOCRATES")
if not os.path.isdir(os.path.join(bldroot,"SOCRATES")):
os.makedirs(os.path.join(bldroot,"SOCRATES"))
filepath = []
# put cam_interface directory at head of Filepath to use CAM interface versions of the SOCRATES files.
filepath.append(os.path.join(socrates_dir,"cam_interface"))
for _dir in glob.iglob(os.path.join(socrates_dir,"socrates_distro","src","*")):
if os.path.isdir(_dir) and not "cime_config" in _dir:
filepath.append(os.path.join(socrates_dir, _dir))
with open(os.path.join(installpath,"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 = "-d -f {} ".format(os.path.join(socrates_dir,"Makefile.cesm"))
gmake_opts += " -C {} ".format(installpath)
gmake_opts += "CASEROOT={} ".format(caseroot)
gmake_opts += "USER_INCLDIR=\"-I{} -I{} \"".format(os.path.join(socrates_dir,"cam_interface"),
os.path.join(bldroot,"SOCRATES") )
gmake_opts += " COMPLIB=libsocrates.a "
gmake_opts += get_standard_makefile_args(case)
gmake_cmd = case.get_value("GMAKE")
# This runs the SOCRATES build
cmd = "{} {}".format(gmake_cmd, gmake_opts)
run_bld_cmd_ensure_logging(cmd, logger)
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__)