Skip to content

Commit 211111e

Browse files
committed
remove symlink and add musica lib to CAM_LINKED_LIBS
1 parent 2965f95 commit 211111e

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

cime_config/buildlib

+56-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sys.path.append(os.path.join(__CIMEROOT, "CIME", "Tools"))
2626
#pylint: disable=wrong-import-position
2727
# CIME imports
2828
from CIME.case import Case
29-
from CIME.utils import run_cmd, expect, symlink_force
29+
from CIME.utils import run_cmd, expect
3030
from CIME.utils import stop_buffering_output
3131
from CIME.buildlib import parse_input
3232
from CIME.build import get_standard_makefile_args
@@ -176,7 +176,12 @@ def _build_cam():
176176
# the MUSICA configuration and build the MUSICA library
177177
if MUSICA_CCPP_SCHEME_NAME in scheme_names:
178178
_download_musica_configuration(caseroot)
179-
musica_install_path = _build_musica_library(caseroot)
179+
musica_install_path = _build_musica(caseroot)
180+
181+
cam_linked_libs = case.get_value("CAM_LINKED_LIBS")
182+
musica_libs = "-lmusica-fortran -lmusica -lyaml-cpp"
183+
if not musica_libs in cam_linked_libs:
184+
_set_musica_lib_path(musica_install_path, caseroot)
180185

181186
cmd += ' USER_INCLDIR="'\
182187
f'-I{os.path.join(musica_install_path, "include", "micm")} '\
@@ -243,7 +248,7 @@ def _copy2_as_needed(src: str, dst: str) -> None:
243248
shutil.copy2(src, dst)
244249

245250
###############################################################################
246-
def _build_musica_library(clone_dest: str) -> str:
251+
def _build_musica(clone_dest: str) -> str:
247252
###############################################################################
248253
"""
249254
Builds and installs the MUSICA library.
@@ -256,7 +261,7 @@ def _build_musica_library(clone_dest: str) -> str:
256261
the MUSICA library build fails, an exception is raised.
257262
258263
Returns:
259-
str: path to the MUSICA installation directory
264+
musica_install_path: path to the MUSICA installation directory
260265
"""
261266
_clone_and_checkout(MUSICA_REPO_URL, MUSICA_TAG, clone_dest)
262267

@@ -288,7 +293,6 @@ def _build_musica_library(clone_dest: str) -> str:
288293
raise Exception(f"Unable to build the MUSICA library. Error: {result.stderr}")
289294

290295
os.chdir(current_dir)
291-
292296
musica_install_path = os.path.join(bld_path, install_dir)
293297

294298
return musica_install_path
@@ -316,12 +320,12 @@ def _download_musica_configuration(download_dest: str) -> None:
316320
renamed_dir = os.path.join(download_dest, "cam-sima-chemistry-data", musica_config_dir_name)
317321
try:
318322
os.rename(original_dir, renamed_dir)
319-
except FileNotFoundError:
320-
raise FileNotFoundError(f"The directory '{original_dir}' was not found.")
321-
except FileExistsError:
322-
raise FileExistsError(f"The destination directory '{renamed_dir}' already exists.")
323-
except PermissionError:
324-
raise PermissionError(f"Permission denied to rename '{original_dir}'.")
323+
except FileNotFoundError as e:
324+
raise FileNotFoundError(f"The directory '{original_dir}' was not found. Error: {e}")
325+
except FileExistsError as e:
326+
raise FileExistsError(f"The destination directory '{renamed_dir}' already exists. Error: {e}")
327+
except PermissionError as e:
328+
raise PermissionError(f"Permission denied to rename '{original_dir}'. Error: {e}")
325329
except OSError as e:
326330
raise OSError(f"An error occurred while renaming: {e}")
327331

@@ -331,15 +335,54 @@ def _download_musica_configuration(download_dest: str) -> None:
331335

332336
shutil.move(renamed_dir, download_dest)
333337

338+
###############################################################################
339+
def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
340+
###############################################################################
341+
"""
342+
Sets the MUSICA libraries path to CAM_LINKED_LIBS, allowing the libraries
343+
to be linked during the CESM build process.
344+
345+
Args:
346+
musica_install_path: path to the MUSICA installation directory
347+
caseroot: CASEROOT where the xmlchange command is located
348+
349+
Raises:
350+
Exception: If the subprocess for the xmlchange command fails,
351+
an exception is raised with the error message.
352+
"""
353+
354+
current_dir = os.getcwd()
355+
os.chdir(caseroot)
356+
357+
command = [
358+
"./xmlchange",
359+
"--append",
360+
# The libraries must be on the same line because CIME flags an
361+
# error for multi-character arguments preceded by a single dash
362+
f"CAM_LINKED_LIBS=-L{os.path.join(musica_install_path, 'lib64')} -lmusica-fortran -lmusica -lyaml-cpp"
363+
]
364+
try:
365+
subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
366+
text=True, check=False)
367+
except subprocess.CalledProcessError as e:
368+
raise subprocess.CalledProcessError(f"The subprocess for xmlchange \
369+
to set the MUSICA library path failed with an error.: {e}")
370+
except FileNotFoundError as e:
371+
raise FileNotFoundError(f"The 'xmlchange' command was not found: {e}")
372+
except OSError as e:
373+
raise OSError(f"An error occurred while running 'xmlchange' command: {e}")
374+
375+
os.chdir(current_dir)
376+
334377
###############################################################################
335378
def _clone_and_checkout(repo_url: str, tag_name: str, clone_dest: str) -> None:
336379
###############################################################################
337380
"""
338381
Clones a Git repository from the URL and checks out a specific branch.
339382
340383
Args:
341-
repo_url: The URL of the Git repository to clone
342-
tag_name: The tag name to check out
384+
repo_url: URL of the Git repository to clone
385+
tag_name: tag name to check out
343386
clone_dest: destination where the repository will be cloned
344387
345388
Raises:

docker/Dockerfile.musica

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ WORKDIR $CASE_NAME
8080
RUN ./case.setup
8181

8282
RUN ./xmlchange CAM_CONFIG_OPTS="--dyn none --physics-suites musica"
83-
RUN ./xmlchange CAM_LINKED_LIBS="-L/home/cam_sima_user/case_name/test-case/musica/build/install/lib64 -lmusica-fortran -lmusica -lyaml-cpp"
8483
RUN ./xmlchange ROF_NCPL=48
8584
RUN ./xmlchange STOP_OPTION=nsteps
8685
RUN ./xmlchange STOP_N=5

0 commit comments

Comments
 (0)