Changeset 227427 in webkit


Ignore:
Timestamp:
Jan 23, 2018 11:31:04 AM (6 years ago)
Author:
ddkilzer@apple.com
Message:

Add ignore_errors keyword argument to Executive.run_command() for replacing the common pattern of error_handler usage
https://bugs.webkit.org/show_bug.cgi?id=180820

Patch by Basuke Suzuki <Basuke Suzuki> on 2018-01-23
Reviewed by David Kilzer.

  • Scripts/webkitpy/common/checkout/scm/git.py:

(Git.in_working_directory):
(Git.clone):
(Git.read_git_config):
(Git.apply_reverse_diff):

  • Scripts/webkitpy/common/checkout/scm/scm.py:

(SCM.run):

  • Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
  • Scripts/webkitpy/common/checkout/scm/svn.py:

(SVNRepository.has_authorization_for_realm):

  • Scripts/webkitpy/common/net/credentials_unittest.py:
  • Scripts/webkitpy/common/system/abstractexecutive.py:

(AbstractExecutive.run_command):

  • Scripts/webkitpy/common/system/executive.py:

(Executive.kill_process.is):
(Executive.running_pids):
(Executive.kill_all):
(Executive.run_command):

  • Scripts/webkitpy/common/system/executive_mock.py:

(MockExecutive.run_command):
(MockExecutive2.run_command):

  • Scripts/webkitpy/common/system/executive_unittest.py:

(ExecutiveTest.test_run_command_with_bad_command.run_bad_command):

  • Scripts/webkitpy/common/system/platforminfo.py:

(PlatformInfo.xcode_sdk_version):

  • Scripts/webkitpy/layout_tests/servers/http_server.py:

(Lighttpd._check_and_kill):

  • Scripts/webkitpy/port/base.py:

(Port._symbols_string):

  • Scripts/webkitpy/port/gtk.py:

(GtkPort.setup_environ_for_server):

  • Scripts/webkitpy/port/win.py:

(WinPort._runtime_feature_list):
(WinPort.read_registry_value):

  • Scripts/webkitpy/port/win_unittest.py:

(WinPortTest.test_runtime_feature_list):

  • Scripts/webkitpy/tool/commands/analyzechangelog.py:
  • Scripts/webkitpy/tool/commands/analyzechangelog_unittest.py:
Location:
trunk/Tools
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r227422 r227427  
     12018-01-23  Basuke Suzuki  <Basuke.Suzuki@sony.com>
     2
     3        Add ignore_errors keyword argument to Executive.run_command() for replacing the common pattern of error_handler usage
     4        https://bugs.webkit.org/show_bug.cgi?id=180820
     5
     6        Reviewed by David Kilzer.
     7
     8        * Scripts/webkitpy/common/checkout/scm/git.py:
     9        (Git.in_working_directory):
     10        (Git.clone):
     11        (Git.read_git_config):
     12        (Git.apply_reverse_diff):
     13        * Scripts/webkitpy/common/checkout/scm/scm.py:
     14        (SCM.run):
     15        * Scripts/webkitpy/common/checkout/scm/scm_unittest.py:
     16        * Scripts/webkitpy/common/checkout/scm/svn.py:
     17        (SVNRepository.has_authorization_for_realm):
     18        * Scripts/webkitpy/common/net/credentials_unittest.py:
     19        * Scripts/webkitpy/common/system/abstractexecutive.py:
     20        (AbstractExecutive.run_command):
     21        * Scripts/webkitpy/common/system/executive.py:
     22        (Executive.kill_process.is):
     23        (Executive.running_pids):
     24        (Executive.kill_all):
     25        (Executive.run_command):
     26        * Scripts/webkitpy/common/system/executive_mock.py:
     27        (MockExecutive.run_command):
     28        (MockExecutive2.run_command):
     29        * Scripts/webkitpy/common/system/executive_unittest.py:
     30        (ExecutiveTest.test_run_command_with_bad_command.run_bad_command):
     31        * Scripts/webkitpy/common/system/platforminfo.py:
     32        (PlatformInfo.xcode_sdk_version):
     33        * Scripts/webkitpy/layout_tests/servers/http_server.py:
     34        (Lighttpd._check_and_kill):
     35        * Scripts/webkitpy/port/base.py:
     36        (Port._symbols_string):
     37        * Scripts/webkitpy/port/gtk.py:
     38        (GtkPort.setup_environ_for_server):
     39        * Scripts/webkitpy/port/win.py:
     40        (WinPort._runtime_feature_list):
     41        (WinPort.read_registry_value):
     42        * Scripts/webkitpy/port/win_unittest.py:
     43        (WinPortTest.test_runtime_feature_list):
     44        * Scripts/webkitpy/tool/commands/analyzechangelog.py:
     45        * Scripts/webkitpy/tool/commands/analyzechangelog_unittest.py:
     46
    1472018-01-23  Commit Queue  <commit-queue@webkit.org>
    248
  • trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py

    r226009 r227427  
    110110        try:
    111111            executive = executive or Executive()
    112             return executive.run_command([cls.executable_name, 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() == "true"
     112            return executive.run_command([cls.executable_name, 'rev-parse', '--is-inside-work-tree'], cwd=path, ignore_errors=True).rstrip() == "true"
    113113        except OSError as e:
    114114            # The Windows bots seem to through a WindowsError when git isn't installed.
     
    119119        try:
    120120            executive = executive or Executive()
    121             return executive.run_command([cls.executable_name, 'clone', '-v', url, directory], error_handler=Executive.ignore_error)
     121            return executive.run_command([cls.executable_name, 'clone', '-v', url, directory], ignore_errors=True)
    122122        except OSError as e:
    123123            return False
     
    143143        # FIXME: This should use an Executive.
    144144        executive = executive or Executive()
    145         return executive.run_command([cls.executable_name, "config", "--get-all", key], error_handler=Executive.ignore_error, cwd=cwd).rstrip('\n')
     145        return executive.run_command([cls.executable_name, "config", "--get-all", key], ignore_errors=True, cwd=cwd).rstrip('\n')
    146146
    147147    @staticmethod
     
    401401        git_commit = self.git_commit_from_svn_revision(revision)
    402402        # I think this will always fail due to ChangeLogs.
    403         self._run_git(['revert', '--no-commit', git_commit], error_handler=Executive.ignore_error)
     403        self._run_git(['revert', '--no-commit', git_commit], ignore_errors=True)
    404404
    405405    def revert_files(self, file_paths):
  • trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py

    r213562 r227427  
    6767
    6868    # A wrapper used by subclasses to create processes.
    69     def run(self, args, cwd=None, input=None, error_handler=None, return_exit_code=False, return_stderr=True, decode_output=True):
     69    def run(self, args, cwd=None, input=None, error_handler=None, ignore_errors=False, return_exit_code=False, return_stderr=True, decode_output=True):
    7070        # FIXME: We should set cwd appropriately.
    7171        return self._executive.run_command(args,
     
    7373            input=input,
    7474            error_handler=error_handler,
     75            ignore_errors=ignore_errors,
    7576            return_exit_code=return_exit_code,
    7677            return_stderr=return_stderr,
  • trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm_unittest.py

    r224548 r227427  
    266266        command_does_not_exist = ['does_not_exist', 'invalid_option']
    267267        self.assertRaises(OSError, run_command, command_does_not_exist)
    268         self.assertRaises(OSError, run_command, command_does_not_exist, error_handler=Executive.ignore_error)
     268        self.assertRaises(OSError, run_command, command_does_not_exist, ignore_errors=True)
    269269
    270270        command_returns_non_zero = ['/bin/sh', '--invalid-option']
    271271        self.assertRaises(ScriptError, run_command, command_returns_non_zero)
    272272        # Check if returns error text:
    273         self.assertTrue(run_command(command_returns_non_zero, error_handler=Executive.ignore_error))
     273        self.assertTrue(run_command(command_returns_non_zero, ignore_errors=True))
    274274
    275275        self.assertRaises(CheckoutNeedsUpdate, commit_error_handler, ScriptError(output=git_failure_message))
  • trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py

    r225733 r227427  
    6161            return False
    6262        find_args = ["find", ".subversion", "-type", "f", "-exec", "grep", "-q", realm, "{}", ";", "-print"]
    63         find_output = self.run(find_args, cwd=home_directory, error_handler=Executive.ignore_error).rstrip()
     63        find_output = self.run(find_args, cwd=home_directory, ignore_errors=True).rstrip()
    6464        if not find_output or not os.path.isfile(os.path.join(home_directory, find_output)):
    6565            return False
  • trunk/Tools/Scripts/webkitpy/common/net/credentials_unittest.py

    r202362 r227427  
    3232
    3333from webkitpy.common.net.credentials import Credentials
    34 from webkitpy.common.system.executive import Executive
    3534from webkitpy.common.system.outputcapture import OutputCapture
    3635from webkitpy.common.system.user_mock import MockUser
  • trunk/Tools/Scripts/webkitpy/common/system/abstractexecutive.py

    r217801 r227427  
    117117        return " ".join(escaped_args)
    118118
    119     def run_command(self, args, cwd=None, env=None, input=None, error_handler=None,
     119    def run_command(self, args, cwd=None, env=None, input=None, error_handler=None, ignore_errors=False,
    120120        return_exit_code=False, return_stderr=True, decode_output=True):
    121121        raise NotImplementedError('subclasses must implement')
  • trunk/Tools/Scripts/webkitpy/common/system/executive.py

    r225733 r227427  
    175175            command = [task_kill_executable, "/f", "/t", "/pid", pid]
    176176            # taskkill will exit 128 if the process is not found.  We should log.
    177             self.run_command(command, error_handler=self.ignore_error)
     177            self.run_command(command, ignore_errors=True)
    178178            return
    179179
     
    272272        running_pids = []
    273273        if sys.platform in ("cygwin"):
    274             ps_process = self.run_command(['ps', '-e'], error_handler=Executive.ignore_error)
     274            ps_process = self.run_command(['ps', '-e'], ignore_errors=True)
    275275            for line in ps_process.splitlines():
    276276                tokens = line.strip().split()
     
    326326            command = [killCommmand, "/f", "/im", image_name]
    327327            # taskkill will exit 128 if the process is not found.  We should log.
    328             self.run_command(command, error_handler=self.ignore_error)
     328            self.run_command(command, ignore_errors=True)
    329329            return
    330330
     
    337337        # FIXME: We should pass a custom error_handler to allow only exit_code 1.
    338338        # We should log in exit_code == 1
    339         self.run_command(command, error_handler=self.ignore_error)
     339        self.run_command(command, ignore_errors=True)
    340340
    341341    def _compute_stdin(self, input):
     
    365365                    input=None,
    366366                    error_handler=None,
     367                    ignore_errors=False,
    367368                    return_exit_code=False,
    368369                    return_stderr=True,
     
    402403                                       output=output,
    403404                                       cwd=cwd)
     405
     406            if ignore_errors:
     407                assert error_handler is None, "don't specify error_handler if ignore_errors is True"
     408                error_handler = Executive.ignore_error
     409
    404410            (error_handler or self.default_error_handler)(script_error)
    405411        return output
  • trunk/Tools/Scripts/webkitpy/common/system/executive_mock.py

    r212905 r227427  
    109109                    input=None,
    110110                    error_handler=None,
     111                    ignore_errors=False,
    111112                    return_exit_code=False,
    112113                    return_stderr=True,
     
    186187                    input=None,
    187188                    error_handler=None,
     189                    ignore_errors=False,
    188190                    return_exit_code=False,
    189191                    return_stderr=True,
     
    192194        self.calls.append(args)
    193195        assert(isinstance(args, list) or isinstance(args, tuple))
     196
     197        if ignore_errors:
     198            assert error_handler is None, "don't specify error_handler if ignore_errors is True"
     199            error_handler = self.ignore_error
     200
    194201        if self._exception:
    195202            raise self._exception  # pylint: disable=E0702
  • trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py

    r202362 r227427  
    106106    def test_run_command_with_bad_command(self):
    107107        def run_bad_command():
    108             Executive().run_command(["foo_bar_command_blah"], error_handler=Executive.ignore_error, return_exit_code=True)
     108            Executive().run_command(["foo_bar_command_blah"], ignore_errors=True, return_exit_code=True)
    109109        self.assertRaises(OSError, run_bad_command)
    110110
  • trunk/Tools/Scripts/webkitpy/common/system/platforminfo.py

    r226652 r227427  
    153153        if self.is_mac():
    154154            # Assumes that xcrun does not write to standard output on failure (e.g. SDK does not exist).
    155             xcrun_output = self.executive.run_command(['xcrun', '--sdk', sdk_name, '--show-sdk-version'], return_stderr=False, error_handler=Executive.ignore_error).rstrip()
     155            xcrun_output = self.executive.run_command(['xcrun', '--sdk', sdk_name, '--show-sdk-version'], return_stderr=False, ignore_errors=True).rstrip()
    156156            if xcrun_output:
    157157                return Version.from_string(xcrun_output)
  • trunk/Tools/Scripts/webkitpy/layout_tests/servers/http_server.py

    r225733 r227427  
    223223                #
    224224                # If this is actually working, we should figure out a clean API.
    225                 self._executive.run_command(["taskkill.exe", "/f", "/t", "/pid", self._pid], error_handler=self._executive.ignore_error)
     225                self._executive.run_command(["taskkill.exe", "/f", "/t", "/pid", self._pid], ignore_errors=True)
    226226            else:
    227227                self._executive.kill_process(self._pid)
  • trunk/Tools/Scripts/webkitpy/port/base.py

    r227222 r227427  
    14911491        for path_to_module in self._modules_to_search_for_symbols():
    14921492            try:
    1493                 symbols += self._executive.run_command([self.nm_command(), path_to_module], error_handler=self._executive.ignore_error)
     1493                symbols += self._executive.run_command([self.nm_command(), path_to_module], ignore_errors=True)
    14941494            except OSError as e:
    14951495                _log.warn("Failed to run nm: %s.  Can't determine supported features correctly." % e)
  • trunk/Tools/Scripts/webkitpy/port/gtk.py

    r225856 r227427  
    128128        if self._driver_class() in [XvfbDriver, WestonDriver] and self._should_use_jhbuild():
    129129            llvmpipe_libgl_path = self.host.executive.run_command(self._jhbuild_wrapper + ['printenv', 'LLVMPIPE_LIBGL_PATH'],
    130                                                                   error_handler=self.host.executive.ignore_error).strip()
     130                                                                  ignore_errors=True).strip()
    131131            dri_libgl_path = os.path.join(llvmpipe_libgl_path, "dri")
    132132            if os.path.exists(os.path.join(llvmpipe_libgl_path, "libGL.so")) and os.path.exists(os.path.join(dri_libgl_path, "swrast_dri.so")):
  • trunk/Tools/Scripts/webkitpy/port/win.py

    r225856 r227427  
    152152        supported_features_command = [self._path_to_driver(), '--print-supported-features']
    153153        try:
    154             output = self._executive.run_command(supported_features_command, error_handler=Executive.ignore_error)
     154            output = self._executive.run_command(supported_features_command, ignore_errors=True)
    155155        except OSError as e:
    156156            _log.warn("Exception running driver: %s, %s.  Driver must be built before calling WebKitPort.test_expectations()." % (supported_features_command, e))
     
    262262            _log.debug("Reading %s" % (registry_key))
    263263            read_registry_command = ["regtool", arch, "get", registry_key]
    264             int_value = self._executive.run_command(read_registry_command, error_handler=Executive.ignore_error)
     264            int_value = self._executive.run_command(read_registry_command, ignore_errors=True)
    265265            # regtool doesn't return the type of the entry, so need this ugly hack:
    266266            if reg_path in (self.WINDOWS_ERROR_REPORTING_KEY, self.WOW64_WINDOWS_ERROR_REPORTING_KEY):
  • trunk/Tools/Scripts/webkitpy/port/win_unittest.py

    r225856 r227427  
    9696    def test_runtime_feature_list(self):
    9797        port = self.make_port()
    98         port._executive.run_command = lambda command, cwd=None, error_handler=None: "Nonsense"
     98        port._executive.run_command = lambda command, cwd=None, ignore_errors=False: "Nonsense"
    9999        # runtime_features_list returns None when its results are meaningless (it couldn't run DRT or parse the output, etc.)
    100100        self.assertEqual(port._runtime_feature_list(), None)
    101         port._executive.run_command = lambda command, cwd=None, error_handler=None: "SupportedFeatures:foo bar"
     101        port._executive.run_command = lambda command, cwd=None, ignore_errors=False: "SupportedFeatures:foo bar"
    102102        self.assertEqual(port._runtime_feature_list(), ['foo', 'bar'])
    103103
  • trunk/Tools/Scripts/webkitpy/tool/commands/analyzechangelog.py

    r225724 r227427  
    3636from webkitpy.common.config.contributionareas import ContributionAreas
    3737from webkitpy.common.system.filesystem import FileSystem
    38 from webkitpy.common.system.executive import Executive
    3938from webkitpy.tool.multicommandtool import Command
    4039from webkitpy.tool import steps
  • trunk/Tools/Scripts/webkitpy/tool/commands/analyzechangelog_unittest.py

    r148360 r227427  
    3232from webkitpy.common.host_mock import MockHost
    3333from webkitpy.common.system.filesystem_mock import MockFileSystem
    34 from webkitpy.common.system.executive import Executive
    3534from webkitpy.common.system.outputcapture import OutputCapture
    3635from webkitpy.tool.commands.analyzechangelog import AnalyzeChangeLog
Note: See TracChangeset for help on using the changeset viewer.