Class: Bake::Blocks::BlockBase

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

Direct Known Subclasses

Compile, Executable, Library

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, config, referencedConfigs, tcs) ⇒ BlockBase

Returns a new instance of BlockBase.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/blocks/blockBase.rb', line 8

def initialize(block, config, referencedConfigs, tcs)
  @block = block
  @config = config
  @referencedConfigs = referencedConfigs
  @projectName = config.parent.name
  @projectDir = config.get_project_dir
  @tcs = tcs
  @config_date = Time.now
  
  @printedCmdAlternate = false
  @lastCommand = nil
  
  calcOutputDir
end

Instance Attribute Details

#tcsObject (readonly)

Returns the value of attribute tcs.



6
7
8
# File 'lib/blocks/blockBase.rb', line 6

def tcs
  @tcs
end

Class Method Details

.isCmdLineEqual?(cmd, cmdLineFile) ⇒ Boolean

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/blocks/blockBase.rb', line 63

def self.isCmdLineEqual?(cmd, cmdLineFile)       
  begin
    if File.exist?cmdLineFile
      lastCmdLineArray = File.readlines(cmdLineFile)[0];
      if lastCmdLineArray == cmd.join(" ")
        FileUtils.touch(cmdLineFile)
        return true
      end
    end
  rescue Exception => e
    if Bake.options.debug
      puts e.message
      puts e.backtrace
    end
  end
  return false
end

.prepareOutput(filename) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/blocks/blockBase.rb', line 35

def self.prepareOutput(filename)
  begin
    if File.exists?(filename)
      FileUtils.rm(filename)
    else 
      FileUtils.mkdir_p(File.dirname(filename))
    end
  rescue Exception => e
    if Bake.options.debug
      puts e.message
      puts e.backtrace
    end
  end        
end

.writeCmdLineFile(cmd, cmdLineFile) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/blocks/blockBase.rb', line 81

def self.writeCmdLineFile(cmd, cmdLineFile) 
  begin
    File.write(cmdLineFile, cmd.join(" "))
  rescue Exception => e
    if Bake.options.debug
      puts e.message
      puts e.backtrace
    end
  end
end

Instance Method Details

#calcOutputDirObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/blocks/blockBase.rb', line 92

def calcOutputDir
  if @tcs[:OUTPUT_DIR] != nil
    p = @block.convPath(@tcs[:OUTPUT_DIR])
    @output_dir = p
  elsif @projectName == Bake.options.main_project_name and @config.name == Bake.options.build_config 
    @output_dir = "build_" + Bake.options.build_config
  else
    @output_dir = "build_" + @config.name + "_" + Bake.options.main_project_name + "_" + Bake.options.build_config
  end
end

#check_config_fileObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/blocks/blockBase.rb', line 23

def check_config_file()
  if File.exists?(@config.file_name) and File.mtime(@config.file_name) > @config_date
    begin
      FileUtils.touch(@config.file_name)
    rescue Exception=>e
      if Bake.options.verbose >= 2
        Bake.formatter.printWarning("Could not touch #{@config.file_name}: #{e.message}", @config.file_name)              
      end
    end
  end
end

#config_changed?(cmdLineFile) ⇒ Boolean

Returns:



54
55
56
57
58
59
60
61
# File 'lib/blocks/blockBase.rb', line 54

def config_changed?(cmdLineFile)
  return "because command line file does not exist" if not File.exist?(cmdLineFile)
  cmdTime = File.mtime(cmdLineFile)
  return "because config file has been changed" if cmdTime < File.mtime(@config.file_name)
  return "because DefaultToolchain has been changed" if cmdTime < defaultToolchainTime
  return "because environment variables used for toolchain have been changed" if (Bake.options.envToolchain)
  false
end

#defaultToolchainTimeObject



50
51
52
# File 'lib/blocks/blockBase.rb', line 50

def defaultToolchainTime
  @defaultToolchainTime ||= File.mtime(Bake.options.main_dir+"/Project.meta")
end

#printCmd(cmd, alternate, reason, forceVerbose) ⇒ Object



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

def printCmd(cmd, alternate, reason, forceVerbose)
  if (cmd == @lastCommand)
    if (Bake.options.verbose >= 2 or (@printedCmdAlternate and not forceVerbose))
      return
    end
  end
  
  @lastCommand = cmd
  
  return if Bake.options.verbose == 0 and not forceVerbose

  if forceVerbose or Bake.options.verbose >= 2 or not alternate
    @printedCmdAlternate = false
    puts "" if Bake.options.verbose >= 2 # for A.K. :-)

    if Bake.options.verbose >= 3
      exedIn = "\n(executed in '#{@projectDir}')"
      because = reason ? "\n(#{reason})" : ""
    else
      exedIn = ""
      because = ""
    end
    
    if cmd.is_a?(Array)
      puts cmd.join(' ') + exedIn + because
    else
      puts cmd + exedIn + because
    end
  else
    @printedCmdAlternate = true
    puts alternate
  end

end

#process_console_output(console_output, error_parser) ⇒ Object



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

def process_console_output(console_output, error_parser)
  ret = false
  incList = nil
  #if not console_output.empty?

    if error_parser
      begin
        x = [console_output]
        error_descs, console_output_full, incList = error_parser.scan_lines(x, @projectDir)
      
        console_output = x[0]
        console_output = console_output_full if Bake.options.consoleOutput_fullnames

        if Bake.options.consoleOutput_visualStudio
          console_output_VS = ""
          descCounter = 0
          console_output.each_line do |l|
            d = error_descs[descCounter]
            console_output_VS << error_parser.makeVsError(l.rstrip, d) << "\n"
            descCounter = descCounter + 1
          end
          console_output = console_output_VS
        end
  
        if Bake.options.lint
          # ignore error output

        else
          ret = error_descs.any? { |e| e.severity == ErrorParser::SEVERITY_ERROR }
        end
  
        console_output.gsub!(/[\r]/, "")
        Bake.formatter.format(console_output, error_descs, error_parser) unless console_output.empty?
  
        Bake::IDEInterface.instance.set_errors(error_descs)
      rescue Exception => e
        Bake.formatter.printWarning("Parsing output failed (maybe language not set to English?): " + e.message)
        Bake.formatter.printWarning("Original output:")
        Bake.formatter.printWarning(console_output)
        raise e
      end
    else
      puts console_output # fallback

    end
  #end

  [ret, incList]
end

#process_result(cmd, console_output, error_parser, alternate, reason, success) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/blocks/blockBase.rb', line 183

def process_result(cmd, console_output, error_parser, alternate, reason, success)
  hasError = (success == false)
  printCmd(cmd, alternate, reason, (hasError and not Bake.options.lint))
  errorPrinted, incList = process_console_output(console_output, error_parser)
  if hasError and not errorPrinted
    Bake.formatter.printError("System command failed", @projectDir)
  end
  if hasError or errorPrinted
    raise SystemCommandFailed.new
  end
  incList
end