Skip to content

Commit 71e05f5

Browse files
Add hostArchitectures to macOS Distribution file
Unless hostArchitectures is set, macOS 11 will assume that the package is x86_64 and require Rosetta 2. * https://scriptingosx.com/2020/12/platform-support-in-macos-installer-packages-pkg/ * https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html#//apple_ref/doc/uid/TP40005370-CH100-SW7 Cherry-picked-from: chef/omnibus@6173b5f Co-authored-by: Régis Desgroppes <regis.desgroppes@datadoghq.com>
1 parent 421b589 commit 71e05f5

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/omnibus/packagers/pkg.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def write_distribution_file
242242
identifier: safe_identifier,
243243
version: safe_version,
244244
component_pkg: component_pkg,
245+
host_architecture: safe_architecture,
245246
})
246247
end
247248

resources/pkg/distribution.xml.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<!-- Generated by productbuild - - synthesize -->
99
<pkg-ref id="<%= identifier %>"/>
10-
<options customize="never" require-scripts="false"/>
10+
<options customize="never" require-scripts="false" hostArchitectures="<%= host_architecture %>" />
1111
<choices-outline>
1212
<line choice="default">
1313
<line choice="<%= identifier %>"/>

spec/unit/packagers/pkg_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,24 @@ module Omnibus
137137

138138
expect(contents).to include('<pkg-ref id="com.getchef.project-full-name"/>')
139139
expect(contents).to include('<line choice="com.getchef.project-full-name"/>')
140+
expect(contents).to include('hostArchitectures="x86_64"')
140141
expect(contents).to include("project-full-name-core.pkg")
141142
end
143+
144+
context "for arm64 builds" do
145+
before do
146+
stub_ohai(platform: "mac_os_x", version: "11.0") do |data|
147+
data["kernel"]["machine"] = "arm64"
148+
end
149+
end
150+
151+
it "sets the hostArchitectures to include arm64" do
152+
subject.write_distribution_file
153+
contents = File.read("#{staging_dir}/Distribution")
154+
155+
expect(contents).to include('hostArchitectures="arm64"')
156+
end
157+
end
142158
end
143159

144160
describe '#build_product_pkg' do

0 commit comments

Comments
 (0)