"""
common utilities for buildlib
"""
from CIME.XML.standard_module_setup import *
from CIME.case import Case
from CIME.utils import parse_args_and_handle_standard_logging_options, setup_standard_logging_options
from CIME.build import get_standard_makefile_args
import sys, os, argparse
logger = logging.getLogger(__name__)
###############################################################################
###############################################################################
[docs]def build_cime_component_lib(case, compname, libroot, bldroot):
###############################################################################
cimeroot = case.get_value("CIMEROOT")
compclass = compname[1:]
comp_interface = case.get_value("COMP_INTERFACE")
with open(os.path.join(bldroot,'Filepath'), 'w') as out:
out.write(os.path.join(case.get_value('CASEROOT'), "SourceMods",
"src.{}\n".format(compname)) + "\n")
if compname.startswith('d'):
if (comp_interface == 'nuopc'):
out.write(os.path.join(cimeroot, "src", "components", "data_comps", "dshr_nuopc") + "\n")
out.write(os.path.join(cimeroot, "src", "components", "data_comps", compname, comp_interface) + "\n")
out.write(os.path.join(cimeroot, "src", "components", "data_comps", compname) + "\n")
elif compname.startswith('x'):
out.write(os.path.join(cimeroot, "src", "components", "xcpl_comps", "xshare") + "\n")
out.write(os.path.join(cimeroot, "src", "components", "xcpl_comps", "xshare", comp_interface) + "\n")
out.write(os.path.join(cimeroot, "src", "components", "xcpl_comps", compname, comp_interface) + "\n")
elif compname.startswith('s'):
out.write(os.path.join(cimeroot, "src", "components", "stub_comps", compname, comp_interface) + "\n")
# Build the component
run_gmake(case, compclass, libroot, bldroot)
###############################################################################
[docs]def run_gmake(case, compclass, libroot, bldroot, libname="", user_cppdefs=""):
###############################################################################
gmake_args = get_standard_makefile_args(case)
gmake_j = case.get_value("GMAKE_J")
gmake = case.get_value("GMAKE")
complib = ""
if libname:
complib = os.path.join(libroot, "lib{}.a".format(libname))
else:
complib = os.path.join(libroot, "lib{}.a".format(compclass))
makefile = os.path.join(case.get_value("CASETOOLS"), "Makefile")
cmd = "{} complib -j {:d} MODEL={} COMPLIB={} {} -f {} -C {} " \
.format(gmake, gmake_j, compclass, complib, gmake_args, makefile, bldroot)
if user_cppdefs:
cmd = cmd + "USER_CPPDEFS='{}'".format(user_cppdefs )
_, out, _ = run_cmd(cmd, combine_output=True)
print(out)