| Differences between
and this patch
- Tools/ChangeLog +60 lines
Lines 1-3 Tools/ChangeLog_sec1
1
2017-11-09  Jonathan Bedard  <jbedard@apple.com>
2
3
        webkitpy: Unify version parsing code
4
        https://bugs.webkit.org/show_bug.cgi?id=179426
5
        <rdar://problem/35415191>
6
7
        Reviewed by David Kilzer.
8
9
        webkitpy needs to parse version strings or version lists frequently. Rather than
10
        duplicate this code each time it's needed, unify it in a Version class.
11
12
        * Scripts/webkitpy/common/system/platforminfo.py:
13
        (PlatformInfo.__init__): Convert mac version string to version object and
14
        use _win_version instead of _win_version_tuple.
15
        (PlatformInfo.xcode_sdk_version): Convert SDK version string to Version object
16
        before returning it.
17
        (PlatformInfo.xcode_version): Return Version object instead of version string.
18
        (PlatformInfo._determine_mac_version): Accept Version object instead of string,
19
        eliminate parsing.
20
        (PlatformInfo._determine_win_version): Accept Version object instead of tuple.
21
        (PlatformInfo._win_version): Return Version object instead of tuple, have Version
22
        object own version string parsing.
23
        (PlatformInfo._win_version_tuple): Renamed to _win_version().
24
        (PlatformInfo._win_version_tuple_from_cmd): Deleted.
25
        * Scripts/webkitpy/common/system/platforminfo_mock.py:
26
        (MockPlatformInfo.xcode_sdk_version): Return Version object instead of string.
27
        (MockPlatformInfo.xcode_version): Dittio.
28
        * Scripts/webkitpy/common/version.py: Added.
29
        (Version): Version object.
30
        (Version.__init__): Initialize the Version object with a string, integer,
31
        tuple of integers, list of integers or another Version object.
32
        (Version.__len__): Return 5 so that the Version object can be treated as
33
        a list or tuple.
34
        (Version.__getitem__): Get item in Version object by index or string.
35
        (Version.__setitem__): Set item in Version object by index or string.
36
        (Version.__str__): Convert version to printable string, omitting trailing 0's.
37
        (Version.__cmp__): Compare two version strings, major taking precedence over
38
        minor, minor taking precedence over build.
39
        * Scripts/webkitpy/common/version_unittest.py: Added.
40
        (VersionTestCase): Test behavior of Version object.
41
        * Scripts/webkitpy/port/ios.py:
42
        (IOSPort.default_baseline_search_path): ios_version now returns a Version object.
43
        (IOSPort._is_valid_ios_version): Deleted.
44
        (IOSPort.get_option): Deleted.
45
        * Scripts/webkitpy/port/ios_device.py:
46
        (IOSDevicePort.determine_full_port_name): Use Version object instead of owning parsing.
47
        (IOSDevicePort.ios_version): Return Version object instead of string.
48
        * Scripts/webkitpy/port/ios_simulator.py:
49
        (IOSSimulatorPort.simulator_runtime): Use from_version instead of from_version_string.
50
        (IOSSimulatorPort.ios_version): Return Version object instead of string.
51
        (IOSSimulatorPort.use_multiple_simulator_apps): Use Version object instead of string.
52
        * Scripts/webkitpy/xcode/simulator.py:
53
        (Runtime.from_version): Accept Version object instead of string.
54
        (Runtime.from_version_string): Replaced by from_version.
55
        (Runtime.__repr__): When printing, a runtime's version will be a Version object instead
56
        of a tuple.
57
        (Simulator._parse_runtimes): Use Version object instead of tuple.
58
        (Simulator._parse_devices): Ditto.
59
        * Scripts/webkitpy/xcode/simulator_unittest.py: Use Version object instead of tuples.
60
1
2017-11-09  Fujii Hironori  <Hironori.Fujii@sony.com>
61
2017-11-09  Fujii Hironori  <Hironori.Fujii@sony.com>
2
62
3
        [WinCairo EWS] svn-apply: 'cp' is not recognized as an internal or external command
63
        [WinCairo EWS] svn-apply: 'cp' is not recognized as an internal or external command
- Tools/Scripts/webkitpy/common/version.py +107 lines
Line 0 Tools/Scripts/webkitpy/common/version.py_sec1
1
# Copyright (C) 2017 Apple 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
5
# are met:
6
# 1.  Redistributions of source code must retain the above copyright
7
#     notice, this list of conditions and the following disclaimer.
8
# 2.  Redistributions in binary form must reproduce the above copyright
9
#     notice, this list of conditions and the following disclaimer in the
10
#     documentation and/or other materials provided with the distribution.
11
#
12
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23
24
class Version(object):
25
26
    def __init__(self, ver='0'):
27
        self.major = 0
28
        self.minor = 0
29
        self.tiny = 0
30
        self.micro = 0
31
        self.nano = 0
32
        if isinstance(ver, int):
33
            self.major = ver
34
            return
35
        elif isinstance(ver, str) or isinstance(ver, unicode):
36
            for i in xrange(len(ver.split('.'))):
37
                self[i] = ver.split('.')[i]
38
            return
39
        elif isinstance(ver, list) or isinstance(ver, Version) or isinstance(ver, tuple):
40
            for i in xrange(len(ver)):
41
                self[i] = ver[i]
42
            return
43
        elif ver is None:
44
            return  # Empty version is implicitly zero
45
        raise ValueError('Version expected to be string, integer, tuple or list of integers')
46
47
    def __len__(self):
48
        return 5
49
50
    def __getitem__(self, key):
51
        if isinstance(key, int):
52
            if key == 0:
53
                return self.major
54
            elif key == 1:
55
                return self.minor
56
            elif key == 2:
57
                return self.tiny
58
            elif key == 3:
59
                return self.micro
60
            elif key == 4:
61
                return self.nano
62
            raise ValueError('Version key must be between 0 and 4')
63
        elif isinstance(key, str):
64
            if hasattr(self, key):
65
                return getattr(self, key)
66
            raise ValueError('Version key must be major, minor, tiny, micro or nano')
67
        raise ValueError('Expected version key to be string or integer')
68
69
    def __setitem__(self, key, value):
70
        if isinstance(key, int):
71
            if key == 0:
72
                self.major = int(value)
73
                return self.major
74
            elif key == 1:
75
                self.minor = int(value)
76
                return self.minor
77
            elif key == 2:
78
                self.tiny = int(value)
79
                return self.tiny
80
            elif key == 3:
81
                self.micro = int(value)
82
                return self.micro
83
            elif key == 4:
84
                self.nano = int(value)
85
                return self.nano
86
            raise ValueError('Version key must be between 0 and 4')
87
        elif isinstance(key, str):
88
            if hasattr(self, key):
89
                return setattr(self, key, value)
90
            raise ValueError('Version key must be major, minor, tiny, micro or nano')
91
        raise ValueError('Expected version key to be string or integer')
92
93
    def __str__(self):
94
        len_to_print = 1
95
        for i in xrange(len(self)):
96
            if self[i]:
97
                len_to_print = i + 1
98
        result = str(self.major)
99
        for i in xrange(len_to_print - 1):
100
            result += '.{}'.format(self[i + 1])
101
        return result
102
103
    def __cmp__(self, other):
104
        for i in xrange(len(self)):
105
            if cmp(self[i], other[i]):
106
                return cmp(self[i], other[i])
107
        return 0
- Tools/Scripts/webkitpy/common/version_unittest.py +132 lines
Line 0 Tools/Scripts/webkitpy/common/version_unittest.py_sec1
1
# Copyright (C) 2017 Apple 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
5
# are met:
6
# 1.  Redistributions of source code must retain the above copyright
7
#     notice, this list of conditions and the following disclaimer.
8
# 2.  Redistributions in binary form must reproduce the above copyright
9
#     notice, this list of conditions and the following disclaimer in the
10
#     documentation and/or other materials provided with the distribution.
11
#
12
# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
13
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15
# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
16
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
23
import unittest
24
25
from version import Version
26
27
28
class VersionTestCase(unittest.TestCase):
29
30
    def test_string_constructor(self):
31
        v = Version('1.2.3.4.5')
32
        self.assertEqual(v.major, 1)
33
        self.assertEqual(v.minor, 2)
34
        self.assertEqual(v.tiny, 3)
35
        self.assertEqual(v.micro, 4)
36
        self.assertEqual(v.nano, 5)
37
38
    def test_list_constructor(self):
39
        v = Version([1, 2, 3, 4, 5])
40
        self.assertEqual(v.major, 1)
41
        self.assertEqual(v.minor, 2)
42
        self.assertEqual(v.tiny, 3)
43
        self.assertEqual(v.micro, 4)
44
        self.assertEqual(v.nano, 5)
45
46
    def test_tuple_constructor(self):
47
        v = Version((1, 2, 3))
48
        self.assertEqual(v.major, 1)
49
        self.assertEqual(v.minor, 2)
50
        self.assertEqual(v.tiny, 3)
51
52
    def test_int_constructor(self):
53
        v = Version(1)
54
        self.assertEqual(v.major, 1)
55
        self.assertEqual(v.minor, 0)
56
        self.assertEqual(v.tiny, 0)
57
        self.assertEqual(v.micro, 0)
58
        self.assertEqual(v.nano, 0)
59
60
    def test_copy_constructor(self):
61
        v = Version(Version([1, 2, 3, 4, 5]))
62
        self.assertEqual(v.major, 1)
63
        self.assertEqual(v.minor, 2)
64
        self.assertEqual(v.tiny, 3)
65
        self.assertEqual(v.micro, 4)
66
        self.assertEqual(v.nano, 5)
67
68
    def test_none_constructor(self):
69
        v = Version(None)
70
        self.assertEqual(v.major, 0)
71
        self.assertEqual(v.minor, 0)
72
        self.assertEqual(v.tiny, 0)
73
        self.assertEqual(v.micro, 0)
74
        self.assertEqual(v.nano, 0)
75
76
    def test_len(self):
77
        self.assertEqual(len(Version('1.2.3.4.5')), 5)
78
        self.assertEqual(len(Version()), 5)
79
80
    def test_set_by_int(self):
81
        v = Version(None)
82
        v[0] = 1
83
        self.assertEqual(v.major, 1)
84
        v[1] = 2
85
        self.assertEqual(v.minor, 2)
86
        v[2] = 3
87
        self.assertEqual(v.tiny, 3)
88
        v[3] = 4
89
        self.assertEqual(v.micro, 4)
90
        v[4] = 5
91
        self.assertEqual(v.nano, 5)
92
93
    def test_set_by_string(self):
94
        v = Version(None)
95
        v['major'] = 1
96
        self.assertEqual(v.major, 1)
97
        v['minor'] = 2
98
        self.assertEqual(v.minor, 2)
99
        v['tiny'] = 3
100
        self.assertEqual(v.tiny, 3)
101
        v['micro'] = 4
102
        self.assertEqual(v.micro, 4)
103
        v['nano'] = 5
104
        self.assertEqual(v.nano, 5)
105
106
    def test_get_by_int(self):
107
        v = Version('1.2.3.4.5')
108
        self.assertEqual(v[0], v.major)
109
        self.assertEqual(v[1], v.minor)
110
        self.assertEqual(v[2], v.tiny)
111
        self.assertEqual(v[3], v.micro)
112
        self.assertEqual(v[4], v.nano)
113
114
    def test_get_by_string(self):
115
        v = Version('1.2.3.4.5')
116
        self.assertEqual(v['major'], v.major)
117
        self.assertEqual(v['minor'], v.minor)
118
        self.assertEqual(v['tiny'], v.tiny)
119
        self.assertEqual(v['micro'], v.micro)
120
        self.assertEqual(v['nano'], v.nano)
121
122
    def test_string(self):
123
        self.assertEqual(str(Version('1.2.3')), '1.2.3')
124
        self.assertEqual(str(Version('1.2.0')), '1.2')
125
        self.assertEqual(str(Version('1.2')), '1.2')
126
        self.assertEqual(str(Version('0.0.3')), '0.0.3')
127
128
    def test_compare_versions(self):
129
        self.assertEqual(Version('1.2.3'), Version('1.2.3'))
130
        self.assertGreater(Version('1.2.4'), Version('1.2.3'))
131
        self.assertGreater(Version('1.3.2'), Version('1.2.3'))
132
        self.assertGreater(Version('2.1.1'), Version('1.2.3'))
- Tools/Scripts/webkitpy/common/system/platforminfo.py -27 / +20 lines
Lines 1-5 Tools/Scripts/webkitpy/common/system/platforminfo.py_sec1
1
# Copyright (c) 2011 Google Inc. All rights reserved.
1
# Copyright (c) 2011 Google Inc. All rights reserved.
2
# Copyright (c) 2015 Apple Inc. All rights reserved.
2
# Copyright (c) 2015-2017 Apple Inc. All rights reserved.
3
#
3
#
4
# Redistribution and use in source and binary forms, with or without
4
# Redistribution and use in source and binary forms, with or without
5
# modification, are permitted provided that the following conditions are
5
# modification, are permitted provided that the following conditions are
Lines 30-35 Tools/Scripts/webkitpy/common/system/platforminfo.py_sec2
30
import re
30
import re
31
import sys
31
import sys
32
32
33
from webkitpy.common.version import Version
33
from webkitpy.common.system.executive import Executive
34
from webkitpy.common.system.executive import Executive
34
35
35
36
Lines 55-63 class PlatformInfo(object): Tools/Scripts/webkitpy/common/system/platforminfo.py_sec3
55
        if self.os_name == 'freebsd' or self.os_name == 'openbsd' or self.os_name == 'netbsd' or self.os_name == 'ios':
56
        if self.os_name == 'freebsd' or self.os_name == 'openbsd' or self.os_name == 'netbsd' or self.os_name == 'ios':
56
            self.os_version = platform_module.release()
57
            self.os_version = platform_module.release()
57
        if self.os_name.startswith('mac'):
58
        if self.os_name.startswith('mac'):
58
            self.os_version = self._determine_mac_version(platform_module.mac_ver()[0])
59
            self.os_version = self._determine_mac_version(Version(platform_module.mac_ver()[0]))
59
        if self.os_name.startswith('win'):
60
        if self.os_name.startswith('win'):
60
            self.os_version = self._determine_win_version(self._win_version_tuple(sys_module))
61
            self.os_version = self._determine_win_version(self._win_version(sys_module))
61
        self._is_cygwin = sys_module.platform == 'cygwin'
62
        self._is_cygwin = sys_module.platform == 'cygwin'
62
63
63
    def is_mac(self):
64
    def is_mac(self):
Lines 127-134 class PlatformInfo(object): Tools/Scripts/webkitpy/common/system/platforminfo.py_sec4
127
    def xcode_sdk_version(self, sdk_name):
128
    def xcode_sdk_version(self, sdk_name):
128
        if self.is_mac():
129
        if self.is_mac():
129
            # Assumes that xcrun does not write to standard output on failure (e.g. SDK does not exist).
130
            # Assumes that xcrun does not write to standard output on failure (e.g. SDK does not exist).
130
            return self._executive.run_command(["xcrun", "--sdk", sdk_name, "--show-sdk-version"], return_stderr=False, error_handler=Executive.ignore_error).rstrip()
131
            return Version(self._executive.run_command(["xcrun", "--sdk", sdk_name, "--show-sdk-version"], return_stderr=False, error_handler=Executive.ignore_error).rstrip())
131
        return ''
132
        return None
132
133
133
    def xcode_simctl_list(self):
134
    def xcode_simctl_list(self):
134
        if not self.is_mac():
135
        if not self.is_mac():
Lines 139-145 class PlatformInfo(object): Tools/Scripts/webkitpy/common/system/platforminfo.py_sec5
139
    def xcode_version(self):
140
    def xcode_version(self):
140
        if not self.is_mac():
141
        if not self.is_mac():
141
            raise NotImplementedError
142
            raise NotImplementedError
142
        return self._executive.run_command(['xcodebuild', '-version']).split()[1]
143
        return Version(self._executive.run_command(['xcodebuild', '-version']).split()[1])
143
144
144
    def _determine_os_name(self, sys_platform):
145
    def _determine_os_name(self, sys_platform):
145
        if sys_platform == 'darwin':
146
        if sys_platform == 'darwin':
Lines 158-165 class PlatformInfo(object): Tools/Scripts/webkitpy/common/system/platforminfo.py_sec6
158
            return 'haiku'
159
            return 'haiku'
159
        raise AssertionError('unrecognized platform string "%s"' % sys_platform)
160
        raise AssertionError('unrecognized platform string "%s"' % sys_platform)
160
161
161
    def _determine_mac_version(self, mac_version_string):
162
    def _determine_mac_version(self, mac_version):
162
        release_version = int(mac_version_string.split('.')[1])
163
        version_strings = {
163
        version_strings = {
164
            5: 'leopard',
164
            5: 'leopard',
165
            6: 'snowleopard',
165
            6: 'snowleopard',
Lines 171-204 class PlatformInfo(object): Tools/Scripts/webkitpy/common/system/platforminfo.py_sec7
171
            12: 'sierra',
171
            12: 'sierra',
172
            13: 'highsierra',
172
            13: 'highsierra',
173
        }
173
        }
174
        assert release_version >= min(version_strings.keys())
174
        assert mac_version.minor >= min(version_strings.keys())
175
        return version_strings.get(release_version, 'future')
175
        return version_strings.get(mac_version.minor, 'future')
176
176
177
    def _determine_linux_version(self):
177
    def _determine_linux_version(self):
178
        # FIXME: we ignore whatever the real version is and pretend it's lucid for now.
178
        # FIXME: we ignore whatever the real version is and pretend it's lucid for now.
179
        return 'lucid'
179
        return 'lucid'
180
180
181
    def _determine_win_version(self, win_version_tuple):
181
    def _determine_win_version(self, win_version):
182
        if win_version_tuple[:2] == (0, 0):
182
        if win_version.major == 0 and win_version.minor == 0:
183
            if win_version_tuple[2] > 10000:
183
            if win_version[2] > 10000:
184
                return 'win10'
184
                return 'win10'
185
        if win_version_tuple[:3] == (6, 1, 7600):
185
        if win_version == Version([6, 1, 7600]):
186
            return '7sp0'
186
            return '7sp0'
187
        if win_version_tuple[:2] == (6, 0):
187
        if win_version.major == 6 and win_version.minor == 0:
188
            return 'vista'
188
            return 'vista'
189
        if win_version_tuple[:2] == (5, 1):
189
        if win_version.major == 5 and win_version.minor == 1:
190
            return 'xp'
190
            return 'xp'
191
        assert win_version_tuple[0] > 6 or win_version_tuple[1] >= 1, 'Unrecognized Windows version tuple: "%s"' % (win_version_tuple,)
191
        assert win_version[0] > 6 or win_version[1] >= 1, 'Unrecognized Windows version: "{}"'.format(win_version)
192
        return 'future'
192
        return 'future'
193
193
194
    def _win_version_tuple(self, sys_module):
194
    def _win_version(self, sys_module):
195
        if hasattr(sys_module, 'getwindowsversion'):
195
        if hasattr(sys_module, 'getwindowsversion'):
196
            return sys_module.getwindowsversion()
196
            return Version(sys_module.getwindowsversion())
197
        return self._win_version_tuple_from_cmd()
197
        return Version(self._executive.run_command(['cmd', '/c', 'ver'], decode_output=False))
198
199
    def _win_version_tuple_from_cmd(self):
200
        # Note that this should only ever be called on windows, so this should always work.
201
        ver_output = self._executive.run_command(['cmd', '/c', 'ver'], decode_output=False)
202
        match_object = re.search(r'(?P<major>\d)\.(?P<minor>\d)\.(?P<build>\d+)', ver_output)
203
        assert match_object, 'cmd returned an unexpected version string: ' + ver_output
204
        return tuple(map(int, match_object.groups()))
- Tools/Scripts/webkitpy/common/system/platforminfo_mock.py -2 / +4 lines
Lines 1-4 Tools/Scripts/webkitpy/common/system/platforminfo_mock.py_sec1
1
# Copyright (C) 2011 Google Inc. All rights reserved.
1
# Copyright (C) 2011 Google Inc. All rights reserved.
2
# Copyright (c) 2017 Apple Inc. All rights reserved.
2
#
3
#
3
# Redistribution and use in source and binary forms, with or without
4
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions are
5
# modification, are permitted provided that the following conditions are
Lines 26-31 Tools/Scripts/webkitpy/common/system/platforminfo_mock.py_sec2
26
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
# (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
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
30
from webkitpy.common.version import Version
29
31
30
class MockPlatformInfo(object):
32
class MockPlatformInfo(object):
31
    def __init__(self, os_name='mac', os_version='snowleopard'):
33
    def __init__(self, os_name='mac', os_version='snowleopard'):
Lines 61-70 class MockPlatformInfo(object): Tools/Scripts/webkitpy/common/system/platforminfo_mock.py_sec3
61
        return 80
63
        return 80
62
64
63
    def xcode_sdk_version(self, sdk_name):
65
    def xcode_sdk_version(self, sdk_name):
64
        return '8.1'
66
        return Version('8.1')
65
67
66
    def xcode_version(self):
68
    def xcode_version(self):
67
        return '8.0'
69
        return Version('8.0')
68
70
69
    def xcode_simctl_list(self):
71
    def xcode_simctl_list(self):
70
        return self.expected_xcode_simctl_list
72
        return self.expected_xcode_simctl_list
- Tools/Scripts/webkitpy/port/ios.py -19 / +4 lines
Lines 24-29 import logging Tools/Scripts/webkitpy/port/ios.py_sec1
24
import traceback
24
import traceback
25
25
26
from webkitpy.common.memoized import memoized
26
from webkitpy.common.memoized import memoized
27
from webkitpy.common.version import Version
27
from webkitpy.layout_tests.models.test_configuration import TestConfiguration
28
from webkitpy.layout_tests.models.test_configuration import TestConfiguration
28
from webkitpy.port.config import apple_additions
29
from webkitpy.port.config import apple_additions
29
from webkitpy.port.darwin import DarwinPort
30
from webkitpy.port.darwin import DarwinPort
Lines 109-119 class IOSPort(DarwinPort): Tools/Scripts/webkitpy/port/ios.py_sec2
109
        if self.get_option('webkit_test_runner'):
110
        if self.get_option('webkit_test_runner'):
110
            wk_string = 'wk2'
111
            wk_string = 'wk2'
111
        fallback_names = [
112
        fallback_names = [
112
            '{}-{}-{}'.format(self.port_name, self.ios_version().split('.')[0], wk_string),
113
            '{}-{}-{}'.format(self.port_name, self.ios_version().major, wk_string),
113
            '{}-{}'.format(self.port_name, self.ios_version().split('.')[0]),
114
            '{}-{}'.format(self.port_name, self.ios_version().major),
114
            '{}-{}'.format(self.port_name, wk_string),
115
            '{}-{}'.format(self.port_name, wk_string),
115
            self.port_name,
116
            self.port_name,
116
            '{}-{}'.format(IOSPort.port_name, self.ios_version().split('.')[0]),
117
            '{}-{}'.format(IOSPort.port_name, self.ios_version().major),
117
            '{}-{}'.format(IOSPort.port_name, wk_string),
118
            '{}-{}'.format(IOSPort.port_name, wk_string),
118
            IOSPort.port_name,
119
            IOSPort.port_name,
119
        ]
120
        ]
Lines 134-155 class IOSPort(DarwinPort): Tools/Scripts/webkitpy/port/ios.py_sec3
134
    def test_expectations_file_position(self):
135
    def test_expectations_file_position(self):
135
        return 4
136
        return 4
136
137
137
    @staticmethod
138
    def _is_valid_ios_version(version_identifier):
139
        # Examples of valid versions: '11', '10.3', '10.3.1'
140
        if not version_identifier:
141
            return False
142
        split_by_period = version_identifier.split('.')
143
        if len(split_by_period) > 3:
144
            return False
145
        return all(part.isdigit() for part in split_by_period)
146
147
    def get_option(self, name, default_value=None):
148
        result = super(IOSPort, self).get_option(name, default_value)
149
        if name == 'version' and result and not IOSPort._is_valid_ios_version(result):
150
            raise RuntimeError('{} is an invalid iOS version'.format(result))
151
        return result
152
153
    def ios_version(self):
138
    def ios_version(self):
154
        raise NotImplementedError
139
        raise NotImplementedError
155
140
- Tools/Scripts/webkitpy/port/ios_device.py -4 / +4 lines
Lines 24-29 import logging Tools/Scripts/webkitpy/port/ios_device.py_sec1
24
24
25
from webkitpy.common.memoized import memoized
25
from webkitpy.common.memoized import memoized
26
from webkitpy.common.system.crashlogs import CrashLogs
26
from webkitpy.common.system.crashlogs import CrashLogs
27
from webkitpy.common.version import Version
27
from webkitpy.port.config import apple_additions
28
from webkitpy.port.config import apple_additions
28
from webkitpy.port.ios import IOSPort
29
from webkitpy.port.ios import IOSPort
29
30
Lines 64-71 class IOSDevicePort(IOSPort): Tools/Scripts/webkitpy/port/ios_device.py_sec2
64
            iphoneos_sdk_version = host.platform.xcode_sdk_version(cls.SDK)
65
            iphoneos_sdk_version = host.platform.xcode_sdk_version(cls.SDK)
65
            if not iphoneos_sdk_version:
66
            if not iphoneos_sdk_version:
66
                raise Exception("Please install the iOS SDK.")
67
                raise Exception("Please install the iOS SDK.")
67
            major_version_number = iphoneos_sdk_version.split('.')[0]
68
            port_name = port_name + '-' + str(iphoneos_sdk_version.major)
68
            port_name = port_name + '-' + major_version_number
69
        return port_name
69
        return port_name
70
70
71
    def path_to_crash_logs(self):
71
    def path_to_crash_logs(self):
Lines 94-100 class IOSDevicePort(IOSPort): Tools/Scripts/webkitpy/port/ios_device.py_sec3
94
    @memoized
94
    @memoized
95
    def ios_version(self):
95
    def ios_version(self):
96
        if self.get_option('version'):
96
        if self.get_option('version'):
97
            return self.get_option('version')
97
            return Version(self.get_option('version'))
98
98
99
        if not apple_additions():
99
        if not apple_additions():
100
            raise RuntimeError(self.NO_ON_DEVICE_TESTING)
100
            raise RuntimeError(self.NO_ON_DEVICE_TESTING)
Lines 109-115 class IOSDevicePort(IOSPort): Tools/Scripts/webkitpy/port/ios_device.py_sec4
109
                if device.platform.os_version != version:
109
                if device.platform.os_version != version:
110
                    raise RuntimeError('Multiple connected devices have different iOS versions')
110
                    raise RuntimeError('Multiple connected devices have different iOS versions')
111
111
112
        return version
112
        return Version(version)
113
113
114
    # FIXME: These need device implementations <rdar://problem/30497991>.
114
    # FIXME: These need device implementations <rdar://problem/30497991>.
115
    def check_for_leaks(self, process_name, process_pid):
115
    def check_for_leaks(self, process_name, process_pid):
- Tools/Scripts/webkitpy/port/ios_simulator.py -4 / +5 lines
Lines 30-35 import time Tools/Scripts/webkitpy/port/ios_simulator.py_sec1
30
30
31
from webkitpy.common.memoized import memoized
31
from webkitpy.common.memoized import memoized
32
from webkitpy.common.system.executive import ScriptError
32
from webkitpy.common.system.executive import ScriptError
33
from webkitpy.common.version import Version
33
from webkitpy.port.device import Device
34
from webkitpy.port.device import Device
34
from webkitpy.port.ios import IOSPort
35
from webkitpy.port.ios import IOSPort
35
from webkitpy.xcode.simulator import Simulator, Runtime, DeviceType
36
from webkitpy.xcode.simulator import Simulator, Runtime, DeviceType
Lines 102-117 class IOSSimulatorPort(IOSPort): Tools/Scripts/webkitpy/port/ios_simulator.py_sec2
102
        if runtime_identifier:
103
        if runtime_identifier:
103
            runtime = Runtime.from_identifier(runtime_identifier)
104
            runtime = Runtime.from_identifier(runtime_identifier)
104
        elif self.get_option('version'):
105
        elif self.get_option('version'):
105
            runtime = Runtime.from_version_string(self.get_option('version'))
106
            runtime = Runtime.from_version(Version(self.get_option('version')))
106
        else:
107
        else:
107
            runtime = Runtime.from_version_string(self.host.platform.xcode_sdk_version('iphonesimulator'))
108
            runtime = Runtime.from_version(self.host.platform.xcode_sdk_version('iphonesimulator'))
108
        return runtime
109
        return runtime
109
110
110
    @memoized
111
    @memoized
111
    def ios_version(self):
112
    def ios_version(self):
112
        runtime_identifier = self.get_option('runtime')
113
        runtime_identifier = self.get_option('runtime')
113
        if self.get_option('version'):
114
        if self.get_option('version'):
114
            return self.get_option('version')
115
            return Version(self.get_option('version'))
115
        if runtime_identifier:
116
        if runtime_identifier:
116
            return '.'.join(str(i) for i in Runtime.from_identifier(runtime_identifier).version)
117
            return '.'.join(str(i) for i in Runtime.from_identifier(runtime_identifier).version)
117
        return self.host.platform.xcode_sdk_version('iphonesimulator')
118
        return self.host.platform.xcode_sdk_version('iphonesimulator')
Lines 187-193 class IOSSimulatorPort(IOSPort): Tools/Scripts/webkitpy/port/ios_simulator.py_sec3
187
                _log.warning('Unable to remove Simulator' + str(i))
188
                _log.warning('Unable to remove Simulator' + str(i))
188
189
189
    def use_multiple_simulator_apps(self):
190
    def use_multiple_simulator_apps(self):
190
        return int(self.host.platform.xcode_version().split('.')[0]) < 9
191
        return int(self.host.platform.xcode_version().major) < 9
191
192
192
    def _create_simulators(self):
193
    def _create_simulators(self):
193
        if (self.default_child_processes() < self.child_processes()):
194
        if (self.default_child_processes() < self.child_processes()):
- Tools/Scripts/webkitpy/xcode/simulator.py -7 / +6 lines
Lines 30-35 import time Tools/Scripts/webkitpy/xcode/simulator.py_sec1
30
30
31
from webkitpy.common.timeout_context import Timeout
31
from webkitpy.common.timeout_context import Timeout
32
from webkitpy.common.host import Host
32
from webkitpy.common.host import Host
33
from webkitpy.common.version import Version
33
34
34
_log = logging.getLogger(__name__)
35
_log = logging.getLogger(__name__)
35
36
Lines 129-136 class Runtime(object): Tools/Scripts/webkitpy/xcode/simulator.py_sec2
129
        self.is_internal_runtime = is_internal_runtime
130
        self.is_internal_runtime = is_internal_runtime
130
131
131
    @classmethod
132
    @classmethod
132
    def from_version_string(cls, version):
133
    def from_version(cls, version):
133
        return cls.from_identifier('com.apple.CoreSimulator.SimRuntime.iOS-' + version.replace('.', '-'))
134
        return cls.from_identifier('com.apple.CoreSimulator.SimRuntime.iOS-' + '{}-{}'.format(version[0], version[1]))
134
135
135
    @classmethod
136
    @classmethod
136
    def from_identifier(cls, identifier):
137
    def from_identifier(cls, identifier):
Lines 156-162 class Runtime(object): Tools/Scripts/webkitpy/xcode/simulator.py_sec3
156
        if self.is_internal_runtime:
157
        if self.is_internal_runtime:
157
            version_suffix = " Internal"
158
            version_suffix = " Internal"
158
        return '<Runtime {version}: {identifier}. Available: {available}, {num_devices} devices>'.format(
159
        return '<Runtime {version}: {identifier}. Available: {available}, {num_devices} devices>'.format(
159
            version='.'.join(map(str, self.version)) + version_suffix,
160
            version=str(self.version) + version_suffix,
160
            identifier=self.identifier,
161
            identifier=self.identifier,
161
            available=self.available,
162
            available=self.available,
162
            num_devices=len(self.devices))
163
            num_devices=len(self.devices))
Lines 334-341 class Simulator(object): Tools/Scripts/webkitpy/xcode/simulator.py_sec4
334
                if line != '== Devices ==':
335
                if line != '== Devices ==':
335
                    raise RuntimeError('Expected == Devices == header but got: "{}"'.format(line))
336
                    raise RuntimeError('Expected == Devices == header but got: "{}"'.format(line))
336
                break
337
                break
337
            version = tuple(map(int, runtime_match.group('version').split('.')))
338
            runtime = Runtime(version=Version(runtime_match.group('version')),
338
            runtime = Runtime(version=version,
339
                              identifier=runtime_match.group('identifier'),
339
                              identifier=runtime_match.group('identifier'),
340
                              available=runtime_match.group('availability') is None,
340
                              available=runtime_match.group('availability') is None,
341
                              is_internal_runtime=bool(runtime_match.group('internal')))
341
                              is_internal_runtime=bool(runtime_match.group('internal')))
Lines 353-360 class Simulator(object): Tools/Scripts/webkitpy/xcode/simulator.py_sec5
353
        for line in lines:
353
        for line in lines:
354
            version_match = self.version_re.match(line)
354
            version_match = self.version_re.match(line)
355
            if version_match:
355
            if version_match:
356
                version = tuple(map(int, version_match.group('version').split('.')))
356
                current_runtime = self.runtime(version=Version(version_match.group('version')), is_internal_runtime=bool(version_match.group('internal')))
357
                current_runtime = self.runtime(version=version, is_internal_runtime=bool(version_match.group('internal')))
358
                assert current_runtime
357
                assert current_runtime
359
                continue
358
                continue
360
359
- Tools/Scripts/webkitpy/xcode/simulator_unittest.py -10 / +11 lines
Lines 1-4 Tools/Scripts/webkitpy/xcode/simulator_unittest.py_sec1
1
# Copyright (C) 2015 Apple Inc. All rights reserved.
1
# Copyright (C) 2015-2017 Apple Inc. All rights reserved.
2
#
2
#
3
# Redistribution and use in source and binary forms, with or without
3
# Redistribution and use in source and binary forms, with or without
4
# modification, are permitted provided that the following conditions
4
# modification, are permitted provided that the following conditions
Lines 23-28 Tools/Scripts/webkitpy/xcode/simulator_unittest.py_sec2
23
import unittest
23
import unittest
24
24
25
from webkitpy.common.host_mock import MockHost
25
from webkitpy.common.host_mock import MockHost
26
from webkitpy.common.version import Version
26
from webkitpy.xcode.simulator import Simulator
27
from webkitpy.xcode.simulator import Simulator
27
28
28
29
Lines 134-140 Apple TV 1080p (55281ABE-9C27-438B-AD50- Tools/Scripts/webkitpy/xcode/simulator_unittest.py_sec3
134
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
135
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
135
        self.assertEqual(True, runtime_ios_8.available)
136
        self.assertEqual(True, runtime_ios_8.available)
136
        self.assertEqual(False, runtime_ios_8.is_internal_runtime)
137
        self.assertEqual(False, runtime_ios_8.is_internal_runtime)
137
        self.assertEqual(tuple([8, 0]), runtime_ios_8.version)
138
        self.assertEqual(Version([8, 0]), runtime_ios_8.version)
138
        self.assertEqual(11, len(runtime_ios_8.devices))
139
        self.assertEqual(11, len(runtime_ios_8.devices))
139
140
140
        device_iphone_4s = runtime_ios_8.devices[0]
141
        device_iphone_4s = runtime_ios_8.devices[0]
Lines 207-227 Apple TV 1080p (55281ABE-9C27-438B-AD50- Tools/Scripts/webkitpy/xcode/simulator_unittest.py_sec4
207
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier)
208
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier)
208
        self.assertEqual(False, runtime_ios_8_internal.available)
209
        self.assertEqual(False, runtime_ios_8_internal.available)
209
        self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime)
210
        self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime)
210
        self.assertEqual(tuple([8, 0]), runtime_ios_8_internal.version)
211
        self.assertEqual(Version([8, 0]), runtime_ios_8_internal.version)
211
        self.assertEqual(0, len(runtime_ios_8_internal.devices))
212
        self.assertEqual(0, len(runtime_ios_8_internal.devices))
212
213
213
        runtime_ios_8_4 = simulator.runtimes[2]
214
        runtime_ios_8_4 = simulator.runtimes[2]
214
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-4', runtime_ios_8_4.identifier)
215
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-4', runtime_ios_8_4.identifier)
215
        self.assertEqual(True, runtime_ios_8_4.available)
216
        self.assertEqual(True, runtime_ios_8_4.available)
216
        self.assertEqual(False, runtime_ios_8_4.is_internal_runtime)
217
        self.assertEqual(False, runtime_ios_8_4.is_internal_runtime)
217
        self.assertEqual(tuple([8, 4]), runtime_ios_8_4.version)
218
        self.assertEqual(Version([8, 4]), runtime_ios_8_4.version)
218
        self.assertEqual(0, len(runtime_ios_8_4.devices))
219
        self.assertEqual(0, len(runtime_ios_8_4.devices))
219
220
220
        runtime_tvos_9 = simulator.runtimes[3]
221
        runtime_tvos_9 = simulator.runtimes[3]
221
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.tvOS-9-0', runtime_tvos_9.identifier)
222
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.tvOS-9-0', runtime_tvos_9.identifier)
222
        self.assertEqual(True, runtime_tvos_9.available)
223
        self.assertEqual(True, runtime_tvos_9.available)
223
        self.assertEqual(False, runtime_tvos_9.is_internal_runtime)
224
        self.assertEqual(False, runtime_tvos_9.is_internal_runtime)
224
        self.assertEqual(tuple([9, 0]), runtime_tvos_9.version)
225
        self.assertEqual(Version([9, 0]), runtime_tvos_9.version)
225
        self.assertEqual(1, len(runtime_tvos_9.devices))
226
        self.assertEqual(1, len(runtime_tvos_9.devices))
226
227
227
        device_apple_tv_1080p = runtime_tvos_9.devices[0]
228
        device_apple_tv_1080p = runtime_tvos_9.devices[0]
Lines 234-247 Apple TV 1080p (55281ABE-9C27-438B-AD50- Tools/Scripts/webkitpy/xcode/simulator_unittest.py_sec5
234
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.watchOS-2-0', runtime_watchos_2.identifier)
235
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.watchOS-2-0', runtime_watchos_2.identifier)
235
        self.assertEqual(True, runtime_watchos_2.available)
236
        self.assertEqual(True, runtime_watchos_2.available)
236
        self.assertEqual(False, runtime_watchos_2.is_internal_runtime)
237
        self.assertEqual(False, runtime_watchos_2.is_internal_runtime)
237
        self.assertEqual(tuple([2, 0]), runtime_watchos_2.version)
238
        self.assertEqual(Version([2, 0]), runtime_watchos_2.version)
238
        self.assertEqual(2, len(runtime_watchos_2.devices))
239
        self.assertEqual(2, len(runtime_watchos_2.devices))
239
240
240
        runtime_ios_10 = simulator.runtimes[5]
241
        runtime_ios_10 = simulator.runtimes[5]
241
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-10-0', runtime_ios_10.identifier)
242
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-10-0', runtime_ios_10.identifier)
242
        self.assertEqual(True, runtime_ios_10.available)
243
        self.assertEqual(True, runtime_ios_10.available)
243
        self.assertEqual(False, runtime_ios_10.is_internal_runtime)
244
        self.assertEqual(False, runtime_ios_10.is_internal_runtime)
244
        self.assertEqual(tuple([10, 0]), runtime_ios_10.version)
245
        self.assertEqual(Version([10, 0]), runtime_ios_10.version)
245
        self.assertEqual(0, len(runtime_ios_10.devices))
246
        self.assertEqual(0, len(runtime_ios_10.devices))
246
247
247
        device_apple_watch_38mm = runtime_watchos_2.devices[0]
248
        device_apple_watch_38mm = runtime_watchos_2.devices[0]
Lines 315-321 iOS 8.0 Internal (8.0 - Unknown) (com.ap Tools/Scripts/webkitpy/xcode/simulator_unittest.py_sec6
315
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
316
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
316
        self.assertEqual(True, runtime_ios_8.available)
317
        self.assertEqual(True, runtime_ios_8.available)
317
        self.assertEqual(False, runtime_ios_8.is_internal_runtime)
318
        self.assertEqual(False, runtime_ios_8.is_internal_runtime)
318
        self.assertEqual(tuple([8, 0]), runtime_ios_8.version)
319
        self.assertEqual(Version([8, 0]), runtime_ios_8.version)
319
        self.assertEqual(1, len(runtime_ios_8.devices))
320
        self.assertEqual(1, len(runtime_ios_8.devices))
320
321
321
        device_iphone_4s = runtime_ios_8.devices[0]
322
        device_iphone_4s = runtime_ios_8.devices[0]
Lines 328-334 iOS 8.0 Internal (8.0 - Unknown) (com.ap Tools/Scripts/webkitpy/xcode/simulator_unittest.py_sec7
328
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier)
329
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0-Internal', runtime_ios_8_internal.identifier)
329
        self.assertEqual(False, runtime_ios_8_internal.available)
330
        self.assertEqual(False, runtime_ios_8_internal.available)
330
        self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime)
331
        self.assertEqual(True, runtime_ios_8_internal.is_internal_runtime)
331
        self.assertEqual(tuple([8, 0]), runtime_ios_8_internal.version)
332
        self.assertEqual(Version([8, 0]), runtime_ios_8_internal.version)
332
        self.assertEqual(0, len(runtime_ios_8_internal.devices))
333
        self.assertEqual(0, len(runtime_ios_8_internal.devices))
333
334
334
    def test_device_pairs(self):
335
    def test_device_pairs(self):
Lines 356-362 iOS 8.0 Internal (8.0 - Unknown) (com.ap Tools/Scripts/webkitpy/xcode/simulator_unittest.py_sec8
356
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
357
        self.assertEqual('com.apple.CoreSimulator.SimRuntime.iOS-8-0', runtime_ios_8.identifier)
357
        self.assertEqual(True, runtime_ios_8.available)
358
        self.assertEqual(True, runtime_ios_8.available)
358
        self.assertEqual(False, runtime_ios_8.is_internal_runtime)
359
        self.assertEqual(False, runtime_ios_8.is_internal_runtime)
359
        self.assertEqual(tuple([8, 0]), runtime_ios_8.version)
360
        self.assertEqual(Version([8, 0]), runtime_ios_8.version)
360
        self.assertEqual(1, len(runtime_ios_8.devices))
361
        self.assertEqual(1, len(runtime_ios_8.devices))
361
362
362
        device_iphone_4s = runtime_ios_8.devices[0]
363
        device_iphone_4s = runtime_ios_8.devices[0]

Return to Bug 179426