Commit ce6c03fe authored by Marc Herbert's avatar Marc Herbert Committed by Chris Lamb
Browse files

Remove StaticLibFile in the ELF comparator; ArFile.compare_details() is...


Remove StaticLibFile in the ELF comparator; ArFile.compare_details() is superior. (Closes: #64)

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: Chris Lamb's avatarChris Lamb <lamby@debian.org>
parent a8a56dbe
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ class ComparatorManager(object):
        ('elf.ElfFile',),
        ('macho.MachoFile',),
        ('fsimage.FsImageFile',),
        ('elf.StaticLibFile',),
        ('llvm.LlvmBitCodeFile',),
        ('sqlite.Sqlite3Database',),
        ('wasm.WasmFile',),
+3 −4
Original line number Diff line number Diff line
@@ -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):
+0 −20
Original line number Diff line number Diff line
@@ -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
+5 −4
Original line number Diff line number Diff line
@@ -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')
+1 −1
Original line number Diff line number Diff line
@@ -4,10 +4,10 @@
@@ -3,10 +3,10 @@
 
 Disassembly of section .text: