Skip to content
Snippets Groups Projects
Commit ec7b3ae9 authored by Marc Herbert's avatar Marc Herbert
Browse files

elf.py: remove StaticLibFile; ArFile.compare_details() is much better


Remove the old code in the StaticLibFile class as it now duplicates the
recursion in ArFile.compare_details() in a much inferior way. Fixes
issue #64, see the multiple use cases there and in the next commit
adding tests.

The patch header line in the test output is decremented one line because
when run on .a files readelf inserted headings like this:

  In archive test1.a:

Signed-off-by: default avatarMarc Herbert <Marc.Herbert@gmail.com>
parent 919f091b
No related branches found
No related tags found
1 merge request!32Remove elf.StaticLibFile
......@@ -55,7 +55,6 @@ class ComparatorManager(object):
('elf.ElfFile',),
('macho.MachoFile',),
('fsimage.FsImageFile',),
('elf.StaticLibFile',),
('llvm.LlvmBitCodeFile',),
('sqlite.Sqlite3Database',),
('wasm.WasmFile',),
......
......@@ -31,10 +31,9 @@ from .utils.libarchive import LibarchiveContainer, list_libarchive
logger = logging.getLogger(__name__)
# TODO: this would also be useful for Go archives. Currently those are handled
# by StaticLibFile, but then readelf complains with "Error: Not an ELF file".
# ArFile gives slightly more reasonable output, e.g. a readable plain diff of
# the __.PKGDEF member which is just a text file containing the Go interface.
# For Go archives this gives a readable plain diff of the __.PKGDEF
# member which is just a text file containing the Go interface.
# TODO: add Go tests and more recursion.
class ArContainer(LibarchiveContainer):
......
......@@ -623,23 +623,3 @@ class ElfFile(File):
def compare_details(self, other, source=None):
return _compare_elf_data(self.path, other.path)
class StaticLibFile(File):
DESCRIPTION = "statically-linked binaries"
CONTAINER_CLASS = ElfContainer
FILE_TYPE_RE = re.compile(r'\bar archive\b')
FILE_EXTENSION_SUFFIX = '.a'
def compare_details(self, other, source=None):
differences = [
Difference.from_text_readers(
list_libarchive(self.path),
list_libarchive(other.path),
self.path,
other.path,
source="file list",
)
]
differences.extend(_compare_elf_data(self.path, other.path))
return differences
......@@ -23,7 +23,8 @@ import os.path
import subprocess
from diffoscope.config import Config
from diffoscope.comparators.elf import ElfFile, StaticLibFile
from diffoscope.comparators.ar import ArFile
from diffoscope.comparators.elf import ElfFile
from diffoscope.comparators.binary import FilesystemFile
from diffoscope.comparators.directory import FilesystemDirectory
from diffoscope.comparators.missing_file import MissingFile
......@@ -108,7 +109,7 @@ def lib2():
def test_lib_identification(lib1):
assert isinstance(lib1, StaticLibFile)
assert isinstance(lib1, ArFile)
def test_lib_no_differences(lib1):
......@@ -129,9 +130,9 @@ def test_lib_differences(lib_differences):
assert lib_differences[0].source1 == 'file list'
expected_metadata_diff = get_data('elf_lib_metadata_expected_diff')
assert lib_differences[0].unified_diff == expected_metadata_diff
assert 'objdump' in lib_differences[1].source1
assert 'objdump' in lib_differences[1].details[0].source1
expected_objdump_diff = get_data('elf_lib_objdump_expected_diff')
assert lib_differences[1].unified_diff == expected_objdump_diff
assert lib_differences[1].details[0].unified_diff == expected_objdump_diff
@skip_unless_tools_exist('readelf', 'objdump')
......
@@ -4,10 +4,10 @@
@@ -3,10 +3,10 @@
Disassembly of section .text:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment