webkit_finder.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (c) 2012 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. class WebKitFinder(object):
  29. def __init__(self, filesystem):
  30. self._filesystem = filesystem
  31. self._webkit_base = None
  32. def webkit_base(self):
  33. """Returns the absolute path to the top of the WebKit tree.
  34. Raises an AssertionError if the top dir can't be determined."""
  35. # Note: This code somewhat duplicates the code in
  36. # scm.find_checkout_root(). However, that code only works if the top
  37. # of the SCM repository also matches the top of the WebKit tree. Some SVN users
  38. # (the chromium test bots, for example), might only check out subdirectories like
  39. # Tools/Scripts. This code will also work if there is no SCM system at all.
  40. if not self._webkit_base:
  41. self._webkit_base = self._webkit_base
  42. module_path = self._filesystem.path_to_module(self.__module__)
  43. tools_index = module_path.rfind('Tools')
  44. assert tools_index != -1, "could not find location of this checkout from %s" % module_path
  45. self._webkit_base = self._filesystem.normpath(module_path[0:tools_index - 1])
  46. return self._webkit_base
  47. def path_from_webkit_base(self, *comps):
  48. return self._filesystem.join(self.webkit_base(), *comps)
  49. def path_to_script(self, script_name):
  50. """Returns the relative path to the script from the top of the WebKit tree."""
  51. # This is intentionally relative in order to force callers to consider what
  52. # their current working directory is (and change to the top of the tree if necessary).
  53. return self._filesystem.join("Tools", "Scripts", script_name)
  54. def layout_tests_dir(self):
  55. return self.path_from_webkit_base('LayoutTests')
  56. def perf_tests_dir(self):
  57. return self.path_from_webkit_base('PerformanceTests')