summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-20 11:05:53 -0700
committerGitHub <noreply@github.com>2018-03-20 11:05:53 -0700
commit8b9b8aeaec0aea62464610b272b804049e2fc70d (patch)
tree5cd1e1f1ea8520df8b185fc4f7d3ad31c8fe97e2
parent15a98e63ba0a046c3b205fd7698bcf94093364f2 (diff)
parentec2f1c1295890617fd83c6117e1f6ec64c0e20e5 (diff)
downloadchef-8b9b8aeaec0aea62464610b272b804049e2fc70d.tar.gz
Merge pull request #7005 from chef/macos_build_essential
Add missing installed logic for macos in build_essential
-rw-r--r--lib/chef/resource/build_essential.rb45
1 files changed, 30 insertions, 15 deletions
diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb
index fb9ef814a5..05303d8fce 100644
--- a/lib/chef/resource/build_essential.rb
+++ b/lib/chef/resource/build_essential.rb
@@ -47,21 +47,22 @@ 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
+ end
end
when "omnios"
declare_resource(:package, "developer/gcc48")
@@ -112,6 +113,20 @@ 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
+ # pkgutil returns an error if the package isn't found aka not installed
+ cmd.error? ? false : true
+ end
+ end
+
# this resource forces itself to run at compile_time
def after_created
return unless compile_time