Commit 724071d7 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

[ios] Strip arm64e from XCTRunner if present

With Xcode 11.4, the arm64e slice of XCTRunner is removed from the
binary when creating the XCUITest runner application. Not doing it
may prevents running the application on a device, so replicate this.

Bug: none
Change-Id: I25925ac7ed20150bb2ef4cffa01e64f8ad9d4e1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127111
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754981}
parent 47206510
......@@ -128,6 +128,9 @@ group("xctest") {
public_configs = [ ":xctest_config" ]
}
_xctrunner_path =
"$ios_sdk_platform_abs_path/Developer/Library/Xcode/Agents/XCTRunner.app"
# When building with Goma RBE, $ios_sdk_platform_abs_path corresponds to a
# symlink below $root_build_dir that points to the real SDK to use. Because
# the files are below $root_build_dir, it is not possible to list them as a
......@@ -142,9 +145,6 @@ group("xctest") {
# To workaround this, add a target that pretends to create those files
# (but does nothing). See https://crbug.com/1061487 for why this is needed.
if (ios_use_goma_rbe) {
_xctrunner_path =
"$ios_sdk_platform_abs_path/Developer/Library/Xcode/Agents/XCTRunner.app"
action("copy_xctrunner_app") {
testonly = true
script = "//build/noop.py"
......@@ -155,3 +155,23 @@ if (ios_use_goma_rbe) {
]
}
}
# When creating the test runner for an XCUITest, the arm64e slice of the binary
# must be removed (at least until the app ships with arm64e slice which is not
# yet supported by Apple).
action("xctest_runner_without_arm64e") {
testonly = true
script = "//build/config/ios/strip_arm64e.py"
sources = [ "$_xctrunner_path/XCTRunner" ]
outputs = [ "$target_out_dir/XCTRunner" ]
args = [
"--output",
rebase_path(outputs[0], root_build_dir),
"--input",
rebase_path(sources[0], root_build_dir),
]
if (ios_use_goma_rbe) {
deps = [ ":copy_xctrunner_app" ]
}
}
......@@ -1938,7 +1938,7 @@ template("ios_xcuitest_test_runner_bundle") {
outputs = [ "{{bundle_contents_dir}}/PkgInfo" ]
if (ios_use_goma_rbe) {
deps = [ "//build/config/ios:copy_xctrunner_app" ]
public_deps = [ "//build/config/ios:copy_xctrunner_app" ]
}
}
......@@ -1946,7 +1946,8 @@ template("ios_xcuitest_test_runner_bundle") {
create_signed_bundle(_target_name) {
testonly = true
bundle_binary_path = "$_xctrunner_path/XCTRunner"
bundle_binary_target = "//build/config/ios:xctest_runner_without_arm64e"
bundle_binary_output = "XCTRunner"
bundle_extension = ".app"
product_type = "com.apple.product-type.application"
......@@ -1969,10 +1970,6 @@ template("ios_xcuitest_test_runner_bundle") {
":$_pkginfo_bundle",
":$_xctest_bundle",
]
if (ios_use_goma_rbe) {
deps = [ "//build/config/ios:copy_xctrunner_app" ]
}
}
}
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Strip arm64e architecture from a binary if present."""
import argparse
import os
import shutil
import subprocess
import sys
def check_output(command):
"""Returns the output from |command| or propagates error, quitting script."""
process = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
outs, errs = process.communicate()
if process.returncode:
sys.stderr.write('error: command failed with retcode %d: %s\n\n' %
(process.returncode, ' '.join(map(repr, command))))
sys.stderr.write(errs)
sys.exit(process.returncode)
return outs
def check_call(command):
"""Invokes |command| or propagates error."""
check_output(command)
def parse_args(args):
"""Parses the command-line."""
parser = argparse.ArgumentParser()
parser.add_argument('--input', required=True, help='Path to input binary')
parser.add_argument('--output', required=True, help='Path to output binary')
return parser.parse_args(args)
def get_archs(path):
"""Extracts the architectures present in binary at |path|."""
outputs = check_output(["xcrun", "lipo", "-info", os.path.abspath(path)])
return outputs.split(': ')[-1].split()
def main(args):
parsed = parse_args(args)
outdir = os.path.dirname(parsed.output)
if not os.path.isdir(outdir):
os.makedirs(outdir)
if os.path.exists(parsed.output):
os.unlink(parsed.output)
# As "lipo" fails with an error if asked to remove an architecture that is
# not included, only use it if "arm64e" is present in the binary. Otherwise
# simply copy the file.
if 'arm64e' in get_archs(parsed.input):
check_output([
"xcrun", "lipo", "-remove", "arm64e", "-output",
os.path.abspath(parsed.output),
os.path.abspath(parsed.input)
])
else:
shutil.copy(parsed.input, parsed.output)
if __name__ == '__main__':
main(sys.argv[1:])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment