Class: Cxx::EvalContext

Inherits:
Object
  • Object
show all
Includes:
Cxxproject, Cxxproject::Context
Defined in:
lib/cxx/eval_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#all_blocksObject

Returns the value of attribute all_blocks.



10
11
12
# File 'lib/cxx/eval_context.rb', line 10

def all_blocks
  @all_blocks
end

Instance Method Details

#attatch_includes(hash, bblock) ⇒ Object



35
36
37
# File 'lib/cxx/eval_context.rb', line 35

def attatch_includes(hash,bblock)
  bblock.set_includes(get_as_array(hash, :includes)) if hash.has_key?(:includes)
end

#attatch_sources(hash, bblock) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/cxx/eval_context.rb', line 24

def attatch_sources(hash,bblock)
  if hash.has_key?(:sources)
    ss = hash[:sources]
    if ss.class == Array || ss.class == Rake::FileList
      bblock.set_sources(ss)
    else
      raise "sources need to be given in an Array or FileList, not a #{ss.class}"
    end
  end
end

#bin_lib(name, hash = Hash.new) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/cxx/eval_context.rb', line 84

def bin_lib(name, hash=Hash.new)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash, [:includes, :lib_path])

  bblock = Cxxproject::BinaryLibrary.new(name)
  attatch_includes(hash,bblock)
  bblock.add_lib_element(Cxxproject::HasLibraries::SEARCH_PATH, hash[:lib_path], true) if hash.has_key?(:lib_path)
  return bblock
end

#bin_libs(names, hash = Hash.new) ⇒ Object

specify some binary libs returns all binary libs as array



96
97
98
99
100
101
102
# File 'lib/cxx/eval_context.rb', line 96

def bin_libs(names, hash=Hash.new)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash, [:includes, :lib_path])

  mapped = names.map{|n|n.to_s}
  return mapped.map{|name|bin_lib(name, hash)}
end

#compile(name, hash) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/cxx/eval_context.rb', line 104

def compile(name, hash)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash,[:sources,:includes])
  bblock = Cxxproject::SingleSource.new(name)
  attatch_sources(hash,bblock)
  attatch_includes(hash,bblock)
  all_blocks << bblock
end

#custom(name, hash) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/cxx/eval_context.rb', line 113

def custom(name, hash)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash,[:execute, :dependencies])
  bblock = Cxxproject::CustomBuildingBlock.new(name)
  bblock.set_actions(hash[:execute]) if hash.has_key?(:execute)
  if hash.has_key?(:dependencies)
    bblock.set_dependencies(hash[:dependencies])
  end
  all_blocks << bblock
end

#cxx_configuration(&block) ⇒ Object

must be called to add building blocks



13
14
15
16
# File 'lib/cxx/eval_context.rb', line 13

def cxx_configuration(&block)
  @all_blocks = []
  block.call
end

#eval_project(project_text, project_file, pwd) ⇒ Object



18
19
20
21
22
# File 'lib/cxx/eval_context.rb', line 18

def eval_project(project_text, project_file, pwd)
  @current_project_file = project_file
  @current_working_dir = pwd
  instance_eval(project_text)
end

#exe(name, hash) ⇒ Object

specify an executable hash supports:

  • :sources

  • :includes

  • :dependencies

  • :output_dir



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cxx/eval_context.rb', line 45

def exe(name, hash)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash,[:sources,:includes,:dependencies,:libpath,:output_dir])
  bblock = Cxxproject::Executable.new(name)
  attatch_sources(hash,bblock)
  attatch_includes(hash,bblock)
  if hash.has_key?(:dependencies)
    bblock.set_dependencies(hash[:dependencies])
    hash[:dependencies].each { |d| bblock.add_lib_element(Cxxproject::HasLibraries::DEPENDENCY, d) }
  end
  bblock.set_output_dir(hash[:output_dir]) if hash.has_key?(:output_dir)
  all_blocks << bblock
end

#source_lib(name, hash) ⇒ Object

specify a sourcelib hash supports:

  • :sources

  • :includes

  • :dependencies

  • :toolchain

  • :file_dependencies

  • :output_dir



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cxx/eval_context.rb', line 67

def source_lib(name, hash)
  raise "not a hash" unless hash.is_a?(Hash)
  check_hash(hash, [:sources, :includes, :dependencies, :toolchain, :file_dependencies, :output_dir, :whole_archive])
  raise ":sources need to be defined" unless hash.has_key?(:sources)
  bblock = Cxxproject::SourceLibrary.new(name, hash[:whole_archive])
  attatch_sources(hash,bblock)
  attatch_includes(hash,bblock)
  bblock.set_tcs(hash[:toolchain]) if hash.has_key?(:toolchain)
  if hash.has_key?(:dependencies)
    bblock.set_dependencies(hash[:dependencies])
    hash[:dependencies].each { |d| bblock.add_lib_element(Cxxproject::HasLibraries::DEPENDENCY, d) }
  end
  bblock.file_dependencies = hash[:file_dependencies] if hash.has_key?(:file_dependencies)
  bblock.set_output_dir(hash[:output_dir]) if hash.has_key?(:output_dir)
  all_blocks << bblock
end