@@ -271,10 +271,6 @@ def _build_musica(clone_dest: str) -> str:
271
271
shutil .rmtree (bld_path )
272
272
os .makedirs (bld_path )
273
273
274
- # To install the target, the working directory must be the build (CMake binary) directory.
275
- current_dir = os .getcwd ()
276
- os .chdir (bld_path )
277
-
278
274
install_dir = "install"
279
275
command = [
280
276
"cmake" ,
@@ -285,8 +281,8 @@ def _build_musica(clone_dest: str) -> str:
285
281
".."
286
282
]
287
283
try :
288
- subprocess .run (command , stdout = subprocess . PIPE , stderr = subprocess .PIPE ,
289
- text = True , check = False )
284
+ subprocess .run (command , cwd = bld_path , stdout = subprocess .PIPE ,
285
+ stderr = subprocess . PIPE , text = True , check = False )
290
286
except subprocess .CalledProcessError as e :
291
287
raise subprocess .CalledProcessError (e .returncode , e .cmd , "The subprocess \
292
288
for cmake to configure the MUSICA CMake project failed." ) from e
@@ -297,8 +293,8 @@ def _build_musica(clone_dest: str) -> str:
297
293
298
294
command = ["cmake" , "--build" , "." , "--target" , "install" ]
299
295
try :
300
- subprocess .run (command , stdout = subprocess . PIPE , stderr = subprocess .PIPE ,
301
- text = True , check = False )
296
+ subprocess .run (command , cwd = bld_path , stdout = subprocess .PIPE ,
297
+ stderr = subprocess . PIPE , text = True , check = False )
302
298
except subprocess .CalledProcessError as e :
303
299
raise subprocess .CalledProcessError (e .returncode , e .cmd , "The subprocess \
304
300
for cmake to build the MUSICA library failed." ) from e
@@ -307,7 +303,6 @@ def _build_musica(clone_dest: str) -> str:
307
303
except OSError as e :
308
304
raise OSError ("An error occurred while executing the 'cmake' command." ) from e
309
305
310
- os .chdir (current_dir )
311
306
musica_install_path = os .path .join (bld_path , install_dir )
312
307
313
308
return musica_install_path
@@ -366,9 +361,6 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
366
361
an exception is raised with the error message.
367
362
"""
368
363
369
- current_dir = os .getcwd ()
370
- os .chdir (caseroot )
371
-
372
364
unlock_file ("env_build.xml" , caseroot )
373
365
374
366
command = [
@@ -379,8 +371,8 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
379
371
f"CAM_LINKED_LIBS=-L{ os .path .join (musica_install_path , 'lib64' )} -lmusica-fortran -lmusica -lyaml-cpp"
380
372
]
381
373
try :
382
- subprocess .run (command , stdout = subprocess . PIPE , stderr = subprocess .PIPE ,
383
- text = True , check = False )
374
+ subprocess .run (command , cwd = caseroot , stdout = subprocess .PIPE ,
375
+ stderr = subprocess . PIPE , text = True , check = False )
384
376
except subprocess .CalledProcessError as e :
385
377
raise subprocess .CalledProcessError (e .returncode , e .cmd , "The subprocess \
386
378
for xmlchange to set the MUSICA library path failed." ) from e
@@ -389,8 +381,6 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
389
381
except OSError as e :
390
382
raise OSError ("An error occurred while executing the 'xmlchange' command." ) from e
391
383
392
- os .chdir (current_dir )
393
-
394
384
lock_file ("env_build.xml" , caseroot )
395
385
396
386
###############################################################################
0 commit comments