[webkitpy] PlatformInfo should have default argument for casual use
[WebKit-https.git] / Tools / Scripts / webkitpy / common / system / platforminfo.py
index aca0c3b3e72edf163dfda4094e99ce322428a15e..c5938acacb8e7b90923d59f7aae41706a9982411 100644 (file)
@@ -29,6 +29,7 @@
 
 import re
 import sys
+import platform
 
 from webkitpy.common.version import Version
 from webkitpy.common.version_name_map import PUBLIC_TABLE, VersionNameMap
@@ -48,13 +49,16 @@ class PlatformInfo(object):
     newer than one known to the code.
     """
 
-    def __init__(self, sys_module, platform_module, executive):
+    def __init__(self, sys_module=None, platform_module=None, executive=None):
+        sys_platform = (sys_module or sys).platform
+        platform_module = platform_module or platform
+
         self._executive = executive
         self._platform_module = platform_module
-        self.os_name = self._determine_os_name(sys_module.platform)
+        self.os_name = self._determine_os_name(sys_platform)
         self.os_version = None
 
-        self._is_cygwin = sys_module.platform == 'cygwin'
+        self._is_cygwin = sys_platform == 'cygwin'
 
         if self.os_name.startswith('mac'):
             self.os_version = Version.from_string(platform_module.mac_ver()[0])
@@ -66,6 +70,13 @@ class PlatformInfo(object):
             # Most other platforms (namely iOS) return conforming version strings.
             self.os_version = Version.from_string(platform_module.release())
 
+    @property
+    def executive(self):
+        if self._executive is None:
+            self._executive = Executive()
+
+        return self._executive
+
     def is_mac(self):
         return self.os_name == 'mac'
 
@@ -110,7 +121,7 @@ class PlatformInfo(object):
 
     def total_bytes_memory(self):
         if self.is_mac():
-            return long(self._executive.run_command(["sysctl", "-n", "hw.memsize"]))
+            return long(self.executive.run_command(["sysctl", "-n", "hw.memsize"]))
         return None
 
     def terminal_width(self):
@@ -141,7 +152,7 @@ class PlatformInfo(object):
     def xcode_sdk_version(self, sdk_name):
         if self.is_mac():
             # Assumes that xcrun does not write to standard output on failure (e.g. SDK does not exist).
-            xcrun_output = self._executive.run_command(['xcrun', '--sdk', sdk_name, '--show-sdk-version'], return_stderr=False, error_handler=Executive.ignore_error).rstrip()
+            xcrun_output = self.executive.run_command(['xcrun', '--sdk', sdk_name, '--show-sdk-version'], return_stderr=False, error_handler=Executive.ignore_error).rstrip()
             if xcrun_output:
                 return Version.from_string(xcrun_output)
         return None
@@ -149,13 +160,13 @@ class PlatformInfo(object):
     def xcode_simctl_list(self):
         if not self.is_mac():
             return ()
-        output = self._executive.run_command(['xcrun', 'simctl', 'list'], return_stderr=False)
+        output = self.executive.run_command(['xcrun', 'simctl', 'list'], return_stderr=False)
         return (line for line in output.splitlines())
 
     def xcode_version(self):
         if not self.is_mac():
             raise NotImplementedError
-        return Version.from_string(self._executive.run_command(['xcodebuild', '-version']).split()[1])
+        return Version.from_string(self.executive.run_command(['xcodebuild', '-version']).split()[1])
 
     def _determine_os_name(self, sys_platform):
         if sys_platform == 'darwin':
@@ -185,4 +196,4 @@ class PlatformInfo(object):
         if version:
             return version
         # Note that this should only ever be called on windows, so this should always work.
-        return self._executive.run_command(['cmd', '/c', 'ver'], decode_output=False)
+        return self.executive.run_command(['cmd', '/c', 'ver'], decode_output=False)