Class: BaseChip::Configuration

Inherits:
Object
  • Object
show all
Includes:
Base, Dsl, Hierarchy
Defined in:
lib/base_chip/configuration.rb

Instance Attribute Summary

Attributes included from Dsl

#modes

Instance Method Summary collapse

Methods included from Hierarchy

included

Methods included from Base

included

Methods included from Dsl

#add_child_mode_as_child, included, #inherit, #mode, #mode?, #type_plural

Instance Method Details

#action_dereference(name, passive) ⇒ Object



140
141
142
143
144
145
146
147
148
149
# 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_configsObject



85
# File 'lib/base_chip/configuration.rb', line 85

def all_configs ; @all_configs ||= self.subblock_configs + [self] ; end

#bomBaseChip::Bom

create a “Bom” object based on the source code in this configuration, and the selected configurations of it’s subblocks

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# 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) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# 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?Boolean

Returns:



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# 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_directoryObject



250
251
252
253
254
255
256
# 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) ⇒ Object

Defines an alias within this block:configuration pointing to actions, test lists or tests. Equvalent to append_shortcuts

Examples:

create a “build” shortcut pointing to 3 build stages

shortcut :build , %w{stage1 stage2 stage3}

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

shortcut :gate  , %w{build starter       }

See Also:

  • shortcuts


55
56
57
58
# File 'lib/base_chip/configuration.rb', line 55

def shortcut(name, array)
  @shortcuts ||= HashWithIndifferentAccess.new
  @shortcuts[name] = array
end

#subblock_configsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 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) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# 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_configsObject



87
# File 'lib/base_chip/configuration.rb', line 87

def  up_configs ;  @up_configs ||= self. upblock_configs + [self] ; end

#upblock_configsObject



122
123
124
125
126
127
128
129
130
131
# 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