-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C Plugin: Expand GCC data & only shellout to gcc if Xcode is installed on macOS #944
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c7dc225
fix gcc and cc for darwin (no cli tools installed)
erikng 7f5878a
refactor c.rb based on PR feedback
erikng 872e075
fixed Chefstyle
erikng b757bd1
move functions to top
erikng 869f4aa
add colons back to debug log
erikng d6bbce1
Further split out platforms in the C plugin
tas50 14b5ce4
Consistent logging
tas50 174849c
Remove extra windows check for glibc
tas50 c869363
Don't check CC on Darwin
tas50 a927aa9
Update GCC sample output
tas50 8531650
Fix gcc data collection
tas50 ddf1d8a
Rework the specs to be platform specific
tas50 90ade0a
Update release notes and chefstyle fixes
tas50 f328bf6
Only look for xlc on AIX and rename collect_cc to collect_sunpro
tas50 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,8 @@ | |
# limitations under the License. | ||
# | ||
|
||
require "rbconfig" | ||
|
||
Ohai.plugin(:C) do | ||
provides "languages/c" | ||
|
||
depends "languages" | ||
|
||
def collect(cmd, &block) | ||
|
@@ -34,94 +31,163 @@ def collect(cmd, &block) | |
Ohai::Log.debug("Plugin C: '#{cmd}' binary could not be found. Skipping data.") | ||
end | ||
|
||
collect_data do | ||
c = Mash.new | ||
def xcode_installed? | ||
Ohai::Log.debug("Plugin C: Checking for Xcode Command Line Tools.") | ||
so = shell_out("/usr/bin/xcode-select -p") | ||
if so.exitstatus == 0 | ||
Ohai::Log.debug("Plugin C: Xcode Command Line Tools found.") | ||
return true | ||
else | ||
Ohai::Log.debug("Plugin C: Xcode Command Line Tools not found.") | ||
return false | ||
end | ||
rescue Ohai::Exceptions::Exec | ||
Ohai::Log.debug("Plugin C: xcode-select binary could not be found. Skipping data.") | ||
end | ||
|
||
#gcc | ||
def collect_gcc | ||
# gcc | ||
# Sample output on os x: | ||
# 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 | ||
# | ||
# | ||
# Sample output on Linux: | ||
# Using built-in specs. | ||
# COLLECT_GCC=gcc | ||
# COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper | ||
# Target: x86_64-linux-gnu | ||
# Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu | ||
# Thread model: posix | ||
# gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) | ||
gcc = Mash.new | ||
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 | ||
so.stderr.each_line do |line| | ||
case line | ||
when /^(.*version\s(\S*).*)/ | ||
gcc[:description] = $1 | ||
gcc[:version] = $2 | ||
when /^Target:\s(.*)/ | ||
gcc[:target] = $1 | ||
when /^Configured with:\s(.*)/ | ||
gcc[:configured_with] = $1 | ||
when /^Thread model:\s(.*)/ | ||
gcc[:thread_model] = $1 | ||
end | ||
end | ||
end | ||
@c[:gcc] = gcc unless gcc.empty? | ||
end | ||
|
||
#glibc | ||
def collect_glibc | ||
# glibc | ||
["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc| | ||
collect( Ohai.abs_path( glibc )) do |so| | ||
description = so.stdout.split($/).first | ||
if description =~ /(\d+\.\d+\.?\d*)/ | ||
c[:glibc] = Mash.new | ||
c[:glibc][:version] = $1 | ||
c[:glibc][:description] = description | ||
@c[:glibc] = Mash.new | ||
@c[:glibc][:version] = $1 | ||
@c[:glibc][:description] = description | ||
end | ||
end unless c[:glibc] || ::RbConfig::CONFIG["host_os"] =~ /mswin|mingw32|windows/ | ||
end | ||
end | ||
end | ||
|
||
#ms cl | ||
def check_for_cl | ||
# ms cl | ||
collect("cl /?") do |so| | ||
description = so.stderr.lines.first.chomp | ||
if description =~ /Compiler Version ([\d\.]+)/ | ||
c[:cl] = Mash.new | ||
c[:cl][:version] = $1 | ||
c[:cl][:description] = description | ||
@c[:cl] = Mash.new | ||
@c[:cl][:version] = $1 | ||
@c[:cl][:description] = description | ||
end | ||
end | ||
end | ||
|
||
#ms vs | ||
def check_for_devenv | ||
# ms vs | ||
collect("devenv.com /?") do |so| | ||
lines = so.stdout.split($/) | ||
description = lines[0].length == 0 ? lines[1] : lines[0] | ||
if description =~ /Visual Studio Version ([\d\.]+)/ | ||
c[:vs] = Mash.new | ||
c[:vs][:version] = $1.chop | ||
c[:vs][:description] = description | ||
@c[:vs] = Mash.new | ||
@c[:vs][:version] = $1.chop | ||
@c[:vs][:description] = description | ||
end | ||
end | ||
end | ||
|
||
#ibm xlc | ||
def collect_xlc | ||
# ibm xlc | ||
begin | ||
so = shell_out("xlc -qversion") | ||
if so.exitstatus == 0 || (so.exitstatus >> 8) == 249 | ||
description = so.stdout.split($/).first | ||
if description =~ /V(\d+\.\d+)/ | ||
c[:xlc] = Mash.new | ||
c[:xlc][:version] = $1 | ||
c[:xlc][:description] = description.strip | ||
@c[:xlc] = Mash.new | ||
@c[:xlc][:version] = $1 | ||
@c[:xlc][:description] = description.strip | ||
end | ||
end | ||
rescue Ohai::Exceptions::Exec | ||
end | ||
end | ||
|
||
#sun pro | ||
def collect_cc | ||
# 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 | ||
@c[:sunpro] = Mash.new | ||
@c[:sunpro][:version] = output[3] | ||
@c[:sunpro][:description] = so.stderr.chomp | ||
end | ||
end | ||
end | ||
|
||
#hpux cc | ||
def collect_hpux_cc | ||
# hpux cc | ||
collect("what /opt/ansic/bin/cc") do |so| | ||
description = so.stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first | ||
if description | ||
output = description.split | ||
c[:hpcc] = Mash.new | ||
c[:hpcc][:version] = output[1] if output.size >= 1 | ||
c[:hpcc][:description] = description.strip | ||
@c[:hpcc] = Mash.new | ||
@c[:hpcc][:version] = output[1] if output.size >= 1 | ||
@c[:hpcc][:description] = description.strip | ||
end | ||
end | ||
end | ||
|
||
collect_data(:darwin) do | ||
@c = Mash.new | ||
collect_gcc if xcode_installed? | ||
languages[:c] = @c unless @c.empty? | ||
end | ||
|
||
collect_data(:windows) do | ||
@c = Mash.new | ||
check_for_cl | ||
check_for_devenv | ||
languages[:c] = @c unless @c.empty? | ||
end | ||
|
||
collect_data(:hpux) do | ||
@c = Mash.new | ||
collect_gcc | ||
collect_hpux_cc | ||
languages[:c] = @c unless @c.empty? | ||
end | ||
|
||
languages[:c] = c unless c.empty? | ||
collect_data(:default) do | ||
@c = Mash.new | ||
collect_gcc | ||
collect_glibc | ||
collect_xlc | ||
collect_cc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
languages[:c] = @c unless @c.empty? | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
believe this is AIX specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed