Title: [282770] trunk/Tools
Revision
282770
Author
jbed...@apple.com
Date
2021-09-20 12:52:35 -0700 (Mon, 20 Sep 2021)

Log Message

[webkitcorepy] Move FileLock from webkitpy
https://bugs.webkit.org/show_bug.cgi?id=230320
<rdar://problem/83168826>

Reviewed by Dewei Zhu.

Move FileLock from webkitpy into webkitcorepy, implement FileLock as a more
modern Python API.

* Scripts/libraries/webkitcorepy/setup.py: Bump version.
* Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Ditto.
* Scripts/libraries/webkitcorepy/webkitcorepy/file_lock.py: Added.
(FileLock):
(FileLock.__init__):
(FileLock.acquired): Check if the current process has acquired the lock.
(FileLock.acquire): Attempt to acquire lockfile.
(FileLock.release): Release lockfile, if this process owns the lock.
(FileLock.__enter__): Invoke acquire.
(FileLock.__exit__): Invoke release.
* Scripts/libraries/webkitcorepy/webkitcorepy/mocks/__init__.py:
* Scripts/libraries/webkitcorepy/webkitcorepy/mocks/file_lock.py: Copied from Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/__init__.py.
(FileLock): Single-thread stub implementation of FileLock for testing without a filesystem.
* Scripts/libraries/webkitcorepy/webkitcorepy/tests/file_lock_unittest.py: Added.
(FileLockTestCase):
(FileLockTestCase.__init__):
(FileLockTestCase.setUp):
(FileLockTestCase.tearDown):
(FileLockTestCase.test_basic):
(FileLockTestCase.test_locked):
(FileLockTestCase.test_locked_timeout):
(FileLockTestCase.test_double):
* Scripts/webkitpy/common/system/file_lock.py: Removed.
* Scripts/webkitpy/common/system/file_lock_integrationtest.py: Removed.
* Scripts/webkitpy/common/system/systemhost.py:
(SystemHost.make_file_lock): Use webkitcorepy's FileLock.
* Scripts/webkitpy/common/system/systemhost_mock.py:
(MockSystemHost.make_file_lock): Use webkitcorepy's mocks.FileLock.
* Scripts/webkitpy/tool/commands/rebaseline.py:
(RebaselineTest._update_expectations_file): Use webkitcorepy's FileLock.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Tools/ChangeLog (282769 => 282770)


--- trunk/Tools/ChangeLog	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/ChangeLog	2021-09-20 19:52:35 UTC (rev 282770)
@@ -1,3 +1,45 @@
+2021-09-20  Jonathan Bedard  <jbed...@apple.com>
+
+        [webkitcorepy] Move FileLock from webkitpy
+        https://bugs.webkit.org/show_bug.cgi?id=230320
+        <rdar://problem/83168826>
+
+        Reviewed by Dewei Zhu.
+
+        Move FileLock from webkitpy into webkitcorepy, implement FileLock as a more
+        modern Python API.
+
+        * Scripts/libraries/webkitcorepy/setup.py: Bump version.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Ditto.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/file_lock.py: Added.
+        (FileLock):
+        (FileLock.__init__):
+        (FileLock.acquired): Check if the current process has acquired the lock.
+        (FileLock.acquire): Attempt to acquire lockfile.
+        (FileLock.release): Release lockfile, if this process owns the lock.
+        (FileLock.__enter__): Invoke acquire.
+        (FileLock.__exit__): Invoke release.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/mocks/__init__.py:
+        * Scripts/libraries/webkitcorepy/webkitcorepy/mocks/file_lock.py: Copied from Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/__init__.py.
+        (FileLock): Single-thread stub implementation of FileLock for testing without a filesystem.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/tests/file_lock_unittest.py: Added.
+        (FileLockTestCase):
+        (FileLockTestCase.__init__):
+        (FileLockTestCase.setUp):
+        (FileLockTestCase.tearDown):
+        (FileLockTestCase.test_basic):
+        (FileLockTestCase.test_locked):
+        (FileLockTestCase.test_locked_timeout):
+        (FileLockTestCase.test_double):
+        * Scripts/webkitpy/common/system/file_lock.py: Removed.
+        * Scripts/webkitpy/common/system/file_lock_integrationtest.py: Removed.
+        * Scripts/webkitpy/common/system/systemhost.py:
+        (SystemHost.make_file_lock): Use webkitcorepy's FileLock.
+        * Scripts/webkitpy/common/system/systemhost_mock.py:
+        (MockSystemHost.make_file_lock): Use webkitcorepy's mocks.FileLock.
+        * Scripts/webkitpy/tool/commands/rebaseline.py:
+        (RebaselineTest._update_expectations_file): Use webkitcorepy's FileLock.
+
 2021-09-20  Brent Fulgham  <bfulg...@apple.com>
 
         Remove XSS Auditor: Part 1 (Turn off by default)

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/setup.py (282769 => 282770)


--- trunk/Tools/Scripts/libraries/webkitcorepy/setup.py	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/setup.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -30,7 +30,7 @@
 
 setup(
     name='webkitcorepy',
-    version='0.10.3',
+    version='0.11.0',
     description='Library containing various Python support classes and functions.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py (282769 => 282770)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -41,8 +41,9 @@
 from webkitcorepy.nested_fuzzy_dict import NestedFuzzyDict
 from webkitcorepy.call_by_need import CallByNeed
 from webkitcorepy.editor import Editor
+from webkitcorepy.file_lock import FileLock
 
-version = Version(0, 10, 3)
+version = Version(0, 11, 0)
 
 from webkitcorepy.autoinstall import Package, AutoInstall
 if sys.version_info > (3, 0):

Added: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/file_lock.py (0 => 282770)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/file_lock.py	                        (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/file_lock.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -0,0 +1,85 @@
+# Copyright (C) 2010 Gabor Rapcsanyi (rga...@inf.u-szeged.hu), University of Szeged
+# Copyright (C) 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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 sys
+import time
+
+if sys.platform.startswith('win'):
+    import msvcrt
+else:
+    import fcntl
+
+
+class FileLock(object):
+
+    def __init__(self, path, timeout=20):
+        self.path = path
+        self.timeout = timeout
+        self._descriptor = None
+
+    @property
+    def acquired(self):
+        return bool(self._descriptor)
+
+    def acquire(self):
+        if self._descriptor:
+            return True
+
+        descriptor = os.open(self.path, os.O_TRUNC | os.O_CREAT)
+        start_time = time.time()
+        while True:
+            try:
+                if sys.platform.startswith('win'):
+                    msvcrt.locking(descriptor, msvcrt.LK_NBLCK, 32)
+                else:
+                    fcntl.flock(descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB)
+                self._descriptor = descriptor
+                return True
+
+            except IOError:
+                if time.time() - start_time > self.timeout:
+                    os.close(descriptor)
+                    self._descriptor = None
+                    return False
+                time.sleep(0.01)
+
+    def release(self):
+        try:
+            if self._descriptor:
+                if sys.platform.startswith('win'):
+                    msvcrt.locking(self._descriptor, msvcrt.LK_UNLCK, 32)
+                else:
+                    fcntl.flock(self._descriptor, fcntl.LOCK_UN)
+                os.close(self._descriptor)
+                self._descriptor = None
+            os.unlink(self.path)
+        except (IOError, OSError):
+            pass
+
+    def __enter__(self):
+        self.acquire()
+        return self
+
+    def __exit__(self, *args, **kwargs):
+        self.release()

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/__init__.py (282769 => 282770)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/__init__.py	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/__init__.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -26,3 +26,4 @@
 
 from webkitcorepy.mocks.requests_ import Response, Requests
 from webkitcorepy.mocks.terminal import Terminal
+from webkitcorepy.mocks.file_lock import FileLock

Copied: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/file_lock.py (from rev 282769, trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/__init__.py) (0 => 282770)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/file_lock.py	                        (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/mocks/file_lock.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -0,0 +1,46 @@
+# Copyright (C) 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
+
+
+class FileLock(object):
+    def __init__(self, path, timeout=20):
+        self.path = path
+        self.timeout = timeout
+        self._acquired = False
+
+    @property
+    def acquired(self):
+        return self._acquired
+
+    def acquire(self):
+        self._acquired = True
+        return True
+
+    def release(self):
+        self._acquired = False
+
+    def __enter__(self):
+        self.acquire()
+        return self
+
+    def __exit__(self, *args, **kwargs):
+        self.release()

Added: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/tests/file_lock_unittest.py (0 => 282770)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/tests/file_lock_unittest.py	                        (rev 0)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/tests/file_lock_unittest.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -0,0 +1,115 @@
+# Copyright (C) 2021 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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 shutil
+import tempfile
+import time
+import unittest
+
+from webkitcorepy import FileLock, mocks
+
+
+class FileLockTestCase(unittest.TestCase):
+
+    def __init__(self, *args, **kwargs):
+        super(FileLockTestCase, self).__init__(*args, **kwargs)
+        self.path = None
+
+    def setUp(self):
+        self.path = tempfile.mkdtemp()
+
+    def tearDown(self):
+        shutil.rmtree(self.path, ignore_errors=True)
+
+    def test_basic(self):
+        path = os.path.join(self.path, 'example-{}.lock'.format(os.getpid()))
+        lock = FileLock(path, timeout=0)
+
+        self.assertFalse(lock.acquired)
+        with lock:
+            self.assertTrue(lock.acquired)
+        self.assertFalse(lock.acquired)
+
+        with lock:
+            self.assertTrue(lock.acquired)
+        self.assertFalse(lock.acquired)
+
+    def test_locked(self):
+        path = os.path.join(self.path, 'example-{}.lock'.format(os.getpid()))
+        lock_a = FileLock(path, timeout=0)
+        lock_b = FileLock(path, timeout=0)
+
+        self.assertFalse(lock_a.acquired)
+        self.assertFalse(lock_b.acquired)
+
+        with lock_a:
+            self.assertTrue(lock_a.acquired)
+            self.assertFalse(lock_b.acquired)
+
+            with lock_b:
+                self.assertTrue(lock_a.acquired)
+                self.assertFalse(lock_b.acquired)
+
+            self.assertTrue(lock_a.acquired)
+            self.assertFalse(lock_b.acquired)
+
+        self.assertFalse(lock_a.acquired)
+        self.assertFalse(lock_b.acquired)
+
+    def test_locked_timeout(self):
+        with mocks.Time:
+            path = os.path.join(self.path, 'example-{}.lock'.format(os.getpid()))
+            lock_a = FileLock(path, timeout=0)
+            lock_b = FileLock(path, timeout=30)
+
+            self.assertFalse(lock_a.acquired)
+            self.assertFalse(lock_b.acquired)
+
+            start_time = int(time.time())
+            with lock_a:
+                self.assertEqual(start_time, int(time.time()))
+                self.assertTrue(lock_a.acquired)
+                self.assertFalse(lock_b.acquired)
+
+                with lock_b:
+                    self.assertEqual(start_time + 30, int(time.time()))
+                    self.assertTrue(lock_a.acquired)
+                    self.assertFalse(lock_b.acquired)
+
+                self.assertTrue(lock_a.acquired)
+                self.assertFalse(lock_b.acquired)
+
+            self.assertFalse(lock_a.acquired)
+            self.assertFalse(lock_b.acquired)
+
+    def test_double(self):
+        path = os.path.join(self.path, 'example-{}.lock'.format(os.getpid()))
+        lock = FileLock(path, timeout=0)
+
+        self.assertFalse(lock.acquired)
+        with lock:
+            self.assertTrue(lock.acquired)
+            with lock:
+                self.assertTrue(lock.acquired)
+            self.assertFalse(lock.acquired)
+        self.assertFalse(lock.acquired)

Deleted: trunk/Tools/Scripts/webkitpy/common/system/file_lock.py (282769 => 282770)


--- trunk/Tools/Scripts/webkitpy/common/system/file_lock.py	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/Scripts/webkitpy/common/system/file_lock.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -1,84 +0,0 @@
-# Copyright (C) 2010 Gabor Rapcsanyi (rga...@inf.u-szeged.hu), University of Szeged
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
-# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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.
-
-"""This class helps to lock files exclusively across processes."""
-
-import logging
-import os
-import sys
-import time
-
-
-_log = logging.getLogger(__name__)
-
-
-class FileLock(object):
-
-    def __init__(self, lock_file_path, max_wait_time_sec=20):
-        self._lock_file_path = lock_file_path
-        self._lock_file_descriptor = None
-        self._max_wait_time_sec = max_wait_time_sec
-
-    def _create_lock(self):
-        if sys.platform.startswith('win'):
-            import msvcrt
-            msvcrt.locking(self._lock_file_descriptor, msvcrt.LK_NBLCK, 32)
-        else:
-            import fcntl
-            fcntl.flock(self._lock_file_descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB)
-
-    def _remove_lock(self):
-        if sys.platform.startswith('win'):
-            import msvcrt
-            msvcrt.locking(self._lock_file_descriptor, msvcrt.LK_UNLCK, 32)
-        else:
-            import fcntl
-            fcntl.flock(self._lock_file_descriptor, fcntl.LOCK_UN)
-
-    def acquire_lock(self):
-        self._lock_file_descriptor = os.open(self._lock_file_path, os.O_TRUNC | os.O_CREAT)
-        start_time = time.time()
-        while True:
-            try:
-                self._create_lock()
-                return True
-            except IOError:
-                if time.time() - start_time > self._max_wait_time_sec:
-                    _log.debug("File locking failed: %s" % str(sys.exc_info()))
-                    os.close(self._lock_file_descriptor)
-                    self._lock_file_descriptor = None
-                    return False
-                # There's no compelling reason to spin hard here, so sleep for a bit.
-                time.sleep(0.01)
-
-    def release_lock(self):
-        try:
-            if self._lock_file_descriptor:
-                self._remove_lock()
-                os.close(self._lock_file_descriptor)
-                self._lock_file_descriptor = None
-            os.unlink(self._lock_file_path)
-        except (IOError, OSError):
-            _log.debug("Warning in release lock: %s" % str(sys.exc_info()))

Deleted: trunk/Tools/Scripts/webkitpy/common/system/file_lock_integrationtest.py (282769 => 282770)


--- trunk/Tools/Scripts/webkitpy/common/system/file_lock_integrationtest.py	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/Scripts/webkitpy/common/system/file_lock_integrationtest.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -1,60 +0,0 @@
-# Copyright (C) 2010 Gabor Rapcsanyi (rga...@inf.u-szeged.hu), University of Szeged
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
-# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
-# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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 tempfile
-import unittest
-
-from webkitpy.common.system.file_lock import FileLock
-
-
-class FileLockTest(unittest.TestCase):
-
-    def setUp(self):
-        self._lock_name = "TestWebKit" + str(os.getpid()) + ".lock"
-        self._lock_path = os.path.join(tempfile.gettempdir(), self._lock_name)
-        self._file_lock1 = FileLock(self._lock_path, 0.1)
-        self._file_lock2 = FileLock(self._lock_path, 0.1)
-
-    def tearDown(self):
-        self._file_lock1.release_lock()
-        self._file_lock2.release_lock()
-
-    def test_lock_lifecycle(self):
-        # Create the lock.
-        self._file_lock1.acquire_lock()
-        self.assertTrue(os.path.exists(self._lock_path))
-
-        # Try to lock again.
-        self.assertFalse(self._file_lock2.acquire_lock())
-
-        # Release the lock.
-        self._file_lock1.release_lock()
-        self.assertFalse(os.path.exists(self._lock_path))
-
-    def test_stuck_lock(self):
-        open(self._lock_path, 'w').close()
-        self._file_lock1.acquire_lock()
-        self._file_lock1.release_lock()

Modified: trunk/Tools/Scripts/webkitpy/common/system/systemhost.py (282769 => 282770)


--- trunk/Tools/Scripts/webkitpy/common/system/systemhost.py	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/Scripts/webkitpy/common/system/systemhost.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -31,7 +31,8 @@
 import platform
 import sys
 
-from webkitpy.common.system import environment, executive, file_lock, filesystem, platforminfo, user, workspace
+from webkitpy.common.system import environment, executive, filesystem, platforminfo, user, workspace
+from webkitcorepy import FileLock
 
 
 class SystemHost(object):
@@ -46,7 +47,7 @@
         return environment.Environment(os.environ.copy())
 
     def make_file_lock(self, path):
-        return file_lock.FileLock(path)
+        return FileLock(path)
 
     def symbolicate_crash_log_if_needed(self, path):
         return self.filesystem.read_text_file(path)

Modified: trunk/Tools/Scripts/webkitpy/common/system/systemhost_mock.py (282769 => 282770)


--- trunk/Tools/Scripts/webkitpy/common/system/systemhost_mock.py	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/Scripts/webkitpy/common/system/systemhost_mock.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -1,5 +1,5 @@
 # Copyright (c) 2011 Google Inc. All rights reserved.
-# Copyright (C) 2019 Apple Inc. All rights reserved.
+# Copyright (C) 2019-2021 Apple Inc. All rights reserved.
 #
 #  Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are
@@ -30,12 +30,13 @@
 from webkitpy.common.system.environment import Environment
 from webkitpy.common.system.executive_mock import MockExecutive
 from webkitpy.common.system.filesystem_mock import MockFileSystem
-from webkitpy.common.system.file_lock_mock import MockFileLock
 from webkitpy.common.system.platforminfo_mock import MockPlatformInfo
 from webkitpy.common.system.user_mock import MockUser
 from webkitpy.common.system.workspace_mock import MockWorkspace
 
+from webkitcorepy import mocks
 
+
 class MockSystemHost(object):
     def __init__(self, log_executive=False, executive_throws_when_run=None, os_name=None, os_version=None, executive=None, filesystem=None):
         self.executive = executive or MockExecutive(should_log=log_executive, should_throw_when_run=executive_throws_when_run)
@@ -54,7 +55,7 @@
         return Environment({"MOCK_ENVIRON_COPY": '1'})
 
     def make_file_lock(self, path):
-        return MockFileLock(path)
+        return mocks.FileLock(path)
 
     def symbolicate_crash_log_if_needed(self, path):
         return self.filesystem.read_text_file(path)

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/rebaseline.py (282769 => 282770)


--- trunk/Tools/Scripts/webkitpy/tool/commands/rebaseline.py	2021-09-20 19:32:34 UTC (rev 282769)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/rebaseline.py	2021-09-20 19:52:35 UTC (rev 282770)
@@ -154,10 +154,11 @@
         # concurrently as well.
         # FIXME: We should rework the code to not need this; maybe just download
         # the files in parallel and rebaseline local files serially?
-        try:
-            path = port.path_to_test_expectations_file()
-            lock = self._tool.make_file_lock(path + '.lock')
-            lock.acquire_lock()
+        path = port.path_to_test_expectations_file()
+        with self._tool.make_file_lock(path + '.lock') as lock:
+            if not lock.acquired:
+                raise OSError('Failed to aquire rebaseline lock for {}'.format(path))
+
             expectations = TestExpectations(port, include_generic=False, include_overrides=False)
             expectations.parse_all_expectations()
             for test_configuration in port.all_test_configurations():
@@ -165,8 +166,6 @@
                     expectationsString = expectations.remove_configuration_from_test(test_name, test_configuration)
 
             self._tool.filesystem.write_text_file(path, expectationsString)
-        finally:
-            lock.release_lock()
 
     def _test_root(self, test_name):
         return self._tool.filesystem.splitext(test_name)[0]
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to