Class: BConv::Bake

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

Overview

class ParserException < Exception end

Constant Summary collapse

START_INFO =

enums

1
END_INFO =
2
BEFORE_INFO =
3
VAR =
4

Instance Method Summary collapse

Constructor Details

#initialize(map, setMock, configFile) ⇒ Bake

Returns a new instance of Bake.



20
21
22
23
24
# File 'lib/Bake.rb', line 20

def initialize(map, setMock, configFile)
  @map = map
  @setMock = setMock
  @configFile = configFile
end

Instance Method Details

#getHash(bakeLines) ⇒ Object



50
51
52
53
54
55
56
57
58
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/Bake.rb', line 50

def getHash(bakeLines)
  b_hash = {}
  key = ""
  value = []
  state = Bake::BEFORE_INFO
  
  bakeLines.each_line do |line|
    if line.start_with?("  ") && line[2] != " "
        if state == Bake::VAR
          value << line.strip if value != nil
          value = line.strip if value == nil
          b_hash.store(key,value)
         
        end
    elsif line.start_with?(" ") && line[1] != " "
      if state == Bake::START_INFO || state == Bake::VAR
        key = ""
        value = []
        key = line.strip
        b_hash.store(key,value)
        
        # if key != "BAKE_INCLUDES" && key != "BAKE_SOURCES" && key != "BAKE_DEFINES"

          # state = Bake::START_INFO           

        # else

          state = VAR
        #end

      end
    #elsif line.start_with?("") && !line.match("START_INFO") && !line.match("END_INFO")

    #  puts "Error: Nothing else than START_INFO and END_INFO starting without blanks!"

    else
      if line.match("START_INFO") && line[0] != " "
        # if state != Bake::BEFORE_INFO

          # abort "Error!" 

        # end

        state = Bake::START_INFO
      elsif line.match("END_INFO")
        state = Bake::END_INFO
      end
    end
  end
  
  if state != Bake::END_INFO
    puts "Error: There is a problem with END_INFO. No output file could be generated!"
    return nil
   #raise ParseException.new("END_INFO missing") 

  end
   
 # begin

   # ...

 # rescue ParseException

   # exit(-1)

 # end

    
  return b_hash
end

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/Bake.rb', line 26

def run
  bakeLines = ''
  begin
  cmd = @setMock ? ['ruby','C:/_dev/projects/bakeMock/bakeMock/bakeMock.rb'] : ['bake']
  cmd << '-b' << @map['BuildConfig']
  cmd << '-m' << @map['MainProj']
  cmd << '-p' << @map['Proj2Convert']
  cmd << '--conversion_info'
  Util.strToArray('Workspace', @map).each { |w| cmd << '-w' << w }

  Dir.chdir(File.dirname(@configFile)) do      
    bakeLines = `#{cmd.join(' ')}`
  end
  
  rescue Exception => e
    puts e.message
    puts e.back_trace    #for debug mode

    abort
  end  
  
  abort "Error while trying to call bake!" unless $?.success?
  return bakeLines
end