Skip to content

Commit 421b589

Browse files
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>
1 parent dbb1b9b commit 421b589

6 files changed

Lines changed: 32 additions & 17 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: 10 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
#
@@ -276,6 +276,15 @@ def component_pkg
276276
"#{safe_base_package_name}-core.pkg"
277277
end
278278

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

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: 4 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

@@ -148,7 +148,7 @@ module Omnibus
148148
productbuild \\
149149
--distribution "#{staging_dir}/Distribution" \\
150150
--resources "#{staging_dir}/Resources" \\
151-
"#{package_dir}/project-full-name-1.2.3-2.pkg"
151+
"#{package_dir}/project-full-name-1.2.3-2.x86_64.pkg"
152152
EOH
153153

154154
subject.build_product_pkg
@@ -166,7 +166,7 @@ module Omnibus
166166
--distribution "#{staging_dir}/Distribution" \\
167167
--resources "#{staging_dir}/Resources" \\
168168
--sign "My Special Identity" \\
169-
"#{package_dir}/project-full-name-1.2.3-2.pkg"
169+
"#{package_dir}/project-full-name-1.2.3-2.x86_64.pkg"
170170
EOH
171171
subject.build_product_pkg
172172
end

0 commit comments

Comments
 (0)