summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-11-13 15:34:37 -0800
committerTim Smith <tsmith84@gmail.com>2020-11-13 15:56:09 -0800
commita6de03f2fc2d64797a5c11fb03493da4f49904b8 (patch)
tree8b351e3d0ebee9bb9b72b7abe71d814c84a9b9c0
parent0b7ab72fa3729c4a880a0c757cc9e46fa0473168 (diff)
downloadchef-a6de03f2fc2d64797a5c11fb03493da4f49904b8.tar.gz
Fix idempotency issues in build_essential on the mac
2 issues this solves: - On some systems the Command Line Tools aren't showing up in the install history plist we're parsing. This means we attempt to install the tools each time chef runs, which takes a LONG time even on a top of the line mac. It was suggested in mac admins slack to just use xcode-select -p which lists the command line tools path or exits 2 if not installed. - When the :upgrade action is used we were parsing out the software update list twice for no reason, which made it take even longer. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/build_essential.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb
index 17b97ebd97..3039f709c8 100644
--- a/lib/chef/resource/build_essential.rb
+++ b/lib/chef/resource/build_essential.rb
@@ -15,7 +15,6 @@
#
require_relative "../resource"
-autoload :Plist, "plist"
class Chef
class Resource
@@ -130,8 +129,8 @@ class Chef
pkg_label = xcode_cli_package_label
# With upgrade action we should install if it's not installed or if there's an available update.
- # `xcode_cli_package_label` will be nil if there's no update.
- install_xcode_cli_tools(pkg_label) if !xcode_cli_installed? || xcode_cli_package_label
+ # `pkg_label` will be nil if there's no update.
+ install_xcode_cli_tools(pkg_label) if !xcode_cli_installed? || pkg_label
else
Chef::Log.info "The build_essential resource :upgrade action is only supported on macOS systems. Skipping..."
end
@@ -160,14 +159,12 @@ class Chef
end
#
- # Determine if the XCode Command Line Tools are installed by parsing the install history plist.
- # We parse the plist data install of running pkgutil because we found that pkgutils doesn't always contain all the packages
+ # Determine if the XCode Command Line Tools are installed by checking
+ # for success from `xcode-select -p`
#
# @return [true, false]
def xcode_cli_installed?
- packages = ::Plist.parse_xml(::File.open("/Library/Receipts/InstallHistory.plist", "r"))
- packages.select! { |package| package["displayName"].match? "Command Line Tools" }
- !packages.empty?
+ !shell_out("xcode-select", "-p").error?
end
#