Class: Bake::Blocks::Show

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

Class Method Summary collapse

Class Method Details

.includesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/blocks/showIncludes.rb', line 19

def self.includes
  secureShow {
  Blocks::ALL_COMPILE_BLOCKS.sort.each do |projName, blocks|
    print projName
    incs = []
    blocks.each do |block|
      if Bake.options.abs_path_in
        incs += block.include_list.map { |i| File.expand_path(i, block.projectDir)  }
      else
        incs += block.include_list
      end
    end

    incs.uniq.each { |inc| print "##{inc}" }
    print "\n"
  end
  ExitHelper.exit(0) }
end

.includesAndDefines(mainConfig, mainTcs) ⇒ Object



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

def self.includesAndDefines(mainConfig, mainTcs)
  secureShow {
  mainBlock = Blocks::ALL_BLOCKS[Bake.options.main_project_name+","+Bake.options.build_config]

  intIncs = readInternalIncludes(mainConfig, mainBlock, mainTcs)
  intDefs = readInternalDefines(mainConfig, mainBlock)


  projs = {}
  Blocks::ALL_COMPILE_BLOCKS.sort.each do |projName, blocks|

    blockIncs = []
    blockDefs = {:CPP => [], :C => [], :ASM => []}
    blocks.each do |block|
      block.calcIncludes
      block.calcDefines
      block.calcFlags 
      if Bake.options.abs_path_in
        blockIncs += block.include_list.map { |i| File.expand_path(i, block.projectDir)  }
      else
        blockIncs += block.include_list
      end
      [:CPP, :C, :ASM].each { |type| blockDefs[type] += block.block.tcs[:COMPILER][type][:DEFINES] }
    end
    if Bake.options.json
      projs[projName] =
        {  :includes => (blockIncs + intIncs).uniq,
           :cpp_defines => (blockDefs[:CPP] + intDefs[:CPP]).uniq + Bake.options.defines,
           :c_defines => (blockDefs[:C] + intDefs[:C]).uniq + Bake.options.defines,
           :asm_defines => (blockDefs[:ASM] + intDefs[:ASM]).uniq + Bake.options.defines,
           :dir => blocks.first.projectDir
        }
    else
      puts projName
      puts " dir #{blocks.first.projectDir}"
      puts " includes"
      (blockIncs + intIncs).uniq.each { |i| puts "  #{i}" }
      [:CPP, :C, :ASM].each do |type|
        puts " #{type} defines"
        (blockDefs[type] + intDefs[type] + Bake.options.defines).uniq.each { |d| puts "  #{d}" }
      end
      puts " done"
    end
  end

  if Bake.options.json
    require "json"
    puts JSON.pretty_generate(projs)
  end

  ExitHelper.exit(0) }
end

.readInternalDefines(mainConfig, mainBlock) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/blocks/showIncludes.rb', line 70

def self.readInternalDefines(mainConfig, mainBlock)
  intDefs = {:CPP => [], :C => [], :ASM => []}
  Dir.chdir(Bake.options.main_dir) do
    mainConfig.defaultToolchain.compiler.each do |c|
      if (c.internalDefines)
        dname = mainBlock.convPath(c.internalDefines)
        if dname != ""
          if not File.exist?(dname)
            Bake.formatter.printError("InternalDefines file #{dname} does not exist", c.internalDefines)
            ExitHelper.exit(1)
          end
          IO.foreach(dname) {|x| add_line_if_no_comment(intDefs[c.ctype],x)  }
        end
      end
    end
  end
  return intDefs
end

.readInternalIncludes(mainConfig, mainBlock, mainTcs) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/blocks/showIncludes.rb', line 38

def self.readInternalIncludes(mainConfig, mainBlock, mainTcs)
  intIncs = []
  iinc = mainConfig.defaultToolchain.internalIncludes
  Dir.chdir(Bake.options.main_dir) do
    if (iinc)

      cppExe      = File.which(mainTcs[:COMPILER][:CPP][:COMMAND])
      cExe        = File.which(mainTcs[:COMPILER][:C][:COMMAND])
      asmExe      = File.which(mainTcs[:COMPILER][:ASM][:COMMAND])
      archiverExe = File.which(mainTcs[:ARCHIVER][:COMMAND])
      linkerExe   = File.which(mainTcs[:LINKER][:COMMAND])

      iname = mainBlock.convPath(iinc)
      if iname != ""
        if not File.exist?(iname)
          Bake.formatter.printError("InternalIncludes file #{iname} does not exist", iinc)
          ExitHelper.exit(1)
        end
        IO.foreach(iname) do |x|
          x.sub!("$(CPPPath)",      cppExe)
          x.sub!("$(CPath)",        cExe)
          x.sub!("$(ASMPath)",      asmExe)
          x.sub!("$(ArchiverPath)", archiverExe)
          x.sub!("$(LinkerPath)",   linkerExe)
          add_line_if_no_comment(intIncs,x)
        end
      end
    end
  end
  return intIncs
end

.secureShowObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/blocks/showIncludes.rb', line 5

def self.secureShow
  begin
    yield
  rescue Exception => e
    if (not SystemExit === e)
      puts e
      puts e.backtrace
      ExitHelper.exit(1)
    else
      raise e
    end
  end
end