Title: [268936] trunk/Tools
Revision
268936
Author
[email protected]
Date
2020-10-23 12:20:13 -0700 (Fri, 23 Oct 2020)

Log Message

[webkitscmpy] Use 'which' to find git and svn paths
https://bugs.webkit.org/show_bug.cgi?id=217717
<rdar://problem/70299192>

Rubber-stamped by Aakash Jain.

* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git):
(Git.executable): Generate git path from 'which' call.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py:
(Scm.executable): Generate a program path from a 'which' call.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
(Svn):
(Svn.executable): Generate svn path from 'which' call.
* Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
(Git):
* Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py:
(Svn.__init__):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (268935 => 268936)


--- trunk/Tools/ChangeLog	2020-10-23 18:54:26 UTC (rev 268935)
+++ trunk/Tools/ChangeLog	2020-10-23 19:20:13 UTC (rev 268936)
@@ -1,3 +1,25 @@
+2020-10-23  Jonathan Bedard  <[email protected]>
+
+        [webkitscmpy] Use 'which' to find git and svn paths
+        https://bugs.webkit.org/show_bug.cgi?id=217717
+        <rdar://problem/70299192>
+
+        Rubber-stamped by Aakash Jain.
+
+        * Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Bump version.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
+        (Git):
+        (Git.executable): Generate git path from 'which' call.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py:
+        (Scm.executable): Generate a program path from a 'which' call.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:
+        (Svn):
+        (Svn.executable): Generate svn path from 'which' call.
+        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py:
+        (Git):
+        * Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py:
+        (Svn.__init__):
+
 2020-10-23  Aakash Jain  <[email protected]>
 
         [build.webkit.org] Add python 3 support - part 2

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py (268935 => 268936)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2020-10-23 18:54:26 UTC (rev 268935)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py	2020-10-23 19:20:13 UTC (rev 268936)
@@ -46,7 +46,7 @@
         "Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
     )
 
-version = Version(0, 2, 3)
+version = Version(0, 2, 4)
 
 AutoInstall.register(Package('dateutil', Version(2, 8, 1), pypi_name='python-dateutil'))
 

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py (268935 => 268936)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2020-10-23 18:54:26 UTC (rev 268935)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py	2020-10-23 19:20:13 UTC (rev 268936)
@@ -20,7 +20,7 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-
+import os
 import re
 import six
 
@@ -30,13 +30,17 @@
 
 
 class Git(Scm):
-    executable = '/usr/bin/git'
     GIT_COMMIT = re.compile(r'commit (?P<hash>[0-9a-f]+)')
     GIT_SVN_REVISION = re.compile(r'git-svn-id: \S+:\/\/.+@(?P<revision>\d+) .+-.+-.+-.+')
 
     @classmethod
+    @decorators.Memoize()
+    def executable(cls):
+        return Scm.executable('git')
+
+    @classmethod
     def is_checkout(cls, path):
-        return run([cls.executable, 'rev-parse', '--show-toplevel'], cwd=path, capture_output=True).returncode == 0
+        return run([cls.executable(), 'rev-parse', '--show-toplevel'], cwd=path, capture_output=True).returncode == 0
 
     def __init__(self, path, dev_branches=None, prod_branches=None):
         super(Git, self).__init__(path, dev_branches=dev_branches, prod_branches=prod_branches)
@@ -48,7 +52,7 @@
         if not self.is_svn:
             raise self.Exception('Cannot run SVN info on a git checkout which is not git-svn')
 
-        info_result = run([self.executable, 'svn', 'info'], cwd=self.path, capture_output=True, encoding='utf-8')
+        info_result = run([self.executable(), 'svn', 'info'], cwd=self.path, capture_output=True, encoding='utf-8')
         if info_result.returncode:
             return {}
 
@@ -63,7 +67,7 @@
     def is_svn(self):
         try:
             return run(
-                [self.executable, 'svn', 'find-rev', 'r1'],
+                [self.executable(), 'svn', 'find-rev', 'r1'],
                 cwd=self.root_path,
                 capture_output=True,
                 encoding='utf-8',
@@ -79,7 +83,7 @@
     @property
     @decorators.Memoize()
     def root_path(self):
-        result = run([self.executable, 'rev-parse', '--show-toplevel'], cwd=self.path, capture_output=True, encoding='utf-8')
+        result = run([self.executable(), 'rev-parse', '--show-toplevel'], cwd=self.path, capture_output=True, encoding='utf-8')
         if result.returncode:
             return None
         return result.stdout.rstrip()
@@ -86,7 +90,7 @@
 
     @property
     def default_branch(self):
-        result = run([self.executable, 'rev-parse', '--abbrev-ref', 'origin/HEAD'], cwd=self.path, capture_output=True, encoding='utf-8')
+        result = run([self.executable(), 'rev-parse', '--abbrev-ref', 'origin/HEAD'], cwd=self.path, capture_output=True, encoding='utf-8')
         if result.returncode:
             candidates = self.branches
             if 'master' in candidates:
@@ -98,13 +102,13 @@
 
     @property
     def branch(self):
-        status = run([self.executable, 'status'], cwd=self.root_path, capture_output=True, encoding='utf-8')
+        status = run([self.executable(), 'status'], cwd=self.root_path, capture_output=True, encoding='utf-8')
         if status.returncode:
             raise self.Exception('Failed to run `git status` for {}'.format(self.root_path))
         if status.stdout.splitlines()[0].startswith('HEAD detached at'):
             return None
 
-        result = run([self.executable, 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=self.root_path, capture_output=True, encoding='utf-8')
+        result = run([self.executable(), 'rev-parse', '--abbrev-ref', 'HEAD'], cwd=self.root_path, capture_output=True, encoding='utf-8')
         if result.returncode:
             raise self.Exception('Failed to retrieve branch for {}'.format(self.root_path))
         return result.stdout.rstrip()
@@ -115,13 +119,13 @@
 
     @property
     def tags(self):
-        tags = run([self.executable, 'tag'], cwd=self.root_path, capture_output=True, encoding='utf-8')
+        tags = run([self.executable(), 'tag'], cwd=self.root_path, capture_output=True, encoding='utf-8')
         if tags.returncode:
             raise self.Exception('Failed to retrieve tag list for {}'.format(self.root_path))
         return tags.stdout.splitlines()
 
     def remote(self, name=None):
-        result = run([self.executable, 'remote', 'get-url', name or 'origin'], cwd=self.root_path, capture_output=True, encoding='utf-8')
+        result = run([self.executable(), 'remote', 'get-url', name or 'origin'], cwd=self.root_path, capture_output=True, encoding='utf-8')
         if result.returncode:
             raise self.Exception('Failed to retrieve remote for {}'.format(self.root_path))
         return result.stdout.rstrip()
@@ -128,7 +132,7 @@
 
     def _commit_count(self, native_parameter):
         revision_count = run(
-            [self.executable, 'rev-list', '--count', '--no-merges', native_parameter],
+            [self.executable(), 'rev-list', '--count', '--no-merges', native_parameter],
             cwd=self.root_path, capture_output=True, encoding='utf-8',
         )
         if revision_count.returncode:
@@ -137,7 +141,7 @@
 
     def _branches_for(self, hash=None):
         branch = run(
-            [self.executable, 'branch', '-a'] + (['--contains', hash] if hash else []),
+            [self.executable(), 'branch', '-a'] + (['--contains', hash] if hash else []),
             cwd=self.root_path,
             capture_output=True,
             encoding='utf-8',
@@ -153,7 +157,7 @@
         elif revision:
             revision = Commit._parse_revision(revision, do_assert=True)
             revision_log = run(
-                [self.executable, 'svn', 'find-rev', 'r{}'.format(revision)],
+                [self.executable(), 'svn', 'find-rev', 'r{}'.format(revision)],
                 cwd=self.root_path, capture_output=True, encoding='utf-8',
                 timeout=3,
             )
@@ -195,7 +199,7 @@
             if identifier > base_count:
                 raise self.Exception('Identifier {} cannot be found on the specified branch in the current checkout'.format(identifier))
             log = run(
-                [self.executable, 'log', '{}~{}'.format(branch or 'HEAD', base_count - identifier), '-1'],
+                [self.executable(), 'log', '{}~{}'.format(branch or 'HEAD', base_count - identifier), '-1'],
                 cwd=self.root_path,
                 capture_output=True,
                 encoding='utf-8',
@@ -212,13 +216,13 @@
         elif branch:
             if hash:
                 raise ValueError('Cannot define both branch and hash')
-            log = run([self.executable, 'log', branch, '-1'], cwd=self.root_path, capture_output=True, encoding='utf-8')
+            log = run([self.executable(), 'log', branch, '-1'], cwd=self.root_path, capture_output=True, encoding='utf-8')
             if log.returncode:
                 raise self.Exception("Failed to retrieve commit information for '{}'".format(branch))
 
         else:
             hash = Commit._parse_hash(hash, do_assert=True)
-            log = run([self.executable, 'log', hash or 'HEAD', '-1'], cwd=self.root_path, capture_output=True, encoding='utf-8')
+            log = run([self.executable(), 'log', hash or 'HEAD', '-1'], cwd=self.root_path, capture_output=True, encoding='utf-8')
             if log.returncode:
                 raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD'))
 
@@ -239,7 +243,7 @@
         revision = int(match.group('revision')) if match else None
 
         commit_time = run(
-            [self.executable, 'show', '-s', '--format=%ct', hash],
+            [self.executable(), 'show', '-s', '--format=%ct', hash],
             cwd=self.root_path, capture_output=True, encoding='utf-8',
         )
         if commit_time.returncode:
@@ -270,7 +274,7 @@
             )
 
         output = run(
-            [self.executable, 'rev-parse', argument],
+            [self.executable(), 'rev-parse', argument],
             cwd=self.root_path, capture_output=True, encoding='utf-8',
         )
         if output.returncode:

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py (268935 => 268936)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py	2020-10-23 18:54:26 UTC (rev 268935)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/scm.py	2020-10-23 19:20:13 UTC (rev 268936)
@@ -22,11 +22,13 @@
 
 
 import logging
+import os
 import re
 import six
 import sys
 
 from logging import NullHandler
+from webkitcorepy import run
 from webkitscmpy import log, Commit
 
 
@@ -39,8 +41,18 @@
     DEV_BRANCHES = re.compile(r'.*[(eng)(dev)(bug)]/.+')
     PROD_BRANCHES = re.compile(r'\S+-[\d+\.]+-branch')
 
-    executable = None
+    @classmethod
+    def executable(cls, program):
+        for candidate in ['usr/bin', 'usr/bin/local']:
+            candidate = os.path.join(candidate, program)
+            if os.path.exists(candidate):
+                return candidate
 
+        which = run(['/usr/bin/which', program], capture_output=True, encoding='utf-8')
+        if not which.returncode:
+            return os.path.realpath(which.stdout.rstrip())
+        raise OSError("Cannot find '{}' program".format(program))
+
     @classmethod
     def from_path(cls, path):
         from webkitscmpy import local

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py (268935 => 268936)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py	2020-10-23 18:54:26 UTC (rev 268935)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py	2020-10-23 19:20:13 UTC (rev 268936)
@@ -37,13 +37,17 @@
 
 
 class Svn(Scm):
-    executable = '/usr/bin/svn' if os.path.exists('/usr/bin/svn') else '/usr/local/bin/svn'
     LOG_RE = re.compile(r'r(?P<revision>\d+) \| (?P<email>.*) \| (?P<date>.*)')
     CACHE_VERSION = Version(1)
 
     @classmethod
+    @decorators.Memoize()
+    def executable(cls):
+        return Scm.executable('svn')
+
+    @classmethod
     def is_checkout(cls, path):
-        return run([cls.executable, 'info'], cwd=path, capture_output=True).returncode == 0
+        return run([cls.executable(), 'info'], cwd=path, capture_output=True).returncode == 0
 
     def __init__(self, path, dev_branches=None, prod_branches=None):
         super(Svn, self).__init__(path, dev_branches=dev_branches, prod_branches=prod_branches)
@@ -70,7 +74,7 @@
         additional_args = ['^/branches/{}'.format(branch)] if branch and branch != self.default_branch else []
         additional_args += ['-r', str(revision)] if revision else []
 
-        info_result = run([self.executable, 'info'] + additional_args, cwd=self.root_path, capture_output=True, encoding='utf-8')
+        info_result = run([self.executable(), 'info'] + additional_args, cwd=self.root_path, capture_output=True, encoding='utf-8')
         if info_result.returncode:
             return {}
 
@@ -100,7 +104,7 @@
         return self.info()['Relative URL'][2:]
 
     def list(self, category):
-        list_result = run([self.executable, 'list', '^/{}'.format(category)], cwd=self.root_path, capture_output=True, encoding='utf-8')
+        list_result = run([self.executable(), 'list', '^/{}'.format(category)], cwd=self.root_path, capture_output=True, encoding='utf-8')
         if list_result.returncode:
             return []
         return [element.rstrip('/') for element in list_result.stdout.splitlines()]
@@ -141,7 +145,7 @@
                 kwargs = dict(encoding='utf-8')
 
             log = subprocess.Popen(
-                [self.executable, 'log', '-q', branch_arg],
+                [self.executable(), 'log', '-q', branch_arg],
                 cwd=self.root_path,
                 stdout=subprocess.PIPE,
                 stderr=subprocess.PIPE,
@@ -207,7 +211,7 @@
             return candidate
 
         process = run(
-            [self.executable, 'log', '-v', '-q', self.remote(), '-r', str(revision), '-l', '1'],
+            [self.executable(), 'log', '-v', '-q', self.remote(), '-r', str(revision), '-l', '1'],
             cwd=self.root_path, capture_output=True, encoding='utf-8',
         )
 
@@ -322,7 +326,7 @@
 
         branch_arg = '^/{}{}'.format('' if branch == self.default_branch else 'branches/', branch)
         log = run(
-            [self.executable, 'log', '-l', '1', '-r', str(revision), branch_arg], cwd=self.root_path,
+            [self.executable(), 'log', '-l', '1', '-r', str(revision), branch_arg], cwd=self.root_path,
             capture_output=True, encoding='utf-8',
         )
         split_log = log.stdout.splitlines()

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py (268935 => 268936)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2020-10-23 18:54:26 UTC (rev 268935)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/git.py	2020-10-23 19:20:13 UTC (rev 268936)
@@ -45,6 +45,11 @@
         self.branches = branches or []
         self.tags = tags or []
 
+        try:
+            self.executable = local.Git.executable()
+        except (OSError, AssertionError):
+            self.executable = '/usr/bin/git'
+
         # Provide a reasonable set of commits to test against
         contributor = Contributor(name='Jonathan Bedard', emails=['[email protected]'])
         self.commits = {
@@ -117,7 +122,7 @@
         if git_svn:
             git_svn_routes = [
                 mocks.Subprocess.Route(
-                    local.Git.executable, 'svn', 'find-rev', re.compile(r'r\d+'),
+                    self.executable, 'svn', 'find-rev', re.compile(r'r\d+'),
                     cwd=self.path,
                     generator=lambda *args, **kwargs:
                         mocks.ProcessCompletion(
@@ -125,7 +130,7 @@
                             stdout=getattr(self.find(args[3][1:]), 'hash', '\n'),
                         )
                 ), mocks.Subprocess.Route(
-                    local.Git.executable, 'svn', 'info',
+                    self.executable, 'svn', 'info',
                     cwd=self.path,
                     generator=lambda *args, **kwargs:
                         mocks.ProcessCompletion(
@@ -153,7 +158,7 @@
 
         else:
             git_svn_routes = [mocks.Subprocess.Route(
-                local.Git.executable, 'svn',
+                self.executable, 'svn',
                 cwd=self.path,
                 completion=mocks.ProcessCompletion(returncode=1, elapsed=2),
             )]
@@ -160,7 +165,13 @@
 
         super(Git, self).__init__(
             mocks.Subprocess.Route(
-                local.Git.executable, 'status',
+                '/usr/bin/which', 'git',
+                completion=mocks.ProcessCompletion(
+                    returncode=0,
+                    stdout='{}\n'.format(self.executable),
+                ),
+            ), mocks.Subprocess.Route(
+                self.executable, 'status',
                 cwd=self.path,
                 generator=lambda *args, **kwargs:
                     mocks.ProcessCompletion(
@@ -175,7 +186,7 @@
                     ),
             ),
             mocks.Subprocess.Route(
-                local.Git.executable, 'rev-parse', '--show-toplevel',
+                self.executable, 'rev-parse', '--show-toplevel',
                 cwd=self.path,
                 completion=mocks.ProcessCompletion(
                     returncode=0,
@@ -182,7 +193,7 @@
                     stdout='{}\n'.format(self.path),
                 ),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'rev-parse', '--abbrev-ref', 'HEAD',
+                self.executable, 'rev-parse', '--abbrev-ref', 'HEAD',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -189,7 +200,7 @@
                     stdout='{}\n'.format('HEAD' if self.detached else self.branch),
                 ),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'remote', 'get-url', '.*',
+                self.executable, 'remote', 'get-url', '.*',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -199,7 +210,7 @@
                     stderr="fatal: No such remote '{}'\n".format(args[3]),
                 ),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'branch', '-a',
+                self.executable, 'branch', '-a',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -207,7 +218,7 @@
                            '\nremotes/origin/HEAD -> origin/{}\n'.format(default_branch),
                 ),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'tag',
+                self.executable, 'tag',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -214,7 +225,7 @@
                     stdout='\n'.join(self.tags) + '\n',
                 ),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'rev-parse', '--abbrev-ref', 'origin/HEAD',
+                self.executable, 'rev-parse', '--abbrev-ref', 'origin/HEAD',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -221,7 +232,7 @@
                     stdout='origin/{}\n'.format(default_branch),
                 ),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'rev-parse', '.*',
+                self.executable, 'rev-parse', '.*',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -228,7 +239,7 @@
                     stdout='{}\n'.format(self.find(args[2]).hash),
                 ) if self.find(args[2]) else mocks.ProcessCompletion(returncode=128)
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'log', re.compile(r'.+'), '-1',
+                self.executable, 'log', re.compile(r'.+'), '-1',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -253,7 +264,7 @@
                         ),
                 ) if self.find(args[2]) else mocks.ProcessCompletion(returncode=128),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'rev-list', '--count', '--no-merges', re.compile(r'.+'),
+                self.executable, 'rev-list', '--count', '--no-merges', re.compile(r'.+'),
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -260,7 +271,7 @@
                     stdout='{}\n'.format(self.count(args[4]))
                 ) if self.find(args[4]) else mocks.ProcessCompletion(returncode=128),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'show', '-s', '--format=%ct', re.compile(r'.+'),
+                self.executable, 'show', '-s', '--format=%ct', re.compile(r'.+'),
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -269,7 +280,7 @@
                     )
                 ) if self.find(args[4]) else mocks.ProcessCompletion(returncode=128),
             ), mocks.Subprocess.Route(
-                local.Git.executable, 'branch', '-a', '--contains', re.compile(r'.+'),
+                self.executable, 'branch', '-a', '--contains', re.compile(r'.+'),
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -276,7 +287,7 @@
                     stdout='\n'.join(sorted(self.branches_on(args[4]))) + '\n',
                 ) if self.find(args[4]) else mocks.ProcessCompletion(returncode=128),
             ), mocks.Subprocess.Route(
-                local.Git.executable,
+                self.executable,
                 cwd=self.path,
                 completion=mocks.ProcessCompletion(
                     returncode=1,
@@ -283,7 +294,7 @@
                     stderr='usage: git [--version] [--help]...\n',
                 ),
             ), mocks.Subprocess.Route(
-                local.Git.executable,
+                self.executable,
                 completion=mocks.ProcessCompletion(
                     returncode=128,
                     stderr='fatal: not a git repository (or any parent up to mount point)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).\n',

Modified: trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py (268935 => 268936)


--- trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py	2020-10-23 18:54:26 UTC (rev 268935)
+++ trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/mocks/local/svn.py	2020-10-23 19:20:13 UTC (rev 268936)
@@ -54,6 +54,11 @@
         self.tags = tags or []
         self.connected = True
 
+        try:
+            self.executable = local.Svn.executable()
+        except (OSError, AssertionError):
+            self.executable = '/usr/bin/svn'
+
         # Provide a reasonable set of commits to test against
         contributor = Contributor(name='Jonathan Bedard', emails=['[email protected]'])
         self.commits = {
@@ -117,15 +122,21 @@
 
         super(Svn, self).__init__(
             mocks.Subprocess.Route(
-                local.Svn.executable, 'info',
+                '/usr/bin/which', 'svn',
+                completion=mocks.ProcessCompletion(
+                    returncode=0,
+                    stdout='{}\n'.format(self.executable),
+                ),
+            ), mocks.Subprocess.Route(
+                self.executable, 'info',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: self._info(cwd=kwargs.get('cwd',''))
             ), mocks.Subprocess.Route(
-                local.Svn.executable, 'info', self.BRANCH_RE,
+                self.executable, 'info', self.BRANCH_RE,
                 cwd=self.path,
                 generator=lambda *args, **kwargs: self._info(branch=self.BRANCH_RE.match(args[2]).group('branch'), cwd=kwargs.get('cwd', ''))
             ), mocks.Subprocess.Route(
-                local.Svn.executable, 'list', '^/branches',
+                self.executable, 'list', '^/branches',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -132,7 +143,7 @@
                     stdout='/\n'.join(sorted(set(self.branches) | set(self.commits.keys()) - {'trunk'})) + '/\n',
                 ) if self.connected else mocks.ProcessCompletion(returncode=1),
             ), mocks.Subprocess.Route(
-                local.Svn.executable, 'list', '^/tags',
+                self.executable, 'list', '^/tags',
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -139,7 +150,7 @@
                     stdout='/\n'.join(self.tags) + '/\n',
                 ) if self.connected else mocks.ProcessCompletion(returncode=1),
             ), mocks.Subprocess.Route(
-                local.Svn.executable, 'log', '-v', '-q', self.remote, '-r', re.compile(r'\d+'),
+                self.executable, 'log', '-v', '-q', self.remote, '-r', re.compile(r'\d+'),
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -153,7 +164,7 @@
                         ),
                 ) if self.connected and self.find(revision=args[6]) else mocks.ProcessCompletion(returncode=1),
             ), mocks.Subprocess.Route(
-                local.Svn.executable, 'log', '-q', self.BRANCH_RE,
+                self.executable, 'log', '-q', self.BRANCH_RE,
                 cwd=self.path,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=0,
@@ -162,7 +173,7 @@
                     ]),
                 ) if self.connected and self.BRANCH_RE.match(args[3]).group('branch') in self.commits else mocks.ProcessCompletion(returncode=1)
             ), mocks.Subprocess.Route(
-                local.Svn.executable, 'log', '-l', '1', '-r', re.compile(r'\d+'), self.BRANCH_RE,
+                self.executable, 'log', '-l', '1', '-r', re.compile(r'\d+'), self.BRANCH_RE,
                 cwd=self.path,
                 generator=lambda *args, **kwargs: self._log_for(
                     branch=self.BRANCH_RE.match(args[6]).group('branch'),
@@ -169,7 +180,7 @@
                     revision=args[5],
                 ) if self.connected else mocks.ProcessCompletion(returncode=1)
             ), mocks.Subprocess.Route(
-                local.Svn.executable,
+                self.executable,
                 cwd=self.path,
                 completion=mocks.ProcessCompletion(
                     returncode=1,
@@ -176,7 +187,7 @@
                     stderr="Type 'svn help' for usage.\n",
                 )
             ), mocks.Subprocess.Route(
-                local.Svn.executable,
+                self.executable,
                 generator=lambda *args, **kwargs: mocks.ProcessCompletion(
                     returncode=1,
                     stderr="svn: E155007: '{}' is not a working copy\n".format(kwargs.get('cwd')),
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to