Title: [127302] trunk/Tools
Revision
127302
Author
[email protected]
Date
2012-08-31 12:49:00 -0700 (Fri, 31 Aug 2012)

Log Message

nrwt: use scm instead of calling svn directly to get the revision in json results generator
https://bugs.webkit.org/show_bug.cgi?id=89616

Reviewed by Eric Seidel.

Add the new 'executive' optional function argument to the SCM.in_working_directory
class method. This way we get to reuse an Executive instance which is necessary in testing
when we're operating with a mock version of the object.

In JSONResultsGeneratorBase, it's now possible to get the current SVN revision by using
the SCMDetector with the generator's FileSystem and Executive instances.

* Scripts/webkitpy/common/checkout/scm/detection.py:
(SCMDetector.detect_scm_system):
* Scripts/webkitpy/common/checkout/scm/detection_unittest.py:
(SCMDetectorTest.test_detect_scm_system): Update the unit test to capture the mock
Executive output and test it against expected output.
* Scripts/webkitpy/common/checkout/scm/git.py:
(Git.in_working_directory):
* Scripts/webkitpy/common/checkout/scm/scm.py:
(SCM.in_working_directory):
* Scripts/webkitpy/common/checkout/scm/svn.py:
(SVN.in_working_directory):
* Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
(JSONResultsGeneratorBase.__init__):
(JSONResultsGeneratorBase._get_svn_revision):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (127301 => 127302)


--- trunk/Tools/ChangeLog	2012-08-31 19:38:40 UTC (rev 127301)
+++ trunk/Tools/ChangeLog	2012-08-31 19:49:00 UTC (rev 127302)
@@ -1,3 +1,32 @@
+2012-08-31  Zan Dobersek  <[email protected]>
+
+        nrwt: use scm instead of calling svn directly to get the revision in json results generator
+        https://bugs.webkit.org/show_bug.cgi?id=89616
+
+        Reviewed by Eric Seidel.
+
+        Add the new 'executive' optional function argument to the SCM.in_working_directory
+        class method. This way we get to reuse an Executive instance which is necessary in testing
+        when we're operating with a mock version of the object.
+
+        In JSONResultsGeneratorBase, it's now possible to get the current SVN revision by using
+        the SCMDetector with the generator's FileSystem and Executive instances.
+
+        * Scripts/webkitpy/common/checkout/scm/detection.py:
+        (SCMDetector.detect_scm_system):
+        * Scripts/webkitpy/common/checkout/scm/detection_unittest.py:
+        (SCMDetectorTest.test_detect_scm_system): Update the unit test to capture the mock
+        Executive output and test it against expected output.
+        * Scripts/webkitpy/common/checkout/scm/git.py:
+        (Git.in_working_directory):
+        * Scripts/webkitpy/common/checkout/scm/scm.py:
+        (SCM.in_working_directory):
+        * Scripts/webkitpy/common/checkout/scm/svn.py:
+        (SVN.in_working_directory):
+        * Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
+        (JSONResultsGeneratorBase.__init__):
+        (JSONResultsGeneratorBase._get_svn_revision):
+
 2012-08-31  Jon Lee  <[email protected]>
 
         [Tests] Add basic tests to http/tests/notifications

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


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/detection.py	2012-08-31 19:38:40 UTC (rev 127301)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/detection.py	2012-08-31 19:49:00 UTC (rev 127302)
@@ -66,10 +66,10 @@
         if patch_directories == []:
             patch_directories = None
 
-        if SVN.in_working_directory(absolute_path):
+        if SVN.in_working_directory(absolute_path, executive=self._executive):
             return SVN(cwd=absolute_path, patch_directories=patch_directories, filesystem=self._filesystem, executive=self._executive)
 
-        if Git.in_working_directory(absolute_path):
+        if Git.in_working_directory(absolute_path, executive=self._executive):
             return Git(cwd=absolute_path, filesystem=self._filesystem, executive=self._executive)
 
         return None

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/detection_unittest.py (127301 => 127302)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/detection_unittest.py	2012-08-31 19:38:40 UTC (rev 127301)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/detection_unittest.py	2012-08-31 19:49:00 UTC (rev 127302)
@@ -33,6 +33,7 @@
 from .detection import SCMDetector
 from webkitpy.common.system.filesystem_mock import MockFileSystem
 from webkitpy.common.system.executive_mock import MockExecutive
+from webkitpy.common.system.outputcapture import OutputCapture
 
 
 class SCMDetectorTest(unittest.TestCase):
@@ -41,5 +42,7 @@
         executive = MockExecutive(should_log=True)
         detector = SCMDetector(filesystem, executive)
 
-        self.assertEqual(detector.detect_scm_system("/"), None)
+        expected_stderr = "MOCK run_command: ['svn', 'info'], cwd=/\nMOCK run_command: ['git', 'rev-parse', '--is-inside-work-tree'], cwd=/\n"
+        scm = OutputCapture().assert_outputs(self, detector.detect_scm_system, ["/"], expected_stderr=expected_stderr)
+        self.assertEqual(scm, None)
         # FIXME: This should make a synthetic tree and test SVN and Git detection in that tree.

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py (127301 => 127302)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py	2012-08-31 19:38:40 UTC (rev 127301)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/git.py	2012-08-31 19:49:00 UTC (rev 127302)
@@ -99,10 +99,10 @@
         log("Warning: This machine is 64-bit, but the git binary (%s) does not support 64-bit.\nInstall a 64-bit git for better performance, see:\n%s\n" % (git_path, webkit_dev_thread_url))
 
     @classmethod
-    def in_working_directory(cls, path):
+    def in_working_directory(cls, path, executive=None):
         try:
-            # FIXME: This should use an Executive.
-            return run_command([cls.executable_name, 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() == "true"
+            executive = executive or Executive()
+            return executive.run_command([cls.executable_name, 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() == "true"
         except OSError, e:
             # The Windows bots seem to through a WindowsError when git isn't installed.
             return False

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py (127301 => 127302)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py	2012-08-31 19:38:40 UTC (rev 127301)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/scm.py	2012-08-31 19:49:00 UTC (rev 127302)
@@ -134,7 +134,7 @@
         raise NotImplementedError("subclasses must implement")
 
     @classmethod
-    def in_working_directory(cls, path):
+    def in_working_directory(cls, path, executive=None):
         SCM._subclass_must_implement()
 
     def find_checkout_root(path):

Modified: trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py (127301 => 127302)


--- trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py	2012-08-31 19:38:40 UTC (rev 127301)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/scm/svn.py	2012-08-31 19:49:00 UTC (rev 127302)
@@ -83,14 +83,15 @@
             self._patch_directories = patch_directories
 
     @classmethod
-    def in_working_directory(cls, path):
+    def in_working_directory(cls, path, executive=None):
         if os.path.isdir(os.path.join(path, '.svn')):
             # This is a fast shortcut for svn info that is usually correct for SVN < 1.7,
             # but doesn't work for SVN >= 1.7.
             return True
 
+        executive = executive or Executive()
         svn_info_args = [cls.executable_name, 'info']
-        exit_code = Executive().run_command(svn_info_args, cwd=path, return_exit_code=True)
+        exit_code = executive.run_command(svn_info_args, cwd=path, return_exit_code=True)
         return (exit_code == 0)
 
     def find_uuid(self, path):

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


--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py	2012-08-31 19:38:40 UTC (rev 127301)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py	2012-08-31 19:49:00 UTC (rev 127302)
@@ -34,6 +34,7 @@
 import urllib2
 import xml.dom.minidom
 
+from webkitpy.common.checkout.scm.detection import SCMDetector
 from webkitpy.common.net.file_uploader import FileUploader
 
 # A JSON results generator for generic tests.
@@ -219,6 +220,7 @@
         """
         self._port = port
         self._filesystem = port._filesystem
+        self._executive = port._executive
         self._builder_name = builder_name
         self._build_name = build_name
         self._build_number = build_number
@@ -384,18 +386,9 @@
         Args:
           in_directory: The directory where svn is to be run.
         """
-        if self._filesystem.exists(self._filesystem.join(in_directory, '.svn')):
-            # Note: Not thread safe: http://bugs.python.org/issue2320
-            output = subprocess.Popen(["svn", "info", "--xml"],
-                                      cwd=in_directory,
-                                      shell=(sys.platform == 'win32'),
-                                      stdout=subprocess.PIPE).communicate()[0]
-            try:
-                dom = xml.dom.minidom.parseString(output)
-                return dom.getElementsByTagName('entry')[0].getAttribute(
-                    'revision')
-            except xml.parsers.expat.ExpatError:
-                return ""
+        scm = SCMDetector(self._filesystem, self._executive).detect_scm_system(in_directory)
+        if scm:
+            return scm.svn_revision(in_directory)
         return ""
 
     def _get_archived_json_results(self):
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to