Class: Bake::ToCxx
- Inherits:
-
Object
- Object
- Bake::ToCxx
- Defined in:
- lib/tocxx.rb
Constant Summary collapse
- @@linkBlock =
0
Class Method Summary collapse
Instance Method Summary collapse
- #addDependencies(block, configDeps) ⇒ Object
- #addSteps(block, blockSteps, configSteps) ⇒ Object
- #calcStartBlocks ⇒ Object
- #callBlock(block, method) ⇒ Object
- #callBlocks(startBlocks, method) ⇒ Object
- #connect ⇒ Object
- #convert2bb ⇒ Object
- #createBaseTcsForConfig ⇒ Object
- #createTcsForConfig ⇒ Object
- #disconnect ⇒ Object
- #doit ⇒ Object
-
#initialize ⇒ ToCxx
constructor
A new instance of ToCxx.
- #substVars ⇒ Object
Constructor Details
#initialize ⇒ ToCxx
Returns a new instance of ToCxx.
50 51 52 |
# File 'lib/tocxx.rb', line 50 def initialize @configTcMap = {} end |
Class Method Details
.linkBlock ⇒ Object
46 47 48 |
# File 'lib/tocxx.rb', line 46 def self.linkBlock @@linkBlock = 1 end |
Instance Method Details
#addDependencies(block, configDeps) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/tocxx.rb', line 94 def addDependencies(block, configDeps) configDeps.each do |dep| @loadedConfig.referencedConfigs[dep.name].each do |config| if config.name == dep.config block.dependencies << config.qname break end end end end |
#addSteps(block, blockSteps, configSteps) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/tocxx.rb', line 84 def addSteps(block, blockSteps, configSteps) Array(configSteps.step).each do |step| if Bake::Metamodel::Makefile === step blockSteps << Blocks::Makefile.new(step, @loadedConfig.referencedConfigs, block) elsif Bake::Metamodel::CommandLine === step blockSteps << Blocks::CommandLine.new(step, @loadedConfig.referencedConfigs) end end if configSteps end |
#calcStartBlocks ⇒ Object
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 |
# File 'lib/tocxx.rb', line 177 def calcStartBlocks startProjectName = nil startConfigName = nil if Bake..project splitted = Bake..project.split(',') startProjectName = splitted[0] startConfigName = splitted[1] if splitted.length == 2 end if startConfigName blockName = startProjectName+","+startConfigName if not Blocks::ALL_BLOCKS.include?(startProjectName+","+startConfigName) Bake.formatter.printError("Error: project #{startProjectName} with config #{startConfigName} not found") ExitHelper.exit(1) end startBlocks = [Blocks::ALL_BLOCKS[startProjectName+","+startConfigName]] Blocks::Block.set_num_projects(1) elsif startProjectName startBlocks = [] Blocks::ALL_BLOCKS.each do |blockName, block| if blockName.start_with?(startProjectName + ",") startBlocks << block end end if startBlocks.length == 0 Bake.formatter.printError("Error: project #{startProjectName} not found") ExitHelper.exit(1) end startBlocks.reverse! # most probably the order of dependencies if any Blocks::Block.set_num_projects(startBlocks.length) else startBlocks = [Blocks::ALL_BLOCKS[Bake..main_project_name+","+Bake..build_config]] Blocks::Block.set_num_projects(Blocks::ALL_BLOCKS.length) end return startBlocks end |
#callBlock(block, method) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/tocxx.rb', line 152 def callBlock(block, method) begin return block.send(method) rescue AbortException raise rescue Exception => ex if Bake..debug puts ex. puts ex.backtrace end return false end end |
#callBlocks(startBlocks, method) ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/tocxx.rb', line 166 def callBlocks(startBlocks, method) Blocks::ALL_BLOCKS.each {|name,block| block.visited = false; block.result = false; block.inDeps = false } Blocks::Block.reset_block_counter result = true startBlocks.each do |block| result = callBlock(block, method) && result return false if not result and Bake..stopOnFirstError end return result end |
#connect ⇒ Object
354 355 356 357 358 |
# File 'lib/tocxx.rb', line 354 def connect() if Bake..socket != 0 Bake::IDEInterface.instance.connect(Bake..socket) end end |
#convert2bb ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/tocxx.rb', line 105 def convert2bb @loadedConfig.referencedConfigs.each do |projName, configs| configs.each do |config| block = Blocks::Block.new(config, @loadedConfig.referencedConfigs) Blocks::ALL_BLOCKS[config.qname] = block addSteps(block, block.startupSteps, config.startupSteps) addSteps(block, block.exitSteps, config.exitSteps) if not Bake..linkOnly and not Bake..prepro and not Bake..lint and not Bake..conversion_info and not Bake..docu and not Bake..filename and not Bake..analyze addSteps(block, block.preSteps, config.preSteps) addSteps(block, block.postSteps, config.postSteps) end if Bake..docu block.mainSteps << Blocks::Docu.new(config, @configTcMap[config]) elsif Metamodel::CustomConfig === config if not Bake..linkOnly and not Bake..prepro and not Bake..lint and not Bake..conversion_info and not Bake..docu and not Bake..filename and not Bake..analyze addSteps(block, block.mainSteps, config) if config.step end elsif Bake..conversion_info block.mainSteps << Blocks::Convert.new(block, config, @loadedConfig.referencedConfigs, @configTcMap[config]) elsif Bake..lint block.mainSteps << Blocks::Lint.new(block, config, @loadedConfig.referencedConfigs, @configTcMap[config]) else compile = Blocks::Compile.new(block, config, @loadedConfig.referencedConfigs, @configTcMap[config]) (Blocks::ALL_COMPILE_BLOCKS[projName] ||= []) << compile block.mainSteps << compile if not Bake..filename and not Bake..analyze if Metamodel::LibraryConfig === config block.mainSteps << Blocks::Library.new(block, config, @loadedConfig.referencedConfigs, @configTcMap[config], compile) else block.mainSteps << Blocks::Executable.new(block, config, @loadedConfig.referencedConfigs, @configTcMap[config], compile) end end end if not Bake..project# and not Bake.options.filename addDependencies(block, config.dependency) end end end end |
#createBaseTcsForConfig ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/tocxx.rb', line 54 def createBaseTcsForConfig @loadedConfig.referencedConfigs.each do |projName, configs| configs.each do |config| tcs = Utils.deep_copy(@defaultToolchain) @configTcMap[config] = tcs end end end |
#createTcsForConfig ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/tocxx.rb', line 63 def createTcsForConfig @loadedConfig.referencedConfigs.each do |projName, configs| configs.each do |config| integrateToolchain(@configTcMap[config], config.toolchain) end end end |
#disconnect ⇒ Object
360 361 362 363 364 |
# File 'lib/tocxx.rb', line 360 def disconnect() if Bake..socket != 0 Bake::IDEInterface.instance.disconnect() end end |
#doit ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/tocxx.rb', line 214 def doit() taskType = "Building" if Bake..lint taskType = "Linting" elsif Bake..conversion_info taskType = "Showing conversion infos" elsif Bake..docu taskType = "Generating documentation" elsif Bake..prepro taskType = "Preprocessing" elsif Bake..linkOnly taskType = "Linking" elsif Bake..rebuild taskType = "Rebuilding" elsif Bake..clean taskType = "Cleaning" end begin @loadedConfig = Config.new @loadedConfig.load taskType = "Analyzing" if Bake..analyze @mainConfig = @loadedConfig.referencedConfigs[Bake..main_project_name].select { |c| c.name == Bake..build_config }.first if Bake..lint @defaultToolchain = Utils.deep_copy(Bake::Toolchain::Provider["Lint"]) else basedOn = @mainConfig.defaultToolchain.basedOn basedOnToolchain = Bake::Toolchain::Provider[basedOn] if basedOnToolchain.nil? Bake.formatter.printError("DefaultToolchain based on unknown compiler '#{basedOn}'", config.defaultToolchain) ExitHelper.exit(1) end # The flag "-FS" must only be set for VS2013 and above ENV["MSVC_FORCE_SYNC_PDB_WRITES"] = "" if basedOn == "MSVC" begin res = `cl.exe 2>&1` raise Exception.new unless $?.success? scan_res = res.scan(/ersion (\d+).(\d+).(\d+)/) if scan_res.length > 0 ENV["MSVC_FORCE_SYNC_PDB_WRITES"] = "-FS" if scan_res[0][0].to_i >= 18 # 18 is the compiler major version in VS2013 else Bake.formatter.printError("Could not read MSVC version") ExitHelper.exit(1) end rescue SystemExit raise rescue Exception => e Bake.formatter.printError("Could not detect MSVC compiler") ExitHelper.exit(1) end end @defaultToolchain = Utils.deep_copy(basedOnToolchain) Bake..envToolchain = true if (basedOn.include?"_ENV") end integrateToolchain(@defaultToolchain, @mainConfig.defaultToolchain) # todo: cleanup this hack Bake..analyze = @defaultToolchain[:COMPILER][:CPP][:COMPILE_FLAGS].include?"analyze" Bake..eclipseOrder = @mainConfig.defaultToolchain.eclipseOrder createBaseTcsForConfig substVars createTcsForConfig @@linkBlock = 0 convert2bb Blocks::Show.includes if Bake..show_includes Blocks::Show.includesAndDefines(@mainConfig, @configTcMap[@mainConfig]) if Bake..show_includes_and_defines startBlocks = calcStartBlocks Bake::IDEInterface.instance.set_build_info(@mainConfig.parent.name, @mainConfig.name, Blocks::ALL_BLOCKS.length) ideAbort = false begin result = callBlocks(startBlocks, :startup) if Bake..clean or Bake..rebuild if not Bake..stopOnFirstError or result result = callBlocks(startBlocks, :clean) && result end end if Bake..rebuild or not Bake..clean if not Bake..stopOnFirstError or result result = callBlocks(startBlocks, :execute) && result end end rescue AbortException ideAbort = true end if not Bake..stopOnFirstError or result result = callBlocks(startBlocks, :exits) && result end if ideAbort Bake.formatter.printError("\n#{taskType} aborted.") ExitHelper.set_exit_code(1) return end if Bake..cc2j_filename Blocks::BlockBase.prepareOutput(Bake..cc2j_filename) File.open(Bake..cc2j_filename, 'w') do |f| f.puts "[" noComma = Blocks::CC2J.length - 1 Blocks::CC2J.each_with_index do |c, index| cmd = c[:command].is_a?(Array) ? c[:command].join(' ') : c[:command] f.puts " { \"directory\": \"" + c[:directory] + "\"," f.puts " \"command\": \"" + cmd + "\"," f.puts " \"file\": \"" + c[:file] + "\" }#{index == noComma ? "" : ","}" end f.puts "]" end end if result == false Bake.formatter.printError("\n#{taskType} failed.") ExitHelper.set_exit_code(1) return else if Bake..linkOnly and @@linkBlock == 0 Bake.formatter.printSuccess("\nNothing to link.") else Bake.formatter.printSuccess("\n#{taskType} done.") end end rescue SystemExit Bake.formatter.printError("\n#{taskType} failed.") if ExitHelper.exit_code != 0 end end |
#substVars ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tocxx.rb', line 71 def substVars Subst.itute(@mainConfig, Bake..main_project_name, true, @configTcMap[@mainConfig], @loadedConfig, @configTcMap) @loadedConfig.referencedConfigs.each do |projName, configs| configs.each do |config| if config != @mainConfig Subst.itute(config, projName, false, @configTcMap[config], @loadedConfig, @configTcMap) end end end end |