Skip to content

Commit

Permalink
Merge pull request easybuilders#3120 from branfosj/20240131094650_new…
Browse files Browse the repository at this point in the history
…_pr_java

replace `run_cmd` with `run_shell_cmd` in custom easyblock for Java (`java.py`)
  • Loading branch information
jfgrimm authored Feb 1, 2024
2 parents d478c3d + ba23528 commit dcd646c
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions easybuild/easyblocks/j/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import build_option
from easybuild.tools.filetools import adjust_permissions, change_dir, copy_dir, copy_file, remove_dir, which
from easybuild.tools.run import run_cmd
from easybuild.tools.run import run_shell_cmd
from easybuild.tools.systemtools import AARCH64, POWER, X86_64, get_cpu_architecture, get_shared_lib_ext
from easybuild.tools.utilities import nub

Expand Down Expand Up @@ -72,7 +72,7 @@ def extract_step(self):
adjust_permissions(os.path.join(self.builddir, self.src[0]['name']), stat.S_IXUSR, add=True)

change_dir(self.builddir)
run_cmd(os.path.join(self.builddir, self.src[0]['name']), log_all=True, simple=True, inp='')
run_shell_cmd(os.path.join(self.builddir, self.src[0]['name']), stdin='')
else:
PackedBinary.extract_step(self)
adjust_permissions(self.builddir, stat.S_IWUSR, add=True, recursive=True)
Expand Down Expand Up @@ -136,33 +136,33 @@ def post_install_step(self):
for bindir in bindirs:
for path in os.listdir(bindir):
path = os.path.join(bindir, path)
out, _ = run_cmd("file %s" % path, trace=False)
if "dynamically linked" in out:
res = run_shell_cmd("file %s" % path, hidden=True)
if "dynamically linked" in res.output:

out, _ = run_cmd("patchelf --print-interpreter %s" % path, trace=False)
self.log.debug("ELF interpreter for %s: %s" % (path, out))
res = run_shell_cmd("patchelf --print-interpreter %s" % path)
self.log.debug("ELF interpreter for %s: %s" % (path, res.output))

run_cmd("patchelf --set-interpreter %s %s" % (elf_interp, path), trace=False)
run_shell_cmd("patchelf --set-interpreter %s %s" % (elf_interp, path), hidden=True)

out, _ = run_cmd("patchelf --print-interpreter %s" % path, trace=False)
self.log.debug("ELF interpreter for %s: %s" % (path, out))
res = run_shell_cmd("patchelf --print-interpreter %s" % path, hidden=True)
self.log.debug("ELF interpreter for %s: %s" % (path, res.output))

out, _ = run_cmd("patchelf --print-rpath %s" % path, simple=False, trace=False)
curr_rpath = out.strip()
res = run_shell_cmd("patchelf --print-rpath %s" % path, hidden=True)
curr_rpath = res.output.strip()
self.log.debug("RPATH for %s: %s" % (path, curr_rpath))

new_rpath = ':'.join([curr_rpath] + sysroot_lib_paths)
# note: it's important to wrap the new RPATH value in single quotes,
# to avoid magic values like $ORIGIN being resolved by the shell
run_cmd("patchelf --set-rpath '%s' %s" % (new_rpath, path), trace=False)
run_shell_cmd("patchelf --set-rpath '%s' %s" % (new_rpath, path), hidden=True)

curr_rpath, _ = run_cmd("patchelf --print-rpath %s" % path, simple=False, trace=False)
self.log.debug("RPATH for %s (prior to shrinking): %s" % (path, curr_rpath))
res = run_shell_cmd("patchelf --print-rpath %s" % path, hidden=True)
self.log.debug("RPATH for %s (prior to shrinking): %s" % (path, res.output))

run_cmd("patchelf --shrink-rpath %s" % path, trace=False)
run_shell_cmd("patchelf --shrink-rpath %s" % path, hidden=True)

curr_rpath, _ = run_cmd("patchelf --print-rpath %s" % path, simple=False, trace=False)
self.log.debug("RPATH for %s (after shrinking): %s" % (path, curr_rpath))
res = run_shell_cmd("patchelf --print-rpath %s" % path, hidden=True)
self.log.debug("RPATH for %s (after shrinking): %s" % (path, res.output))

libdirs = [os.path.join(self.installdir, libdir) for libdir in module_guesses['LIBRARY_PATH'] if
os.path.exists(os.path.join(self.installdir, libdir))]
Expand All @@ -173,22 +173,22 @@ def post_install_step(self):
for path, _, filenames in os.walk(libdir):
shlibs = [os.path.join(path, x) for x in filenames if x.endswith(shlib_ext)]
for shlib in shlibs:
out, _ = run_cmd("patchelf --print-rpath %s" % shlib, simple=False, trace=False)
curr_rpath = out.strip()
res = run_shell_cmd("patchelf --print-rpath %s" % shlib, hidden=True)
curr_rpath = res.output.strip()
self.log.debug("RPATH for %s: %s" % (shlib, curr_rpath))

new_rpath = ':'.join([curr_rpath] + sysroot_lib_paths)
# note: it's important to wrap the new RPATH value in single quotes,
# to avoid magic values like $ORIGIN being resolved by the shell
run_cmd("patchelf --set-rpath '%s' %s" % (new_rpath, shlib), trace=False)
run_shell_cmd("patchelf --set-rpath '%s' %s" % (new_rpath, shlib), hidden=True)

curr_rpath, _ = run_cmd("patchelf --print-rpath %s" % shlib, simple=False, trace=False)
self.log.debug("RPATH for %s (prior to shrinking): %s" % (path, curr_rpath))
res = run_shell_cmd("patchelf --print-rpath %s" % shlib, hidden=True)
self.log.debug("RPATH for %s (prior to shrinking): %s" % (path, res.output))

run_cmd("patchelf --shrink-rpath %s" % shlib, trace=False)
run_shell_cmd("patchelf --shrink-rpath %s" % shlib, hidden=True)

curr_rpath, _ = run_cmd("patchelf --print-rpath %s" % shlib, simple=False, trace=False)
self.log.debug("RPATH for %s (after shrinking): %s" % (path, curr_rpath))
res = run_shell_cmd("patchelf --print-rpath %s" % shlib, hidden=True)
self.log.debug("RPATH for %s (after shrinking): %s" % (path, res.output))

except OSError as err:
raise EasyBuildError("Failed to patch RPATH section in binaries/libraries: %s", err)
Expand Down

0 comments on commit dcd646c

Please sign in to comment.