Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # Store a Module class object to an INF file.\r | |
3 | #\r | |
40d841f6 LG |
4 | # Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r |
5 | # This program and the accompanying materials\r | |
30fdf114 LG |
6 | # are licensed and made available under the terms and conditions of the BSD License\r |
7 | # which accompanies this distribution. The full text of the license may be found at\r | |
8 | # http://opensource.org/licenses/bsd-license.php\r | |
9 | #\r | |
10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | #\r | |
13 | \r | |
14 | ##\r | |
15 | # Import Modules\r | |
16 | #\r | |
17 | from LoadMsa import LoadMsa\r | |
18 | from CommonDataClass.ModuleClass import *\r | |
19 | from Common.MigrationUtilities import *\r | |
20 | \r | |
21 | ## Get the produced library class.\r | |
22 | #\r | |
23 | # Return the item of Library Class based on Library .\r | |
24 | #\r | |
25 | # @param LibraryClasses A list of library classes the module produces.\r | |
26 | #\r | |
27 | # @retval LibraryClassItem A text format library class item.\r | |
28 | #\r | |
29 | def GetModuleLibraryClass(LibraryClasses):\r | |
30 | ProducedLibraryClasses = []\r | |
31 | for LibraryClass in LibraryClasses:\r | |
32 | ProducedLibraryClass = LibraryClass.LibraryClass\r | |
33 | SupportedModueTypes = " ".join(LibraryClass.SupModuleList)\r | |
34 | if SupportedModueTypes != "":\r | |
35 | ProducedLibraryClass += "|" + SupportedModueTypes\r | |
36 | ProducedLibraryClasses.append(ProducedLibraryClass)\r | |
37 | \r | |
38 | return "|".join(ProducedLibraryClasses)\r | |
39 | \r | |
40 | \r | |
41 | ## Store Defines section.\r | |
42 | #\r | |
43 | # Write [Defines] section to the InfFile based on Module class object.\r | |
44 | # Different CPU architectures are specified in the subsection if possible.\r | |
45 | #\r | |
46 | # @param InfFile The output INF file to store the Defines section.\r | |
47 | # @param Module An input Module class object.\r | |
48 | #\r | |
49 | def StoreModuleDefinesSection(InfFile, Module):\r | |
50 | ModuleHeader = Module.Header\r | |
51 | \r | |
52 | DefinesTupleList = []\r | |
53 | DefinesTupleList.append(("INF_VERSION", ModuleHeader.InfVersion))\r | |
54 | \r | |
55 | if ModuleHeader.Name != "":\r | |
56 | DefinesTupleList.append(("BASE_NAME", ModuleHeader.Name))\r | |
57 | \r | |
58 | if ModuleHeader.Guid != "":\r | |
59 | DefinesTupleList.append(("FILE_GUID", ModuleHeader.Guid))\r | |
60 | \r | |
61 | if ModuleHeader.Version != "":\r | |
62 | DefinesTupleList.append(("VERSION_STRING", ModuleHeader.Version))\r | |
63 | \r | |
64 | if ModuleHeader.ModuleType != "":\r | |
65 | DefinesTupleList.append(("MODULE_TYPE", ModuleHeader.ModuleType))\r | |
66 | \r | |
52302d4d LG |
67 | if ModuleHeader.UefiSpecificationVersion != "":\r |
68 | DefinesTupleList.append(("UEFI_SPECIFICATION_VERSION", ModuleHeader.UefiSpecificationVersion))\r | |
30fdf114 LG |
69 | \r |
70 | if ModuleHeader.EdkReleaseVersion != "":\r | |
71 | DefinesTupleList.append(("EDK_RELEASE_VERSION", ModuleHeader.EdkReleaseVersion))\r | |
72 | \r | |
73 | ProducedLibraryClass = GetModuleLibraryClass(ModuleHeader.LibraryClass)\r | |
74 | if ProducedLibraryClass != "":\r | |
75 | DefinesTupleList.append(("LIBRARY_CLASS", ProducedLibraryClass))\r | |
76 | \r | |
77 | if ModuleHeader.MakefileName != "":\r | |
78 | DefinesTupleList.append(("MAKEFILE_NAME", ModuleHeader.MakeFileName))\r | |
79 | \r | |
80 | if ModuleHeader.PcdIsDriver != "":\r | |
81 | DefinesTupleList.append(("PCD_DRIVER", "TRUE"))\r | |
82 | \r | |
83 | if len(Module.ExternImages) > 0:\r | |
84 | ModuleEntryPoint = Module.ExternImages[0].ModuleEntryPoint\r | |
85 | ModuleUnloadImage = Module.ExternImages[0].ModuleUnloadImage\r | |
86 | if ModuleEntryPoint != "":\r | |
87 | DefinesTupleList.append(("ENTRY_POINT", ModuleEntryPoint))\r | |
88 | if ModuleUnloadImage != "":\r | |
89 | DefinesTupleList.append(("UNLOAD_IMAGE", ModuleUnloadImage))\r | |
90 | \r | |
91 | if len(Module.ExternLibraries) > 0:\r | |
92 | Constructor = Module.ExternLibraries[0].Constructor\r | |
93 | Destructor = Module.ExternLibraries[0].Destructor\r | |
94 | if Constructor != "":\r | |
95 | DefinesTupleList.append(("CONSTRUCTOR", Constructor))\r | |
96 | if Destructor != "":\r | |
97 | DefinesTupleList.append(("DESTRUCTOR", Destructor))\r | |
98 | \r | |
99 | StoreDefinesSection(InfFile, DefinesTupleList)\r | |
100 | \r | |
101 | \r | |
102 | ## Return a Module Source Item.\r | |
103 | #\r | |
104 | # Read the input ModuleSourceFile class object and return one line of Source Item.\r | |
105 | #\r | |
106 | # @param ModuleSourceFile An input ModuleSourceFile class object.\r | |
107 | #\r | |
108 | # @retval SourceItem A Module Source Item.\r | |
109 | #\r | |
110 | def GetModuleSourceItem(ModuleSourceFile):\r | |
111 | Source = []\r | |
112 | Source.append(ModuleSourceFile.SourceFile)\r | |
113 | Source.append(ModuleSourceFile.ToolChainFamily)\r | |
114 | Source.append(ModuleSourceFile.TagName)\r | |
115 | Source.append(ModuleSourceFile.ToolCode)\r | |
116 | Source.append(ModuleSourceFile.FeatureFlag)\r | |
117 | return "|".join(Source).rstrip("|")\r | |
118 | \r | |
119 | \r | |
120 | ## Store Sources section.\r | |
121 | #\r | |
122 | # Write [Sources] section to the InfFile based on Module class object.\r | |
123 | # Different CPU architectures are specified in the subsection if possible.\r | |
124 | #\r | |
125 | # @param InfFile The output INF file to store the Sources section.\r | |
126 | # @param Module An input Module class object.\r | |
127 | #\r | |
128 | def StoreModuleSourcesSection(InfFile, Module):\r | |
129 | Section = GetSection("Sources", GetModuleSourceItem, Module.Sources)\r | |
130 | StoreTextFile(InfFile, Section)\r | |
131 | \r | |
132 | \r | |
133 | ## Return a Module Binary Item.\r | |
134 | #\r | |
135 | # Read the input ModuleBinaryFile class object and return one line of Binary Item.\r | |
136 | #\r | |
137 | # @param ModuleBinaryFile An input ModuleBinaryFile class object.\r | |
138 | #\r | |
139 | # @retval BinaryItem A Module Binary Item.\r | |
140 | #\r | |
141 | def GetModuleBinaryItem(ModuleBinaryFile):\r | |
142 | Binary = []\r | |
143 | Binary.append(ModuleBinaryFile.FileType)\r | |
144 | Binary.append(ModuleBinaryFile.BinaryFile)\r | |
145 | Binary.append(ModuleBinaryFile.Target)\r | |
146 | Binary.append(ModuleBinaryFile.FeatureFlag)\r | |
147 | return "|".join(Binary).rstrip("|")\r | |
148 | \r | |
149 | \r | |
150 | ## Store Binaries section.\r | |
151 | #\r | |
152 | # Write [Binaries] section to the InfFile based on Module class object.\r | |
153 | # Different CPU architectures are specified in the subsection if possible.\r | |
154 | #\r | |
155 | # @param InfFile The output INF file to store the Binaries section.\r | |
156 | # @param Module An input Module class object.\r | |
157 | #\r | |
158 | def StoreModuleBinariesSection(InfFile, Module):\r | |
159 | Section = GetSection("Binaries", GetModuleBinaryItem, Module.Binaries)\r | |
160 | StoreTextFile(InfFile, Section)\r | |
161 | \r | |
162 | \r | |
163 | ## Return a Module Library Class Item.\r | |
164 | #\r | |
165 | # Read the input LibraryClass class object and return one line of Library Class Item.\r | |
166 | #\r | |
167 | # @param LibraryClass An input LibraryClass class object.\r | |
168 | #\r | |
169 | # @retval LibraryClassItem A Module Library Class Item.\r | |
170 | #\r | |
171 | def GetModuleLibraryClassItem(LibraryClass):\r | |
172 | if "ALWAYS_PRODUCED" in LibraryClass.Usage:\r | |
173 | return ""\r | |
174 | \r | |
175 | LibraryClassList = []\r | |
176 | LibraryClassList.append(LibraryClass.LibraryClass)\r | |
177 | LibraryClassList.append(LibraryClass.RecommendedInstance)\r | |
178 | LibraryClassList.append(LibraryClass.FeatureFlag)\r | |
179 | \r | |
180 | return "|".join(LibraryClassList).rstrip("|")\r | |
181 | \r | |
182 | \r | |
183 | ## Store Library Classes section.\r | |
184 | #\r | |
185 | # Write [LibraryClasses] section to the InfFile based on Module class object.\r | |
186 | # Different CPU architectures are specified in the subsection if possible.\r | |
187 | #\r | |
188 | # @param InfFile The output INF file to store the Library Classes section.\r | |
189 | # @param Module An input Module class object.\r | |
190 | #\r | |
191 | def StoreModuleLibraryClassesSection(InfFile, Module):\r | |
192 | Section = GetSection("LibraryClasses", GetModuleLibraryClassItem, Module.LibraryClasses)\r | |
193 | StoreTextFile(InfFile, Section)\r | |
194 | \r | |
195 | \r | |
196 | ## Return a Module Package Item.\r | |
197 | #\r | |
198 | # Read the input PackageDependency class object and return one line of Package Item.\r | |
199 | #\r | |
200 | # @param PackageDependency An input PackageDependency class object.\r | |
201 | #\r | |
202 | # @retval PackageItem A Module Package Item.\r | |
203 | #\r | |
204 | def GetModulePackageItem(PackageDependency):\r | |
205 | return PackageDependency.FilePath\r | |
206 | \r | |
207 | \r | |
208 | ## Store Packages section.\r | |
209 | #\r | |
210 | # Write [Packages] section to the InfFile based on Module class object.\r | |
211 | # Different CPU architectures are specified in the subsection if possible.\r | |
212 | #\r | |
213 | # @param InfFile The output INF file to store the Packages section.\r | |
214 | # @param Module An input Module class object.\r | |
215 | #\r | |
216 | def StoreModulePackagesSection(InfFile, Module):\r | |
217 | Section = GetSection("Packages", GetModulePackageItem, Module.PackageDependencies)\r | |
218 | StoreTextFile(InfFile, Section)\r | |
219 | \r | |
220 | \r | |
221 | ## Return a Module Guid C Name Item.\r | |
222 | #\r | |
223 | # Read the input Guid class object and return one line of Guid C Name Item.\r | |
224 | #\r | |
225 | # @param Guid An input Guid class object.\r | |
226 | #\r | |
227 | # @retval GuidCNameItem A Module Guid C Name Item.\r | |
228 | #\r | |
229 | def GetModuleGuidCNameItem(Guid):\r | |
230 | try:\r | |
231 | return Guid.GuidCName\r | |
232 | except:\r | |
233 | return Guid.CName\r | |
234 | \r | |
235 | \r | |
236 | ## Store Protocols section.\r | |
237 | #\r | |
238 | # Write [Protocols] section to the InfFile based on Module class object.\r | |
239 | # Different CPU architectures are specified in the subsection if possible.\r | |
240 | #\r | |
241 | # @param InfFile The output INF file to store the Protocols section.\r | |
242 | # @param Module An input Module class object.\r | |
243 | #\r | |
244 | def StoreModuleProtocolsSection(InfFile, Module):\r | |
245 | Section = GetSection("Protocols", GetModuleGuidCNameItem, Module.Protocols)\r | |
246 | StoreTextFile(InfFile, Section)\r | |
247 | \r | |
248 | \r | |
249 | ## Store Ppis section.\r | |
250 | #\r | |
251 | # Write [Ppis] section to the InfFile based on Module class object.\r | |
252 | # Different CPU architectures are specified in the subsection if possible.\r | |
253 | #\r | |
254 | # @param InfFile The output INF file to store the Ppis section.\r | |
255 | # @param Module An input Module class object.\r | |
256 | #\r | |
257 | def StoreModulePpisSection(InfFile, Module):\r | |
258 | Section = GetSection("Ppis", GetModuleGuidCNameItem, Module.Ppis)\r | |
259 | StoreTextFile(InfFile, Section)\r | |
260 | \r | |
261 | \r | |
262 | ## Store Guids section.\r | |
263 | #\r | |
264 | # Write [Guids] section to the InfFile based on Module class object.\r | |
265 | # Different CPU architectures are specified in the subsection if possible.\r | |
266 | #\r | |
267 | # @param InfFile The output INF file to store the Guids section.\r | |
268 | # @param Module An input Module class object.\r | |
269 | #\r | |
270 | def StoreModuleGuidsSection(InfFile, Module):\r | |
271 | Guids = []\r | |
272 | Guids += Module.Guids\r | |
273 | Guids += Module.Events\r | |
274 | Guids += Module.Hobs\r | |
275 | Guids += Module.Variables\r | |
276 | Guids += Module.SystemTables\r | |
277 | Guids += Module.DataHubs\r | |
278 | Guids += Module.HiiPackages\r | |
279 | Section = GetSection("Guids", GetModuleGuidCNameItem, Guids)\r | |
280 | StoreTextFile(InfFile, Section)\r | |
281 | \r | |
282 | \r | |
283 | ## Return a Module Pcd Item.\r | |
284 | #\r | |
285 | # Read the input Pcd class object and return one line of Pcd Item.\r | |
286 | #\r | |
287 | # @param Pcd An input Pcd class object.\r | |
288 | #\r | |
289 | # @retval PcdItem A Module Pcd Item.\r | |
290 | #\r | |
291 | def GetModulePcdItem(Pcd):\r | |
292 | PcdItem = "%s.%s" % (Pcd.TokenSpaceGuidCName, Pcd.CName)\r | |
293 | if Pcd.DefaultValue != "":\r | |
294 | PcdItem = "%s|%s" % (PcdItem, Pcd.DefaultValue)\r | |
295 | \r | |
296 | return PcdItem\r | |
297 | \r | |
298 | \r | |
299 | ## DEC Pcd Section Name dictionary indexed by PCD Item Type.\r | |
300 | mInfPcdSectionNameDict = {\r | |
301 | "FEATURE_FLAG" : "FeaturePcd",\r | |
302 | "FIXED_AT_BUILD" : "FixedPcd",\r | |
303 | "PATCHABLE_IN_MODULE" : "PatchPcd",\r | |
304 | "DYNAMIC" : "Pcd",\r | |
305 | "DYNAMIC_EX" : "PcdEx"\r | |
306 | }\r | |
307 | \r | |
308 | ## Store Pcds section.\r | |
309 | #\r | |
310 | # Write [(PcdType)] section to the InfFile based on Module class object.\r | |
311 | # Different CPU architectures are specified in the subsection if possible.\r | |
312 | #\r | |
313 | # @param InfFile The output INF file to store the Pcds section.\r | |
314 | # @param Module An input Module class object.\r | |
315 | #\r | |
316 | def StoreModulePcdsSection(InfFile, Module):\r | |
317 | PcdsDict = {}\r | |
318 | for Pcd in Module.PcdCodes:\r | |
319 | PcdSectionName = mInfPcdSectionNameDict.get(Pcd.ItemType)\r | |
320 | if PcdSectionName:\r | |
321 | PcdsDict.setdefault(PcdSectionName, []).append(Pcd)\r | |
322 | else:\r | |
323 | EdkLogger.info("Unknown Pcd Item Type: %s" % Pcd.ItemType)\r | |
324 | \r | |
325 | Section = ""\r | |
326 | for PcdSectionName in PcdsDict:\r | |
327 | Pcds = PcdsDict[PcdSectionName]\r | |
328 | Section += GetSection(PcdSectionName, GetModulePcdItem, Pcds)\r | |
329 | Section += "\n"\r | |
330 | \r | |
331 | StoreTextFile(InfFile, Section)\r | |
332 | \r | |
333 | \r | |
334 | ## Return a Module Depex Item.\r | |
335 | #\r | |
336 | # Read the input Depex class object and return one line of Depex Item.\r | |
337 | #\r | |
338 | # @param Depex An input Depex class object.\r | |
339 | #\r | |
340 | # @retval DepexItem A Module Depex Item.\r | |
341 | #\r | |
342 | def GetModuleDepexItem(Depex):\r | |
343 | return Depex.Depex\r | |
344 | \r | |
345 | \r | |
346 | ## Store Depex section.\r | |
347 | #\r | |
348 | # Write [Depex] section to the InfFile based on Module class object.\r | |
349 | # Different CPU architectures are specified in the subsection if possible.\r | |
350 | #\r | |
351 | # @param InfFile The output INF file to store the Depex section.\r | |
352 | # @param Module An input Module class object.\r | |
353 | #\r | |
354 | def StoreModuleDepexSection(InfFile, Module):\r | |
355 | Section = GetSection("Depex", GetModuleDepexItem, Module.Depex)\r | |
356 | StoreTextFile(InfFile, Section)\r | |
357 | \r | |
358 | \r | |
359 | ## Return a Module Build Option Item.\r | |
360 | #\r | |
361 | # Read the input BuildOption class object and return one line of Build Option Item.\r | |
362 | #\r | |
363 | # @param BuildOption An input BuildOption class object.\r | |
364 | #\r | |
365 | # @retval BuildOptionItem A Module Build Option Item.\r | |
366 | #\r | |
367 | def GetModuleBuildOptionItem(BuildOption):\r | |
368 | BuildTarget = BuildOption.BuildTarget\r | |
369 | if BuildTarget == "":\r | |
370 | BuildTarget = "*"\r | |
371 | \r | |
372 | TagName = BuildOption.TagName\r | |
373 | if TagName == "":\r | |
374 | TagName = "*"\r | |
375 | \r | |
376 | ToolCode = BuildOption.ToolCode\r | |
377 | if ToolCode == "":\r | |
378 | ToolCode = "*"\r | |
379 | \r | |
380 | Item = "_".join((BuildTarget, TagName, "*", ToolCode, "Flag"))\r | |
381 | \r | |
382 | ToolChainFamily = BuildOption.ToolChainFamily\r | |
383 | if ToolChainFamily != "":\r | |
384 | Item = "%s:%s" % (ToolChainFamily, Item)\r | |
385 | \r | |
386 | return "%-30s = %s" % (Item, BuildOption.Option)\r | |
387 | \r | |
388 | \r | |
389 | ## Store Build Options section.\r | |
390 | #\r | |
391 | # Write [BuildOptions] section to the InfFile based on Module class object.\r | |
392 | # Different CPU architectures are specified in the subsection if possible.\r | |
393 | #\r | |
394 | # @param InfFile The output INF file to store the Build Options section.\r | |
395 | # @param Module An input Module class object.\r | |
396 | #\r | |
397 | def StoreModuleBuildOptionsSection(InfFile, Module):\r | |
398 | Section = GetSection("BuildOption", GetModuleBuildOptionItem, Module.BuildOptions)\r | |
399 | StoreTextFile(InfFile, Section)\r | |
400 | \r | |
401 | \r | |
402 | ## Store User Extensions section.\r | |
403 | #\r | |
404 | # Write [UserExtensions] section to the InfFile based on Module class object.\r | |
405 | #\r | |
406 | # @param InfFile The output INF file to store the User Extensions section.\r | |
407 | # @param Module An input Module class object.\r | |
408 | #\r | |
409 | def StoreModuleUserExtensionsSection(InfFile, Module):\r | |
410 | Section = "".join(map(GetUserExtensions, Module.UserExtensions))\r | |
411 | StoreTextFile(InfFile, Section)\r | |
412 | \r | |
413 | \r | |
414 | ## Store a Module class object to a new INF file.\r | |
415 | #\r | |
416 | # Read an input Module class object and save the contents to a new INF file.\r | |
417 | #\r | |
418 | # @param INFFileName The output INF file.\r | |
419 | # @param Module An input Package class object.\r | |
420 | #\r | |
421 | def StoreInf(InfFileName, Module):\r | |
422 | InfFile = open(InfFileName, "w+")\r | |
423 | EdkLogger.info("Save file to %s" % InfFileName)\r | |
424 | \r | |
425 | StoreHeader(InfFile, Module.Header)\r | |
426 | StoreModuleDefinesSection(InfFile, Module)\r | |
427 | StoreModuleSourcesSection(InfFile, Module)\r | |
428 | StoreModuleBinariesSection(InfFile, Module)\r | |
429 | StoreModulePackagesSection(InfFile, Module)\r | |
430 | StoreModuleLibraryClassesSection(InfFile, Module)\r | |
431 | StoreModuleProtocolsSection(InfFile, Module)\r | |
432 | StoreModulePpisSection(InfFile, Module)\r | |
433 | StoreModuleGuidsSection(InfFile, Module)\r | |
434 | StoreModulePcdsSection(InfFile, Module)\r | |
435 | StoreModuleDepexSection(InfFile, Module)\r | |
436 | StoreModuleBuildOptionsSection(InfFile, Module)\r | |
437 | StoreModuleUserExtensionsSection(InfFile, Module)\r | |
438 | \r | |
439 | InfFile.close()\r | |
440 | \r | |
441 | if __name__ == '__main__':\r | |
442 | pass\r |