[Git][reproducible-builds/diffoscope][master] Don't emit "javap not found in path" if it is available in the path but it did...

Chris Lamb gitlab at salsa.debian.org
Tue Jul 14 10:56:39 UTC 2020



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
d9ff65b0 by Chris Lamb at 2020-07-14T11:52:14+01:00
Don't emit "javap not found in path" if it is available in the path but it did not result in an actual difference.

- - - - -


1 changed file:

- diffoscope/comparators/java.py


Changes:

=====================================
diffoscope/comparators/java.py
=====================================
@@ -34,15 +34,13 @@ logger = logging.getLogger(__name__)
 
 
 class ProcyonDecompiler(Command):
-    TOOL = "procyon"
-
     def __init__(self, path, *args, **kwargs):
         super().__init__(path, *args, **kwargs)
         self.real_path = os.path.realpath(path)
 
-    @tool_required(TOOL)
+    @tool_required("procyon")
     def cmdline(self):
-        return [self.TOOL, "-ec", self.path]
+        return ["procyon", "-ec", self.path]
 
     def filter(self, line):
         if re.match(r"^(//)", line.decode("utf-8")):
@@ -51,16 +49,14 @@ class ProcyonDecompiler(Command):
 
 
 class Javap(Command):
-    TOOL = "javap"
-
     def __init__(self, path, *args, **kwargs):
         super().__init__(path, *args, **kwargs)
         self.real_path = os.path.realpath(path)
 
-    @tool_required(TOOL)
+    @tool_required("javap")
     def cmdline(self):
         return [
-            self.TOOL,
+            "javap",
             "-verbose",
             "-constants",
             "-s",
@@ -86,6 +82,7 @@ class ClassFile(File):
 
     def compare_details(self, other, source=None):
         diff = []
+        last_exc = None
 
         for decompiler in self.decompilers:
             try:
@@ -95,12 +92,17 @@ class ClassFile(File):
                 if single_diff:
                     diff.append(single_diff)
                     break
-            except RequiredToolNotFound:
+            except RequiredToolNotFound as exc:
+                # Save our exception
+                last_exc = exc
                 logger.debug(
-                    "Unable to find %s. Falling back...", decompiler.TOOL,
+                    "Unable to find %s. Falling back...", decompiler,
                 )
 
-        if not diff:
-            raise RequiredToolNotFound(self.decompilers[-1].TOOL)
+        # Re-raise the last exception we would have raised from the previous
+        # loop; we want to raise the least-common demoninator from our
+        # `decompilers` list.
+        if last_exc:
+            raise last_exc
 
         return diff



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

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/d9ff65b029b301c31fe21abc42c0330a301c9894
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/20200714/39623933/attachment.htm>


More information about the rb-commits mailing list