Skip to content

Commit 29d81c0

Browse files
committed
remove chdir and update subprocess command to add cwd
1 parent 91414fd commit 29d81c0

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

cime_config/buildlib

+6-16
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,6 @@ def _build_musica(clone_dest: str) -> str:
271271
shutil.rmtree(bld_path)
272272
os.makedirs(bld_path)
273273

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-
278274
install_dir = "install"
279275
command = [
280276
"cmake",
@@ -285,8 +281,8 @@ def _build_musica(clone_dest: str) -> str:
285281
".."
286282
]
287283
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)
290286
except subprocess.CalledProcessError as e:
291287
raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \
292288
for cmake to configure the MUSICA CMake project failed.") from e
@@ -297,8 +293,8 @@ def _build_musica(clone_dest: str) -> str:
297293

298294
command = ["cmake", "--build", ".", "--target", "install"]
299295
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)
302298
except subprocess.CalledProcessError as e:
303299
raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \
304300
for cmake to build the MUSICA library failed.") from e
@@ -307,7 +303,6 @@ def _build_musica(clone_dest: str) -> str:
307303
except OSError as e:
308304
raise OSError("An error occurred while executing the 'cmake' command.") from e
309305

310-
os.chdir(current_dir)
311306
musica_install_path = os.path.join(bld_path, install_dir)
312307

313308
return musica_install_path
@@ -366,9 +361,6 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
366361
an exception is raised with the error message.
367362
"""
368363

369-
current_dir = os.getcwd()
370-
os.chdir(caseroot)
371-
372364
unlock_file("env_build.xml", caseroot)
373365

374366
command = [
@@ -379,8 +371,8 @@ def _set_musica_lib_path(musica_install_path: str, caseroot: str) -> None:
379371
f"CAM_LINKED_LIBS=-L{os.path.join(musica_install_path, 'lib64')} -lmusica-fortran -lmusica -lyaml-cpp"
380372
]
381373
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)
384376
except subprocess.CalledProcessError as e:
385377
raise subprocess.CalledProcessError(e.returncode, e.cmd, "The subprocess \
386378
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:
389381
except OSError as e:
390382
raise OSError("An error occurred while executing the 'xmlchange' command.") from e
391383

392-
os.chdir(current_dir)
393-
394384
lock_file("env_build.xml", caseroot)
395385

396386
###############################################################################

0 commit comments

Comments
 (0)