class Cxxproject::BuildingBlock

Attributes

config_files[R]
config_name[R]
name[R]
output_dir[RW]
output_dir_abs[R]
pre_step[RW]
project_dir[R]
tags[RW]

Public Class Methods

new(name) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 116
def initialize(name)
  @name = name
  @config_name = nil
  @config_files = []
  @config_date = nil
  @project_dir = nil
  @tcs = nil
  @output_dir = nil
  @output_dir_abs = false
  @complete_output_dir = nil
  @pre_step = nil
  @printedCmdAlternate = false
  @lastCommand = nil

  if ALL_BUILDING_BLOCKS.include?(@name)
    existing_bb = ALL_BUILDING_BLOCKS[@name]
    if not (existing_bb.class == BinaryLibrary && self.class == BinaryLibrary)
      raise "building block already exists: #{name} of type #{ALL_BUILDING_BLOCKS[@name].class} conflicts with #{self.class}"
    end
  end
  ALL_BUILDING_BLOCKS[@name] = self
end

Public Instance Methods

add_output_dir_dependency(file, taskOfFile, addDirToCleanTask) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 178
def add_output_dir_dependency(file, taskOfFile, addDirToCleanTask)
  d = File.dirname(file)
  directory d
  taskOfFile.enhance([d])

  if addDirToCleanTask
    CLOBBER.include(complete_output_dir)
    if (@output_dir_abs)
      CLEAN.include(file)
    else
      CLEAN.include(complete_output_dir)
    end
  end
end
additional_path_components() click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 279
def additional_path_components
  []
end
calc_complete_output_dir() click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 108
def calc_complete_output_dir
  if @output_dir_abs
    @output_dir
  else
    File.join(@project_dir,  @output_dir)
  end
end
catch_output(cmd) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 257
def catch_output(cmd)
  new_command = "#{cmd} 2>&1"
  # "/" does not work on windows with backticks, switch the separator on windows:
  new_command.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR
  return `#{new_command}`
end
check_config_file() click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 264
def check_config_file()
  if @config_date
    @config_files.each do |c|
      err_msg = nil
      if File.exists?(c) and File.mtime(c) > @config_date
        @config_date = File.mtime(c)
        begin
          FileUtils.touch(c)
        rescue Exception
        end
      end
    end
  end
end
complete_init() click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 143
def complete_init()
  if self.respond_to?(:calc_compiler_strings)
    calc_compiler_strings
  end
end
complete_output_dir() click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 104
def complete_output_dir
  @complete_output_dir ||= calc_complete_output_dir
end
get_task_name() click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 149
def get_task_name()
  raise "this method must be implemented by decendants"
end
has_tcs?() click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 69
def has_tcs?
  @tcs != nil
end
printCmd(cmd, alternate, showPath) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 193
def printCmd(cmd, alternate, showPath)
  @lastCommand = cmd
  if showPath or (RakeFileUtils.verbose == true) or (alternate.nil? and not Rake::application.options.silent)
    @printedCmdAlternate = false
    exedIn = ""
    exedIn = " (executed in '#{@project_dir}')" if (showPath or (RakeFileUtils.verbose == true))
    puts "" if Rake::application.addEmptyLine
    if cmd.is_a?(Array)
      puts cmd.join(' ') + exedIn
    else
      puts cmd + exedIn
    end
  else
    @printedCmdAlternate = true
    puts alternate unless Rake::application.options.silent
  end
  @lastCommand = cmd
end
process_result(cmd, console_output, error_parser, alternate) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 213
def process_result(cmd, console_output, error_parser, alternate)
  hasError = ($?.success? == false)
  if (cmd != @lastCommand) or (@printedCmdAlternate and hasError)
    printCmd(cmd, alternate, hasError)
  end
  errorPrinted = process_console_output(console_output, error_parser)

  if hasError
    if not errorPrinted
      Printer.printError "Error: system command failed"
      Printer.printError console_output
      res = ErrorDesc.new
      res.file_name = @project_dir
      res.line_number = 0
      res.message = "Unknown error, see log output. Maybe the lake error parser has to be updated..."
      res.severity = ErrorParser::SEVERITY_ERROR
      Rake.application.idei.set_errors([res])
    end
  end
  if hasError or errorPrinted
    raise SystemCommandFailed.new
  end
end
read_file_or_empty_string(filename) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 237
def read_file_or_empty_string(filename)
  begin
    return File.read(filename)
  rescue
    return ""
  end
end
remove_empty_strings_and_join(a, j=' ') click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 253
def remove_empty_strings_and_join(a, j=' ')
  return a.reject{|e|e.to_s.empty?}.join(j)
end
set_config_files(x) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 78
def set_config_files(x)
  @config_files = x
  @config_date = Time.now
  self
end
set_config_name(x) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 139
def set_config_name(x)
  @config_name = x
end
set_name(x) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 59
def set_name(x)
  @name = x
  self
end
set_output_dir(x) click to toggle source

if output dir is absolute, -L and -l is used for linker (“linux mode”)

# File lib/cxxproject/buildingblocks/building_block.rb, line 93
def set_output_dir(x)
  return self if @output_dir

  @output_dir = x
  @output_dir_abs = File.is_absolute?(@output_dir)
  if @project_dir
    @output_dir_relPath = File.rel_from_to_project(@project_dir, @output_dir)
  end
  self
end
set_project_dir(x) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 84
def set_project_dir(x)
  @project_dir = File.expand_path(x)
  if @output_dir_abs
    @output_dir_relPath = File.rel_from_to_project(@project_dir, @output_dir)
  end
  self
end
set_tcs(x) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 64
def set_tcs(x)
  @tcs = x
  self
end
setup_rake_dependencies(task, multitask = nil) click to toggle source

convert all dependencies of a building block to rake task prerequisites (e.g. exe needs lib)

# File lib/cxxproject/buildingblocks/building_block.rb, line 156
def setup_rake_dependencies(task, multitask = nil)
  dependencies.reverse_each do |d|
    begin
      bb = ALL_BUILDING_BLOCKS[d]
      raise "Error: tried to add the dependencies of \"#{d}\" to \"#{@name}\" but such a building block could not be found!" unless bb

      if multitask and bb.pre_step
        multitask.prerequisites.unshift(bb.get_task_name)
      else
        task.prerequisites.unshift(bb.get_task_name)
      end
    rescue ExitHelperException
      raise
    rescue Exception => e
      Printer.printError e.message
      ExitHelper.exit(1)
    end
  end

  task
end
tcs() click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 73
def tcs()
  raise "Toolchain settings must be set before!" unless has_tcs?
  @tcs
end
typed_file_task(type, hash, &block) click to toggle source
# File lib/cxxproject/buildingblocks/building_block.rb, line 245
def typed_file_task(type, hash, &block)
  t = file hash do
    block.call
  end
  t.type = type
  return t
end