@@ -26,7 +26,7 @@ sys.path.append(os.path.join(__CIMEROOT, "CIME", "Tools"))
26
26
#pylint: disable=wrong-import-position
27
27
# CIME imports
28
28
from CIME .case import Case
29
- from CIME .utils import run_cmd , expect , symlink_force
29
+ from CIME .utils import run_cmd , expect
30
30
from CIME .utils import stop_buffering_output
31
31
from CIME .buildlib import parse_input
32
32
from CIME .build import get_standard_makefile_args
@@ -176,7 +176,12 @@ def _build_cam():
176
176
# the MUSICA configuration and build the MUSICA library
177
177
if MUSICA_CCPP_SCHEME_NAME in scheme_names :
178
178
_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 )
180
185
181
186
cmd += ' USER_INCLDIR="' \
182
187
f'-I{ os .path .join (musica_install_path , "include" , "micm" )} ' \
@@ -243,7 +248,7 @@ def _copy2_as_needed(src: str, dst: str) -> None:
243
248
shutil .copy2 (src , dst )
244
249
245
250
###############################################################################
246
- def _build_musica_library (clone_dest : str ) -> str :
251
+ def _build_musica (clone_dest : str ) -> str :
247
252
###############################################################################
248
253
"""
249
254
Builds and installs the MUSICA library.
@@ -256,7 +261,7 @@ def _build_musica_library(clone_dest: str) -> str:
256
261
the MUSICA library build fails, an exception is raised.
257
262
258
263
Returns:
259
- str : path to the MUSICA installation directory
264
+ musica_install_path : path to the MUSICA installation directory
260
265
"""
261
266
_clone_and_checkout (MUSICA_REPO_URL , MUSICA_TAG , clone_dest )
262
267
@@ -288,7 +293,6 @@ def _build_musica_library(clone_dest: str) -> str:
288
293
raise Exception (f"Unable to build the MUSICA library. Error: { result .stderr } " )
289
294
290
295
os .chdir (current_dir )
291
-
292
296
musica_install_path = os .path .join (bld_path , install_dir )
293
297
294
298
return musica_install_path
@@ -316,12 +320,12 @@ def _download_musica_configuration(download_dest: str) -> None:
316
320
renamed_dir = os .path .join (download_dest , "cam-sima-chemistry-data" , musica_config_dir_name )
317
321
try :
318
322
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 } " )
325
329
except OSError as e :
326
330
raise OSError (f"An error occurred while renaming: { e } " )
327
331
@@ -331,15 +335,54 @@ def _download_musica_configuration(download_dest: str) -> None:
331
335
332
336
shutil .move (renamed_dir , download_dest )
333
337
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
+
334
377
###############################################################################
335
378
def _clone_and_checkout (repo_url : str , tag_name : str , clone_dest : str ) -> None :
336
379
###############################################################################
337
380
"""
338
381
Clones a Git repository from the URL and checks out a specific branch.
339
382
340
383
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
343
386
clone_dest: destination where the repository will be cloned
344
387
345
388
Raises:
0 commit comments