[Git][reproducible-builds/diffoscope][master] Add support for comparing OCaml files via ocamlobjinfo. (Closes: #910542)

Chris Lamb gitlab at salsa.debian.org
Tue Oct 16 23:00:13 CEST 2018


Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
bc92ac31 by Chris Lamb at 2018-10-16T20:59:49Z
Add support for comparing OCaml files via ocamlobjinfo. (Closes: #910542)

- - - - -


8 changed files:

- debian/control
- diffoscope/comparators/__init__.py
- + diffoscope/comparators/ocaml.py
- diffoscope/external_tools.py
- + tests/comparators/test_ocaml.py
- + tests/data/ocaml_expected_diff
- + tests/data/test1.cmi
- + tests/data/test2.cmi


Changes:

=====================================
debian/control
=====================================
@@ -44,6 +44,7 @@ Build-Depends:
  llvm <!nocheck>,
  lz4 <!nocheck> | liblz4-tool <!nocheck>,
  mono-utils <!nocheck>,
+ ocaml-nox <!nocheck>,
  odt2txt <!nocheck>,
 # oggvideotools [!s390x] <!nocheck>,
  openssh-client <!nocheck>,


=====================================
diffoscope/comparators/__init__.py
=====================================
@@ -83,6 +83,7 @@ class ComparatorManager(object):
         ('xz.XzFile',),
         ('apk.ApkFile',),
         ('odt.OdtFile',),
+        ('ocaml.OcamlInterfaceFile',),
         ('docx.DocxFile',),
         ('zip.ZipFile',),
         ('zip.MozillaZipFile',),


=====================================
diffoscope/comparators/ocaml.py
=====================================
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2018 Chris Lamb <lamby at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import re
+
+from diffoscope.tools import tool_required
+from diffoscope.difference import Difference
+
+from .utils.file import File
+from .utils.command import Command
+
+
+class Ocamlobjinfo(Command):
+    @tool_required('ocamlobjinfo')
+    def cmdline(self):
+        return ('ocamlobjinfo', self.path)
+
+    def filter(self, line):
+        val = line.decode('utf-8')
+        if val.startswith('File '):
+            return b''
+        return line
+
+
+class OcamlInterfaceFile(File):
+    DESCRIPTION = "OCaml interface files"
+    FILE_TYPE_RE = re.compile(r'^OCaml interface file ')
+
+    def compare_details(self, other, source=None):
+        return [Difference.from_command(
+            Ocamlobjinfo,
+            self.path,
+            other.path,
+            source="ocamlobjinfo",
+        )]


=====================================
diffoscope/external_tools.py
=====================================
@@ -170,6 +170,9 @@ EXTERNAL_TOOLS = {
         'debian': 'binutils-multiarch',
         'arch': 'binutils',
     },
+    'ocamlobjinfo': {
+        'debian': 'ocaml-nox',
+    },
     'odt2txt': {
         'debian': 'odt2txt',
         'arch': 'odt2txt',


=====================================
tests/comparators/test_ocaml.py
=====================================
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2018 Chris Lamb <lamby at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+
+from diffoscope.comparators.ocaml import OcamlInterfaceFile
+
+from ..utils.data import load_fixture, get_data
+from ..utils.tools import skip_unless_tools_exist
+from ..utils.nonexisting import assert_non_existing
+
+cmi1 = load_fixture('test1.cmi')
+cmi2 = load_fixture('test2.cmi')
+
+
+def test_identification(cmi1):
+    assert isinstance(cmi1, OcamlInterfaceFile)
+
+
+ at pytest.fixture
+def differences(cmi1, cmi2):
+    return cmi1.compare(cmi2).details
+
+
+def test_no_differences(cmi1):
+    difference = cmi1.compare(cmi1)
+    assert difference is None
+
+
+ at skip_unless_tools_exist('ocamlobjinfo')
+def test_diff(differences):
+    expected_diff = get_data('ocaml_expected_diff')
+    assert differences[0].unified_diff == expected_diff
+
+
+ at skip_unless_tools_exist('ocamlobjinfo')
+def test_compare_non_existing(monkeypatch, cmi1):
+    assert_non_existing(monkeypatch, cmi1, has_null_source=False)


=====================================
tests/data/ocaml_expected_diff
=====================================
@@ -0,0 +1,15 @@
+@@ -1,5 +1,14 @@
+ Unit name: Uchar
+ Interfaces imported:
+ 	84838649f9351de166bfa8b9f2c84db4	Uchar
+ 	07ea9e20ae94d62c35cfecbe7d66d3ea	Pervasives
+ 	cbd5f2d6b649925222e1e9fb63b89db6	CamlinternalFormatBasics
++Cmt unit name: Uchar
++Cmt interfaces imported:
++	cbd5f2d6b649925222e1e9fb63b89db6	CamlinternalFormatBasics
++	07ea9e20ae94d62c35cfecbe7d66d3ea	Pervasives
++	84838649f9351de166bfa8b9f2c84db4	Uchar
++Source file: uchar.mli
++Compilation flags: ../ocamlc -strict-sequence -absname -w +a-4-9-41-42-44-45-48 -g -warn-error A -bin-annot -nostdlib -safe-string -strict-formats -c uchar.mli
++Load path: 
++cmt interface digest: 84838649f9351de166bfa8b9f2c84db4


=====================================
tests/data/test1.cmi
=====================================
Binary files /dev/null and b/tests/data/test1.cmi differ


=====================================
tests/data/test2.cmi
=====================================
Binary files /dev/null and b/tests/data/test2.cmi differ



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/bc92ac311960b43abd1067df83ddee1729dc38bd

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/commit/bc92ac311960b43abd1067df83ddee1729dc38bd
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20181016/53a17a6d/attachment.html>


More information about the rb-commits mailing list