Class: Bake::Blocks::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/blocks/block.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, referencedConfigs) ⇒ Block

Returns a new instance of Block.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/blocks/block.rb', line 57

def initialize(config, referencedConfigs)
  @inDeps = false
  @circularCheck
  @visited = false
  @library = nil
  @config = config
  @referencedConfigs = referencedConfigs
  @projectName = config.parent.name
  @configName = config.name
  @projectDir = config.get_project_dir
  @@block_counter = 0
  @result = true
  
  @lib_elements = Bake::LibElements.calcLibElements(self)
end

Instance Attribute Details

#circularCheckObject

Returns the value of attribute circularCheck.



19
20
21
# File 'lib/blocks/block.rb', line 19

def circularCheck
  @circularCheck
end

#configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/blocks/block.rb', line 18

def config
  @config
end

#inDepsObject

Returns the value of attribute inDeps.



19
20
21
# File 'lib/blocks/block.rb', line 19

def inDeps
  @inDeps
end

#lib_elementsObject (readonly)

Returns the value of attribute lib_elements.



18
19
20
# File 'lib/blocks/block.rb', line 18

def lib_elements
  @lib_elements
end

#libraryObject (readonly)

Returns the value of attribute library.



18
19
20
# File 'lib/blocks/block.rb', line 18

def library
  @library
end

#projectDirObject (readonly)

Returns the value of attribute projectDir.



18
19
20
# File 'lib/blocks/block.rb', line 18

def projectDir
  @projectDir
end

#projectNameObject (readonly)

Returns the value of attribute projectName.



18
19
20
# File 'lib/blocks/block.rb', line 18

def projectName
  @projectName
end

#resultObject

Returns the value of attribute result.



19
20
21
# File 'lib/blocks/block.rb', line 19

def result
  @result
end

#visitedObject

Returns the value of attribute visited.



19
20
21
# File 'lib/blocks/block.rb', line 19

def visited
  @visited
end

Class Method Details

.block_counterObject



122
123
124
# File 'lib/blocks/block.rb', line 122

def self.block_counter
  @@block_counter += 1
end

.reset_block_counterObject



126
127
128
# File 'lib/blocks/block.rb', line 126

def self.reset_block_counter
  @@block_counter = 0
end

.set_num_projects(num) ⇒ Object



130
131
132
# File 'lib/blocks/block.rb', line 130

def self.set_num_projects(num)
  @@num_projects = num
end

Instance Method Details

#add_lib_element(elem) ⇒ Object



73
74
75
# File 'lib/blocks/block.rb', line 73

def add_lib_element(elem)
  @lib_elements[2000000000] = [elem]
end

#callDeps(method) ⇒ Object



158
159
160
161
162
163
164
165
# File 'lib/blocks/block.rb', line 158

def callDeps(method)
  depResult = true
  dependencies.each do |dep|
    depResult = (ALL_BLOCKS[dep].send(method) and depResult)
    break if not depResult and Bake.options.stopOnFirstError
  end
  return depResult
end

#callSteps(method) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/blocks/block.rb', line 167

def callSteps(method)
  
  preSteps.each do |step|
    @result = executeStep(step, method) if @result
    return false if not @result and Bake.options.stopOnFirstError
  end
  
  mainSteps.each do |step|
    @result = executeStep(step, method) if @result
    return false if not @result and Bake.options.stopOnFirstError
  end
  
  postSteps.each do |step|
    @result = executeStep(step, method) if @result
    return false if not @result and Bake.options.stopOnFirstError
  end
  
  return @result        
end

#childsObject



45
46
47
# File 'lib/blocks/block.rb', line 45

def childs
  @childs ||= []
end

#cleanObject



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/blocks/block.rb', line 213

def clean
  return true if (@visited)
  @visited = true

  depResult = callDeps(:clean)
  return false if not depResult and Bake.options.stopOnFirstError
  
  if Bake.options.verbose >= 2
    Bake.formatter.printAdditionalInfo "**** Cleaning #{Block.block_counter} of #{@@num_projects}: #{@projectName} (#{@configName}) ****"     
  end
  
  @result = callSteps(:clean)
  
  if Bake.options.clobber
    Dir.chdir(@projectDir) do
      if File.exist?".bake" 
        puts "Deleting folder .bake" if Bake.options.verbose >= 2
        FileUtils.rm_rf(".bake")
      end
    end          
  end
  
  return (depResult && @result)
end

#convPath(dir, elem = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
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
# File 'lib/blocks/block.rb', line 77

def convPath(dir, elem=nil)
  if dir.respond_to?("name")
    d = dir.name
    elem = dir
  else
    d = dir
  end
  
  return d if Bake.options.no_autodir
  
  inc = d.split("/")
  if (inc[0] == @projectName)
    res = inc[1..-1].join("/") # within self

    res = "." if res == "" 
  elsif @referencedConfigs.include?(inc[0])
    dirOther = @referencedConfigs[inc[0]].first.parent.get_project_dir
    res = File.rel_from_to_project(@projectDir, dirOther, false)
    postfix = inc[1..-1].join("/")
    res = res + "/" + postfix if postfix != ""
  else
    if (inc[0] != "..")
      return d if File.exists?(@projectDir + "/" + d) # e.g. "include"

    
      # check if dir exists without Project.meta entry

      Bake.options.roots.each do |r|
        absIncDir = r+"/"+d
        if File.exists?(absIncDir)
          res = File.rel_from_to_project(@projectDir,absIncDir,false)
          if not res.nil?
            return res
          end 
        end
      end
    else
      if elem and Bake.options.verbose >= 2
        Bake.formatter.printInfo("\"..\" in path name found", elem)
      end
    end
    
    res = d # relative from self as last resort

  end
  res
end

#dependenciesObject



41
42
43
# File 'lib/blocks/block.rb', line 41

def dependencies
  @dependencies ||= []
end

#executeObject



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
# File 'lib/blocks/block.rb', line 187

def execute
  if (@inDeps)
    if Bake.options.verbose >= 1
      Bake.formatter.printWarning("Circular dependency found including project #{@projectName} with config #{@configName}", @config)
    end
    return true
  end

  return true if (@visited)
  @visited = true
   
  @inDeps = true
  depResult = callDeps(:execute)
  @inDeps = false
  return false if not depResult and Bake.options.stopOnFirstError
  
  Bake::IDEInterface.instance.set_build_info(@projectName, @configName)
  
  if Bake.options.verbose >= 1
    Bake.formatter.printAdditionalInfo "**** Building #{Block.block_counter} of #{@@num_projects}: #{@projectName} (#{@configName}) ****"     
  end

  @result = callSteps(:execute)
  return (depResult && @result)
end

#executeStep(step, method) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/blocks/block.rb', line 134

def executeStep(step, method)
  begin
    @result = step.send(method) && @result
  rescue Bake::SystemCommandFailed => scf
    @result = false
    ProcessHelper.killProcess(true)
  rescue SystemExit => exSys
    @result = false
    ProcessHelper.killProcess(true)
  rescue Exception => ex1
    @result = false
    if not Bake::IDEInterface.instance.get_abort
      Bake.formatter.printError("Error: #{ex1.message}")
      puts ex1.backtrace if Bake.options.debug
    end
  end 
  
  if Bake::IDEInterface.instance.get_abort
    raise AbortException.new
  end

  return @result
end

#exitsObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/blocks/block.rb', line 255

def exits
  return true if (@visited)
  @visited = true

  depResult = callDeps(:exits)
  
  if Bake.options.verbose >= 1 and not exitSteps.empty?
    Bake.formatter.printAdditionalInfo "**** Exiting #{@projectName} (#{@configName}) ****"     
  end
  
  exitSteps.each do |step|
    @result = executeStep(step, :exitStep) && @result
  end
  
  return (depResult && @result)
end

#exitStepsObject



37
38
39
# File 'lib/blocks/block.rb', line 37

def exitSteps
  @exitSteps ||= []
end

#mainStepsObject



29
30
31
# File 'lib/blocks/block.rb', line 29

def mainSteps
  @mainSteps ||= []
end

#parentsObject



49
50
51
# File 'lib/blocks/block.rb', line 49

def parents
  @parents ||= []
end

#postStepsObject



33
34
35
# File 'lib/blocks/block.rb', line 33

def postSteps
  @postSteps ||= []
end

#preStepsObject



25
26
27
# File 'lib/blocks/block.rb', line 25

def preSteps
  @preSteps ||= []
end

#set_library(library) ⇒ Object



53
54
55
# File 'lib/blocks/block.rb', line 53

def set_library(library)
  @library = library
end

#startupObject



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/blocks/block.rb', line 238

def startup
  return true if (@visited)
  @visited = true

  depResult = callDeps(:startup)
          
  if Bake.options.verbose >= 1 and not startupSteps.empty? 
    Bake.formatter.printAdditionalInfo "**** Starting up #{@projectName} (#{@configName}) ****"     
  end
  
  startupSteps.each do |step|
    @result = executeStep(step, :startupStep) && @result
  end
  
  return (depResult && @result)
end

#startupStepsObject



21
22
23
# File 'lib/blocks/block.rb', line 21

def startupSteps
  @startupSteps ||= []
end