[Reproducible-commits] [debbindiff] 08/09: Add support for comparing static libraries
Jérémy Bobbio
lunar at moszumanska.debian.org
Tue Sep 30 15:10:11 UTC 2014
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository debbindiff.
commit 3dbd095d737b9b8b2017f208295f8427d2fa8f8d
Author: Jérémy Bobbio <lunar at debian.org>
Date: Tue Sep 30 16:43:24 2014 +0200
Add support for comparing static libraries
---
debbindiff/comparators/__init__.py | 3 ++-
debbindiff/comparators/deb.py | 6 +-----
debbindiff/comparators/elf.py | 30 +++++++++++++++++++++++++-----
debbindiff/comparators/utils.py | 4 ++++
4 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/debbindiff/comparators/__init__.py b/debbindiff/comparators/__init__.py
index ed44dd3..39b0d71 100644
--- a/debbindiff/comparators/__init__.py
+++ b/debbindiff/comparators/__init__.py
@@ -27,7 +27,7 @@ from debbindiff.comparators.binary import compare_binary_files
from debbindiff.comparators.bzip2 import compare_bzip2_files
from debbindiff.comparators.changes import compare_changes_files
from debbindiff.comparators.deb import compare_deb_files, compare_md5sums_files
-from debbindiff.comparators.elf import compare_elf_files
+from debbindiff.comparators.elf import compare_elf_files, compare_static_lib_files
from debbindiff.comparators.gettext import compare_mo_files
from debbindiff.comparators.gzip import compare_gzip_files
from debbindiff.comparators.haskell import compare_hi_files
@@ -70,6 +70,7 @@ COMPARATORS = [
(r'^application/x-bzip2(;|$)', r'\.bzip2$', compare_bzip2_files),
(r'^application/x-executable(;|$)', None, compare_elf_files),
(r'^application/x-sharedlib(;|$)', r'\.so($|\.[0-9.]+$)', compare_elf_files),
+ (None, r'\.a$', compare_static_lib_files),
]
def compare_files(path1, path2, source=None):
diff --git a/debbindiff/comparators/deb.py b/debbindiff/comparators/deb.py
index 043aa57..3fafcd1 100644
--- a/debbindiff/comparators/deb.py
+++ b/debbindiff/comparators/deb.py
@@ -18,15 +18,11 @@
# along with debbindiff. If not, see <http://www.gnu.org/licenses/>.
import os.path
-import subprocess
from debian.arfile import ArFile
from debbindiff import logger
from debbindiff.difference import Difference, get_source
import debbindiff.comparators
-from debbindiff.comparators.utils import binary_fallback, make_temp_directory, are_same_binaries
-
-def get_ar_content(path):
- return subprocess.check_output(['ar', 'tv', path], shell=False)
+from debbindiff.comparators.utils import binary_fallback, make_temp_directory, are_same_binaries, get_ar_content
@binary_fallback
def compare_deb_files(path1, path2, source=None):
diff --git a/debbindiff/comparators/elf.py b/debbindiff/comparators/elf.py
index 77d410a..cec8983 100644
--- a/debbindiff/comparators/elf.py
+++ b/debbindiff/comparators/elf.py
@@ -20,22 +20,27 @@
import os.path
import re
import subprocess
-from debbindiff.comparators.utils import binary_fallback
+from debbindiff.comparators.utils import binary_fallback, get_ar_content
from debbindiff.difference import Difference
def readelf_all(path):
- return subprocess.check_output(['readelf', '--all', path], shell=False)
+ output = subprocess.check_output(['readelf', '--all', path], shell=False)
+ # the full path can appear in the output, we need to remove it
+ return re.sub(re.escape(path), os.path.basename(path), output)
def readelf_debug_dump(path):
- return subprocess.check_output(['readelf', '--debug-dump', path], shell=False)
+ output = subprocess.check_output(['readelf', '--debug-dump', path], shell=False)
+ # the full path can appear in the output, we need to remove it
+ return re.sub(re.escape(path), os.path.basename(path), output)
def objdump_disassemble(path):
output = subprocess.check_output(['objdump', '--disassemble', path], shell=False)
# the full path appears in the output, we need to remove it
return re.sub(re.escape(path), os.path.basename(path), output)
- at binary_fallback
-def compare_elf_files(path1, path2, source=None):
+# this one is not wrapped with binary_fallback and is used
+# by both compare_elf_files and compare_static_lib_files
+def _compare_elf_data(path1, path2, source=None):
differences = []
all1 = readelf_all(path1)
all2 = readelf_all(path2)
@@ -50,3 +55,18 @@ def compare_elf_files(path1, path2, source=None):
if objdump1 != objdump2:
differences.append(Difference(objdump1.splitlines(1), objdump2.splitlines(1), path1, path2, source='objdump --disassemble'))
return differences
+
+ at binary_fallback
+def compare_elf_files(path1, path2, source=None):
+ return _compare_elf_data(path1, path2, source=None)
+
+ at binary_fallback
+def compare_static_lib_files(path1, path2, source=None):
+ differences = []
+ # look up differences in metadata
+ content1 = get_ar_content(path1)
+ content2 = get_ar_content(path2)
+ if content1 != content2:
+ differences.append(Difference(content1.splitlines(1), content2.splitlines(1), path1, path2, source="metadata"))
+ differences.extend(_compare_elf_data(path1, path2, source))
+ return differences
diff --git a/debbindiff/comparators/utils.py b/debbindiff/comparators/utils.py
index cc31f45..28c1249 100644
--- a/debbindiff/comparators/utils.py
+++ b/debbindiff/comparators/utils.py
@@ -20,6 +20,7 @@
from contextlib import contextmanager
import hashlib
import shutil
+import subprocess
import tempfile
from debbindiff.comparators.binary import compare_binary_files
from debbindiff.difference import Difference, get_source
@@ -63,3 +64,6 @@ def make_temp_directory():
temp_dir = tempfile.mkdtemp(suffix='debbindiff')
yield temp_dir
shutil.rmtree(temp_dir)
+
+def get_ar_content(path):
+ return subprocess.check_output(['ar', 'tv', path], shell=False)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/debbindiff.git
More information about the Reproducible-commits
mailing list