Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / Scripts / webkitpy / common / host.py
1 # Copyright (c) 2010 Google Inc. All rights reserved.
2 # Copyright (c) 2009 Apple Inc. All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 #     * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 #     * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 #     * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 import logging
31 import os
32 import sys
33
34 from webkitpy.common.checkout.scm.detection import SCMDetector
35 from webkitpy.common.memoized import memoized
36 from webkitpy.common.net import buildbot, web
37 from webkitpy.common.system.systemhost import SystemHost
38 from webkitpy.layout_tests.port.factory import PortFactory
39
40
41 _log = logging.getLogger(__name__)
42
43
44 class Host(SystemHost):
45     def __init__(self):
46         SystemHost.__init__(self)
47         self.web = web.Web()
48
49         self._scm = None
50
51         # Everything below this line is WebKit-specific and belongs on a higher-level object.
52         self.buildbot = buildbot.BuildBot()
53
54         # FIXME: Unfortunately Port objects are currently the central-dispatch objects of the NRWT world.
55         # In order to instantiate a port correctly, we have to pass it at least an executive, user, scm, and filesystem
56         # so for now we just pass along the whole Host object.
57         # FIXME: PortFactory doesn't belong on this Host object if Port is going to have a Host (circular dependency).
58         self.port_factory = PortFactory(self)
59
60         self._engage_awesome_locale_hacks()
61
62     # We call this from the Host constructor, as it's one of the
63     # earliest calls made for all webkitpy-based programs.
64     def _engage_awesome_locale_hacks(self):
65         # To make life easier on our non-english users, we override
66         # the locale environment variables inside webkitpy.
67         # If we don't do this, programs like SVN will output localized
68         # messages and svn.py will fail to parse them.
69         # FIXME: We should do these overrides *only* for the subprocesses we know need them!
70         # This hack only works in unix environments.
71         os.environ['LANGUAGE'] = 'en'
72         os.environ['LANG'] = 'en_US.UTF-8'
73         os.environ['LC_MESSAGES'] = 'en_US.UTF-8'
74         os.environ['LC_ALL'] = ''
75
76     # FIXME: This is a horrible, horrible hack for WinPort and should be removed.
77     # Maybe this belongs in SVN in some more generic "find the svn binary" codepath?
78     # Or possibly Executive should have a way to emulate shell path-lookups?
79     # FIXME: Unclear how to test this, since it currently mutates global state on SVN.
80     def _engage_awesome_windows_hacks(self):
81         try:
82             self.executive.run_command(['svn', 'help'])
83         except OSError, e:
84             try:
85                 self.executive.run_command(['svn.bat', 'help'])
86                 # The Win port uses the depot_tools package, which contains a number
87                 # of development tools, including Python and svn. Instead of using a
88                 # real svn executable, depot_tools indirects via a batch file, called
89                 # svn.bat. This batch file allows depot_tools to auto-update the real
90                 # svn executable, which is contained in a subdirectory.
91                 #
92                 # That's all fine and good, except that subprocess.popen can detect
93                 # the difference between a real svn executable and batch file when we
94                 # don't provide use shell=True. Rather than use shell=True on Windows,
95                 # We hack the svn.bat name into the SVN class.
96                 _log.debug('Engaging svn.bat Windows hack.')
97                 from webkitpy.common.checkout.scm.svn import SVN
98                 SVN.executable_name = 'svn.bat'
99             except OSError, e:
100                 _log.debug('Failed to engage svn.bat Windows hack.')
101         try:
102             self.executive.run_command(['git', 'help'])
103         except OSError, e:
104             try:
105                 self.executive.run_command(['git.bat', 'help'])
106                 # The Win port uses the depot_tools package, which contains a number
107                 # of development tools, including Python and git. Instead of using a
108                 # real git executable, depot_tools indirects via a batch file, called
109                 # git.bat. This batch file allows depot_tools to auto-update the real
110                 # git executable, which is contained in a subdirectory.
111                 #
112                 # That's all fine and good, except that subprocess.popen can detect
113                 # the difference between a real git executable and batch file when we
114                 # don't provide use shell=True. Rather than use shell=True on Windows,
115                 # We hack the git.bat name into the SVN class.
116                 _log.debug('Engaging git.bat Windows hack.')
117                 from webkitpy.common.checkout.scm.git import Git
118                 Git.executable_name = 'git.bat'
119             except OSError, e:
120                 _log.debug('Failed to engage git.bat Windows hack.')
121
122     def initialize_scm(self, patch_directories=None):
123         if sys.platform == "win32":
124             self._engage_awesome_windows_hacks()
125         detector = SCMDetector(self.filesystem, self.executive)
126         self._scm = detector.default_scm(patch_directories)
127
128     def scm(self):
129         return self._scm
130
131     def scm_for_path(self, path):
132         # FIXME: make scm() be a wrapper around this, and clean up the way
133         # callers call initialize_scm() (to remove patch_directories) and scm().
134         if sys.platform == "win32":
135             self._engage_awesome_windows_hacks()
136         return SCMDetector(self.filesystem, self.executive).detect_scm_system(path)