1# Copyright (C) 2010 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
29"""Chromium Mac implementation of the Port interface."""
30
31import logging
32import signal
33
34from webkitpy.layout_tests.port import base
35
36
37_log = logging.getLogger(__name__)
38
39
40class MacPort(base.Port):
41    SUPPORTED_VERSIONS = ('snowleopard', 'lion', 'retina', 'mountainlion', 'mavericks')
42    port_name = 'mac'
43
44    # FIXME: We treat Retina (High-DPI) devices as if they are running
45    # a different operating system version. This is lame and should be fixed.
46    # Note that the retina versions fallback to the non-retina versions and so no
47    # baselines are shared between retina versions; this keeps the fallback graph as a tree
48    # and maximizes the number of baselines we can share that way.
49    # We also currently only support Retina on 10.8; we need to either upgrade to 10.9 or support both.
50
51    FALLBACK_PATHS = {}
52    FALLBACK_PATHS['mavericks'] = ['mac']
53    FALLBACK_PATHS['mountainlion'] = ['mac-mountainlion'] + FALLBACK_PATHS['mavericks']
54    FALLBACK_PATHS['retina'] = ['mac-retina'] + FALLBACK_PATHS['mountainlion']
55    FALLBACK_PATHS['lion'] = ['mac-lion'] + FALLBACK_PATHS['mountainlion']
56    FALLBACK_PATHS['snowleopard'] = ['mac-snowleopard'] + FALLBACK_PATHS['lion']
57
58    DEFAULT_BUILD_DIRECTORIES = ('xcodebuild', 'out')
59
60    CONTENT_SHELL_NAME = 'Content Shell'
61
62    BUILD_REQUIREMENTS_URL = 'https://code.google.com/p/chromium/wiki/MacBuildInstructions'
63
64    @classmethod
65    def determine_full_port_name(cls, host, options, port_name):
66        if port_name.endswith('mac'):
67            if host.platform.os_version in ('future',):
68                version = 'mavericks'
69            else:
70                version = host.platform.os_version
71            if host.platform.is_highdpi():
72                version = 'retina'
73            return port_name + '-' + version
74        return port_name
75
76    def __init__(self, host, port_name, **kwargs):
77        super(MacPort, self).__init__(host, port_name, **kwargs)
78        self._version = port_name[port_name.index('mac-') + len('mac-'):]
79        assert self._version in self.SUPPORTED_VERSIONS
80
81    def _modules_to_search_for_symbols(self):
82        return [self._build_path('ffmpegsumo.so')]
83
84    def check_build(self, needs_http, printer):
85        result = super(MacPort, self).check_build(needs_http, printer)
86        if result:
87            _log.error('For complete Mac build requirements, please see:')
88            _log.error('')
89            _log.error('    http://code.google.com/p/chromium/wiki/MacBuildInstructions')
90
91        return result
92
93    def operating_system(self):
94        return 'mac'
95
96    #
97    # PROTECTED METHODS
98    #
99
100    def _wdiff_missing_message(self):
101        return 'wdiff is not installed; please install from MacPorts or elsewhere'
102
103    def path_to_apache(self):
104        return '/usr/sbin/httpd'
105
106    def path_to_apache_config_file(self):
107        return self._filesystem.join(self.layout_tests_dir(), 'http', 'conf', 'apache2-httpd.conf')
108
109    def _path_to_driver(self, configuration=None):
110        # FIXME: make |configuration| happy with case-sensitive file systems.
111        return self._build_path_with_configuration(configuration, self.driver_name() + '.app', 'Contents', 'MacOS', self.driver_name())
112
113    def _path_to_helper(self):
114        binary_name = 'layout_test_helper'
115        return self._build_path(binary_name)
116
117    def _path_to_wdiff(self):
118        return 'wdiff'
119