Skip to content

Commit

Permalink
adapt for api changes in py-lief 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
tkelman authored Dec 11, 2024
1 parent afe0570 commit 6246b5b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
17 changes: 11 additions & 6 deletions conda_build/os_utils/liefldd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
except AttributeError:
# Fallback for lief<0.14.
EXE_FORMATS = lief.EXE_FORMATS
try:
ELF_DYNAMIC_TAGS = lief.ELF.DynamicEntry.TAG
except AttributeError:
# Fallback for lief<0.15.
ELF_DYNAMIC_TAGS = lief.ELF.DYNAMIC_TAGS
except ImportError:
have_lief = False

Expand Down Expand Up @@ -155,15 +160,15 @@ def _set_elf_rpathy_thing(binary, old_matching, new_rpath, set_rpath, set_runpat
for e in dynamic_entries:
if (
set_runpath
and e.tag == lief.ELF.DYNAMIC_TAGS.RUNPATH
and e.tag == ELF_DYNAMIC_TAGS.RUNPATH
and fnmatch(e.runpath, old_matching)
and e.runpath != new_rpath
):
e.runpath = new_rpath
changed = True
elif (
set_rpath
and e.tag == lief.ELF.DYNAMIC_TAGS.RPATH
and e.tag == ELF_DYNAMIC_TAGS.RPATH
and fnmatch(e.rpath, old_matching)
and e.rpath != new_rpath
):
Expand Down Expand Up @@ -196,7 +201,7 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag):
elif (
binary_format == EXE_FORMATS.MACHO
and binary.has_rpath
and elf_dyn_tag == lief.ELF.DYNAMIC_TAGS.RPATH
and elf_dyn_tag == ELF_DYNAMIC_TAGS.RPATH
):
rpaths.extend(
[
Expand All @@ -210,12 +215,12 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag):
get_runpaths_raw = partial(
get_rpathy_thing_raw_partial,
elf_attribute="runpath",
elf_dyn_tag=lief.ELF.DYNAMIC_TAGS.RUNPATH,
elf_dyn_tag=ELF_DYNAMIC_TAGS.RUNPATH,
)
get_rpaths_raw = partial(
get_rpathy_thing_raw_partial,
elf_attribute="rpath",
elf_dyn_tag=lief.ELF.DYNAMIC_TAGS.RPATH,
elf_dyn_tag=ELF_DYNAMIC_TAGS.RPATH,
)
else:

Expand Down Expand Up @@ -365,7 +370,7 @@ def get_uniqueness_key(filename, file):
):
dynamic_entries = binary.dynamic_entries
result = [
e.name for e in dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.SONAME
e.name for e in dynamic_entries if e.tag == ELF_DYNAMIC_TAGS.SONAME
]
if result:
return result[0]
Expand Down
6 changes: 3 additions & 3 deletions tests/test-recipes/metadata/_rpath/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ requirements:

test:
requires:
- py-lief
- py-lief >=0.15
commands:
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RPATH])" # [linux]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RPATH])" | grep \$ORIGIN/../previous:\$ORIGIN/../lib:\$ORIGIN/../plugins:\$ORIGIN/../successive # [linux]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == lief.ELF.DynamicEntry.TAG.RPATH])" # [linux]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == lief.ELF.DynamicEntry.TAG.RPATH])" | grep \$ORIGIN/../previous:\$ORIGIN/../lib:\$ORIGIN/../plugins:\$ORIGIN/../successive # [linux]
- python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print(':'.join([command.path.rstrip('/') for command in binary.commands if command.command == lief.MachO.LOAD_COMMAND_TYPES.RPATH]))" | grep ${PREFIX}/../previous:${PREFIX}/../lib:${PREFIX}/plugins:${PREFIX}/../successive # [osx]
4 changes: 2 additions & 2 deletions tests/test-recipes/metadata/_rpath_symlink/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ requirements:

test:
requires:
- py-lief
- py-lief >=0.15
commands:
# Test that we get only a single entry that is the library's own directory.
- |
python -c '
import os, lief
lib = lief.parse(os.environ["PREFIX"] + "/lib/{{ lib_file }}")
assert {"$ORIGIN/."} == {e.rpath for e in lib.dynamic_entries if e.tag == lief.ELF.DYNAMIC_TAGS.RPATH} # [linux]
assert {"$ORIGIN/."} == {e.rpath for e in lib.dynamic_entries if e.tag == lief.ELF.DynamicEntry.TAG.RPATH} # [linux]
assert {"@loader_path/"} == {command.path for command in lib.commands if command.command == lief.MachO.LOAD_COMMAND_TYPES.RPATH} # [osx]
'

0 comments on commit 6246b5b

Please sign in to comment.