[diffoscope] 01/01: On a non-GNU system, prefer tools that start with "g". (Closes: #871029)

Ximin Luo infinity0 at debian.org
Wed Aug 16 15:57:24 CEST 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository diffoscope.

commit f8d8a742925a353fccd689fc75a4df2e3032d6b8
Author: Ximin Luo <infinity0 at debian.org>
Date:   Wed Aug 16 15:56:39 2017 +0200

    On a non-GNU system, prefer tools that start with "g". (Closes: #871029)
---
 diffoscope/diff.py  | 4 ++--
 diffoscope/tools.py | 9 +++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/diffoscope/diff.py b/diffoscope/diff.py
index 17a5289..762acde 100644
--- a/diffoscope/diff.py
+++ b/diffoscope/diff.py
@@ -31,7 +31,7 @@ from multiprocessing.dummy import Queue
 
 from diffoscope.tempfiles import get_temporary_directory
 
-from .tools import tool_required
+from .tools import get_tool_name, tool_required
 from .config import Config
 
 DIFF_CHUNK = 4096
@@ -161,7 +161,7 @@ class DiffParser(object):
 
 @tool_required('diff')
 def run_diff(fifo1, fifo2, end_nl_q1, end_nl_q2):
-    cmd = ['diff', '-aU7', fifo1, fifo2]
+    cmd = [get_tool_name('diff'), '-aU7', fifo1, fifo2]
 
     logger.debug("Running %s", ' '.join(cmd))
 
diff --git a/diffoscope/tools.py b/diffoscope/tools.py
index 370d39e..5408fa3 100644
--- a/diffoscope/tools.py
+++ b/diffoscope/tools.py
@@ -47,14 +47,12 @@ OS_NAMES = collections.OrderedDict([
 def get_tool_name(tool):
     return REMAPPED_TOOL_NAMES.get(tool, tool)
 
-
 def tool_prepend_prefix(prefix, *tools):
     if not prefix:
         return
     for tool in tools:
         REMAPPED_TOOL_NAMES[tool] = prefix + tool
 
-
 def tool_required(command):
     """
     Decorator that checks if the specified tool is installed
@@ -77,6 +75,10 @@ def tool_required(command):
             This ensures that any os.environ['PATH'] modifications are
             performed prior to the `find_executable` tests.
             """
+            if not os_is_gnu():
+                # try "g" + command for each tool, if we're on a non-GNU system
+                if find_executable("g" + command):
+                    tool_prepend_prefix("g", command)
 
             if not find_executable(get_tool_name(command)):
                 raise RequiredToolNotFound(command)
@@ -86,6 +88,9 @@ def tool_required(command):
         return tool_check
     return wrapper
 
+def os_is_gnu():
+    system = platform.system()
+    return system in ("Linux", "GNU") or system.startswith("GNU/")
 
 def get_current_os():
     system = platform.system()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list