summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-17 20:53:42 -0700
committerTim Smith <tsmith@chef.io>2018-03-19 15:27:32 -0700
commitf26246c3f28a4aab33c5d43b45731c761d376007 (patch)
treed43b70fba96a93282ec03b8a46d8ef4d466095e8
parent4e6c7972620e68753946abe109895762a6301efd (diff)
downloadchef-macos_build_essential.tar.gz
Add missing installed logic for macos in build_essentialmacos_build_essential
Add the missing installed? check that makes this fast. Also use tail instead of head in the execute so we install the latest not the oldest xcode release if more than 1 is available on the system (upgrades). Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/build_essential.rb48
1 files changed, 33 insertions, 15 deletions
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb
index 7998006398..302ba5c25e 100644
--- a/lib/chef/resource/build_essential.rb
+++ b/lib/chef/resource/build_essential.rb
@@ -47,21 +47,23 @@ class Chef
declare_resource(:package, "devel/m4")
declare_resource(:package, "devel/gettext")
when "mac_os_x"
- # This script was graciously borrowed and modified from Tim Sutton's
- # osx-vm-templates at https://github.com/timsutton/osx-vm-templates/blob/b001475df54a9808d3d56d06e71b8fa3001fff42/scripts/xcode-cli-tools.sh
- declare_resource(:execute, "install XCode Command Line tools") do
- command <<-EOH.gsub(/^ {14}/, "")
- # create the placeholder file that's checked by CLI updates' .dist code
- # in Apple's SUS catalog
- touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
- # find the CLI Tools update
- PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
- # install it
- softwareupdate -i "$PROD" --verbose
- # Remove the placeholder to prevent perpetual appearance in the update utility
- rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
- EOH
- # rubocop:enable Metrics/LineLength
+ unless xcode_cli_installed?
+ # This script was graciously borrowed and modified from Tim Sutton's
+ # osx-vm-templates at https://github.com/timsutton/osx-vm-templates/blob/b001475df54a9808d3d56d06e71b8fa3001fff42/scripts/xcode-cli-tools.sh
+ declare_resource(:execute, "install XCode Command Line tools") do
+ command <<-EOH.gsub(/^ {14}/, "")
+ # create the placeholder file that's checked by CLI updates' .dist code
+ # in Apple's SUS catalog
+ touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
+ # find the CLI Tools update. We tail here because sometimes there's 2 and newest is last
+ PROD=$(softwareupdate -l | grep "\*.*Command Line" | tail -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n')
+ # install it
+ softwareupdate -i "$PROD" --verbose
+ # Remove the placeholder to prevent perpetual appearance in the update utility
+ rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
+ EOH
+ # rubocop:enable Metrics/LineLength
+ end
end
when "omnios"
declare_resource(:package, "developer/gcc48")
@@ -112,6 +114,22 @@ class Chef
end
end
+ action_class do
+ #
+ # Determine if the XCode Command Line Tools are installed
+ #
+ # @return [true, false]
+ #
+ def xcode_cli_installed?
+ cmd = Mixlib::ShellOut.new("pkgutil --pkgs=com.apple.pkg.CLTools_Executables")
+ cmd.run_command
+ cmd.error!
+ true
+ rescue Mixlib::ShellOut::ShellCommandFailed
+ false
+ end
+ end
+
# this resource forces itself to run at compile_time
def after_created
return unless compile_time