summaryrefslogtreecommitdiffstats
path: root/WebKitTools/Scripts/webkitpy/layout_tests/port/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/layout_tests/port/config.py')
-rw-r--r--WebKitTools/Scripts/webkitpy/layout_tests/port/config.py68
1 files changed, 42 insertions, 26 deletions
diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/port/config.py b/WebKitTools/Scripts/webkitpy/layout_tests/port/config.py
index 2364098..cad5e37 100644
--- a/WebKitTools/Scripts/webkitpy/layout_tests/port/config.py
+++ b/WebKitTools/Scripts/webkitpy/layout_tests/port/config.py
@@ -32,28 +32,29 @@
# FIXME: This file needs to be unified with common/checkout/scm.py and
# common/config/ports.py .
-from __future__ import with_statement
-
-import codecs
import os
-from webkitpy.common.checkout import scm
from webkitpy.common.system import logutils
+from webkitpy.common.system import executive
_log = logutils.get_logger(__file__)
#
-# This is used to record if we've already hit the filesystem to look
+# FIXME: This is used to record if we've already hit the filesystem to look
# for a default configuration. We cache this to speed up the unit tests,
-# but this can be reset with clear_cached_configuration().
+# but this can be reset with clear_cached_configuration(). This should be
+# replaced with us consistently using MockConfigs() for tests that don't
+# hit the filesystem at all and provide a reliable value.
#
-_determined_configuration = None
+_have_determined_configuration = False
+_configuration = "Release"
def clear_cached_configuration():
- global _determined_configuration
- _determined_configuration = -1
+ global _have_determined_configuration, _configuration
+ _have_determined_configuration = False
+ _configuration = "Release"
class Config(object):
@@ -62,8 +63,9 @@ class Config(object):
"Release": "--release",
}
- def __init__(self, executive):
+ def __init__(self, executive, filesystem):
self._executive = executive
+ self._filesystem = filesystem
self._webkit_base_dir = None
self._default_configuration = None
self._build_directories = {}
@@ -115,40 +117,54 @@ class Config(object):
return self._default_configuration
def path_from_webkit_base(self, *comps):
- return os.path.join(self.webkit_base_dir(), *comps)
+ return self._filesystem.join(self.webkit_base_dir(), *comps)
def webkit_base_dir(self):
"""Returns the absolute path to the top of the WebKit tree.
Raises an AssertionError if the top dir can't be determined."""
- # FIXME: Consider determining this independently of scm in order
- # to be able to run in a bare tree.
+ # Note: this code somewhat duplicates the code in
+ # scm.find_checkout_root(). However, that code only works if the top
+ # of the SCM repository also matches the top of the WebKit tree. The
+ # Chromium ports, for example, only check out subdirectories like
+ # WebKitTools/Scripts, and so we still have to do additional work
+ # to find the top of the tree.
+ #
+ # This code will also work if there is no SCM system at all.
if not self._webkit_base_dir:
- self._webkit_base_dir = scm.find_checkout_root()
- assert self._webkit_base_dir, "Could not determine the top of the WebKit checkout"
+ abspath = os.path.abspath(__file__)
+ self._webkit_base_dir = abspath[0:abspath.find('WebKitTools')]
return self._webkit_base_dir
def _script_path(self, script_name):
- return os.path.join(self.webkit_base_dir(), "WebKitTools",
- "Scripts", script_name)
+ return self._filesystem.join(self.webkit_base_dir(), "WebKitTools",
+ "Scripts", script_name)
def _determine_configuration(self):
# This mirrors the logic in webkitdirs.pm:determineConfiguration().
- global _determined_configuration
- if _determined_configuration == -1:
+ #
+ # FIXME: See the comment at the top of the file regarding unit tests
+ # and our use of global mutable static variables.
+ global _have_determined_configuration, _configuration
+ if not _have_determined_configuration:
contents = self._read_configuration()
+ if not contents:
+ contents = "Release"
if contents == "Deployment":
contents = "Release"
if contents == "Development":
contents = "Debug"
- _determined_configuration = contents
- return _determined_configuration
+ _configuration = contents
+ _have_determined_configuration = True
+ return _configuration
def _read_configuration(self):
- configuration_path = os.path.join(self.build_directory(None),
- "Configuration")
- if not os.path.exists(configuration_path):
+ try:
+ configuration_path = self._filesystem.join(self.build_directory(None),
+ "Configuration")
+ if not self._filesystem.exists(configuration_path):
+ return None
+ except (OSError, executive.ScriptError):
return None
- with codecs.open(configuration_path, "r", "utf-8") as fh:
- return fh.read().rstrip()
+ return self._filesystem.read_text_file(configuration_path).rstrip()