Class: Bake::Blocks::Executable

Inherits:
BlockBase show all
Defined in:
lib/blocks/executable.rb

Instance Attribute Summary

Attributes inherited from BlockBase

#block, #projectDir

Instance Method Summary collapse

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.



9
10
11
12
13
14
15
16
17
# File 'lib/blocks/executable.rb', line 9

def initialize(block, config, referencedConfigs, compileBlock)
  super(block, config, referencedConfigs)
  @compileBlock = compileBlock

  calcArtifactName
  calcMapFile
  calcLinkerScript

end

Instance Method Details

#calcArtifactNameObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/blocks/executable.rb', line 23

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])
end

#calcCmdlineFileObject



40
41
42
# File 'lib/blocks/executable.rb', line 40

def calcCmdlineFile()
  @exe_name + ".cmdline"
end

#calcLinkerScriptObject



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

def calcLinkerScript
  @linker_script = @config.linkerScript.nil? ? nil : @block.convPath(@config.linkerScript)
end

#calcMapFileObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/blocks/executable.rb', line 44

def calcMapFile
  @mapfile = nil
  if (not Bake.options.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

#cleanObject



190
191
192
# File 'lib/blocks/executable.rb', line 190

def clean
  return cleanProjectDir()
end

#executeObject



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

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.options.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.expand_path(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.options.fileCmd ? calcFileCmd(cmd, onlyCmd, @exe_name, linker) : cmd
      
    # pre print because linking can take much time
    cmdLinePrint = Bake.options.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(@exe_name)

      printCmd(cmdLinePrint, "Linking   #{@projectName} (#{@config.name}): #{@exe_name}", reason, false)
      BlockBase.writeCmdLineFile(cmd, cmdLineFile)
      success = true
      consoleOutput = ""
      success, consoleOutput = ProcessHelper.run(realCmd, false, false, outPipe) if !Bake.options.dry
      process_result(cmdLinePrint, consoleOutput, linker[:ERROR_PARSER], nil, reason, success)

      check_config_file()
    end

    return success
  end
end

#ignore?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/blocks/executable.rb', line 55

def ignore?
  Bake.options.prepro
end

#needed?(libs) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/blocks/executable.rb', line 59

def needed?(libs)
  return "because linkOnly was specified" if Bake.options.linkOnly

  # exe
  return "because executable does not exist" if not File.exists?(@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.exists?(@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.exists?(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.exists?(lib)
    return "because library #{lib} is newer than executable" if eTime < File.mtime(lib)
  end
  false
end