class BaseChip::Configuration

Public Instance Methods

action_dereference(name,passive) click to toggle source

@private

# File lib/base_chip/configuration.rb, line 140
def action_dereference(name,passive)
  if action = @actions[name]
    action.deep_configure
    [action]
  elsif passive
    []
  else
    fault "Could not find action or shortcut #{n} in configuration #{full_name}" # FIXME say who wanted it, and if shortcut occurred
  end
end
all_configs() click to toggle source

@private

# File lib/base_chip/configuration.rb, line 85
def all_configs ; @all_configs ||= self.subblock_configs + [self] ; end
bom() click to toggle source

create a “Bom” object based on the source code in this configuration, and the selected configurations of it’s subblocks @return [BaseChip::Bom]

# File lib/base_chip/configuration.rb, line 62
def bom
  return @bom if @bom
  hash = HashWithIndifferentAccess.new
  all_configs.each do |sc|
    sc.configure
    next unless sc.source_types
    sc.source_types.each do |stn,st|
      next if sc != self and stn.to_s =~ /^top/
      st.configure
      next unless st.source_languages
      hash[stn] ||= HashWithIndifferentAccess.new
      tmp = hash[stn]
      st.source_languages.each do |sln,sl|
        sl.configure
        tmp[sln] ||= []
        tmp[sln]  += sl.files
      end
    end
  end

  @bom = Bom.new(hash)
end
dereference_workload(names = nil,passive=false) click to toggle source

@private

# File lib/base_chip/configuration.rb, line 162
def dereference_workload(names = nil,passive=false)
  configure
  names = names ? names.dup : ['all']
  if @shortcuts
    loop do # dereference shortcuts
      found = false
      names.map! do |n| # FIXME error if shortcuts contain 'all' or 'gate'
        if a = @shortcuts[n.to_sym]
          found = n
          a 
        else
          n 
        end
      end
      if found
        names.flatten!
        # TODO Catch infinite shortcut loop
      else
        break
      end
    end
  end

  out        = Array.new
  test_lists = HashWithIndifferentAccess.new
  names.each do |n|
    n = n.to_s
    case n
    when 'upgate'   ;  up_configs.each {|c| out += c.dereference_workload(['gate'], true)}
    when 'downgate' ; all_configs.each {|c| out += c.dereference_workload(['gate'], true)}
    when 'diffgate' ;
      all_configs.each do |c|
        if c.files_changed?
          out += self.dereference_workload(['upgate'], true)
          break
        end
      end
    when 'all'      # FIXME , 'alltests', 'allactions'
      if @actions   ; @actions        .each { |k,v| out +=    action_dereference(k,          true) unless v.abstract } end
      if @test_lists; @test_lists.keys.each { |k  | out += test_list_dereference(k, ['all'], true)                   } end
    when /^all:(.*)$/
      tmp = $1
      @test_lists.each_key do |k|
        out += test_list_dereference k, [tmp], passive
      end
    when /^(.*?):(.*)$/
      out += test_list_dereference $1.to_sym, [$2], passive
    else
      fault "No actions or test lists specified for configuration #{full_name}" unless @actions || @test_lists || passive
      if    @actions    && @actions[n.to_sym]
        out += action_dereference n.to_sym, passive
      elsif @test_lists && @test_lists[n.to_sym]
        out += test_list_dereference n.to_sym, ['all'], true
      else
        fault "Could not find action, test list, or shortcut named #{n} in configuration #{full_name}" unless passive # FIXME say who wanted it, and if shortcut occurred
      end
    end
  end
  out.uniq!
  out
end
files_changed?() click to toggle source

@private

# File lib/base_chip/configuration.rb, line 224
def files_changed?
  my_dirs = [                   "base_chip",
             "#{block.directory}/base_chip",
             "#{self .directory}/base_chip"]
  if self.source_types
    self.source_types.values.each do |st|
      next unless st.source_languages
      st.source_languages.values.each do |sl|
        my_dirs += sl.directories if sl.directories
      end
    end
  end
            
  BaseChip.version_control.changed.each do |theirs|
    my_dirs.each do |mine|
      mine = mine.gsub(/#{Regexp.escape project.directory}\/?\b/,'')
      if theirs =~ /#{Regexp.escape mine}\b/
        puts "theirs = #{theirs} mine = #{mine}"
        return true
      end
    end
  end
  false
end
out_directory() click to toggle source

@private

# File lib/base_chip/configuration.rb, line 250
def out_directory
  @out_directory ||= if BaseChip.options.out_dir
                       BaseChip.options.out_dir
                     else
                       @directory + '/out'
                     end
end
shortcut(name, array) click to toggle source

Defines an alias within this block:configuration pointing to actions, test lists or tests. Equvalent to {append_shortcuts} @example create a “build” shortcut pointing to 3 build stages

shortcut :build , %w{stage1 stage2 stage3}

@example create a “gate” shortcut to build (from the above example) and run the starter list

shortcut :gate  , %w{build starter       }

@see shortcuts

# File lib/base_chip/configuration.rb, line 55
def shortcut(name, array)
  @shortcuts ||= HashWithIndifferentAccess.new
  @shortcuts[name] = array
end
subblock_configs() click to toggle source

@private

# File lib/base_chip/configuration.rb, line 89
def subblock_configs
  return @subblock_configs if @subblock_configs
  configure
  @subblock_configs = []
  return @subblock_configs unless @subblocks
  @subblocks.map do |s|
    full    = s.to_s.split(/:/)

    if @project.subprojects && (project = @project.subprojects[full[0].to_sym])
      full.shift
      project.configure
    else
      project = @project
    end

    block = project.blocks[full[0].to_sym]
    if block
      full.shift
    elsif project != @project
      fault "couldn't find block '#{full[0]}' in project '#{project.name}' needed by #{full_name} as subblock"
    else
      fault "couldn't find block/subproject '#{full[0]}' needed by #{full_name} as subblock"
    end
    block.configure

    full[0] ||= :default
    c = block.configurations[full[0].to_sym] || (fault "couldn't find configuration '#{full[1]}' for block '#{block.full_name}' needed by #{full_name} as subblock")
    @subblock_configs += c.all_configs
  end
  @subblock_configs.uniq!
  @subblock_configs
end
test_list_dereference(name,names,passive) click to toggle source

@private

# File lib/base_chip/configuration.rb, line 151
def test_list_dereference(name,names,passive)
  if test_list = @test_lists[name]
    test_list.deep_configure
    test_list.dereference_workload(names,passive)
  elsif passive
    []
  else
    fault "Could not find test list or shortcut #{n} in configuration #{full_name}" # FIXME say who wanted it, and if shortcut occurred
  end
end
up_configs() click to toggle source

@private

# File lib/base_chip/configuration.rb, line 87
def  up_configs ;  @up_configs ||= self. upblock_configs + [self] ; end
upblock_configs() click to toggle source

@private

# File lib/base_chip/configuration.rb, line 122
def upblock_configs
  return @upblock_configs if @upblock_configs
  configure
  @upblock_configs = []
  BaseChip.configurations.each do |c|
    @upblock_configs << c if c.all_configs.include? self
  end
  @upblock_configs.uniq!
  @upblock_configs
end