Commit f3303da5 authored by qyearsley's avatar qyearsley Committed by Commit bot

Clean up webkitpy.layout_tests.port.factory.

In this CL:
  Make docstring style consistent
  Make quotes consistent
  Move helper functions to below main class
  Edit comments

This CL should not change behavior. Reason for this change:
Was reading this file when making another change and saw
a few trivial things to improve.

Review-Url: https://codereview.chromium.org/2719483003
Cr-Commit-Position: refs/heads/master@{#453283}
parent ada3cefb
...@@ -35,6 +35,76 @@ import re ...@@ -35,6 +35,76 @@ import re
from webkitpy.common.webkit_finder import WebKitFinder from webkitpy.common.webkit_finder import WebKitFinder
class PortFactory(object):
PORT_CLASSES = (
'android.AndroidPort',
'linux.LinuxPort',
'mac.MacPort',
'win.WinPort',
'mock_drt.MockDRTPort',
'test.TestPort',
)
def __init__(self, host):
self._host = host
def _default_port(self):
platform = self._host.platform
if platform.is_linux() or platform.is_freebsd():
return 'linux'
elif platform.is_mac():
return 'mac'
elif platform.is_win():
return 'win'
raise NotImplementedError('unknown platform: %s' % platform)
def get(self, port_name=None, options=None, **kwargs):
"""Returns an object implementing the Port interface.
If port_name is None, this routine attempts to guess at the most
appropriate port on this platform.
"""
port_name = port_name or self._default_port()
_check_configuration_and_target(self._host.filesystem, options)
if 'browser_test' in port_name:
module_name, class_name = port_name.rsplit('.', 1)
module = __import__(module_name, globals(), locals(), [], -1)
port_class_name = module.get_port_class_name(class_name)
if port_class_name is not None:
cls = module.__dict__[port_class_name]
port_name = cls.determine_full_port_name(self._host, options, class_name)
return cls(self._host, port_name, options=options, **kwargs)
else:
for port_class in self.PORT_CLASSES:
module_name, class_name = port_class.rsplit('.', 1)
module = __import__(module_name, globals(), locals(), [], -1)
cls = module.__dict__[class_name]
if port_name.startswith(cls.port_name):
port_name = cls.determine_full_port_name(self._host, options, port_name)
return cls(self._host, port_name, options=options, **kwargs)
raise NotImplementedError('unsupported platform: "%s"' % port_name)
def all_port_names(self, platform=None):
"""Returns a list of all valid, fully-specified, "real" port names.
This is the list of directories that are used as actual baseline_paths()
by real ports. This does not include any "fake" names like "test"
or "mock-mac", and it does not include any directories that are not
port names.
If platform is not specified, all known port names will be returned.
"""
platform = platform or '*'
return fnmatch.filter(self._host.builders.all_port_names(), platform)
def get_from_builder_name(self, builder_name):
port_name = self._host.builders.port_name_for_builder_name(builder_name)
assert port_name, 'unrecognized builder name: "%s"' % builder_name
return self.get(port_name, options=_builder_options(builder_name))
def platform_options(use_globs=False): def platform_options(use_globs=False):
return [ return [
optparse.make_option('--android', action='store_const', dest='platform', optparse.make_option('--android', action='store_const', dest='platform',
...@@ -49,11 +119,11 @@ def platform_options(use_globs=False): ...@@ -49,11 +119,11 @@ def platform_options(use_globs=False):
def configuration_options(): def configuration_options():
return [ return [
optparse.make_option('--debug', action='store_const', const='Debug', dest="configuration", optparse.make_option('--debug', action='store_const', const='Debug', dest='configuration',
help='Set the configuration to Debug'), help='Set the configuration to Debug'),
optparse.make_option("-t", "--target", dest="target", optparse.make_option('-t', '--target', dest='target',
help="Specify the target build subdirectory under src/out/"), help='Specify the target build subdirectory under src/out/'),
optparse.make_option('--release', action='store_const', const='Release', dest="configuration", optparse.make_option('--release', action='store_const', const='Release', dest='configuration',
help='Set the configuration to Release'), help='Set the configuration to Release'),
] ]
...@@ -61,12 +131,13 @@ def configuration_options(): ...@@ -61,12 +131,13 @@ def configuration_options():
def _builder_options(builder_name): def _builder_options(builder_name):
return optparse.Values({ return optparse.Values({
'builder_name': builder_name, 'builder_name': builder_name,
'configuration': "Debug" if re.search(r"[d|D](ebu|b)g", builder_name) else "Release", 'configuration': 'Debug' if re.search(r'[d|D](ebu|b)g', builder_name) else 'Release',
'target': None, 'target': None,
}) })
def _check_configuration_and_target(host, options): def _check_configuration_and_target(host, options):
"""Updates options.configuration based on options.target."""
if not options or not getattr(options, 'target', None): if not options or not getattr(options, 'target', None):
return return
...@@ -89,10 +160,9 @@ def _check_configuration_and_target(host, options): ...@@ -89,10 +160,9 @@ def _check_configuration_and_target(host, options):
def _read_configuration_from_gn(fs, options): def _read_configuration_from_gn(fs, options):
"""Return the configuration to used based on args.gn, if possible.""" """Returns the configuration to used based on args.gn, if possible."""
# We should really default to 'out' everywhere at this point, but # TODO(qyearsley): Default to 'out' everywhere.
# that's a separate cleanup CL.
build_directory = getattr(options, 'build_directory', None) or 'out' build_directory = getattr(options, 'build_directory', None) or 'out'
target = options.target target = options.target
...@@ -110,78 +180,10 @@ def _read_configuration_from_gn(fs, options): ...@@ -110,78 +180,10 @@ def _read_configuration_from_gn(fs, options):
return 'Debug' return 'Debug'
args = fs.read_text_file(path) args = fs.read_text_file(path)
for l in args.splitlines(): for line in args.splitlines():
if re.match(r'^\s*is_debug\s*=\s*false(\s*$|\s*#.*$)', l): if re.match(r'^\s*is_debug\s*=\s*false(\s*$|\s*#.*$)', line):
return 'Release' return 'Release'
# if is_debug is set to anything other than false, or if it # If is_debug is set to anything other than false, or if it
# does not exist at all, we should use the default value (True). # does not exist at all, we should use the default value (True).
return 'Debug' return 'Debug'
class PortFactory(object):
PORT_CLASSES = (
'android.AndroidPort',
'linux.LinuxPort',
'mac.MacPort',
'win.WinPort',
'mock_drt.MockDRTPort',
'test.TestPort',
)
def __init__(self, host):
self._host = host
def _default_port(self):
platform = self._host.platform
if platform.is_linux() or platform.is_freebsd():
return 'linux'
elif platform.is_mac():
return 'mac'
elif platform.is_win():
return 'win'
raise NotImplementedError('unknown platform: %s' % platform)
def get(self, port_name=None, options=None, **kwargs):
"""Returns an object implementing the Port interface. If
port_name is None, this routine attempts to guess at the most
appropriate port on this platform.
"""
port_name = port_name or self._default_port()
_check_configuration_and_target(self._host.filesystem, options)
if 'browser_test' in port_name:
module_name, class_name = port_name.rsplit('.', 1)
module = __import__(module_name, globals(), locals(), [], -1)
port_class_name = module.get_port_class_name(class_name)
if port_class_name is not None:
cls = module.__dict__[port_class_name]
port_name = cls.determine_full_port_name(self._host, options, class_name)
return cls(self._host, port_name, options=options, **kwargs)
else:
for port_class in self.PORT_CLASSES:
module_name, class_name = port_class.rsplit('.', 1)
module = __import__(module_name, globals(), locals(), [], -1)
cls = module.__dict__[class_name]
if port_name.startswith(cls.port_name):
port_name = cls.determine_full_port_name(self._host, options, port_name)
return cls(self._host, port_name, options=options, **kwargs)
raise NotImplementedError('unsupported platform: "%s"' % port_name)
def all_port_names(self, platform=None):
"""Return a list of all valid, fully-specified, "real" port names.
This is the list of directories that are used as actual baseline_paths()
by real ports. This does not include any "fake" names like "test"
or "mock-mac", and it does not include any directories that are not.
If platform is not specified, we will glob-match all ports
"""
platform = platform or '*'
return fnmatch.filter(self._host.builders.all_port_names(), platform)
def get_from_builder_name(self, builder_name):
port_name = self._host.builders.port_name_for_builder_name(builder_name)
assert port_name, "unrecognized builder name '%s'" % builder_name
return self.get(port_name, _builder_options(builder_name))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment