diff --git a/conda_build/os_utils/liefldd.py b/conda_build/os_utils/liefldd.py index b3b155c6c5..c1938590e3 100644 --- a/conda_build/os_utils/liefldd.py +++ b/conda_build/os_utils/liefldd.py @@ -44,6 +44,16 @@ except AttributeError: # Fallback for lief<0.15. ELF_DYNAMIC_TAGS = lief.ELF.DYNAMIC_TAGS + try: + LOAD_COMMAND_TYPES = lief.MachO.LoadCommand.TYPE + except AttributeError: + # Fallback for lief<0.15. + LOAD_COMMAND_TYPES = lief.MachO.LOAD_COMMAND_TYPES + try: + ELF_CLASS = lief.ELF.Header.CLASS + except AttributeError: + # Fallback for lief<0.15. + ELF_CLASS = lief.ELF.ELF_CLASS except ImportError: have_lief = False @@ -134,7 +144,7 @@ def get_libraries(file): binary_name = [ command.name for command in binary.commands - if command.command == lief.MachO.LOAD_COMMAND_TYPES.ID_DYLIB + if command.command == LOAD_COMMAND_TYPES.ID_DYLIB ] binary_name = binary_name[0] if len(binary_name) else None result = [ @@ -193,10 +203,7 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag): binary_format = binary.format if binary_format == EXE_FORMATS.ELF: binary_type = binary.type - if ( - binary_type == lief.ELF.ELF_CLASS.CLASS32 - or binary_type == lief.ELF.ELF_CLASS.CLASS64 - ): + if binary_type == ELF_CLASS.CLASS32 or binary_type == ELF_CLASS.CLASS64: rpaths = _get_elf_rpathy_thing(binary, elf_attribute, elf_dyn_tag) elif ( binary_format == EXE_FORMATS.MACHO @@ -207,7 +214,7 @@ def get_rpathy_thing_raw_partial(file, elf_attribute, elf_dyn_tag): [ command.path for command in binary.commands - if command.command == lief.MachO.LOAD_COMMAND_TYPES.RPATH + if command.command == LOAD_COMMAND_TYPES.RPATH ] ) return rpaths, binary_format, binary_type @@ -250,8 +257,7 @@ def set_rpath(old_matching, new_rpath, file): if not binary: return if binary.format == EXE_FORMATS.ELF and ( - binary.type == lief.ELF.ELF_CLASS.CLASS32 - or binary.type == lief.ELF.ELF_CLASS.CLASS64 + binary.type == ELF_CLASS.CLASS32 or binary.type == ELF_CLASS.CLASS64 ): if _set_elf_rpathy_thing( binary, old_matching, new_rpath, set_rpath=True, set_runpath=False @@ -339,7 +345,7 @@ def from_os_varnames(binary_format, binary_type, input_): .replace("@rpath", "$RPATH") ) elif binary_format == EXE_FORMATS.ELF: - if binary_type == lief.ELF.ELF_CLASS.CLASS64: + if binary_type == ELF_CLASS.CLASS64: libdir = "/lib64" else: libdir = "/lib" @@ -365,8 +371,7 @@ def get_uniqueness_key(filename, file): elif binary.format == EXE_FORMATS.MACHO: return filename elif binary.format == EXE_FORMATS.ELF and ( # noqa - binary.type == lief.ELF.ELF_CLASS.CLASS32 - or binary.type == lief.ELF.ELF_CLASS.CLASS64 + binary.type == ELF_CLASS.CLASS32 or binary.type == ELF_CLASS.CLASS64 ): dynamic_entries = binary.dynamic_entries result = [e.name for e in dynamic_entries if e.tag == ELF_DYNAMIC_TAGS.SONAME] @@ -483,7 +488,7 @@ def inspect_linkages_lief( if not binary: default_paths = [] elif binary.format == EXE_FORMATS.ELF: - if binary.type == lief.ELF.ELF_CLASS.CLASS64: + if binary.type == ELF_CLASS.CLASS64: default_paths = [ "$SYSROOT/lib64", "$SYSROOT/usr/lib64", diff --git a/news/5595-more-lief-compat b/news/5595-more-lief-compat new file mode 100644 index 0000000000..7e4fe53bed --- /dev/null +++ b/news/5595-more-lief-compat @@ -0,0 +1,19 @@ +### Enhancements + +* Additional compatibility fixes for LIEF>=0.15. (#5594 via #5595) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/tests/test-recipes/metadata/_rpath/meta.yaml b/tests/test-recipes/metadata/_rpath/meta.yaml index 1a9ba6a97f..87459cfce6 100755 --- a/tests/test-recipes/metadata/_rpath/meta.yaml +++ b/tests/test-recipes/metadata/_rpath/meta.yaml @@ -19,4 +19,4 @@ test: commands: - python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == getattr(lief.ELF, 'DYNAMIC_TAGS', getattr(lief.ELF.DynamicEntry, 'TAG', None)).RPATH])" # [linux] - python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print([e.rpath for e in binary.dynamic_entries if e.tag == getattr(lief.ELF, 'DYNAMIC_TAGS', getattr(lief.ELF.DynamicEntry, 'TAG', None)).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] + - python -c "import lief; binary = lief.parse(\"${PREFIX}/bin/rpath\"); print(':'.join([command.path.rstrip('/') for command in binary.commands if command.command == getattr(lief.MachO, 'LOAD_COMMAND_TYPES', getattr(lief.MachO.LoadCommand, 'TYPE', None)).RPATH]))" | grep ${PREFIX}/../previous:${PREFIX}/../lib:${PREFIX}/plugins:${PREFIX}/../successive # [osx] diff --git a/tests/test-recipes/metadata/_rpath_symlink/meta.yaml b/tests/test-recipes/metadata/_rpath_symlink/meta.yaml index 8d50f711ab..ef7ec6a27b 100644 --- a/tests/test-recipes/metadata/_rpath_symlink/meta.yaml +++ b/tests/test-recipes/metadata/_rpath_symlink/meta.yaml @@ -35,5 +35,5 @@ test: 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 == getattr(lief.ELF, "DYNAMIC_TAGS", getattr(lief.ELF.DynamicEntry, "TAG", None)).RPATH} # [linux] - assert {"@loader_path/"} == {command.path for command in lib.commands if command.command == lief.MachO.LOAD_COMMAND_TYPES.RPATH} # [osx] + assert {"@loader_path/"} == {command.path for command in lib.commands if command.command == getattr(lief.MachO, "LOAD_COMMAND_TYPES", getattr(lief.MachO.LoadCommand, "TYPE", None)).RPATH} # [osx] '