Title: [249749] trunk/Tools
Revision
249749
Author
jlew...@apple.com
Date
2019-09-10 18:12:37 -0700 (Tue, 10 Sep 2019)

Log Message

run-webkit-test: Allow results to be uploaded without scm checkout
https://bugs.webkit.org/show_bug.cgi?id=200787

Reviewed by Jonathan Bedard.

* Scripts/webkitpy/common/checkout/scm/detection.py:
(SCMDetector.detect_scm_system): Added in detection of stub repository.
* Scripts/webkitpy/common/checkout/scm/stub_repository.py: Added.
(StubRepository):
(StubRepository.__init__):
(StubRepository._find_parent_path_matching_callback_condition): Checks up the path given to
find the directory containing the checkout_information.json of the stub repository.
(StubRepository.in_working_directory): Required functions to be implemented.
(StubRepository.svn_revision): Required functions to be implemented.
(StubRepository.native_revision): Required functions to be implemented.
(StubRepository.native_branch): Required functions to be implemented.
(StubRepository._decode_json): Decodes checkout_information.json.
(StubRepository.find_checkout_root): Required functions to be implemented.
* Scripts/webkitpy/common/checkout/scm/stub_repository_unittest.py: Added.
(StubRepositoryTest): Unit test for stub_repository SCM.
(StubRepositoryTest.mock_host_for_stub_repository):
(StubRepositoryTest.test_in_working_directory):
(StubRepositoryTest.test_native_revision):
(StubRepositoryTest.test_native_branch):
(StubRepositoryTest.test_svn_revision):
(StubRepositoryTest.test_find_checkout_root):
* Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
(JSONResultsGenerator._get_svn_revision): Removed unnecessary scm initialization.
* Scripts/webkitpy/port/base.py:
(Port.commits_for_upload): Removed unnecessary scm initialization.

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (249748 => 249749)


--- trunk/Tools/ChangeLog	2019-09-11 00:54:05 UTC (rev 249748)
+++ trunk/Tools/ChangeLog	2019-09-11 01:12:37 UTC (rev 249749)
@@ -1,3 +1,36 @@
+2019-09-10  Matt Lewis  <jlew...@apple.com>
+
+        run-webkit-test: Allow results to be uploaded without scm checkout
+        https://bugs.webkit.org/show_bug.cgi?id=200787
+
+        Reviewed by Jonathan Bedard.
+
+        * Scripts/webkitpy/common/checkout/scm/detection.py:
+        (SCMDetector.detect_scm_system): Added in detection of stub repository.
+        * Scripts/webkitpy/common/checkout/scm/stub_repository.py: Added.
+        (StubRepository):
+        (StubRepository.__init__):
+        (StubRepository._find_parent_path_matching_callback_condition): Checks up the path given to
+        find the directory containing the checkout_information.json of the stub repository.
+        (StubRepository.in_working_directory): Required functions to be implemented.
+        (StubRepository.svn_revision): Required functions to be implemented.
+        (StubRepository.native_revision): Required functions to be implemented.
+        (StubRepository.native_branch): Required functions to be implemented.
+        (StubRepository._decode_json): Decodes checkout_information.json.
+        (StubRepository.find_checkout_root): Required functions to be implemented.
+        * Scripts/webkitpy/common/checkout/scm/stub_repository_unittest.py: Added.
+        (StubRepositoryTest): Unit test for stub_repository SCM.
+        (StubRepositoryTest.mock_host_for_stub_repository):
+        (StubRepositoryTest.test_in_working_directory):
+        (StubRepositoryTest.test_native_revision):
+        (StubRepositoryTest.test_native_branch):
+        (StubRepositoryTest.test_svn_revision):
+        (StubRepositoryTest.test_find_checkout_root):
+        * Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
+        (JSONResultsGenerator._get_svn_revision): Removed unnecessary scm initialization.
+        * Scripts/webkitpy/port/base.py:
+        (Port.commits_for_upload): Removed unnecessary scm initialization.
+
 2019-09-10  Brady Eidson  <beid...@apple.com>
 
         Add SPI to save a PDF from the contents of a WKWebView.

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/detection.py (249748 => 249749)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/detection.py	2019-09-11 00:54:05 UTC (rev 249748)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/detection.py	2019-09-11 01:12:37 UTC (rev 249749)
@@ -34,6 +34,7 @@
 
 from .svn import SVN
 from .git import Git
+from .stub_repository import StubRepository
 
 _log = logging.getLogger(__name__)
 
@@ -74,6 +75,9 @@
         if Git.in_working_directory(real_path, executive=self._executive):
             return Git(cwd=real_path, patch_directories=patch_directories, filesystem=self._filesystem, executive=self._executive)
 
+        if StubRepository.in_working_directory(real_path, filesystem=self._filesystem):
+            return StubRepository(cwd=real_path, patch_directories=patch_directories, filesystem=self._filesystem, executive=self._executive)
+
         return None
 
 

Added: trunk/Tools/Scripts/webkitpy/common/checkout/scm/stub_repository.py (0 => 249749)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/stub_repository.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/stub_repository.py	2019-09-11 01:12:37 UTC (rev 249749)
@@ -0,0 +1,77 @@
+# Copyright (c) 2019 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:
+#
+#     * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#     * 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 THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+# OWNER 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.
+#
+# Python module for interacting with an SCM system (like SVN or Git)
+
+import logging
+import json
+
+from webkitpy.common.system.filesystem import FileSystem
+from .scm import SCM
+
+_log = logging.getLogger(__name__)
+
+
+class StubRepository(SCM):
+    _stub_repository_json = 'checkout_information.json'
+
+    def __init__(self, cwd, filesystem, **kwargs):
+        self._filesystem = filesystem
+
+    @classmethod
+    def _find_parent_path_matching_callback_condition(cls, path, callback, filesystem=None):
+        if not filesystem:
+            filesystem = FileSystem()
+        previous_path = ''
+        path = filesystem.abspath(path)
+        while path and path != previous_path:
+            if filesystem.exists(filesystem.join(path, cls._stub_repository_json)):
+                return callback(path)
+            previous_path = path
+            path = filesystem.dirname(path)
+        return None
+
+    @classmethod
+    def in_working_directory(cls, path, executive=None, filesystem=None):
+        try:
+            return bool(cls._find_parent_path_matching_callback_condition(path, lambda path: True, filesystem=filesystem))
+        except OSError:
+            return False
+
+    def svn_revision(self, path):
+        return self.native_revision(path)
+
+    def native_revision(self, path):
+        return self._find_parent_path_matching_callback_condition(path, lambda path: self._decode_json(path)['id'], filesystem=self._filesystem)
+
+    def native_branch(self, path):
+        return self._find_parent_path_matching_callback_condition(path, lambda path: self._decode_json(path)['branch'], filesystem=self._filesystem)
+
+    def _decode_json(self, path):
+        with self._filesystem.open_text_file_for_reading(self._filesystem.join(path, self._stub_repository_json)) as json_file:
+            return json.load(json_file)
+
+    def find_checkout_root(self, path):
+        return self._find_parent_path_matching_callback_condition(path, lambda path: path, filesystem=self._filesystem)

Added: trunk/Tools/Scripts/webkitpy/common/checkout/scm/stub_repository_unittest.py (0 => 249749)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/stub_repository_unittest.py	                        (rev 0)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/stub_repository_unittest.py	2019-09-11 01:12:37 UTC (rev 249749)
@@ -0,0 +1,78 @@
+# Copyright (C) 2019 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 unittest
+
+from webkitpy.common.system import filesystem_mock
+from .stub_repository import StubRepository
+
+mock_stub_repository_json = {'branch': 'trunk', 'id': '2738499'}
+
+FAKE_FILES = {
+    '/TestDirectory/test.txt': 'test',
+    '/TestDirectory/TestDirectory2/checkout_information.json': '{ "branch": "trunk", "id": "2738499" }',
+    '/TestDirectory/TestDirectory2/TestDirectory3/test2.txt': 'test',
+}
+
+
+class StubRepositoryTest(unittest.TestCase):
+
+    @staticmethod
+    def mock_host_for_stub_repository():
+        host = filesystem_mock.MockFileSystem(files=FAKE_FILES)
+        return host
+
+    def test_in_working_directory(self):
+        host = StubRepositoryTest.mock_host_for_stub_repository()
+        self.assertTrue(StubRepository.in_working_directory(path=host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3'), filesystem=host))
+
+    def test_native_revision(self):
+        host = StubRepositoryTest.mock_host_for_stub_repository()
+        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
+        self.assertEqual(repository.native_revision(path=host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['id'])
+
+    def test_native_branch(self):
+        host = StubRepositoryTest.mock_host_for_stub_repository()
+        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
+        self.assertEqual(repository.native_branch(path=host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['branch'])
+
+    def test_svn_revision(self):
+        host = StubRepositoryTest.mock_host_for_stub_repository()
+        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
+        self.assertEqual(repository.svn_revision(path=host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2', 'TestDirectory3')), mock_stub_repository_json['id'])
+
+    def test_find_checkout_root(self):
+        host = StubRepositoryTest.mock_host_for_stub_repository()
+        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
+        self.assertEquals(repository.find_checkout_root(path=host.join('TestDirectory', 'TestDirectory2', 'TestDirectory3')), host.join(host.getcwd(), 'TestDirectory', 'TestDirectory2'))
+
+    def test_find_checkout_root_failure(self):
+        host = StubRepositoryTest.mock_host_for_stub_repository()
+        repository = StubRepository(cwd=host.getcwd(), filesystem=host)
+        self.assertIsNone(repository.find_checkout_root(path=host.getcwd()))
+
+    def test_find_parent_path_matching_callback_condition_with_file_system(self):
+        host = StubRepositoryTest.mock_host_for_stub_repository()
+        self.assertIsNone(StubRepository._find_parent_path_matching_callback_condition(path=host.join('TestDirectory'), callback=lambda path: True, filesystem=host))
+
+    def test_find_parent_path_matching_callback_condition_without_file_system(self):
+        self.assertIsNone(StubRepository._find_parent_path_matching_callback_condition(path='/Volumes/', callback=lambda path: True, filesystem=None))

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py (249748 => 249749)


--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py	2019-09-11 00:54:05 UTC (rev 249748)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py	2019-09-11 01:12:37 UTC (rev 249749)
@@ -443,11 +443,6 @@
         Args:
           in_directory: The directory where svn is to be run.
         """
-
-        # FIXME: We initialize this here in order to engage the stupid windows hacks :).
-        # We can't reuse an existing scm object because the specific directories may
-        # be part of other checkouts.
-        self._port.host.initialize_scm()
         scm = SCMDetector(self._filesystem, self._executive).detect_scm_system(in_directory)
         if scm:
             return scm.svn_revision(in_directory)

Modified: trunk/Tools/Scripts/webkitpy/port/base.py (249748 => 249749)


--- trunk/Tools/Scripts/webkitpy/port/base.py	2019-09-11 00:54:05 UTC (rev 249748)
+++ trunk/Tools/Scripts/webkitpy/port/base.py	2019-09-11 01:12:37 UTC (rev 249749)
@@ -1603,8 +1603,6 @@
     def commits_for_upload(self):
         from webkitpy.results.upload import Upload
 
-        self.host.initialize_scm()
-
         repos = {}
         if port_config.apple_additions() and getattr(port_config.apple_additions(), 'repos', False):
             repos = port_config.apple_additions().repos()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to