Skip to content

Commit fb400d5

Browse files
authored
[ABLD-28] Backport upstream macOS multiarch support (#240)
While looking at the macOS installation script, I realized no architecture was passed to the `dd-agent` [query string](https://github.com/DataDog/datadog-agent/blob/711ec69670e90a5066d5672a6ac8a9783871a37b/cmd/agent/install_mac_os.sh#L78): ```bash curl "https://s3.amazonaws.com/dd-agent?prefix=datadog-agent-${major_minor}." ``` There was no architecture disambiguation so far because our PKGs and DMGs had been primarily targeting x86_64/AMD64, and relying on Rosetta 2 translation for AArch64/ARM64. The present change is therefore to backport (`git cherry-pick`) upstream efforts on the matter, i.e.: 1. chef/omnibus@2b1b503 2. chef/omnibus@6173b5f [Without](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1031599309#L1387)/[with](https://gitlab.ddbuild.io/DataDog/datadog-agent/-/jobs/1032219779#L2302) an architecture qualifier: ```diff -datadog-agent-7.70.0-devel.git.75.d018f55.pipeline.70720451-1.dmg +datadog-agent-7.70.0-devel.git.79.1816262.pipeline.70752546-1.x86_64.dmg ``` (examples from development pipelines) Squashed here: * Add support for macOS 11 and multiple architectures * Provide the correct platform version (11 vs 11.x) for macOS. * Add the architecture (x86_64, arm64) to the file name Cherry-picked-from: chef/omnibus@2b1b503 Co-authored-by: Régis Desgroppes <regis.desgroppes@datadoghq.com> * 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 dbb1b9b commit fb400d5

7 files changed

Lines changed: 50 additions & 18 deletions

File tree

lib/omnibus/metadata.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,13 @@ def truncate_platform_version(platform_version, platform)
170170
when "centos", "debian", "el", "fedora", "freebsd", "omnios", "pidora", "raspbian", "rhel", "sles", "suse", "smartos", "nexus", "ios_xr"
171171
# Only want MAJOR (e.g. Debian 7, OmniOS r151006, SmartOS 20120809T221258Z)
172172
platform_version.split(".").first
173-
when "aix", "gentoo", "mac_os_x", "openbsd", "slackware", "solaris2", "opensuse", "ubuntu", "macos"
174-
# Only want MAJOR.MINOR (e.g. Mac OS X 10.9, Ubuntu 12.04)
173+
when "aix", "gentoo", "openbsd", "slackware", "solaris2", "opensuse", "ubuntu"
174+
# Only want MAJOR.MINOR (e.g. Ubuntu 12.04)
175175
platform_version.split(".")[0..1].join(".")
176+
when "mac_os_x", "darwin", "macos"
177+
# If running macOS >= 11, use only MAJOR version. Otherwise, use MAJOR.MINOR
178+
pv_bits = platform_version.split(".")
179+
pv_bits[0].to_i >= 11 ? pv_bits[0] : pv_bits[0..1].join(".")
176180
when "arch"
177181
# Arch Linux does not have a platform_version ohai attribute, it is rolling release (lsb_release -r)
178182
"rolling"

lib/omnibus/packagers/pkg.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def install_location(val = NULL)
146146

147147
# @see Base#package_name
148148
def package_name
149-
"#{safe_base_package_name}-#{safe_version}-#{safe_build_iteration}.pkg"
149+
"#{safe_base_package_name}-#{safe_version}-#{safe_build_iteration}.#{safe_architecture}.pkg"
150150
end
151151

152152
#
@@ -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

@@ -276,6 +277,15 @@ def component_pkg
276277
"#{safe_base_package_name}-core.pkg"
277278
end
278279

280+
#
281+
# Return the architecture
282+
#
283+
# @return [String]
284+
#
285+
def safe_architecture
286+
@safe_architecture ||= Ohai["kernel"]["machine"]
287+
end
288+
279289
#
280290
# Return the PKG-ready base package name, removing any invalid characters.
281291
#

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/compressors/dmg_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ module Omnibus
114114
--detach-retries=5 \\
115115
--settings="#{subject.resource_path('settings.py')}" \\
116116
-Dbackground="#{subject.resource_path('background.png')}" \\
117-
-Dpkg="#{package_dir}/project-1.2.3-2.pkg" \\
117+
-Dpkg="#{package_dir}/project-1.2.3-2.x86_64.pkg" \\
118118
-Dpkg_position="535, 50" \\
119119
-Dvolume_icon="#{staging_dir}/tmp.icns" \\
120120
-Dwindow_bounds="100, 100, 750, 600" \\
@@ -136,7 +136,7 @@ module Omnibus
136136
expect(subject).to receive(:shellout!)
137137
.with <<-EOH.gsub(/^ {12}/, "")
138138
hdiutil verify \\
139-
"#{package_dir}/project-1.2.3-2.dmg" \\
139+
"#{package_dir}/project-1.2.3-2.x86_64.dmg" \\
140140
-puppetstrings
141141
EOH
142142

@@ -162,10 +162,10 @@ module Omnibus
162162
DeRez -only icns "#{icon}" > tmp.rsrc
163163
164164
# Append the icon reosurce to the DMG
165-
Rez -append tmp.rsrc -o "#{package_dir}/project-1.2.3-2.dmg"
165+
Rez -append tmp.rsrc -o "#{package_dir}/project-1.2.3-2.x86_64.dmg"
166166
167167
# Source the icon
168-
SetFile -a C "#{package_dir}/project-1.2.3-2.dmg"
168+
SetFile -a C "#{package_dir}/project-1.2.3-2.x86_64.dmg"
169169
EOH
170170

171171
subject.set_dmg_icon
@@ -174,11 +174,11 @@ module Omnibus
174174

175175
describe '#package_name' do
176176
it 'reflects the packager\'s unmodified package_name' do
177-
expect(subject.package_name).to eq("project-1.2.3-2.dmg")
177+
expect(subject.package_name).to eq("project-1.2.3-2.x86_64.dmg")
178178
end
179179

180180
it 'reflects the packager\'s modified package_name' do
181-
package_basename = "projectsub-1.2.3-3"
181+
package_basename = "projectsub-1.2.3-3.x86_64"
182182
allow(project.packagers_for_system[0]).to receive(:package_name)
183183
.and_return("#{package_basename}.pkg")
184184

spec/unit/compressors/tgz_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ module Omnibus
3838

3939
describe '#package_name' do
4040
it "returns the name of the packager" do
41-
expect(subject.package_name).to eq("project-1.2.3-2.pkg.tar.gz")
41+
expect(subject.package_name).to eq("project-1.2.3-2.x86_64.pkg.tar.gz")
4242
end
4343
end
4444

4545
describe '#write_tgz' do
4646
before do
47-
File.open("#{staging_dir}/project-1.2.3-2.pkg", "wb") do |f|
47+
File.open("#{staging_dir}/project-1.2.3-2.x86_64.pkg", "wb") do |f|
4848
f.write " " * 1_000_000
4949
end
5050
end
5151

5252
it "generates the file" do
5353
subject.write_tgz
54-
expect("#{staging_dir}/project-1.2.3-2.pkg.tar.gz").to be_a_file
54+
expect("#{staging_dir}/project-1.2.3-2.x86_64.pkg.tar.gz").to be_a_file
5555
end
5656

5757
it "has the correct content" do
5858
subject.write_tgz
59-
file = File.open("#{staging_dir}/project-1.2.3-2.pkg.tar.gz", "rb")
59+
file = File.open("#{staging_dir}/project-1.2.3-2.x86_64.pkg.tar.gz", "rb")
6060
contents = file.read
6161
file.close
6262

spec/unit/metadata_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ module Omnibus
220220
it_behaves_like "a version manipulator", "gentoo", "2004.3", "2004.3"
221221
it_behaves_like "a version manipulator", "ios_xr", "6.0.0.14I", "6"
222222
it_behaves_like "a version manipulator", "mac_os_x", "10.9.1", "10.9"
223+
it_behaves_like "a version manipulator", "mac_os_x", "10.15.7", "10.15"
224+
it_behaves_like "a version manipulator", "mac_os_x", "11.2.1", "11"
223225
it_behaves_like "a version manipulator", "nexus", "5.0", "5"
224226
it_behaves_like "a version manipulator", "omnios", "r151010", "r151010"
225227
it_behaves_like "a version manipulator", "openbsd", "5.4.4", "5.4"

spec/unit/packagers/pkg_spec.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ module Omnibus
4747
end
4848

4949
describe '#package_name' do
50-
it "includes the name, version, and build iteration" do
51-
expect(subject.package_name).to eq("project-full-name-1.2.3-2.pkg")
50+
it "includes the name, version, build iteration, and architecture" do
51+
expect(subject.package_name).to eq("project-full-name-1.2.3-2.x86_64.pkg")
5252
end
5353
end
5454

@@ -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
@@ -148,7 +164,7 @@ module Omnibus
148164
productbuild \\
149165
--distribution "#{staging_dir}/Distribution" \\
150166
--resources "#{staging_dir}/Resources" \\
151-
"#{package_dir}/project-full-name-1.2.3-2.pkg"
167+
"#{package_dir}/project-full-name-1.2.3-2.x86_64.pkg"
152168
EOH
153169

154170
subject.build_product_pkg
@@ -166,7 +182,7 @@ module Omnibus
166182
--distribution "#{staging_dir}/Distribution" \\
167183
--resources "#{staging_dir}/Resources" \\
168184
--sign "My Special Identity" \\
169-
"#{package_dir}/project-full-name-1.2.3-2.pkg"
185+
"#{package_dir}/project-full-name-1.2.3-2.x86_64.pkg"
170186
EOH
171187
subject.build_product_pkg
172188
end

0 commit comments

Comments
 (0)