Module: Libv8::Compiler

Defined in:
ext/libv8/compiler.rb,
ext/libv8/compiler/gcc.rb,
ext/libv8/compiler/clang.rb,
ext/libv8/compiler/apple_llvm.rb,
ext/libv8/compiler/generic_compiler.rb

Defined Under Namespace

Classes: AppleLLVM, Clang, ExecutionResult, GCC, GenericCompiler

Class Method Summary collapse

Class Method Details

.available?(command) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'ext/libv8/compiler.rb', line 50

def available?(command)
  execute_command("which #{command} 2>&1").status.success?
end

.available_compilers(*compiler_names) ⇒ Object



26
27
28
29
# File 'ext/libv8/compiler.rb', line 26

def available_compilers(*compiler_names)
  available = compiler_names.select { |compiler_name| available? compiler_name }
  available.map { |compiler_name| type_of(compiler_name).new compiler_name }
end

.execute_command(command) ⇒ Object



54
55
56
57
58
# File 'ext/libv8/compiler.rb', line 54

def execute_command(command)
  output = `env LC_ALL=C LANG=C #{command}`
  status = $?
  ExecutionResult.new output, status
end

.type_of(compiler_name) ⇒ Object



31
32
33
34
35
36
37
38
# File 'ext/libv8/compiler.rb', line 31

def type_of(compiler_name)
  case version_string_of(compiler_name)
  when /^Apple LLVM\b/ then AppleLLVM
  when /\bclang\b/i then Clang
  when /^gcc/i then GCC
  else GenericCompiler
  end
end

.version_string_of(compiler_name) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'ext/libv8/compiler.rb', line 40

def version_string_of(compiler_name)
  command_result = execute_command "#{compiler_name} -v 2>&1"

  unless command_result.status.success?
    raise "Could not get version string of compiler #{compiler_name}"
  end

  command_result.output
end

.well_known_compilersObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'ext/libv8/compiler.rb', line 11

def well_known_compilers
  compilers = []

  # The default system compiler
  compilers << 'c++'

  # FreeBSD GCC command names
  compilers += ['g++48', 'g++49', 'g++5', 'g++6', 'g++7']

  # Default compiler names
  compilers += ['clang++', 'g++']

  compilers.uniq
end