summaryrefslogtreecommitdiff
path: root/lib/chef/resource/build_essential.rb
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-17 20:53:42 -0700
committerTim Smith <tsmith@chef.io>2018-03-20 09:19:13 -0700
commitf7d34c26a323806fe0ee95ea7795ad451a6617a8 (patch)
tree35e0e6ae1d61c07bf544367a7a9aa5bbe25ea59e /lib/chef/resource/build_essential.rb
parent51c59ecb887e9122aa849d8153b9984df74b2b09 (diff)
downloadchef-f7d34c26a323806fe0ee95ea7795ad451a6617a8.tar.gz
Add missing installed logic for macos in 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>
Diffstat (limited to 'lib/chef/resource/build_essential.rb')
-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 fb9ef814a5..be07f153f8 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