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) ⇒ BlockBase

Returns a new instance of BlockBase.



8
9
10
11
12
13
14
15
# File 'lib/blocks/blockBase.rb', line 8

def initialize(block, config, referencedConfigs)
  @block = block
  @config = config
  @referencedConfigs = referencedConfigs
  @projectName = config.parent.name
  @projectDir = config.get_project_dir
  @config_date = Time.now
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#projectDirObject (readonly)

Returns the value of attribute projectDir.



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

def projectDir
  @projectDir
end

Class Method Details

.isCmdLineEqual?(cmd, cmdLineFile) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/blocks/blockBase.rb', line 59

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

.prepareOutput(filename, block = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/blocks/blockBase.rb', line 29

def self.prepareOutput(filename, block = nil)
  return if Bake.options.dry
  filename = File.expand_path(filename, @projectDir)
  begin
    if File.exist?(filename)
      FileUtils.rm(filename)
    else
      FileUtils::mkdir_p(File.dirname(filename))
    end
    Utils.gitIgnore(File.expand_path(block.output_dir, @projectDir)) if block
  rescue Exception => e
    if Bake.options.debug
      puts e.message
      puts e.backtrace
    end
  end
end

.writeCmdLineFile(cmd, cmdLineFile) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/blocks/blockBase.rb', line 77

def self.writeCmdLineFile(cmd, cmdLineFile)
  begin
    if !Bake.options.dry
      File.open(cmdLineFile, 'w') { |f| f.write(cmd.join(" ")) }
    end
  rescue Exception => e
    if Bake.options.debug
      puts e.message
      puts e.backtrace
    end
  end
end

Instance Method Details

#calcFileCmd(cmd, onlyCmd, orgOut, tcs, postfix = "") ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/blocks/blockBase.rb', line 203

def calcFileCmd(cmd, onlyCmd, orgOut, tcs, postfix = "")
  if tcs[:FILE_COMMAND] == ""
    Bake.formatter.printWarning("Warning: file command option not yet supported for this toolchain")
    return cmd
  end
  args = cmd.drop(onlyCmd.length)
  argsFlat = args.join(' ')

  splittedArgs = argsFlat.split("\"")
  argsFlat = ""
  splittedArgs.each_with_index do |s,i|
    argsFlat << s
    argsFlat << (i%2 == 0 ? "\"\\\"" : "\\\"\"") if i != splittedArgs.length - 1 
  end

  cmdFile = orgOut + ".file" + postfix
  cmdFileLong = File.expand_path(cmdFile, @projectDir)
  Utils.gitIgnore(File.dirname(cmdFileLong))
  File.open(cmdFileLong, "w") { |f| f.puts argsFlat }
  return onlyCmd + ["#{tcs[:FILE_COMMAND]}#{cmdFile}"]
end

#check_config_fileObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/blocks/blockBase.rb', line 17

def check_config_file()
  if File.exist?(@config.file_name) and File.mtime(@config.file_name) > @config_date
    begin
      FileUtils.touch(@config.file_name) if !Bake.options.dry
    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

#cleanProjectDirObject



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/blocks/blockBase.rb', line 178

def cleanProjectDir
  if !Bake.options.filename
    Dir.chdir(@projectDir) do
      if File.exist?@block.output_dir
        puts "Deleting folder #{@block.output_dir}" if Bake.options.verbose >= 2
        if !Bake.options.dry
          FileUtils.rm_rf(@block.output_dir)
        end

        if (@block.tcs[:OUTPUT_DIR] == nil) && (Bake.options.buildDirDelimiter == "/") # in this case all builds are placed in a "build" folder
          buildDir = File.dirname(@block.output_dir)
          if (File.basename(buildDir) == "build") && (Dir.entries(buildDir).size == 2)# double check if it's really "build" and check if it's empty (except "." and "..")
            puts "Deleting folder #{buildDir}" if Bake.options.verbose >= 2
            if !Bake.options.dry
              FileUtils.rm_rf(buildDir)
            end
          end
        end

      end
    end
  end
  return true
end

#config_changed?(cmdLineFile) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/blocks/blockBase.rb', line 51

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 command line has been changed"
end

#defaultToolchainTimeObject



47
48
49
# File 'lib/blocks/blockBase.rb', line 47

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

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



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

def printCmd(cmd, alternate, reason, forceVerbose)
  if (cmd == Thread.current[:lastCommand])
    if (Bake.options.verbose >= 2 or (Thread.current[:printedCmdAlternate] and not forceVerbose))
      return
    end
  end

  Thread.current[:lastCommand] = cmd

  return if Bake.options.verbose == 0 and not forceVerbose

  if forceVerbose or Bake.options.verbose >= 2 or not alternate
    Thread.current[: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
    Thread.current[:printedCmdAlternate] = true
    puts alternate
  end

end

#process_console_output(console_output, error_parser) ⇒ Object



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

def process_console_output(console_output, error_parser)
  ret = false
  incList = nil
  #if not console_output.empty?
    if error_parser
      begin
        x = [console_output]
        if  = Bake.options.dev_features.include?("no-error-parser")
          error_descs = []
          console_output_full = x[0]
        else
          error_descs, console_output_full, incList = error_parser.scan_lines(x, @projectDir)
        end

        console_output = x[0]
        console_output = console_output_full if Bake.options.abs_path_out

        ret = error_descs.any? { |e| e.severity == ErrorParser::SEVERITY_ERROR }

        console_output.gsub!(/[\r]/, "")
        if  = Bake.options.dev_features.include?("no-error-parser")
          puts console_output
        else
          Bake.formatter.format(console_output, error_descs, error_parser) unless console_output.empty?
          Bake::IDEInterface.instance.set_errors(error_descs)
        end

      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



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/blocks/blockBase.rb', line 164

def process_result(cmd, console_output, error_parser, alternate, reason, success)
  hasError = (success == false)
  printCmd(cmd, alternate, reason, hasError)
  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 (Bake.options.wparse and errorPrinted)
    raise SystemCommandFailed.new
  end
  incList
end