Class: Cxxproject::BuildingBlock

Inherits:
Object
  • Object
show all
Includes:
HasDependencies
Defined in:
lib/cxxproject/buildingblocks/building_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasDependencies

#add_unique, #all_dependencies, #all_dependencies_recursive, #collect_dependencies, #convert_named_values_to_string, #dependencies, #direct_deps, #helper_dependencies, #resolve_by_name, #set_dependencies, #set_helper_dependencies

Constructor Details

#initialize(name) ⇒ BuildingBlock

Returns a new instance of BuildingBlock.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# 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

Instance Attribute Details

#config_filesObject (readonly)

Returns the value of attribute config_files.



51
52
53
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 51

def config_files
  @config_files
end

#config_nameObject (readonly)

Returns the value of attribute config_name.



50
51
52
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 50

def config_name
  @config_name
end

#nameObject (readonly)

Returns the value of attribute name.



49
50
51
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 49

def name
  @name
end

#output_dirObject

Returns the value of attribute output_dir.



54
55
56
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 54

def output_dir
  @output_dir
end

#output_dir_absObject (readonly)

Returns the value of attribute output_dir_abs.



56
57
58
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 56

def output_dir_abs
  @output_dir_abs
end

#pre_stepObject

Returns the value of attribute pre_step.



55
56
57
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 55

def pre_step
  @pre_step
end

#project_dirObject (readonly)

Returns the value of attribute project_dir.



53
54
55
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 53

def project_dir
  @project_dir
end

#tagsObject

Returns the value of attribute tags.



57
58
59
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 57

def tags
  @tags
end

Instance Method Details

#add_output_dir_dependency(file, taskOfFile, addDirToCleanTask) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# 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_componentsObject



279
280
281
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 279

def additional_path_components
  []
end

#calc_complete_output_dirObject



108
109
110
111
112
113
114
# 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) ⇒ Object



257
258
259
260
261
262
# 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_fileObject



264
265
266
267
268
269
270
271
272
273
274
275
276
277
# 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_initObject



143
144
145
146
147
# 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_dirObject



104
105
106
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 104

def complete_output_dir
  @complete_output_dir ||= calc_complete_output_dir
end

#get_task_nameObject



149
150
151
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 149

def get_task_name()
  raise "this method must be implemented by decendants"
end

#has_tcs?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 69

def has_tcs?
  @tcs != nil
end

#printCmd(cmd, alternate, showPath) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# 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) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# 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) ⇒ Object



237
238
239
240
241
242
243
# 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 = ' ') ⇒ Object



253
254
255
# 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) ⇒ Object



78
79
80
81
82
# 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) ⇒ Object



139
140
141
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 139

def set_config_name(x)
  @config_name = x
end

#set_name(x) ⇒ Object



59
60
61
62
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 59

def set_name(x)
  @name = x
  self
end

#set_output_dir(x) ⇒ Object

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



93
94
95
96
97
98
99
100
101
102
# 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) ⇒ Object



84
85
86
87
88
89
90
# 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) ⇒ Object



64
65
66
67
# File 'lib/cxxproject/buildingblocks/building_block.rb', line 64

def set_tcs(x)
  @tcs = x
  self
end

#setup_rake_dependencies(task, multitask = nil) ⇒ Object

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



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# 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

#tcsObject



73
74
75
76
# 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) ⇒ Object



245
246
247
248
249
250
251
# 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