Skip to content

Commit

Permalink
Fix TypeError when running get_rpaths on rez.utils.elf module (#1798)
Browse files Browse the repository at this point in the history
Signed-off-by: Ruzette Krukkert <[email protected]>
Signed-off-by: Jean-Christophe Morin <[email protected]>
Co-authored-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
ruzette and JeanChristopheMorinPerso authored Jul 21, 2024
1 parent 9c27f5e commit 3d0f224
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
38 changes: 38 additions & 0 deletions src/rez/tests/test_utils_elf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Contributors to the Rez Project


"""
unit tests for 'rez.utils.elf' module
"""
import platform
import unittest

from rez.tests.util import TestBase, program_dependent
from rez.utils.elf import get_rpaths, patch_rpaths


class TestElfUtils(TestBase):

def __init__(self, *nargs, **kwargs):
super().__init__(*nargs, **kwargs)

@classmethod
def setUpClass(cls):
super().setUpClass()

@classmethod
def tearDownClass(cls):
super().tearDownClass()

@unittest.skipUnless(platform.system() == "Linux", "Linux only")
@program_dependent("readelf")
def test_get_rpaths_raises_runtime_exception(self):
"""Tests that no TypeError from elf functions are raised."""
with self.assertRaises(RuntimeError) as exc:
get_rpaths("/path/to/elfpath")
self.assertIn("'/path/to/elfpath': No such file", str(exc.exception))

with self.assertRaises(RuntimeError) as exc:
patch_rpaths("/path/to/elfpath", ["$ORIGIN", "$ORIGINTEST"])
self.assertIn("'/path/to/elfpath': No such file", str(exc.exception))
23 changes: 1 addition & 22 deletions src/rez/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,33 +187,12 @@ def find_file_in_path(to_find, path_str, pathsep=None, reverse=True):
def program_dependent(program_name, *program_names):
"""Function decorator that skips the function if not all given programs are
visible."""
import subprocess

program_tests = {
"cmake": ['cmake', '-h'],
"make": ['make', '-h'],
"g++": ["g++", "--help"]
}

# test if programs all exist
def _test(name):
command = program_tests[name]

with open(os.devnull, 'wb') as DEVNULL:
try:
subprocess.check_call(command, stdout=DEVNULL, stderr=DEVNULL)
except (OSError, IOError, subprocess.CalledProcessError):
return False
else:
return True

names = [program_name] + list(program_names)
all_exist = all(_test(x) for x in names)

def decorator(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
if not all_exist:
if not all(shutil.which(x) for x in names):
self.skipTest(
"Requires all programs to be present and functioning: %s"
% names
Expand Down
4 changes: 3 additions & 1 deletion src/rez/utils/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import subprocess

from rez.utils.filesystem import make_path_writable
from rez.utils.execution import Popen


def get_rpaths(elfpath):
Expand Down Expand Up @@ -54,10 +55,11 @@ def patch_rpaths(elfpath, rpaths):


def _run(*nargs, **popen_kwargs):
proc = subprocess.Popen(
proc = Popen(
nargs,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
**popen_kwargs
)

Expand Down

0 comments on commit 3d0f224

Please sign in to comment.