class Cxxproject::PluginContext

context in which plugins are evaluated a cxx_plugin is a gem that:

the context contains

Public Class Methods

create_no_args_context() click to toggle source
# File lib/cxxproject/plugin_context.rb, line 18
def self.create_no_args_context
  return PluginContext.new(nil, nil, nil, 0)
end
create_three_args_context(cxx, building_blocks, log) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 22
def self.create_three_args_context(cxx, building_blocks, log)
  return PluginContext.new(cxx, building_blocks, log, 3)
end
expand(toolchain) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 64
def self.expand(toolchain)
  to_expand = nil
  from = nil
  while (needs_expansion(toolchain)) do
    to_expand = find_toolchain_subhash(toolchain)
    from = find_toolchain_element(toolchain,to_expand[:BASED_ON])
    to_expand.delete(:BASED_ON)
    Cxxproject::Toolchain::Provider.merge(to_expand, from, false)
  end
  return toolchain
end
find_toolchain_element(tc,name) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 107
def self.find_toolchain_element(tc,name)
  res = []
  loop = lambda do |res,tc,name|
    tc.each do |k,v|
      if k == name
        res << v
      elsif v.is_a?(Hash)
        loop.call(res,v,name)
      end
    end
  end
  loop.call(res,tc,name)
  return res[0] if res.length > 0
end
find_toolchain_subhash(tc) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 91
def self.find_toolchain_subhash(tc)
  res = []
  loop = lambda do |res,tc|
    tc.each do |k,v|
      if(k == :BASED_ON)
        res << tc
      elsif v.is_a?(Hash)
        loop.call(res,v)
      end
    end
  end
  loop.call(res,tc)
  return res[0] if res.length > 0
end
needs_expansion(tc) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 76
def self.needs_expansion(tc)
  res = false
  tc.each do |k,v|
    if k == :BASED_ON
      res = true
    elsif v.is_a?(Hash)
      res = needs_expansion(v)
    end
    if res
      break
    end
  end
  return res
end
new(cxxproject2rake, building_blocks, log, expected_arity) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 26
def initialize(cxxproject2rake, building_blocks, log, expected_arity)
  @cxxproject2rake = cxxproject2rake
  @building_blocks = building_blocks
  @log = log
  @expected_arity = expected_arity
end

Public Instance Methods

check_archiver(hash) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 138
def check_archiver(hash)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash, Cxxproject::Toolchain::Provider.default[:ARCHIVER].keys)
end
check_compiler(hash) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 125
def check_compiler(hash)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash, Cxxproject::Toolchain::Provider.default[:COMPILER].keys)
  [:CPP, :C, :ASM].each do |sym|
    check_compiler_hash(hash, sym)
  end
end
check_compiler_hash(hash, sym) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 122
def check_compiler_hash(hash, sym)
  check_hash(hash[sym], Cxxproject::Toolchain::Provider.default[:COMPILER][sym].keys << :BASED_ON) if hash[sym]
end
check_linker(hash) click to toggle source
# File lib/cxxproject/plugin_context.rb, line 133
def check_linker(hash)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash, Cxxproject::Toolchain::Provider.default[:LINKER].keys)
end
cxx_plugin(&blk) click to toggle source

method for plugins to get the cxxproject2rake building_blocks log

# File lib/cxxproject/plugin_context.rb, line 37
def cxx_plugin(&blk)
  if blk.arity != @expected_arity
    return
  end

  case blk.arity
  when 0
    blk.call()
  when 3
    blk.call(@cxxproject2rake, @building_blocks, @log)
  end
end
eval_plugin(plugin_text) click to toggle source

will use the content of the plugin.rb file and evaluate it this will in turn result in a call to cxx_plugin

# File lib/cxxproject/plugin_context.rb, line 145
def eval_plugin(plugin_text)
  instance_eval(plugin_text)
end
toolchain(name, tc) click to toggle source

specify a toolchain hash supports:

  • :command

# File lib/cxxproject/plugin_context.rb, line 53
def toolchain(name, tc)
  raise "not a tc" unless tc.is_a?(Hash)
  check_hash(tc, Cxxproject::Toolchain::Provider.default.keys)
  check_compiler(tc[:COMPILER]) if tc[:COMPILER]
  check_linker(tc[:LINKER]) if tc[:LINKER]
  check_archiver(tc[:ARCHIVER]) if tc[:ARCHIVER]
  PluginContext::expand(tc)
  Cxxproject::Toolchain::Provider.add(name)
  Cxxproject::Toolchain::Provider.merge(Cxxproject::Toolchain::Provider[name], tc)
end