Skip to content

Commit

Permalink
refactor clean bld
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Feb 14, 2017
1 parent d0a1616 commit 28f88da
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 47 deletions.
19 changes: 7 additions & 12 deletions scripts/Tools/case.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from CIME.test_status import *
def parse_command_line(args, description):
###############################################################################
parser = argparse.ArgumentParser(
usage="""\n%s [--verbose]
usage="""\n%s [--verbose] [--clean [atm lnd pio ...]] [--clean-all]
OR
%s --help
OR
Expand Down Expand Up @@ -51,20 +51,16 @@ OR

parser.add_argument("--clean", nargs="*", choices=allobjs,
help="objects to clean"
"if no arguments then clean all objects other than csmshare, mct, pio, and gptl")
"if no arguments then clean all objects other than sharedlib objects")

parser.add_argument("--clean-all", action="store_true",
help="clean all objects ")
help="clean all objects including sharedlibobjects that may be used by other builds")

args = parser.parse_args(args[1:])

cleanlist = allobjs if args.clean_all else []
if args.clean is not None:
cleanlist = args.clean if args.clean else comps

CIME.utils.handle_standard_logging_options(args)

return args.caseroot, args.sharedlib_only, args.model_only, cleanlist
return args.caseroot, args.sharedlib_only, args.model_only, args.clean, args.clean_all

###############################################################################
def _main_func(description):
Expand All @@ -73,15 +69,14 @@ def _main_func(description):
test_results = doctest.testmod(verbose=True)
sys.exit(1 if test_results.failed > 0 else 0)

caseroot, sharedlib_only, model_only, cleanlist = parse_command_line(sys.argv, description)
logging.info("calling build.case_build with caseroot=%s" %caseroot)
caseroot, sharedlib_only, model_only, cleanlist, clean_all = parse_command_line(sys.argv, description)

success = True
with Case(caseroot, read_only=False) as case:
testname = case.get_value('TESTCASE')

if cleanlist:
build.clean(case, cleanlist)
if cleanlist is not None or clean_all:
build.clean(case, cleanlist, clean_all)
elif(testname is not None):
logging.warn("Building test for %s in directory %s" %
(testname, caseroot))
Expand Down
76 changes: 41 additions & 35 deletions utils/python/CIME/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,42 +509,42 @@ def _build_model_thread(config_dir, compclass, caseroot, libroot, bldroot, incro
shutil.copy(mod_file, incroot)

###############################################################################
def clean(case, cleanlist=None):
def clean(case, cleanlist=None, clean_all=False):
###############################################################################
caseroot = case.get_value("CASEROOT")
if clean_all or cleanlist is not None and len(cleanlist) == 0:
# If cleanlist is empty just remove the bld directory
exeroot = case.get_value("EXEROOT")
if os.path.isdir(exeroot):
logging.info("removing directory %s" %exeroot)
shutil.rmtree(case.get_value("EXEROOT"))
# if clean_all is True also remove the sharedlibpath
sharedlibroot = case.get_value("SHAREDLIBROOT")
if clean_all and os.path.isdir(sharedlibroot):
logging.info("removing directory %s" %sharedlibroot)
shutil.rmtree(sharedlibroot)
else:
debug = case.get_value("DEBUG")
use_esmf_lib = case.get_value("USE_ESMF_LIB")
build_threaded = case.get_value("BUILD_THREADED")
gmake = case.get_value("GMAKE")
caseroot = case.get_value("CASEROOT")
casetools = case.get_value("CASETOOLS")
clm_config_opts = case.get_value("CLM_CONFIG_OPTS")

os.environ["DEBUG"] = stringify_bool(debug)
os.environ["USE_ESMF_LIB"] = stringify_bool(use_esmf_lib)
os.environ["BUILD_THREADED"] = stringify_bool(build_threaded)
os.environ["CASEROOT"] = caseroot
os.environ["COMP_INTERFACE"] = case.get_value("COMP_INTERFACE")
os.environ["PIO_VERSION"] = str(case.get_value("PIO_VERSION"))
os.environ["CLM_CONFIG_OPTS"] = clm_config_opts if clm_config_opts is not None else ""

clm_config_opts = case.get_value("CLM_CONFIG_OPTS")
comp_lnd = case.get_value("COMP_LND")
if cleanlist is None:
cleanlist = case.get_values("COMP_CLASSES")
cleanlist = [x.lower().replace('drv','cpl') for x in cleanlist]
testcase = case.get_value("TESTCASE")
# we only want to clean clm here if it is clm4_0 otherwise remove
# it from the cleanlist
if testcase is not None and comp_lnd == "clm" and \
clm_config_opts is not None and "lnd" in cleanlist and \
"clm4_0" not in clm_config_opts:
cleanlist.remove('lnd')

debug = case.get_value("DEBUG")
use_esmf_lib = case.get_value("USE_ESMF_LIB")
build_threaded = case.get_value("BUILD_THREADED")
gmake = case.get_value("GMAKE")
caseroot = case.get_value("CASEROOT")
casetools = case.get_value("CASETOOLS")

os.environ["DEBUG"] = stringify_bool(debug)
os.environ["USE_ESMF_LIB"] = stringify_bool(use_esmf_lib)
os.environ["BUILD_THREADED"] = stringify_bool(build_threaded)
os.environ["CASEROOT"] = case.get_value("CASEROOT")
os.environ["COMP_INTERFACE"] = case.get_value("COMP_INTERFACE")
os.environ["PIO_VERSION"] = str(case.get_value("PIO_VERSION"))
os.environ["CLM_CONFIG_OPTS"] = clm_config_opts if clm_config_opts is not None else ""

cmd = gmake + " -f " + casetools + "/Makefile"
for item in cleanlist:
cmd = cmd + " clean" + item
logger.info("calling %s "%(cmd))
run_cmd_no_fail(cmd)
cmd = gmake + " -f " + casetools + "/Makefile"
for item in cleanlist:
cmd = cmd + " clean" + item
logger.info("calling %s "%(cmd))
run_cmd_no_fail(cmd)

# unlink Locked files directory
unlock_file("env_build.xml")
Expand All @@ -557,5 +557,11 @@ def clean(case, cleanlist=None):
case.flush()

# append call of to CaseStatus
msg = "cleanbuild %s "%" ".join(cleanlist)
if cleanlist:
msg = "clean %s "%" ".join(cleanlist)
elif clean_all:
msg = "clean_all"
else:
msg = "clean bld"

append_status(msg, caseroot=caseroot, sfile="CaseStatus")

0 comments on commit 28f88da

Please sign in to comment.