Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError when running get_rpaths on rez.utils.elf module #1798

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading