Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit a70af7c

Browse files
author
Lawson Kurtz
committed
Use semver-compatible compiler version comparisons
Fixes #154
1 parent 95d62fd commit a70af7c

8 files changed

Lines changed: 47 additions & 18 deletions

File tree

ext/libv8/compiler/apple_llvm.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ module Libv8
22
module Compiler
33
class AppleLLVM < Clang
44
LLVM_VERSION_REGEXP = /Apple LLVM version (\d+\.\d+(\.\d+)*) \(/i
5+
REQUIRED_VERSION = '4.3'
56

67
def name
78
'Apple LLVM'
89
end
910

10-
def compatible?
11-
version >= '4.3' unless version.nil?
12-
end
13-
1411
private
1512

13+
def required_version
14+
REQUIRED_VERSION
15+
end
16+
1617
def version_regexp
1718
LLVM_VERSION_REGEXP
1819
end

ext/libv8/compiler/clang.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ module Libv8
22
module Compiler
33
class Clang < GenericCompiler
44
CLANG_VERSION_REGEXP = /clang version (\d+\.\d+(\.\d+)*) \(/i
5+
REQUIRED_VERSION = '3.1'
56

67
def name
78
'clang'
89
end
910

10-
def compatible?
11-
version >= '3.1' unless version.nil?
12-
end
13-
1411
private
1512

13+
def required_version
14+
REQUIRED_VERSION
15+
end
16+
1617
def version_regexp
1718
CLANG_VERSION_REGEXP
1819
end

ext/libv8/compiler/gcc.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ module Libv8
22
module Compiler
33
class GCC < GenericCompiler
44
GCC_VERSION_REGEXP = /gcc version (\d+\.\d+(\.\d+)*)/i
5+
REQUIRED_VERSION = '4.7'
56

67
def name
78
'GCC'
89
end
910

10-
def compatible?
11-
version > '4.7' unless version.nil?
12-
end
13-
1411
private
1512

13+
def required_version
14+
REQUIRED_VERSION
15+
end
16+
1617
def version_regexp
1718
GCC_VERSION_REGEXP
1819
end

ext/libv8/compiler/generic_compiler.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def target
2727
end
2828

2929
def compatible?
30-
false
30+
return false unless required_version && !version.nil?
31+
32+
(string_to_semver(version) <=> string_to_semver(required_version)) > -1
3133
end
3234

3335
def call(*arguments)
@@ -51,6 +53,14 @@ def version_regexp
5153
def target_regexp
5254
GENERIC_TARGET_REGEXP
5355
end
56+
57+
def required_version
58+
nil
59+
end
60+
61+
def string_to_semver(version)
62+
version.split('.').map(&:to_i)
63+
end
5464
end
5565
end
5666
end

spec/compiler/apple_llvm_spec.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@ module Libv8::Compiler
1313

1414
describe '#version' do
1515
it 'returns the version of the compiler' do
16-
stub_as_available 'c++', :apple_llvm, '5.1'
17-
expect(subject.version).to eq '5.1'
16+
stub_as_available 'c++', :apple_llvm, '4.20'
17+
expect(subject.version).to eq '4.20'
1818
end
1919
end
2020

2121
describe '#compatible?' do
2222
context 'when Apple LLVM\'s version is >= 4.3' do
2323
it 'returns true' do
24-
stub_as_available 'c++', :apple_llvm, '5.1'
24+
stub_as_available 'c++', :apple_llvm, '4.20'
2525
expect(subject).to be_compatible
2626
end
2727
end
28+
29+
context 'when Apple LLVM\'s version is < 4.3' do
30+
it 'returns false' do
31+
stub_as_available 'c++', :apple_llvm, '4.2'
32+
expect(subject).to_not be_compatible
33+
end
34+
end
2835
end
2936
end
3037
end

spec/compiler/clang_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ module Libv8::Compiler
2525
expect(subject).to be_compatible
2626
end
2727
end
28+
29+
context 'when clang\'s version is < 3.1' do
30+
it 'returns false' do
31+
stub_as_available 'c++', :clang, '3.0.9'
32+
expect(subject).to_not be_compatible
33+
end
34+
end
2835
end
2936
end
3037
end

spec/compiler_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Libv8
2121
end
2222

2323
it 'recognises correctly Apple\'s LLVM' do
24-
stub_as_available 'c++', :apple_llvm, '5.1'
24+
stub_as_available 'c++', :apple_llvm, '4.20'
2525
expect(Compiler.type_of('c++').new('c++')).to be_a Compiler::AppleLLVM
2626
end
2727
end

spec/support/compiler_helpers.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ module CompilerHelpers
55
"4.9.0" => %Q{Using built-in specs.\nCOLLECT_GCC=c++\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper\nTarget: x86_64-unknown-linux-gnu\nConfigured with: /build/gcc-multilib/src/gcc-4.9-20140604/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --disable-cloog-version-check --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-multilib --disable-werror --enable-checking=release\nThread model: posix\ngcc version 4.9.0 20140604 (prerelease) (GCC)\n}
66
},
77
:clang => {
8+
"3.0.9" => %Q{clang version 3.0.9 (tags/RELEASE_34/dot1-final)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nFound candidate GCC installation: /usr/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\nSelected GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\n},
89
"3.3-freebsd" => %Q{FreeBSD clang version 3.3 (tags/RELEASE_33/final 183502) 20130610\nTarget: i386-unknown-freebsd9.2\nThread model: posix},
910
"3.4.1" => %Q{clang version 3.4.1 (tags/RELEASE_34/dot1-final)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nFound candidate GCC installation: /usr/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\nSelected GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\n},
1011
},
1112
:apple_llvm => {
12-
'5.1' => %Q{Configured with: --prefix=/Applications/Xcode.app/Contents/Developer//usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1\nApple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)\nTarget: x86_64-apple-darwin14.0.0\nThread model: posix\n}
13+
'4.20' => %Q{Configured with: --prefix=/Applications/Xcode.app/Contents/Developer//usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1\nApple LLVM version 4.20 (clang-503.0.38) (based on LLVM 3.4svn)\nTarget: x86_64-apple-darwin14.0.0\nThread model: posix\n},
14+
'4.2' => %Q{Configured with: --prefix=/Applications/Xcode.app/Contents/Developer//usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1\nApple LLVM version 4.2 (clang-503.0.38) (based on LLVM 3.4svn)\nTarget: x86_64-apple-darwin14.0.0\nThread model: posix\n}
1315
}
1416
}
1517

0 commit comments

Comments
 (0)