From 437a3b366ada3d0a1a09ce5b553518792303e815 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Thu, 6 Oct 2016 09:36:54 -0700 Subject: [PATCH 1/7] make ruby tools use x86 directory names for sub-x86 cpu --- src/ruby/tools/bin/grpc_tools_ruby_protoc | 4 +- .../tools/bin/grpc_tools_ruby_protoc_plugin | 3 +- src/ruby/tools/cpu_check.rb | 43 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/ruby/tools/cpu_check.rb diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc b/src/ruby/tools/bin/grpc_tools_ruby_protoc index dab06e7958d..723842bf1e6 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc @@ -31,6 +31,7 @@ require 'rbconfig' require_relative '../os_check' +require_relative '../cpu_check' ext = RbConfig::CONFIG['EXEEXT'] @@ -38,8 +39,7 @@ protoc_name = 'protoc' + ext plugin_name = 'grpc_ruby_plugin' + ext -protoc_dir = File.join(File.dirname(__FILE__), - RbConfig::CONFIG['host_cpu'] + '-' + OS.os_name) +protoc_dir = File.join(File.dirname(__FILE__), CPU.arch + '-' + OS.os_name) protoc_path = File.join(protoc_dir, protoc_name) diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin index 4b296dedc75..773281fa8e6 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin @@ -31,11 +31,12 @@ require 'rbconfig' require_relative '../os_check' +require_relative '../cpu_check' plugin_name = 'grpc_ruby_plugin' + RbConfig::CONFIG['EXEEXT'] plugin_path = File.join(File.dirname(__FILE__), - RbConfig::CONFIG['host_cpu'] + '-' + OS.os_name, + CPU.arch + '-' + OS.os_name, plugin_name) exec([ plugin_path, plugin_path ], *ARGV) diff --git a/src/ruby/tools/cpu_check.rb b/src/ruby/tools/cpu_check.rb new file mode 100644 index 00000000000..9e281242226 --- /dev/null +++ b/src/ruby/tools/cpu_check.rb @@ -0,0 +1,43 @@ +# Copyright 2016, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +require 'rbconfig' + +module CPU + def CPU.arch + case RbConfig::CONFIG['host_cpu'] + when /x86_64/ + 'x86_64' + when /x86|i686/ + 'x86' + else + fail 'cpu architecture detection failed' + end + end +end From 8d970ea2b6411d4bcf01d175cf9a2628b0dd3338 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Thu, 6 Oct 2016 09:55:16 -0700 Subject: [PATCH 2/7] merge os_check and cpu_check into platform_check --- src/ruby/tools/bin/grpc_tools_ruby_protoc | 6 +-- .../tools/bin/grpc_tools_ruby_protoc_plugin | 5 +-- src/ruby/tools/os_check.rb | 45 ------------------- .../tools/{cpu_check.rb => platform_check.rb} | 16 ++++++- 4 files changed, 19 insertions(+), 53 deletions(-) delete mode 100644 src/ruby/tools/os_check.rb rename src/ruby/tools/{cpu_check.rb => platform_check.rb} (84%) diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc b/src/ruby/tools/bin/grpc_tools_ruby_protoc index 723842bf1e6..7e619e74a96 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc @@ -30,8 +30,7 @@ require 'rbconfig' -require_relative '../os_check' -require_relative '../cpu_check' +require_relative '../platform_check' ext = RbConfig::CONFIG['EXEEXT'] @@ -39,7 +38,8 @@ protoc_name = 'protoc' + ext plugin_name = 'grpc_ruby_plugin' + ext -protoc_dir = File.join(File.dirname(__FILE__), CPU.arch + '-' + OS.os_name) +protoc_dir = File.join(File.dirname(__FILE__), + PLATFORM.architecture + '-' + PLATFORM.os_name) protoc_path = File.join(protoc_dir, protoc_name) diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin index 773281fa8e6..e6af2fe3651 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin @@ -30,13 +30,12 @@ require 'rbconfig' -require_relative '../os_check' -require_relative '../cpu_check' +require_relative '../platform_check' plugin_name = 'grpc_ruby_plugin' + RbConfig::CONFIG['EXEEXT'] plugin_path = File.join(File.dirname(__FILE__), - CPU.arch + '-' + OS.os_name, + PLATFORM.architecture + '-' + PLATFORM.os_name, plugin_name) exec([ plugin_path, plugin_path ], *ARGV) diff --git a/src/ruby/tools/os_check.rb b/src/ruby/tools/os_check.rb deleted file mode 100644 index 2677306457b..00000000000 --- a/src/ruby/tools/os_check.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2016, Google Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Google Inc. nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# This is based on http://stackoverflow.com/a/171011/159388 by Aaron Hinni - -require 'rbconfig' - -module OS - def OS.os_name - case RbConfig::CONFIG['host_os'] - when /cygwin|mswin|mingw|bccwin|wince|emx/ - 'windows' - when /darwin/ - 'macos' - else - 'linux' - end - end -end diff --git a/src/ruby/tools/cpu_check.rb b/src/ruby/tools/platform_check.rb similarity index 84% rename from src/ruby/tools/cpu_check.rb rename to src/ruby/tools/platform_check.rb index 9e281242226..e891ec23a81 100644 --- a/src/ruby/tools/cpu_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -29,8 +29,20 @@ require 'rbconfig' -module CPU - def CPU.arch +# This is based on http://stackoverflow.com/a/171011/159388 by Aaron Hinni + +module PLATFORM + def PLATFORM.os_name + case RbConfig::CONFIG['host_os'] + when /cygwin|mswin|mingw|bccwin|wince|emx/ + 'windows' + when /darwin/ + 'macos' + else + 'linux' + end + end + def PLATFORM.architecture case RbConfig::CONFIG['host_cpu'] when /x86_64/ 'x86_64' From fb4509bd73fde1525b07c74b2446c1c365e4f26c Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 12 Oct 2016 14:36:20 -0700 Subject: [PATCH 3/7] add i386 to recognized x86 cpu in ruby tools package --- src/ruby/tools/platform_check.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb index e891ec23a81..c058deb5f5c 100644 --- a/src/ruby/tools/platform_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -46,7 +46,7 @@ module PLATFORM case RbConfig::CONFIG['host_cpu'] when /x86_64/ 'x86_64' - when /x86|i686/ + when /x86|i686|i386/ 'x86' else fail 'cpu architecture detection failed' From 9d45c051e7b7770dd1a799de3ac32eb4fba1f79a Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 12 Oct 2016 15:56:39 -0700 Subject: [PATCH 4/7] enumerate more x86 cpus in ruby tools package --- src/ruby/tools/platform_check.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb index c058deb5f5c..19ea2a07fc1 100644 --- a/src/ruby/tools/platform_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -42,11 +42,15 @@ module PLATFORM 'linux' end end + + # The 'host_cpu' value on x86, 32-bit rubies, appears to turn out to + # be the name of the cpu. Only need to know the architecture, + # so enumerating x86 cpu's here. def PLATFORM.architecture case RbConfig::CONFIG['host_cpu'] when /x86_64/ 'x86_64' - when /x86|i686|i386/ + when /x86|i386|i486|i586|i686|i786/ 'x86' else fail 'cpu architecture detection failed' From 0da964435445bcddcb1fecf55283bcf7e347a509 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 12 Oct 2016 16:32:46 -0700 Subject: [PATCH 5/7] use target cpu to get rid of cpu enumerations --- src/ruby/tools/platform_check.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb index 19ea2a07fc1..2c5ccffdda6 100644 --- a/src/ruby/tools/platform_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -43,14 +43,11 @@ module PLATFORM end end - # The 'host_cpu' value on x86, 32-bit rubies, appears to turn out to - # be the name of the cpu. Only need to know the architecture, - # so enumerating x86 cpu's here. def PLATFORM.architecture - case RbConfig::CONFIG['host_cpu'] + case RbConfig::CONFIG['target_cpu'] when /x86_64/ 'x86_64' - when /x86|i386|i486|i586|i686|i786/ + when /x86|i386/ 'x86' else fail 'cpu architecture detection failed' From aaddb5cb93bd983265002f189ae65e72765c36a5 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Fri, 13 Jan 2017 09:42:12 -0800 Subject: [PATCH 6/7] continue use of host_cpu and use x86 whenever not x86_64 --- src/ruby/tools/platform_check.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb index 2c5ccffdda6..1f4d5a68b71 100644 --- a/src/ruby/tools/platform_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -42,15 +42,13 @@ module PLATFORM 'linux' end end - + def PLATFORM.architecture - case RbConfig::CONFIG['target_cpu'] + case RbConfig::CONFIG['host_cpu'] when /x86_64/ 'x86_64' - when /x86|i386/ - 'x86' else - fail 'cpu architecture detection failed' + 'x86' end end end From 4d08937206b81d0e2462ff2088d2e8cd8fe12233 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Fri, 13 Jan 2017 10:00:50 -0800 Subject: [PATCH 7/7] update grpc-tools.gemspec after with os_check -> plactform_check.rb --- src/ruby/tools/grpc-tools.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ruby/tools/grpc-tools.gemspec b/src/ruby/tools/grpc-tools.gemspec index 68e2a7a1133..bc142ae3cb5 100644 --- a/src/ruby/tools/grpc-tools.gemspec +++ b/src/ruby/tools/grpc-tools.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.description = 'protoc and the Ruby gRPC protoc plugin' s.license = 'BSD-3-Clause' - s.files = %w( version.rb os_check.rb README.md ) + s.files = %w( version.rb platform_check.rb README.md ) s.files += Dir.glob('bin/**/*') s.bindir = 'bin'