mirror of
https://github.com/rubyjs/libv8
synced 2023-03-27 23:21:48 -04:00
Remove compiler inference support
This commit is contained in:
parent
9d1bc41a79
commit
7cbcb1face
12 changed files with 0 additions and 425 deletions
|
@ -1,39 +0,0 @@
|
|||
require 'rbconfig'
|
||||
require File.expand_path '../compiler/generic_compiler', __FILE__
|
||||
require File.expand_path '../compiler/gcc', __FILE__
|
||||
require File.expand_path '../compiler/clang', __FILE__
|
||||
require File.expand_path '../compiler/apple_llvm', __FILE__
|
||||
|
||||
module Libv8
|
||||
module Compiler
|
||||
module_function
|
||||
|
||||
def type_of(compiler)
|
||||
case version_string_of(compiler)
|
||||
when /^Apple LLVM\b/ then AppleLLVM
|
||||
when /\bclang\b/i then Clang
|
||||
when /^gcc/i then GCC
|
||||
else GenericCompiler
|
||||
end
|
||||
end
|
||||
|
||||
def version_string_of(compiler)
|
||||
command_result = execute_command "env LC_ALL=C LANG=C #{compiler} -v 2>&1"
|
||||
|
||||
unless command_result.status.success?
|
||||
raise "Could not get version string of compiler #{compiler}"
|
||||
end
|
||||
|
||||
command_result.output
|
||||
end
|
||||
|
||||
def execute_command(command)
|
||||
output = `#{command}`
|
||||
status = $?
|
||||
ExecutionResult.new output, status
|
||||
end
|
||||
|
||||
class ExecutionResult < Struct.new(:output, :status)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
module Libv8
|
||||
module Compiler
|
||||
class AppleLLVM < Clang
|
||||
LLVM_VERSION_REGEXP = /Apple LLVM version (\d+\.\d+(\.\d+)*) \(/i
|
||||
REQUIRED_VERSION = '4.3'
|
||||
|
||||
def name
|
||||
'Apple LLVM'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def required_version
|
||||
REQUIRED_VERSION
|
||||
end
|
||||
|
||||
def version_regexp
|
||||
LLVM_VERSION_REGEXP
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
module Libv8
|
||||
module Compiler
|
||||
class Clang < GenericCompiler
|
||||
CLANG_VERSION_REGEXP = /clang version (\d+\.\d+(\.\d+)*) \(/i
|
||||
REQUIRED_VERSION = '3.1'
|
||||
|
||||
def name
|
||||
'clang'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def required_version
|
||||
REQUIRED_VERSION
|
||||
end
|
||||
|
||||
def version_regexp
|
||||
CLANG_VERSION_REGEXP
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
module Libv8
|
||||
module Compiler
|
||||
class GCC < GenericCompiler
|
||||
GCC_VERSION_REGEXP = /gcc version (\d+\.\d+(\.\d+)*)/i
|
||||
REQUIRED_VERSION = '4.7'
|
||||
|
||||
def name
|
||||
'GCC'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def required_version
|
||||
REQUIRED_VERSION
|
||||
end
|
||||
|
||||
def version_regexp
|
||||
GCC_VERSION_REGEXP
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,66 +0,0 @@
|
|||
module Libv8
|
||||
module Compiler
|
||||
class GenericCompiler
|
||||
GENERIC_VERSION_REGEXP = /(\d+\.\d+(\.\d+)*)/
|
||||
GENERIC_TARGET_REGEXP = /Target: ([a-z0-9\-_.]*)/
|
||||
|
||||
def initialize(command)
|
||||
@command = command
|
||||
end
|
||||
|
||||
def name
|
||||
File.basename @command
|
||||
end
|
||||
|
||||
def to_s
|
||||
@command
|
||||
end
|
||||
|
||||
def version
|
||||
version_string =~ version_regexp
|
||||
$1
|
||||
end
|
||||
|
||||
def target
|
||||
version_string =~ target_regexp
|
||||
$1
|
||||
end
|
||||
|
||||
def compatible?
|
||||
return false unless required_version && !version.nil?
|
||||
|
||||
(string_to_semver(version) <=> string_to_semver(required_version)) > -1
|
||||
end
|
||||
|
||||
def call(*arguments)
|
||||
Compiler::execute_command arguments.unshift(@command).join(' ')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def version_string
|
||||
begin
|
||||
Compiler::version_string_of @command
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def version_regexp
|
||||
GENERIC_VERSION_REGEXP
|
||||
end
|
||||
|
||||
def target_regexp
|
||||
GENERIC_TARGET_REGEXP
|
||||
end
|
||||
|
||||
def required_version
|
||||
nil
|
||||
end
|
||||
|
||||
def string_to_semver(version)
|
||||
version.split('.').map(&:to_i)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'compiler'
|
||||
|
||||
module Libv8::Compiler
|
||||
describe AppleLLVM do
|
||||
subject { AppleLLVM.new 'c++' }
|
||||
|
||||
describe '#name' do
|
||||
it 'returns Apple LLVM' do
|
||||
expect(subject.name).to eq 'Apple LLVM'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#version' do
|
||||
it 'returns the version of the compiler' do
|
||||
stub_as_available 'c++', :apple_llvm, '4.20'
|
||||
expect(subject.version).to eq '4.20'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#compatible?' do
|
||||
context 'when Apple LLVM\'s version is >= 4.3' do
|
||||
it 'returns true' do
|
||||
stub_as_available 'c++', :apple_llvm, '4.20'
|
||||
expect(subject).to be_compatible
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Apple LLVM\'s version is < 4.3' do
|
||||
it 'returns false' do
|
||||
stub_as_available 'c++', :apple_llvm, '4.2'
|
||||
expect(subject).to_not be_compatible
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'compiler'
|
||||
|
||||
module Libv8::Compiler
|
||||
describe Clang do
|
||||
subject { Clang.new 'c++' }
|
||||
|
||||
describe '#name' do
|
||||
it 'returns clang' do
|
||||
expect(subject.name).to eq 'clang'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#version' do
|
||||
it 'returns the version of the compiler' do
|
||||
stub_as_available 'c++', :clang, '3.4.1'
|
||||
expect(subject.version).to eq '3.4.1'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#compatible?' do
|
||||
context 'when clang\'s version is >= 3.1' do
|
||||
it 'returns true' do
|
||||
stub_as_available 'c++', :clang, '3.4.1'
|
||||
expect(subject).to be_compatible
|
||||
end
|
||||
end
|
||||
|
||||
context 'when clang\'s version is < 3.1' do
|
||||
it 'returns false' do
|
||||
stub_as_available 'c++', :clang, '3.0.9'
|
||||
expect(subject).to_not be_compatible
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'compiler'
|
||||
|
||||
module Libv8::Compiler
|
||||
describe GCC do
|
||||
subject { GCC.new 'c++' }
|
||||
|
||||
describe '#name' do
|
||||
it 'returns GCC' do
|
||||
expect(subject.name).to eq 'GCC'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#version' do
|
||||
it 'returns the version of the compiler' do
|
||||
stub_as_available 'c++', :gcc, '4.9.0'
|
||||
expect(subject.version).to eq '4.9.0'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#compatible?' do
|
||||
context 'when GCC\'s version is >= 4.8' do
|
||||
it 'returns true' do
|
||||
stub_as_available 'c++', :gcc, '4.9.0'
|
||||
expect(subject).to be_compatible
|
||||
end
|
||||
end
|
||||
|
||||
context 'when GCC\'s version is < 4.3' do
|
||||
it 'returns false' do
|
||||
stub_as_available 'c++', :gcc, '4.2.1-freebsd'
|
||||
expect(subject).to_not be_compatible
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,50 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'compiler'
|
||||
|
||||
module Libv8::Compiler
|
||||
describe GenericCompiler do
|
||||
subject { GenericCompiler.new 'c++' }
|
||||
|
||||
describe '#name' do
|
||||
it 'returns just the base name of the command' do
|
||||
expect(GenericCompiler.new('/usr/sbin/c++').name).to eq 'c++'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_s' do
|
||||
it 'should be the command used to call the compiler' do
|
||||
expect(subject.to_s).to eq 'c++'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#version' do
|
||||
it 'returns the version of the compiler' do
|
||||
stub_as_available 'c++', :clang, '3.4.1'
|
||||
expect(subject.version).to eq '3.4.1'
|
||||
end
|
||||
|
||||
it 'returns nil when determining the version fails' do
|
||||
stub_as_unavailable 'c++'
|
||||
expect(subject.version).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#target' do
|
||||
it 'returns the target of the compiler' do
|
||||
stub_as_available 'c++', :clang, '3.4.1'
|
||||
expect(subject.target).to eq 'x86_64-unknown-linux-gnu'
|
||||
end
|
||||
|
||||
it 'returns nil when determining the target fails' do
|
||||
stub_as_unavailable 'c++'
|
||||
expect(subject.target).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '#compatible?' do
|
||||
it 'returns false' do
|
||||
expect(GenericCompiler.new('c++')).to_not be_compatible
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,45 +0,0 @@
|
|||
require 'spec_helper'
|
||||
require 'compiler'
|
||||
|
||||
module Libv8
|
||||
describe Compiler do
|
||||
describe '::type_of' do
|
||||
it 'recognises correctly GCC' do
|
||||
stub_as_available 'c++', :gcc, '4.9.0'
|
||||
expect(Compiler.type_of('c++').new('c++')).to be_a Compiler::GCC
|
||||
|
||||
stub_as_available 'g++', :gcc, '4.2.1-freebsd'
|
||||
expect(Compiler.type_of('g++').new('g++')).to be_a Compiler::GCC
|
||||
end
|
||||
|
||||
it 'recognises correctly Clang' do
|
||||
stub_as_available 'c++', :clang, '3.4.1'
|
||||
expect(Compiler.type_of('c++').new('c++')).to be_a Compiler::Clang
|
||||
|
||||
stub_as_available 'freebsd-clang++', :clang, '3.3-freebsd'
|
||||
expect(Compiler.type_of('freebsd-clang++').new('freebsd-clang++')).to be_a Compiler::Clang
|
||||
end
|
||||
|
||||
it 'recognises correctly Apple\'s LLVM' do
|
||||
stub_as_available 'c++', :apple_llvm, '4.20'
|
||||
expect(Compiler.type_of('c++').new('c++')).to be_a Compiler::AppleLLVM
|
||||
end
|
||||
end
|
||||
|
||||
describe '::version_string_of' do
|
||||
context 'when calling the compiler command succedes' do
|
||||
it 'returns the version string of the compiler' do
|
||||
stub_as_available 'c++', :clang, '3.4.1'
|
||||
expect(Compiler.version_string_of('c++')).to eq version_output_of(:clang, '3.4.1')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when calling the compiler command fails' do
|
||||
it 'raises an exception' do
|
||||
stub_as_unavailable 'c++'
|
||||
expect { Compiler.version_string_of('c++') }.to raise_exception(RuntimeError, /Could not get version string of compiler/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,4 +2,3 @@ $:.unshift File.expand_path '../../ext/libv8', __FILE__
|
|||
$:.unshift File.expand_path '../../lib', __FILE__
|
||||
require 'rspec'
|
||||
require 'libv8'
|
||||
require File.expand_path '../support/compiler_helpers', __FILE__
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
module CompilerHelpers
|
||||
VERSION_OUTPUTS = {
|
||||
:gcc => {
|
||||
"4.2.1-freebsd" => %Q{Using built-in specs.\nTarget: i386-undermydesk-freebsd\nConfigured with: FreeBSD/i386 system compiler\nThread model: posix\ngcc version 4.2.1 20070831 patched [FreeBSD]\n},
|
||||
"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}
|
||||
},
|
||||
:clang => {
|
||||
"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},
|
||||
"3.3-freebsd" => %Q{FreeBSD clang version 3.3 (tags/RELEASE_33/final 183502) 20130610\nTarget: i386-unknown-freebsd9.2\nThread model: posix},
|
||||
"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},
|
||||
},
|
||||
:apple_llvm => {
|
||||
'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},
|
||||
'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}
|
||||
}
|
||||
}
|
||||
|
||||
def version_output_of(name, version)
|
||||
VERSION_OUTPUTS[name][version]
|
||||
end
|
||||
|
||||
def success_status
|
||||
double :success? => true
|
||||
end
|
||||
|
||||
def failure_status
|
||||
double :success? => false
|
||||
end
|
||||
|
||||
def stub_shell_command(command, output, status)
|
||||
allow(Libv8::Compiler).to receive(:execute_command).with(command) do
|
||||
double :output => output, :status => status
|
||||
end
|
||||
end
|
||||
|
||||
def stub_as_available(command, name, version)
|
||||
stub_shell_command "env LC_ALL=C LANG=C #{command} -v 2>&1", version_output_of(name, version), success_status
|
||||
end
|
||||
|
||||
def stub_as_unavailable(command)
|
||||
stub_shell_command(/^env LC_ALL=C LANG=C #{Regexp.escape(command)}/, '', failure_status)
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.include CompilerHelpers
|
||||
end
|
Loading…
Add table
Reference in a new issue