Class: Bake::Blocks::Executable
- Defined in:
- lib/blocks/executable.rb
Instance Attribute Summary collapse
-
#compileBlock ⇒ Object
readonly
Returns the value of attribute compileBlock.
Attributes inherited from BlockBase
Instance Method Summary collapse
- #calcArtifactName ⇒ Object
- #calcCmdlineFile ⇒ Object
- #calcLinkerScript ⇒ Object
- #calcMapFile ⇒ Object
- #clean ⇒ Object
- #execute ⇒ Object
- #ignore? ⇒ Boolean
-
#initialize(block, config, referencedConfigs, compileBlock) ⇒ Executable
constructor
A new instance of Executable.
- #needed?(libs) ⇒ Boolean
Methods inherited from BlockBase
#calcFileCmd, #check_config_file, #cleanProjectDir, #config_changed?, #defaultToolchainTime, isCmdLineEqual?, prepareOutput, #printCmd, #process_console_output, #process_result, writeCmdLineFile
Constructor Details
#initialize(block, config, referencedConfigs, compileBlock) ⇒ Executable
Returns a new instance of Executable.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/blocks/executable.rb', line 11 def initialize(block, config, referencedConfigs, compileBlock) super(block, config, referencedConfigs) @compileBlock = compileBlock block.set_executable(self) calcArtifactName calcMapFile calcLinkerScript end |
Instance Attribute Details
#compileBlock ⇒ Object (readonly)
Returns the value of attribute compileBlock.
9 10 11 |
# File 'lib/blocks/executable.rb', line 9 def compileBlock @compileBlock end |
Instance Method Details
#calcArtifactName ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/blocks/executable.rb', line 31 def calcArtifactName if not @config.artifactName.nil? and @config.artifactName.name != "" baseFilename = @config.artifactName.name baseFilename += Bake::Toolchain.outputEnding(@block.tcs) if !baseFilename.include?(".") else baseFilename = "#{@projectName}#{Bake::Toolchain.outputEnding(@block.tcs)}" end if !@config.artifactExtension.nil? && @config.artifactExtension.name != "default" extension = ".#{@config.artifactExtension.name}" if baseFilename.include?(".") baseFilename = baseFilename.split(".")[0...-1].join(".") end baseFilename += ".#{@config.artifactExtension.name}" end @exe_name ||= File.join([@block.output_dir, baseFilename]) if Bake..abs_path_in @exe_name = File.(@exe_name, @projectDir) end return @exe_name end |
#calcCmdlineFile ⇒ Object
52 53 54 |
# File 'lib/blocks/executable.rb', line 52 def calcCmdlineFile() @exe_name + ".cmdline" end |
#calcLinkerScript ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/blocks/executable.rb', line 23 def calcLinkerScript if Metamodel::LibraryConfig === @config @linker_script = nil else @linker_script = @config.linkerScript.nil? ? nil : @block.convPath(@config.linkerScript) end end |
#calcMapFile ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/blocks/executable.rb', line 56 def calcMapFile @mapfile = nil if Metamodel::LibraryConfig === @config def @config.mapFile Metamodel::MapFile.new end end if (not Bake..docu) and (not @config.mapFile.nil?) if @config.mapFile.name == "" @mapfile = @exe_name.chomp(File.extname(@exe_name)) + ".map" else @mapfile = @config.mapFile.name end end end |
#clean ⇒ Object
213 214 215 |
# File 'lib/blocks/executable.rb', line 213 def clean return cleanProjectDir() end |
#execute ⇒ Object
104 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 151 152 153 154 155 156 157 158 159 160 161 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 |
# File 'lib/blocks/executable.rb', line 104 def execute Dir.chdir(@projectDir) do subBlocks = @block.bes.select{|d| Metamodel::Dependency === d}.map { |d| ALL_BLOCKS["#{d.name},#{d.config}"] } if subBlocks.any? { |d| d.result == false } if Bake..stopOnFirstError Blocks::Block.set_delayed_result return true else return false end end allSources = [] (subBlocks + [@block]).each do |b| Dir.chdir(b.projectDir) do b.getCompileBlocks.each do |c| srcs = c.calcSources(true, true).map { |s| File.(s) } allSources += srcs end end end duplicateSources = allSources.group_by{ |e| e }.select { |k, v| v.size > 1 }.map(&:first) duplicateSources.each do |d| Bake.formatter.printError("Source compiled more than once: #{d}") end ExitHelper.exit(1) if duplicateSources.length > 0 libs, linker_libs_array = LibElements.calc_linker_lib_string(@block, @block.tcs) cmdLineCheck = false cmdLineFile = calcCmdlineFile() return true if ignore? reason = needed?(libs) if not reason cmdLineCheck = true reason = config_changed?(cmdLineFile) end linker = @block.tcs[:LINKER] cmd = Utils.flagSplit(linker[:PREFIX], true) cmd += Utils.flagSplit(linker[:COMMAND], true) # g++ onlyCmd = cmd cmd += linker[:MUST_FLAGS].split(" ") cmd += Bake::Utils::flagSplit(linker[:FLAGS],true) cmd << linker[:EXE_FLAG] if linker[:EXE_FLAG_SPACE] cmd << @exe_name else cmd[cmd.length-1] += @exe_name end cmd += @compileBlock.objects if @linker_script if linker[:SCRIPT_SPACE] cmd << linker[:SCRIPT] # -T cmd << @linker_script # xy/xy.dld else cmd << linker[:SCRIPT]+@linker_script end end cmd += linker[:MAP_FILE_FLAG].split(" ") if @mapfile # -Wl,-m6 if not linker[:MAP_FILE_PIPE] and @mapfile cmd[cmd.length-1] << @mapfile end cmd += Bake::Utils::flagSplit(linker[:LIB_PREFIX_FLAGS],true) # "-Wl,--whole-archive " cmd += linker_libs_array cmd += Bake::Utils::flagSplit(linker[:LIB_POSTFIX_FLAGS],true) # "-Wl,--no-whole-archive " realCmd = Bake..fileCmd ? calcFileCmd(cmd, onlyCmd, @exe_name, linker) : cmd # pre print because linking can take much time cmdLinePrint = Bake..fileCmd ? realCmd.dup : cmd.dup # some mapfiles are printed in stdout outPipe = (@mapfile and linker[:MAP_FILE_PIPE]) ? "#{@mapfile}" : nil cmdLinePrint << "> #{outPipe}" if outPipe if cmdLineCheck and BlockBase.isCmdLineEqual?(cmd, cmdLineFile) success = true else ToCxx.linkBlock BlockBase.prepareOutput(File.(@exe_name,@projectDir), @block) printCmd(cmdLinePrint, "Linking #{@projectName} (#{@config.name}): #{@exe_name}", reason, false) BlockBase.writeCmdLineFile(cmd, cmdLineFile) success = true consoleOutput = "" retry_linking = Bake..dev_features.include?("retry-linking") ? 5 : 1 begin success, consoleOutput = ProcessHelper.run(realCmd, false, false, outPipe) if !Bake..dry process_result(cmdLinePrint, consoleOutput, linker[:ERROR_PARSER], nil, reason, success) rescue Exception retry_linking -= 1 retry if !success && retry_linking > 0 raise end check_config_file() end return success end end |
#needed?(libs) ⇒ Boolean
76 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 |
# File 'lib/blocks/executable.rb', line 76 def needed?(libs) return "because linkOnly was specified" if Bake..linkOnly # exe return "because executable does not exist" if not File.exist?(@exe_name) eTime = File.mtime(@exe_name) # linkerscript if @linker_script return "because linker script does not exist - will most probably result in an error" if not File.exist?(@linker_script) return "because linker script is newer than executable" if eTime < File.mtime(@linker_script) end # sources @compileBlock.objects.each do |obj| return "because object #{obj} does not exist" if not File.exist?(obj) return "because object #{obj} is newer than executable" if eTime < File.mtime(obj) end if @compileBlock # libs libs.each do |lib| return "because library #{lib} does not exist" if not File.exist?(lib) return "because library #{lib} is newer than executable" if eTime < File.mtime(lib) end false end |