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

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 <>
parent a8a56dbe
......@@ -55,7 +55,6 @@ class ComparatorManager(object):
......@@ -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"
FILE_TYPE_RE = re.compile(r'\bar archive\b')
def compare_details(self, other, source=None):
differences = [
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 import ArFile
from diffoscope.comparators.elf import ElfFile
from diffoscope.comparators.binary import FilesystemFile
from 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:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment