Class: Bake::MergeConfig

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

Instance Method Summary collapse

Constructor Details

#initialize(child, parent) ⇒ MergeConfig



5
6
7
8
# File 'lib/bake/mergeConfig.rb', line 5

def initialize(child, parent)
  @child = child
  @parent = parent
end

Instance Method Details

#manipulateLineNumbers(ar) ⇒ Object



77
78
79
# File 'lib/bake/mergeConfig.rb', line 77

def manipulateLineNumbers(ar)
  ar.each { |l| l.line_number -= 1000000 if l.line_number > 0 }
end

#mergeObject



81
82
83
84
85
86
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
# File 'lib/bake/mergeConfig.rb', line 81

def merge()

  # Valid for all config types


  deps = @parent.dependency
  @child.dependency.each do |cd|
    deps << cd if deps.none? {|pd| pd.name == cd.name and pd.config == cd.config }
  end
  @child.setDependency(deps)
  
  @child.setSet(@parent.set + @child.set)

  manipulateLineNumbers(@parent.exLib)
  manipulateLineNumbers(@parent.exLibSearchPath)
  manipulateLineNumbers(@parent.userLibrary)

  @child.setExLib(@parent.exLib           + @child.exLib)
  @child.setExLibSearchPath(@parent.exLibSearchPath + @child.exLibSearchPath)
  @child.setUserLibrary(@parent.userLibrary     + @child.userLibrary)
  
  if not @parent.startupSteps.nil?
    if (@child.startupSteps.nil?)
      @child.setStartupSteps(@parent.startupSteps)
    else
      @child.startupSteps.setStep(@parent.startupSteps.step + @child.startupSteps.step)
    end
  end
  
  if not @parent.preSteps.nil?
    if (@child.preSteps.nil?)
      @child.setPreSteps(@parent.preSteps)
    else
      @child.preSteps.setStep(@parent.preSteps.step + @child.preSteps.step)
    end
  end
  
  if not @parent.postSteps.nil?
    if (@child.postSteps.nil?)
      @child.setPostSteps(@parent.postSteps)
    else
      @child.postSteps.setStep(@parent.postSteps.step + @child.postSteps.step)
    end
  end

  if not @parent.exitSteps.nil?
    if (@child.exitSteps.nil?)
      @child.setExitSteps(@parent.exitSteps)
    else
      @child.exitSteps.setStep(@parent.exitSteps.step + @child.exitSteps.step)
    end
  end
  
  pt = @parent.defaultToolchain
  ct = @child.defaultToolchain
  
  if not pt.nil?
    if (ct.nil?)
      @child.setDefaultToolchain(pt)
    else
      mergeToolchain(pt,ct,true)
    end
  end
  
  pt = @parent.toolchain
  ct = @child.toolchain
  
  if not pt.nil?
    if (ct.nil?)
      @child.setToolchain(pt)
    else
      mergeToolchain(pt,ct,false)
    end
  end
  
  # Valid for custom config

  
  if (Metamodel::CustomConfig === @child && Metamodel::CustomConfig === @parent)
    @child.setStep(@parent.step) if @child.step.nil? and not @parent.step.nil?
  end
  
  # Valid for library and exe config

  
  if ((Metamodel::LibraryConfig === @child || Metamodel::ExecutableConfig === @child) && (Metamodel::LibraryConfig === @parent || Metamodel::ExecutableConfig === @parent))
    @child.setFiles(@parent.files + @child.files)
    @child.setExcludeFiles(@parent.excludeFiles + @child.excludeFiles)
    @child.setIncludeDir(@parent.includeDir + @child.includeDir)
  end
  
  # Valid for exe config

  
  if (Metamodel::ExecutableConfig === @child && Metamodel::ExecutableConfig === @parent)
    @child.setLinkerScript(@parent.linkerScript) if @child.linkerScript.nil? and not @parent.linkerScript.nil?
    @child.setArtifactName(@parent.artifactName) if @child.artifactName.nil? and not @parent.artifactName.nil?
    @child.setMapFile(@parent.mapFile) if @child.mapFile.nil?  and not @parent.mapFile.nil?
  end

end

#mergeToolchain(pt, ct, isDefault) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
69
70
71
72
73
74
75
# File 'lib/bake/mergeConfig.rb', line 10

def mergeToolchain(pt,ct, isDefault)
  pt.compiler.each do |pc|
    found = false
    ct.compiler.each do |cc|
      if cc.ctype == pc.ctype
        found = true
        cc.setFlags(pc.flags + cc.flags)
        cc.setDefine(pc.define + cc.define)
        if cc.internalDefines.nil? and not pc.internalDefines.nil?
          cc.setInternalDefines(pc.internalDefines)
        end 
        if cc.command == "" and pc.command != ""
          cc.setCommand(pc.command)
        end
      end
    end
    ct.addCompiler(pc) if not found
  end

  if not pt.archiver.nil?
    if (ct.archiver.nil?)
      ct.setArchiver(pt.archiver)
    else
      if ct.archiver.command == "" and pt.archiver.command != ""
        ct.archiver.setCommand(pt.archiver.command)
      end
      ct.archiver.setFlags(pt.archiver.flags + ct.archiver.flags)
    end
  end 
 
  if not pt.linker.nil?
    if (ct.linker.nil?)
      ct.setLinker(pt.linker)
    else
      if ct.linker.command == "" and pt.linker.command != ""
        ct.linker.setCommand(pt.linker.command)
      end
      ct.linker.setFlags(pt.linker.flags + ct.linker.flags)
      ct.linker.setLibprefixflags(pt.linker.libprefixflags + ct.linker.libprefixflags)
      ct.linker.setLibpostfixflags(pt.linker.libpostfixflags + ct.linker.libpostfixflags)
    end
  end 
  
  if ct.outputDir == "" and pt.outputDir != ""
    ct.setOutputDir(pt.outputDir)
  end

  if ct.docu.nil? and not pt.docu.nil?
    ct.setDocu(pt.docu)
  end
  
  ct.setLintPolicy(pt.lintPolicy + ct.lintPolicy)
  
  if (isDefault)
    if ct.basedOn == "" and pt.basedOn != ""
      ct.setBasedOn(pt.basedOn)
    end
    if pt.eclipseOrder # is that a good idea?

      ct.setEclipseOrder(pt.eclipseOrder)
    end
    if ct.internalIncludes.nil? and not pt.internalIncludes.nil?
      ct.setInternalIncludes(pt.internalIncludes)
    end 
  end
  
end