summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Gomez <e@eriknicolasgomez.com>2017-01-14 16:09:55 -0800
committerTim Smith <tsmith@chef.io>2017-01-20 11:34:40 -0800
commitc7dc225241f1c4c46fe86aa176d8e9886bcecc42 (patch)
treea07a2cc50aed1a417c1b212119785894eac905fc
parent5653b0571b9415dcd8789af61f7dc6120bc19b75 (diff)
downloadohai-c7dc225241f1c4c46fe86aa176d8e9886bcecc42.tar.gz
fix gcc and cc for darwin (no cli tools installed)
If darwin is found: 1. shell out to /usr/bin/xcode-select -p 2a. If it returns an exit code other than 0, assume xcode command line tools are not installed and do not run these commands. 2b. If it returns an exit code of 0, run the commands. Signed-off-by: Erik Gomez <e@eriknicolasgomez.com>
-rw-r--r--lib/ohai/plugins/c.rb79
1 files changed, 58 insertions, 21 deletions
diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb
index 3dee1492..ec400840 100644
--- a/lib/ohai/plugins/c.rb
+++ b/lib/ohai/plugins/c.rb
@@ -28,29 +28,48 @@ Ohai.plugin(:C) do
if so.exitstatus == 0
yield(so)
else
- Ohai::Log.debug("Plugin C: '#{cmd}' failed. Skipping data.")
+ Ohai::Log.debug("Plugin C '#{cmd}' failed. Skipping data.")
end
rescue Ohai::Exceptions::Exec
- Ohai::Log.debug("Plugin C: '#{cmd}' binary could not be found. Skipping data.")
+ Ohai::Log.debug("Plugin C '#{cmd}' binary could not be found. Skipping data.")
end
collect_data do
c = Mash.new
#gcc
- collect("gcc -v") do |so|
- # Sample output:
- # Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
- # Apple LLVM version 7.3.0 (clang-703.0.29)
- # Target: x86_64-apple-darwin15.4.0
- # Thread model: posix
- # InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
- description = so.stderr.split($/).last
- output = description.split
- if output.length >= 3
- c[:gcc] = Mash.new
- c[:gcc][:version] = output[2]
- c[:gcc][:description] = description
+ if :darwin
+ Ohai::Log.debug("Checking for Xcode Command Line Tools.")
+ so = shell_out("/usr/bin/xcode-select -p")
+ if so.exitstatus == 0
+ Ohai::Log.debug("Xcode Command Line Tools found.")
+ collect("gcc -v") do |so|
+ description = so.stderr.split($/).last
+ output = description.split
+ if output.length >= 3
+ c[:gcc] = Mash.new
+ c[:gcc][:version] = output[2]
+ c[:gcc][:description] = description
+ end
+ end
+ else
+ Ohai::Log.debug("Xcode Command Line Tools not found.")
+ end
+ else
+ collect("gcc -v") do |so|
+ # Sample output:
+ # Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
+ # Apple LLVM version 7.3.0 (clang-703.0.29)
+ # Target: x86_64-apple-darwin15.4.0
+ # Thread model: posix
+ # InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
+ description = so.stderr.split($/).last
+ output = description.split
+ if output.length >= 3
+ c[:gcc] = Mash.new
+ c[:gcc][:version] = output[2]
+ c[:gcc][:description] = description
+ end
end
end
@@ -102,12 +121,30 @@ Ohai.plugin(:C) do
end
#sun pro
- collect("cc -V -flags") do |so|
- output = so.stderr.split
- if so.stderr =~ /^cc: Sun C/ && output.size >= 4
- c[:sunpro] = Mash.new
- c[:sunpro][:version] = output[3]
- c[:sunpro][:description] = so.stderr.chomp
+ if :darwin
+ Ohai::Log.debug("Checking for Xcode Command Line Tools.")
+ so = shell_out("/usr/bin/xcode-select -p")
+ if so.exitstatus == 0
+ Ohai::Log.debug("Xcode Command Line Tools found.")
+ collect("cc -V -flags") do |so|
+ output = so.stderr.split
+ if so.stderr =~ /^cc: Sun C/ && output.size >= 4
+ c[:sunpro] = Mash.new
+ c[:sunpro][:version] = output[3]
+ c[:sunpro][:description] = so.stderr.chomp
+ end
+ end
+ else
+ Ohai::Log.debug("Xcode Command Line Tools not found.")
+ end
+ else
+ collect("cc -V -flags") do |so|
+ output = so.stderr.split
+ if so.stderr =~ /^cc: Sun C/ && output.size >= 4
+ c[:sunpro] = Mash.new
+ c[:sunpro][:version] = output[3]
+ c[:sunpro][:description] = so.stderr.chomp
+ end
end
end