Commit 99d4525f authored by Avi Drissman's avatar Avi Drissman Committed by Chromium LUCI CQ

Add architectures to the distribution pkg

If no architectures are specified in the distribution
pkg, the installer on M1 Macs will assume the package
requires Rosetta and will show a dialog asking to
install it. Showing such a dialog prevents the package
from being installed unattended or at the login screen.

Therefore, include architecture information in the
distribution xml.

For reference: https://scriptingosx.com/2020/12/platform-support-in-macos-installer-packages-pkg/

Fixed: 1169145
Change-Id: I63e26ede4ec4d583ca090121e91c3c4a5d7ebe04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2643167
Commit-Queue: Avi Drissman <avi@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846248}
parent 61a01042
...@@ -31,6 +31,24 @@ def _include_branding_code_in_app(dist): ...@@ -31,6 +31,24 @@ def _include_branding_code_in_app(dist):
return dist.package_as_dmg or not dist.package_as_pkg return dist.package_as_dmg or not dist.package_as_pkg
def _binary_architectures(binary_path):
"""Returns a comma-separated list of architectures of a binary.
Args:
binary_path: The path to the binary on disk.
Returns:
A comma-separated string of architectures.
"""
command = ['lipo', '-archs', binary_path]
output = commands.run_command_output(command)
output = output.strip()
output = output.replace(' ', ',')
return output
def _customize_and_sign_chrome(paths, dist_config, dest_dir, signed_frameworks): def _customize_and_sign_chrome(paths, dist_config, dest_dir, signed_frameworks):
"""Does channel customization and signing of a Chrome distribution. The """Does channel customization and signing of a Chrome distribution. The
resulting app bundle is moved into |dest_dir|. resulting app bundle is moved into |dest_dir|.
...@@ -197,7 +215,7 @@ def _component_property_path(paths, dist_config): ...@@ -197,7 +215,7 @@ def _component_property_path(paths, dist_config):
def _productbuild_distribution_path(app_paths, pkg_paths, dist_config, def _productbuild_distribution_path(app_paths, pkg_paths, dist_config,
component_pkg_path): component_pkg_path):
"""Creates a distribution XML file for use by `productbuild`. This copies """Creates a distribution XML file for use by `productbuild`. This copies
the OS requirement from the copy of Chrome being packaged. the OS and architecture requirements from the copy of Chrome being packaged.
Args: Args:
app_paths: A |model.Paths| object for the app. app_paths: A |model.Paths| object for the app.
...@@ -211,6 +229,8 @@ def _productbuild_distribution_path(app_paths, pkg_paths, dist_config, ...@@ -211,6 +229,8 @@ def _productbuild_distribution_path(app_paths, pkg_paths, dist_config,
distribution_path = os.path.join(pkg_paths.work, distribution_path = os.path.join(pkg_paths.work,
'{}.dist'.format(dist_config.app_product)) '{}.dist'.format(dist_config.app_product))
app_binary_path = os.path.join(app_paths.work, dist_config.app_dir,
'Contents', 'MacOS', dist_config.app_product)
app_plist_path = os.path.join(app_paths.work, dist_config.app_dir, app_plist_path = os.path.join(app_paths.work, dist_config.app_dir,
'Contents', 'Info.plist') 'Contents', 'Info.plist')
with commands.PlistContext(app_plist_path) as app_plist: with commands.PlistContext(app_plist_path) as app_plist:
...@@ -221,7 +241,7 @@ def _productbuild_distribution_path(app_paths, pkg_paths, dist_config, ...@@ -221,7 +241,7 @@ def _productbuild_distribution_path(app_paths, pkg_paths, dist_config,
<!-- Top-level info about the distribution. --> <!-- Top-level info about the distribution. -->
<title>{app_product}</title> <title>{app_product}</title>
<options customize="never" require-scripts="false"/> <options customize="never" require-scripts="false" hostArchitectures="{host_architectures}"/>
<domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/> <domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/>
<volume-check> <volume-check>
<allowed-os-versions> <allowed-os-versions>
...@@ -252,6 +272,7 @@ def _productbuild_distribution_path(app_paths, pkg_paths, dist_config, ...@@ -252,6 +272,7 @@ def _productbuild_distribution_path(app_paths, pkg_paths, dist_config,
</installer-gui-script>""".format( </installer-gui-script>""".format(
app_product=dist_config.app_product, app_product=dist_config.app_product,
bundle_id=dist_config.base_bundle_id, bundle_id=dist_config.base_bundle_id,
host_architectures=_binary_architectures(app_binary_path),
minimum_system=app_plist['LSMinimumSystemVersion'], minimum_system=app_plist['LSMinimumSystemVersion'],
component_pkg_filename=os.path.basename(component_pkg_path), component_pkg_filename=os.path.basename(component_pkg_path),
version=dist_config.version) version=dist_config.version)
......
...@@ -46,6 +46,10 @@ def _last_written_plist(): ...@@ -46,6 +46,10 @@ def _last_written_plist():
return _write_plist.contents return _write_plist.contents
def _run_command_output_lipo(b):
return 'x86_64,arm64'
def _read_file(p): def _read_file(p):
if p == '/$I/Product Packaging/pkg_postinstall.in': if p == '/$I/Product Packaging/pkg_postinstall.in':
return """app dir is '@APP_DIR@' return """app dir is '@APP_DIR@'
...@@ -347,6 +351,7 @@ framework dir is 'App Product.app/Contents/Frameworks/Product Framework.framewor ...@@ -347,6 +351,7 @@ framework dir is 'App Product.app/Contents/Frameworks/Product Framework.framewor
}]) }])
@mock.patch('signing.commands.plistlib.readPlist', _read_plist) @mock.patch('signing.commands.plistlib.readPlist', _read_plist)
@mock.patch('signing.commands.run_command_output', _run_command_output_lipo)
def test_productbuild_distribution_path(self, **kwargs): def test_productbuild_distribution_path(self, **kwargs):
manager = mock.Mock() manager = mock.Mock()
for attr in kwargs: for attr in kwargs:
......
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