[webkitpy] Automatically detect hw architecture for supporting Apple Silicon
authorjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Jun 2020 22:09:59 +0000 (22:09 +0000)
committerjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Jun 2020 22:09:59 +0000 (22:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=213653
<rdar://problem/64817656>

Rubber-stamped by Aakash Jain.

* Scripts/webkitpy/common/config/ews.json: iOS has the correct defaults, no need to override them.
* Scripts/webkitpy/common/system/platforminfo.py:
(PlatformInfo):
(PlatformInfo.architecture): Retrieve the current system's architecture.
* Scripts/webkitpy/common/system/platforminfo_mock.py:
(MockPlatformInfo.__init__):
(MockPlatformInfo.architecture):
* Scripts/webkitpy/port/base.py:
(Port.__init__): Remove 'did_override_architecture', should be implied by architecture compared with DEFAULT_ARCHITECTURE.
(Port.architecture): Return the architecture specified by the user, if it exists.
(Port.set_architecture): Remove 'did_override_architecture'.
* Scripts/webkitpy/port/factory.py:
(configuration_options): Add --arm and --architecture flags.
* Scripts/webkitpy/port/mac.py:
(MacPort): Add arm64 to supported architectures.
(MacPort.architecture): Convert arm64e to arm64, check the host's architecture.
(MacPort._build_driver_flags): Always specify the build architecture since it may be x86_64 or arm64.
* Scripts/webkitpy/port/mac_unittest.py:
(MacTest.test_64bit):
(MacTest):
(MacTest.test_arm):
(MacTest.test_default):
* Scripts/webkitpy/tool/commands/earlywarningsystem.py:
(AbstractEarlyWarningSystem.run_command): Remove did_override_architecture.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263592 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/config/ews.json
Tools/Scripts/webkitpy/common/system/platforminfo.py
Tools/Scripts/webkitpy/common/system/platforminfo_mock.py
Tools/Scripts/webkitpy/port/base.py
Tools/Scripts/webkitpy/port/factory.py
Tools/Scripts/webkitpy/port/mac.py
Tools/Scripts/webkitpy/port/mac_unittest.py
Tools/Scripts/webkitpy/tool/commands/earlywarningsystem.py

index 00d514c..12a86bf 100644 (file)
@@ -1,5 +1,38 @@
 2020-06-26  Jonathan Bedard  <jbedard@apple.com>
 
+        [webkitpy] Automatically detect hw architecture for supporting Apple Silicon
+        https://bugs.webkit.org/show_bug.cgi?id=213653
+        <rdar://problem/64817656>
+
+        Rubber-stamped by Aakash Jain.
+
+        * Scripts/webkitpy/common/config/ews.json: iOS has the correct defaults, no need to override them.
+        * Scripts/webkitpy/common/system/platforminfo.py:
+        (PlatformInfo):
+        (PlatformInfo.architecture): Retrieve the current system's architecture.
+        * Scripts/webkitpy/common/system/platforminfo_mock.py:
+        (MockPlatformInfo.__init__):
+        (MockPlatformInfo.architecture):
+        * Scripts/webkitpy/port/base.py:
+        (Port.__init__): Remove 'did_override_architecture', should be implied by architecture compared with DEFAULT_ARCHITECTURE.
+        (Port.architecture): Return the architecture specified by the user, if it exists.
+        (Port.set_architecture): Remove 'did_override_architecture'.
+        * Scripts/webkitpy/port/factory.py:
+        (configuration_options): Add --arm and --architecture flags.
+        * Scripts/webkitpy/port/mac.py:
+        (MacPort): Add arm64 to supported architectures.
+        (MacPort.architecture): Convert arm64e to arm64, check the host's architecture.
+        (MacPort._build_driver_flags): Always specify the build architecture since it may be x86_64 or arm64.
+        * Scripts/webkitpy/port/mac_unittest.py:
+        (MacTest.test_64bit):
+        (MacTest):
+        (MacTest.test_arm):
+        (MacTest.test_default):
+        * Scripts/webkitpy/tool/commands/earlywarningsystem.py:
+        (AbstractEarlyWarningSystem.run_command): Remove did_override_architecture.
+
+2020-06-26  Jonathan Bedard  <jbedard@apple.com>
+
         [Big Sur] Handle baseline search path (Follow-up fix)
         https://bugs.webkit.org/show_bug.cgi?id=213639
         <rdar://problem/64789480>
index cab648b..b070217 100644 (file)
@@ -14,8 +14,7 @@
     },
     "iOS EWS": {
         "port": "ios-device",
-        "name": "ios-ews",
-        "architecture": "arm64"
+        "name": "ios-ews"
     },
     "iOS Simulator EWS": {
         "port": "ios-simulator-wk2",
index ce5f761..104a645 100644 (file)
@@ -27,6 +27,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import os
 import logging
 import re
 import sys
@@ -34,7 +35,7 @@ import sys
 from webkitpy.common.memoized import memoized
 from webkitpy.common.version import Version
 from webkitpy.common.version_name_map import PUBLIC_TABLE, INTERNAL_TABLE, VersionNameMap
-from webkitpy.common.system.executive import Executive
+from webkitpy.common.system.executive import Executive, ScriptError
 
 
 _log = logging.getLogger(__name__)
@@ -105,6 +106,19 @@ class PlatformInfo(object):
     def is_netbsd(self):
         return self.os_name == 'netbsd'
 
+    @memoized
+    def architecture(self):
+        try:
+            # os.uname() won't work on embedded devices, we may support multiple architectures for a single embedded platform
+            output = self._executive.run_command(['uname', '-m']).rstrip()
+            if output:
+                if self.is_mac() and output != 'x86_64':
+                    output = 'arm64'
+                return output
+        except ScriptError:
+            pass
+        return os.uname()[4]
+
     def display_name(self):
         # platform.platform() returns Darwin information for Mac, which is just confusing.
         if self.is_mac():
index 0b1495e..161cc4c 100644 (file)
@@ -32,11 +32,15 @@ from webkitpy.common.version_name_map import PUBLIC_TABLE, INTERNAL_TABLE, Versi
 
 
 class MockPlatformInfo(object):
-    def __init__(self, os_name='mac', os_version=Version.from_name('High Sierra')):
+    def __init__(self, os_name='mac', os_version=Version.from_name('High Sierra'), architecture=None):
         assert isinstance(os_version, Version)
         self.os_name = os_name
         self.os_version = os_version
         self.expected_xcode_simctl_list = None
+        self._architecture = architecture or dict(
+            mac='x86_64',
+            ios='arm64',
+        ).get(self.os_name, 'x86')
 
     def is_mac(self):
         return self.os_name == 'mac'
@@ -59,6 +63,9 @@ class MockPlatformInfo(object):
     def is_freebsd(self):
         return self.os_name == 'freebsd'
 
+    def architecture(self):
+        return self._architecture
+
     def display_name(self):
         return "MockPlatform 1.0"
 
index 109bbe7..276ca5f 100644 (file)
@@ -102,19 +102,11 @@ class Port(object):
         # These are default values that should be overridden in a subclasses.
         self._os_version = None
 
-        # FIXME: This can be removed once default architectures for GTK and EFL EWS bots are set.
-        self.did_override_architecture = False
-
         # FIXME: Ideally we'd have a package-wide way to get a
         # well-formed options object that had all of the necessary
         # options defined on it.
         self._options = options or optparse.Values()
 
-        if self.get_option('architecture'):
-            self.did_override_architecture = True
-        else:
-            self.set_option('architecture', self.DEFAULT_ARCHITECTURE)
-
         if self._name and '-wk2' in self._name:
             self._options.webkit_test_runner = True
 
@@ -149,10 +141,9 @@ class Port(object):
         return self.host
 
     def architecture(self):
-        return self.get_option('architecture')
+        return self.get_option('architecture') or self.DEFAULT_ARCHITECTURE
 
     def set_architecture(self, arch):
-        self.did_override_architecture = True
         self.set_option('architecture', arch)
 
     def additional_drt_flag(self):
index 50284c1..c743003 100644 (file)
@@ -84,8 +84,12 @@ def configuration_options():
         optparse.make_option('--64-bit', action='store_const', const='x86_64', default=None, dest="architecture",
             help='use 64-bit binaries by default (x86_64 instead of x86)'),
         optparse.make_option('--32-bit', action='store_const', const='x86', default=None, dest="architecture",
-            help='use 32-bit binaries by default (x86 instead of x86_64)'),
-        ]
+             help='use 32-bit binaries by default (x86 instead of x86_64)'),
+        optparse.make_option('--arm', action='store_const', const='arm64e', default=None, dest="architecture",
+             help='Use arm64e binaries by default'),
+        optparse.make_option('--architecture', action='store_const', const='x86', default=None, dest="architecture",
+             help='Use binaries of the specified architecture by default.'),
+    ]
 
 
 def _builder_options(builder_name):
index caa48d4..586128f 100644 (file)
@@ -50,7 +50,7 @@ class MacPort(DarwinPort):
 
     SDK = 'macosx'
 
-    ARCHITECTURES = ['x86_64', 'x86']
+    ARCHITECTURES = ['x86_64', 'x86', 'arm64']
 
     DEFAULT_ARCHITECTURE = 'x86_64'
 
@@ -66,8 +66,14 @@ class MacPort(DarwinPort):
         if not self._os_version:
             self._os_version = MacPort.CURRENT_VERSION
 
+    def architecture(self):
+        result = self.get_option('architecture') or self.host.platform.architecture()
+        if result == 'arm64e':
+            return 'arm64'
+        return result
+
     def _build_driver_flags(self):
-        return ['ARCHS=i386'] if self.architecture() == 'x86' else []
+        return ['ARCHS=i386'] if self.architecture() == 'x86' else ['ARCHS={}'.format(self.architecture())]
 
     def default_baseline_search_path(self, **kwargs):
         versions_to_fallback = []
index 930cc49..d879387 100644 (file)
@@ -125,8 +125,7 @@ class MacTest(darwin_testcase.DarwinTest):
         self.assertEqual(self.args, ['ARCHS=i386'])
 
     def test_64bit(self):
-        # Apple Mac port is 64-bit by default
-        port = self.make_port()
+        port = self.make_port(options=MockOptions(architecture='x86_64'))
         self.assertEqual(port.architecture(), 'x86_64')
 
         def run_script(script, args=None, env=None):
@@ -134,7 +133,29 @@ class MacTest(darwin_testcase.DarwinTest):
 
         port._run_script = run_script
         port._build_driver()
-        self.assertEqual(self.args, [])
+        self.assertEqual(self.args, ['ARCHS=x86_64'])
+
+    def test_arm(self):
+        port = self.make_port(options=MockOptions(architecture='arm64e'))
+        self.assertEqual(port.architecture(), 'arm64')
+
+        def run_script(script, args=None, env=None):
+            self.args = args
+
+        port._run_script = run_script
+        port._build_driver()
+        self.assertEqual(self.args, ['ARCHS=arm64'])
+
+    def test_default(self):
+        port = self.make_port()
+        self.assertEqual(port.architecture(), port.host.platform.architecture())
+
+        def run_script(script, args=None, env=None):
+            self.args = args
+
+        port._run_script = run_script
+        port._build_driver()
+        self.assertEqual(self.args, ['ARCHS={}'.format(port.host.platform.architecture())])
 
     def test_sdk_name(self):
         port = self.make_port()
index 8490d2a..b8dff2a 100644 (file)
@@ -117,7 +117,7 @@ class AbstractEarlyWarningSystem(AbstractReviewQueue, EarlyWarningSystemTaskDele
         return self.name
 
     def run_command(self, command):
-        self.run_webkit_patch(command + [self._deprecated_port.flag()] + (['--architecture=%s' % self._port.architecture()] if self._port.architecture() and self._port.did_override_architecture else []))
+        self.run_webkit_patch(command + [self._deprecated_port.flag()] + (['--architecture=%s' % self._port.architecture()] if self._port.architecture() != self._port.DEFAULT_ARCHITECTURE else []))
 
     def test_results(self):
         return self._test_results_reader.results()