From 421b589070962f325a4cb32af5dd9450edc3e6ea Mon Sep 17 00:00:00 2001 From: Tom Duffield Date: Tue, 16 Feb 2021 16:43:48 -0600 Subject: [PATCH 1/2] Add support for macOS 11 and multiple architectures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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@2b1b503fc7e532771788be349e597c2798cb401a Co-authored-by: Régis Desgroppes --- lib/omnibus/metadata.rb | 8 ++++++-- lib/omnibus/packagers/pkg.rb | 11 ++++++++++- spec/unit/compressors/dmg_spec.rb | 12 ++++++------ spec/unit/compressors/tgz_spec.rb | 8 ++++---- spec/unit/metadata_spec.rb | 2 ++ spec/unit/packagers/pkg_spec.rb | 8 ++++---- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/omnibus/metadata.rb b/lib/omnibus/metadata.rb index 20f6bf7fc..c0b4e188c 100644 --- a/lib/omnibus/metadata.rb +++ b/lib/omnibus/metadata.rb @@ -170,9 +170,13 @@ def truncate_platform_version(platform_version, platform) when "centos", "debian", "el", "fedora", "freebsd", "omnios", "pidora", "raspbian", "rhel", "sles", "suse", "smartos", "nexus", "ios_xr" # Only want MAJOR (e.g. Debian 7, OmniOS r151006, SmartOS 20120809T221258Z) platform_version.split(".").first - when "aix", "gentoo", "mac_os_x", "openbsd", "slackware", "solaris2", "opensuse", "ubuntu", "macos" - # Only want MAJOR.MINOR (e.g. Mac OS X 10.9, Ubuntu 12.04) + when "aix", "gentoo", "openbsd", "slackware", "solaris2", "opensuse", "ubuntu" + # Only want MAJOR.MINOR (e.g. Ubuntu 12.04) platform_version.split(".")[0..1].join(".") + when "mac_os_x", "darwin", "macos" + # If running macOS >= 11, use only MAJOR version. Otherwise, use MAJOR.MINOR + pv_bits = platform_version.split(".") + pv_bits[0].to_i >= 11 ? pv_bits[0] : pv_bits[0..1].join(".") when "arch" # Arch Linux does not have a platform_version ohai attribute, it is rolling release (lsb_release -r) "rolling" diff --git a/lib/omnibus/packagers/pkg.rb b/lib/omnibus/packagers/pkg.rb index b86d8b907..8aac2599b 100644 --- a/lib/omnibus/packagers/pkg.rb +++ b/lib/omnibus/packagers/pkg.rb @@ -146,7 +146,7 @@ def install_location(val = NULL) # @see Base#package_name def package_name - "#{safe_base_package_name}-#{safe_version}-#{safe_build_iteration}.pkg" + "#{safe_base_package_name}-#{safe_version}-#{safe_build_iteration}.#{safe_architecture}.pkg" end # @@ -276,6 +276,15 @@ def component_pkg "#{safe_base_package_name}-core.pkg" end + # + # Return the architecture + # + # @return [String] + # + def safe_architecture + @safe_architecture ||= Ohai["kernel"]["machine"] + end + # # Return the PKG-ready base package name, removing any invalid characters. # diff --git a/spec/unit/compressors/dmg_spec.rb b/spec/unit/compressors/dmg_spec.rb index 3fed07373..5f2b540d7 100644 --- a/spec/unit/compressors/dmg_spec.rb +++ b/spec/unit/compressors/dmg_spec.rb @@ -114,7 +114,7 @@ module Omnibus --detach-retries=5 \\ --settings="#{subject.resource_path('settings.py')}" \\ -Dbackground="#{subject.resource_path('background.png')}" \\ - -Dpkg="#{package_dir}/project-1.2.3-2.pkg" \\ + -Dpkg="#{package_dir}/project-1.2.3-2.x86_64.pkg" \\ -Dpkg_position="535, 50" \\ -Dvolume_icon="#{staging_dir}/tmp.icns" \\ -Dwindow_bounds="100, 100, 750, 600" \\ @@ -136,7 +136,7 @@ module Omnibus expect(subject).to receive(:shellout!) .with <<-EOH.gsub(/^ {12}/, "") hdiutil verify \\ - "#{package_dir}/project-1.2.3-2.dmg" \\ + "#{package_dir}/project-1.2.3-2.x86_64.dmg" \\ -puppetstrings EOH @@ -162,10 +162,10 @@ module Omnibus DeRez -only icns "#{icon}" > tmp.rsrc # Append the icon reosurce to the DMG - Rez -append tmp.rsrc -o "#{package_dir}/project-1.2.3-2.dmg" + Rez -append tmp.rsrc -o "#{package_dir}/project-1.2.3-2.x86_64.dmg" # Source the icon - SetFile -a C "#{package_dir}/project-1.2.3-2.dmg" + SetFile -a C "#{package_dir}/project-1.2.3-2.x86_64.dmg" EOH subject.set_dmg_icon @@ -174,11 +174,11 @@ module Omnibus describe '#package_name' do it 'reflects the packager\'s unmodified package_name' do - expect(subject.package_name).to eq("project-1.2.3-2.dmg") + expect(subject.package_name).to eq("project-1.2.3-2.x86_64.dmg") end it 'reflects the packager\'s modified package_name' do - package_basename = "projectsub-1.2.3-3" + package_basename = "projectsub-1.2.3-3.x86_64" allow(project.packagers_for_system[0]).to receive(:package_name) .and_return("#{package_basename}.pkg") diff --git a/spec/unit/compressors/tgz_spec.rb b/spec/unit/compressors/tgz_spec.rb index 32dfefc86..0594d4965 100644 --- a/spec/unit/compressors/tgz_spec.rb +++ b/spec/unit/compressors/tgz_spec.rb @@ -38,25 +38,25 @@ module Omnibus describe '#package_name' do it "returns the name of the packager" do - expect(subject.package_name).to eq("project-1.2.3-2.pkg.tar.gz") + expect(subject.package_name).to eq("project-1.2.3-2.x86_64.pkg.tar.gz") end end describe '#write_tgz' do before do - File.open("#{staging_dir}/project-1.2.3-2.pkg", "wb") do |f| + File.open("#{staging_dir}/project-1.2.3-2.x86_64.pkg", "wb") do |f| f.write " " * 1_000_000 end end it "generates the file" do subject.write_tgz - expect("#{staging_dir}/project-1.2.3-2.pkg.tar.gz").to be_a_file + expect("#{staging_dir}/project-1.2.3-2.x86_64.pkg.tar.gz").to be_a_file end it "has the correct content" do subject.write_tgz - file = File.open("#{staging_dir}/project-1.2.3-2.pkg.tar.gz", "rb") + file = File.open("#{staging_dir}/project-1.2.3-2.x86_64.pkg.tar.gz", "rb") contents = file.read file.close diff --git a/spec/unit/metadata_spec.rb b/spec/unit/metadata_spec.rb index 8115f7e1f..efa5d6cae 100644 --- a/spec/unit/metadata_spec.rb +++ b/spec/unit/metadata_spec.rb @@ -220,6 +220,8 @@ module Omnibus it_behaves_like "a version manipulator", "gentoo", "2004.3", "2004.3" it_behaves_like "a version manipulator", "ios_xr", "6.0.0.14I", "6" it_behaves_like "a version manipulator", "mac_os_x", "10.9.1", "10.9" + it_behaves_like "a version manipulator", "mac_os_x", "10.15.7", "10.15" + it_behaves_like "a version manipulator", "mac_os_x", "11.2.1", "11" it_behaves_like "a version manipulator", "nexus", "5.0", "5" it_behaves_like "a version manipulator", "omnios", "r151010", "r151010" it_behaves_like "a version manipulator", "openbsd", "5.4.4", "5.4" diff --git a/spec/unit/packagers/pkg_spec.rb b/spec/unit/packagers/pkg_spec.rb index 32e493342..8bfa1e8a4 100644 --- a/spec/unit/packagers/pkg_spec.rb +++ b/spec/unit/packagers/pkg_spec.rb @@ -47,8 +47,8 @@ module Omnibus end describe '#package_name' do - it "includes the name, version, and build iteration" do - expect(subject.package_name).to eq("project-full-name-1.2.3-2.pkg") + it "includes the name, version, build iteration, and architecture" do + expect(subject.package_name).to eq("project-full-name-1.2.3-2.x86_64.pkg") end end @@ -148,7 +148,7 @@ module Omnibus productbuild \\ --distribution "#{staging_dir}/Distribution" \\ --resources "#{staging_dir}/Resources" \\ - "#{package_dir}/project-full-name-1.2.3-2.pkg" + "#{package_dir}/project-full-name-1.2.3-2.x86_64.pkg" EOH subject.build_product_pkg @@ -166,7 +166,7 @@ module Omnibus --distribution "#{staging_dir}/Distribution" \\ --resources "#{staging_dir}/Resources" \\ --sign "My Special Identity" \\ - "#{package_dir}/project-full-name-1.2.3-2.pkg" + "#{package_dir}/project-full-name-1.2.3-2.x86_64.pkg" EOH subject.build_product_pkg end From 71e05f51d988d783ea0db2711fcf2ac75d8a0a15 Mon Sep 17 00:00:00 2001 From: Tom Duffield Date: Fri, 12 Mar 2021 10:31:05 -0600 Subject: [PATCH 2/2] Add hostArchitectures to macOS Distribution file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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@6173b5fc28e69416e378804030719148f0a7e1de Co-authored-by: Régis Desgroppes --- lib/omnibus/packagers/pkg.rb | 1 + resources/pkg/distribution.xml.erb | 2 +- spec/unit/packagers/pkg_spec.rb | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/omnibus/packagers/pkg.rb b/lib/omnibus/packagers/pkg.rb index 8aac2599b..0484f1d24 100644 --- a/lib/omnibus/packagers/pkg.rb +++ b/lib/omnibus/packagers/pkg.rb @@ -242,6 +242,7 @@ def write_distribution_file identifier: safe_identifier, version: safe_version, component_pkg: component_pkg, + host_architecture: safe_architecture, }) end diff --git a/resources/pkg/distribution.xml.erb b/resources/pkg/distribution.xml.erb index d56d81783..bef76cb07 100644 --- a/resources/pkg/distribution.xml.erb +++ b/resources/pkg/distribution.xml.erb @@ -7,7 +7,7 @@ - + diff --git a/spec/unit/packagers/pkg_spec.rb b/spec/unit/packagers/pkg_spec.rb index 8bfa1e8a4..564759e46 100644 --- a/spec/unit/packagers/pkg_spec.rb +++ b/spec/unit/packagers/pkg_spec.rb @@ -137,8 +137,24 @@ module Omnibus expect(contents).to include('') expect(contents).to include('') + expect(contents).to include('hostArchitectures="x86_64"') expect(contents).to include("project-full-name-core.pkg") end + + context "for arm64 builds" do + before do + stub_ohai(platform: "mac_os_x", version: "11.0") do |data| + data["kernel"]["machine"] = "arm64" + end + end + + it "sets the hostArchitectures to include arm64" do + subject.write_distribution_file + contents = File.read("#{staging_dir}/Distribution") + + expect(contents).to include('hostArchitectures="arm64"') + end + end end describe '#build_product_pkg' do