]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/fpd2dsc/StoreDsc.py
MdeModulePkg: Fix build warning on Xhci driver with XCode 32 tool chain.
[mirror_edk2.git] / BaseTools / Source / Python / fpd2dsc / StoreDsc.py
1 ## @file
2 # Store a Platform class object to an INF file.
3 #
4 # Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ##
15 # Import Modules
16 #
17 from LoadFpd import LoadFpd
18 from CommonDataClass.PlatformClass import *
19 from CommonDataClass.FdfClass import *
20 from Common.MigrationUtilities import *
21 from Common.ToolDefClassObject import *
22 from Common.TargetTxtClassObject import *
23
24 ## Store Defines section
25 #
26 # Write [Defines] section to the DscFile based on Platform class object.
27 # Different CPU architectures are specified in the subsection if possible.
28 #
29 # @param DscFile The output DSC file to store the Defines section
30 # @param Platform An input Platform class object
31 #
32 def StorePlatformDefinesSection(DscFile, Platform):
33 PlatformHeader = Platform.Header
34
35 DefinesTupleList = []
36
37 if PlatformHeader.Name != "":
38 DefinesTupleList.append(("PLATFORM_NAME", PlatformHeader.Name))
39
40 if PlatformHeader.Guid != "":
41 DefinesTupleList.append(("PLATFORM_GUID", PlatformHeader.Guid))
42
43 if PlatformHeader.Version != "":
44 DefinesTupleList.append(("PLATFORM_VERSION", PlatformHeader.Version))
45 for key in PlatformHeader.Specification.keys():
46 SpecificationValue = PlatformHeader.Specification.get(key)
47 DefinesTupleList.append(("DSC_ SPECIFICATION", SpecificationValue))
48
49 if PlatformHeader.OutputDirectory != "":
50 DefinesTupleList.append(("OUTPUT_DIRECTORY", PlatformHeader.OutputDirectory))
51
52 if PlatformHeader.SupArchList != "":
53 String = "|".join(PlatformHeader.SupArchList)
54 DefinesTupleList.append(("SUPPORTED_ARCHITECTURES", String))
55
56 if PlatformHeader.BuildTargets != "":
57 String = "|".join(PlatformHeader.BuildTargets)
58 DefinesTupleList.append(("BUILD_TARGETS", String))
59
60 if PlatformHeader.SkuIdName != "":
61 #DefinesTupleList.append(("SKUID_IDENTIFIER", PlatformHeader.SkuIdName))
62 String = "|".join(PlatformHeader.SkuIdName)
63 if String != "":
64 DefinesTupleList.append(("SKUID_IDENTIFIER", String))
65
66 String = Platform.FlashDefinitionFile.FilePath
67 if String != "":
68 DefinesTupleList.append(("FLASH_DEFINITION", String))
69
70 List = []
71 List.append("################################################################################")
72 List.append("#")
73 List.append("# Defines Section - statements that will be processed to create a Makefile.")
74 List.append("#")
75 List.append("################################################################################")
76 Section = "\n".join(List)
77 Section += "\n"
78 StoreTextFile(DscFile, Section)
79
80 StoreDefinesSection(DscFile, DefinesTupleList)
81
82 ## Store SkuIds section
83 #
84 # Write [SkuIds] section to the DscFile based on Platform class object.
85 # Different CPU architectures are specified in the subsection if possible.
86 #
87 # @param DscFile The output DSC file to store the Library Classes section
88 # @param Platform An input Platform class object
89 #
90 def StorePlatformSkuIdsSection(DscFile, Platform):
91 List = []
92 List.append("################################################################################")
93 List.append("#")
94 List.append("# SKU Identification section - list of all SKU IDs supported by this Platform.")
95 List.append("#")
96 List.append("################################################################################")
97 Section = "\n".join(List)
98 Section += "\n"
99
100 Section += "[SkuIds]" + '\n'
101
102 List = Platform.SkuInfos.SkuInfoList
103 for Item in List:
104 Section = Section + "%s" % Item[0] + '|' + "%s" % Item[1] + '\n'
105 Section = Section + '\n'
106
107 StoreTextFile(DscFile, Section)
108
109 ## Store Build Options section
110 #
111 # Write [BuildOptions] section to the DscFile based on Platform class object.
112 # Different CPU architectures are specified in the subsection if possible.
113 #
114 # @param DscFile The output DSC file to store the Build Options section
115 # @param Platform An input Platform class object
116 #
117 def StorePlatformBuildOptionsSection(DscFile, Platform):
118 # which is from tools_def.txt
119 StandardBuildTargets = ["DEBUG", "RELEASE"]
120 SupportedArches = ["COMMON", "IA32", "X64", "IPF", "EBC", "ARM"]
121 Target = TargetTxtClassObject()
122 WorkSpace = os.getenv('WORKSPACE')
123 Target.LoadTargetTxtFile(WorkSpace + '\\Conf\\target.txt')
124 ToolDef = ToolDefClassObject()
125 ToolDef.LoadToolDefFile(WorkSpace + '\\' + Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF])
126 # Now we have got ToolDef object
127 #ToolDef.ToolsDefTxtDictionary
128 Dict = ToolDef.ToolsDefTxtDatabase
129
130 Dict1 = ToolDef.ToolsDefTxtDictionary # we care the info in this Dict
131 #
132 # We only support *(DEBUG/RELEASE) and *(All Arch: IA32, X64, IPF and EBC) for now
133 #
134 SectionWINDDK = ''
135 SectionVS2003 = ''
136 SectionVS2005EXP = ''
137 SectionVS2005STD = ''
138 SectionVS2005PRO = ''
139 SectionVS2005TEAMSUITE = ''
140 SectionUNIXGCC = ''
141 SectionCYGWINGCC = ''
142 SectionELFGCC = ''
143 SectionICC = ''
144 SectionMYTOOLS = ''
145 for key in Dict1.keys():
146 if key.find("_CC_FLAGS") != -1:
147 if key.find('WINDDK3790x1830') != -1:
148 SectionWINDDK = " = " + Dict1.get(key) + "\n"
149 elif key.find('VS2003') != -1:
150 SectionVS2003 = " = " + Dict1.get(key)+ "\n"
151 elif key.find('VS2005EXP') != -1:
152 SectionVS2005EXP = " = " + Dict1.get(key) + "\n"
153 elif key.find('VS2005STD') != -1:
154 SectionVS2005STD = " = " + Dict1.get(key) + "\n"
155 elif key.find('VS2005PRO') != -1:
156 SectionVS2005PRO = " = " + Dict1.get(key) + "\n"
157 elif key.find('VS2005TEAMSUITE') != -1:
158 SectionVS2005TEAMSUITE = " = " + Dict1.get(key) + "\n"
159 elif key.find('UNIXGCC') != -1:
160 SectionUNIXGCC = " = " + Dict1.get(key) + "\n"
161 elif key.find('CYGWINGCC') != -1:
162 SectionCYGWINGCC = " = " + Dict1.get(key) + "\n"
163 elif key.find('ELFGCC') != -1:
164 SectionELFGCC = " = " + Dict1.get(key) + "\n"
165 elif key.find('ICC') != -1:
166 SectionICC = " = " + Dict1.get(key) + "\n"
167 elif key.find('MYTOOLS') != -1:
168 SectionMYTOOLS = " = " + Dict1.get(key) + "\n"
169 else:
170 print "Error!"
171
172 #
173 # First need to check which arch
174 #
175 Archs = Platform.Header.SupArchList
176 BuildTargets = Platform.Header.BuildTargets
177 #if BuildTargets == StandardBuildTargets:
178 #print "Debug and Release both support" # skip debug/release string search
179 #else:
180 #print "need to search debug/release string"
181
182 if len(Archs) == 4:
183 Arch = "*"
184 SectionName = "[BuildOptions.Common]\n"
185 else:
186 for Arch in Archs:
187 if Arch == 'IA32':
188 SectionName = "[BuildOptions.IA32]\n"
189 elif Arch == 'X64':
190 SectionName = "[BuildOptions.X64]\n"
191 elif Arch == 'IPF':
192 SectionName = "[BuildOptions.IPF]\n"
193 elif Arch == 'EBC':
194 SectionName = "[BuildOptions.EBC]\n"
195 else:
196 print 'Error!'
197 Section = ""
198 if SectionWINDDK != "":
199 SectionWINDDK = "*_WINDDK3790x1830_" + Arch + "_CC_FLAGS" + SectionWINDDK
200 Section += SectionWINDDK
201 if SectionVS2003 != "":
202 SectionVS2003 = "*_VS2003_" + Arch + "_CC_FLAGS" + SectionVS2003
203 Section += SectionVS2003
204 if SectionVS2005EXP != "":
205 SectionVS2005EXP = "*_VS2005EXP_" + Arch + "_CC_FLAGS" + SectionVS2005EXP
206 Section += SectionVS2005EXP
207 if SectionVS2005STD != "":
208 SectionVS2005STD = "*_VS2005STD_" + Arch + "_CC_FLAGS" + SectionVS2005STD
209 Section += SectionVS2005STD
210 if SectionVS2005PRO != "":
211 SectionVS2005PRO = "*_VS2005PRO_" + Arch + "_CC_FLAGS" + SectionVS2005PRO
212 Section += SectionVS2005PRO
213 if SectionVS2005TEAMSUITE != "":
214 SectionVS2005TEAMSUITE = "*_VS2005TEAMSUITE_" + Arch + "_CC_FLAGS" + SectionVS2005TEAMSUITE
215 Section += SectionVS2005TEAMSUITE
216 if SectionUNIXGCC != "":
217 SectionUNIXGCC = "*_UNIXGCC_" + Arch + "_CC_FLAGS" + SectionUNIXGCC
218 Section += SectionUNIXGCC
219 if SectionCYGWINGCC != "":
220 SectionCYGWINGCC = "*_CYGWINGCC_" + Arch + "_CC_FLAGS" + SectionCYGWINGCC
221 Section += SectionCYGWINGCC
222 if SectionELFGCC != "":
223 SectionELFGCC = "*_ELFGCC_" + Arch + "_CC_FLAGS" + SectionELFGCC
224 Section += SectionELFGCC
225 if SectionICC != "":
226 SectionICC = "*_ICC_" + Arch + "_CC_FLAGS" + SectionICC
227 Section += SectionICC
228 if SectionMYTOOLS != "":
229 SectionMYTOOLS = "*_MYTOOLS_" + Arch + "_CC_FLAGS" + SectionMYTOOLS
230 Section += SectionMYTOOLS
231
232 List = []
233 List.append("################################################################################")
234 List.append("#")
235 List.append("# Build Options section - list of all Build Options supported by this Platform.")
236 List.append("#")
237 List.append("################################################################################")
238 SectionHeader = "\n".join(List)
239 SectionHeader += "\n"
240
241 Section = SectionHeader + SectionName + Section
242 Section += "\n"
243 StoreTextFile(DscFile, Section)
244
245 ## Store Libraries section
246 #
247 # Write [Libraries] section to the DscFile based on Platform class object.
248 # Different CPU architectures are specified in the subsection if possible.
249 #
250 # @param DscFile The output DSC file to store the Library Classes section
251 # @param Platform An input Platform class object
252 #
253 def StorePlatformLibrariesSection(DscFile,Platform):
254 List = []
255 List.append("################################################################################")
256 List.append("#")
257 List.append("# Libraries section - list of all Libraries needed by this Platform.")
258 List.append("#")
259 List.append("################################################################################")
260 SectionHeader = "\n".join(List)
261 SectionHeader += "\n"
262
263 Section = SectionHeader + '[Libraries]\n\n'
264 StoreTextFile(DscFile, Section)
265
266 ## Return a Platform Library Class Item
267 #
268 # Read the input LibraryClass class object and return one line of Library Class Item.
269 #
270 # @param LibraryClass An input LibraryClass class object
271 #
272 # @retval LibraryClassItem A Module Library Class Item
273 #
274 def GetPlatformLibraryClassItem(LibraryClass):
275 LibraryClassList = []
276 LibraryClassList.append(LibraryClass.Name)
277 LibraryClassList.append(LibraryClass.FilePath)
278
279 return "|$(WORKSPACE)/".join(LibraryClassList).rstrip("|")
280
281 ## Add item to a LibraryClass section
282 #
283 # Add an Item with specific Module Type to section dictionary.
284 # The possible duplication is ensured to be removed.
285 #
286 # @param Section Section dictionary indexed by CPU architecture
287 # @param SupModuleList LibraryClass SupModuleList: BASE, SEC, PEI_CORE, PEIM, etc
288 # @param Item The Item to be added to section dictionary
289 #
290 def AddToLibraryClassSection(Section, SupModuleList, Item):
291 for ModuleType in SupModuleList:
292 SectionModule = Section.get(ModuleType, [])
293 if Item not in SectionModule:
294 SectionModule.append(Item)
295 Section[ModuleType] = SectionModule
296
297 ## Get Library Classes section contents
298 #
299 # Return the content of section named SectionName.
300 # the contents is based on Methods and ObjectLists.
301 #
302 # @param SectionName The name of the section
303 # @param Method A function returning a string item of an object
304 # @param ObjectList The list of object
305 #
306 # @retval Section The string content of a section
307 #
308 def GetLibraryClassesSection(SectionName, Method, ObjectList):
309 SupportedArches = ["COMMON", "IA32", "X64", "IPF", "EBC"]
310 ModuleTypes = ["BASE","SEC","PEI_CORE","PEIM","DXE_CORE","DXE_DRIVER","DXE_SMM_DRIVER","DXE_SAL_DRIVER","DXE_RUNTIME_DRIVER","UEFI_DRIVER","UEFI_APPLICATION"]
311 SectionCommonDict = {}
312 SectionIA32Dict = {}
313 SectionX64Dict = {}
314 SectionIPFDict = {}
315 SectionEBCDict = {}
316 #ObjectList = list(set(ObjectList)) # delete the same element in the list
317 for Object in ObjectList:
318 if Object == None:
319 continue
320 Item = Method(Object)
321 if Item == "":
322 continue
323 Item = " %s" % Item
324 Arches = Object.SupArchList
325 if len(Arches) == 4:
326 ModuleType = Object.ModuleType
327 # [LibraryClasses.Common.ModuleType]
328 if ModuleType == "BASE":
329 SupModuleList = ["BASE"]
330 AddToLibraryClassSection(SectionCommonDict, SupModuleList, Item)
331 else:
332 #
333 SupModuleList = Object.SupModuleList
334 #AddToSection(SectionDict, "|".join(SupModuleList), Item)
335 AddToLibraryClassSection(SectionCommonDict, SupModuleList, Item)
336 else:
337 # Arch
338 for Arch in SupportedArches:
339 if Arch.upper() in Arches:
340 if Arch == "IA32":
341 # [LibraryClasses.IA32.ModuleType]
342 ModuleType = Object.ModuleType
343 if ModuleType == "BASE":
344 SupModuleList = ["BASE"]
345 AddToLibraryClassSection(SectionIA32Dict, SupModuleList, Item)
346 else:
347 SupModuleList = Object.SupModuleList
348 AddToLibraryClassSection(SectionIA32Dict, SupModuleList, Item)
349 elif Arch == "X64":
350 # [LibraryClasses.X64.ModuleType]
351 ModuleType = Object.ModuleType
352 if ModuleType == "BASE":
353 SupModuleList = ["BASE"]
354 AddToLibraryClassSection(SectionX64Dict, SupModuleList, Item)
355 else:
356 SupModuleList = Object.SupModuleList
357 AddToLibraryClassSection(SectionX64Dict, SupModuleList, Item)
358 elif Arch == "IPF":
359 # [LibraryClasses.IPF.ModuleType]
360 ModuleType = Object.ModuleType
361 if ModuleType == "BASE":
362 SupModuleList = ["BASE"]
363 AddToLibraryClassSection(SectionIPFDict, SupModuleList, Item)
364 else:
365 SupModuleList = Object.SupModuleList
366 AddToLibraryClassSection(SectionIPFDict, SupModuleList, Item)
367 elif Arch == "EBC":
368 # [LibraryClasses.EBC.ModuleType]
369 ModuleType = Object.ModuleType
370 if ModuleType == "BASE":
371 SupModuleList = ["BASE"]
372 AddToLibraryClassSection(SectionEBCDict, SupModuleList, Item)
373 else:
374 SupModuleList = Object.SupModuleList
375 AddToLibraryClassSection(SectionEBCDict, SupModuleList, Item)
376
377 Section = ""
378 for ModuleType in ModuleTypes:
379 SectionCommonModule = "\n".join(SectionCommonDict.get(ModuleType, []))
380 if SectionCommonModule != "":
381 Section += "[%s.Common.%s]\n%s\n" % (SectionName, ModuleType, SectionCommonModule)
382 Section += "\n"
383 for ModuleType in ModuleTypes:
384 ListIA32 = SectionIA32Dict.get(ModuleType, [])
385 if ListIA32 != []:
386 SectionIA32Module = "\n".join(SectionIA32Dict.get(ModuleType, []))
387 if SectionIA32Module != "":
388 Section += "[%s.IA32.%s]\n%s\n" % (SectionName, ModuleType, SectionIA32Module)
389 Section += "\n"
390 ListX64 = SectionX64Dict.get(ModuleType, [])
391 if ListX64 != []:
392 SectionX64Module = "\n".join(SectionX64Dict.get(ModuleType, []))
393 if SectionX64Module != "":
394 Section += "[%s.X64.%s]\n%s\n" % (SectionName, ModuleType, SectionX64Module)
395 Section += "\n"
396 ListIPF = SectionIPFDict.get(ModuleType, [])
397 if ListIPF != []:
398 SectionIPFModule = "\n".join(SectionIPFDict.get(ModuleType, []))
399 if SectionIPFModule != "":
400 Section += "[%s.IPF.%s]\n%s\n" % (SectionName, ModuleType, SectionIPFModule)
401 Section += "\n"
402 ListEBC = SectionEBCDict.get(ModuleType, [])
403 if ListEBC != []:
404 SectionEBCModule = "\n".join(SectionEBCDict.get(ModuleType, []))
405 if SectionEBCModule != "":
406 Section += "[%s.EBC.%s]\n%s\n" % (SectionName, ModuleType, SectionEBCModule)
407 Section += "\n"
408
409 if Section != "":
410 Section += "\n"
411 return Section
412
413 ## Store Library Classes section
414 #
415 # Write [LibraryClasses] section to the DscFile based on Platform class object.
416 # Different CPU architectures are specified in the subsection if possible.
417 #
418 # @param DscFile The output DSC file to store the Library Classes section
419 # @param Platform An input Platform class object
420 #
421 def StorePlatformLibraryClassesSection(DscFile, Platform):
422 Section = GetLibraryClassesSection("LibraryClasses", GetPlatformLibraryClassItem, Platform.LibraryClasses.LibraryList)
423 List = []
424 List.append("################################################################################")
425 List.append("#")
426 List.append("# Library Class section - list of all Library Classes needed by this Platform.")
427 List.append("#")
428 List.append("################################################################################")
429 SectionHeader = "\n".join(List)
430 SectionHeader += "\n"
431 Section = SectionHeader + Section
432 StoreTextFile(DscFile, Section)
433
434 ## Store Pcd section
435 #
436 # Write [Pcd] section to the DscFile based on Platform class object.
437 # Different CPU architectures are specified in the subsection if possible.
438 #
439 # @param DscFile The output DSC file to store the Build Options section
440 # @param Platform An input Platform class object
441 #
442 def StorePlatformPcdSection(DscFile, Platform):
443 # {PcdsFixedAtBuild:String1, PcdsFixedAtBuild:String2, PcdsPatchableInModule:String3}
444 SectionDict = {}
445 #
446 # [PcdsFixedAtBuild], [PcdsPatchableInModule] and [PcdsFeatureFlag] are from platform.modules
447 # [PcdsDynamic] is from platform.DynamicPcdBuildDefinitions
448 #
449 Modules = Platform.Modules.ModuleList # it's a list of modules
450 for Module in Modules:
451 PcdBuildDefinitions = Module.PcdBuildDefinitions # it's a list of PcdData
452 for PcdData in PcdBuildDefinitions:
453 if PcdData.ItemType == "FEATURE_FLAG":
454 List = []
455 List.append(PcdData.TokenSpaceGuidCName + "." + PcdData.C_NAME)
456 List.append(PcdData.Value)
457 String = "|".join(List)
458 ItemType = PcdData.ItemType
459 SectionPcdsFeatureFlag = SectionDict.get(ItemType, [])
460 if String not in SectionPcdsFeatureFlag:
461 SectionPcdsFeatureFlag.append(String)
462 SectionDict[ItemType] = SectionPcdsFeatureFlag
463 else:
464 List = []
465 List.append(PcdData.TokenSpaceGuidCName + "." + PcdData.C_NAME)
466 List.append(PcdData.Value)
467 List.append(PcdData.Token)
468 List.append(PcdData.DatumType)
469 List.append(PcdData.MaxDatumSize)
470 String = "|".join(List)
471 ItemType = PcdData.ItemType
472 if PcdData.ItemType == "FIXED_AT_BUILD":
473 SectionPcdsFixedAtBuild = SectionDict.get(ItemType, [])
474 if String not in SectionPcdsFixedAtBuild:
475 SectionPcdsFixedAtBuild.append(String)
476 SectionDict[ItemType] = SectionPcdsFixedAtBuild
477 #elif PcdData.ItemType == "FEATURE_FLAG":
478 #SectionPcdsFeatureFlag = SectionDict.get(ItemType, [])
479 #if String not in SectionPcdsFeatureFlag:
480 #SectionPcdsFeatureFlag.append(String)
481 #SectionDict[ItemType] = SectionPcdsFeatureFlag
482 elif PcdData.ItemType == "PATCHABLE_IN_MODULE":
483 SectionPcdsPatchableInModule = SectionDict.get(ItemType, [])
484 if String not in SectionPcdsPatchableInModule:
485 SectionPcdsPatchableInModule.append(String)
486 SectionDict[ItemType] = SectionPcdsPatchableInModule
487 elif PcdData.ItemType == "DYNAMIC":
488 SectionPcdsDynamic = SectionDict.get(ItemType, [])
489 if String not in SectionPcdsDynamic:
490 SectionPcdsDynamic.append(String)
491 SectionDict[ItemType] = SectionPcdsDynamic
492
493 DynamicPcdBuildDefinitions = Platform.DynamicPcdBuildDefinitions # It's a list
494 for PcdBuildData in DynamicPcdBuildDefinitions:
495 List = []
496 List.append(PcdData.TokenSpaceGuidCName + "." + PcdData.C_NAME)
497 List.append(PcdData.Token)
498 List.append(PcdData.DatumType)
499 List.append(PcdData.MaxDatumSize)
500 String = "|".join(List)
501 if PcdBuildData.ItemType == "DYNAMIC":
502 ItemType = PcdBuildData.ItemType
503 SectionPcdsDynamic = SectionDict.get(ItemType, [])
504 if String not in SectionPcdsDynamic:
505 SectionPcdsDynamic.append(String)
506 SectionDict[ItemType] = SectionPcdsDynamic
507 ItemType = "FIXED_AT_BUILD"
508 Section = "[PcdsFixedAtBuild]\n " + "\n ".join(SectionDict.get(ItemType, []))
509 ItemType = "FEATURE_FLAG"
510 Section += "\n\n[PcdsFeatureFlag]\n " + "\n ".join(SectionDict.get(ItemType, []))
511 ItemType = "PATCHABLE_IN_MODULE"
512 Section += "\n\n[PcdsPatchableInModule]\n " + "\n ".join(SectionDict.get(ItemType, []))
513 Section += "\n\n"
514 List = []
515 List.append("################################################################################")
516 List.append("#")
517 List.append("# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform.")
518 List.append("#")
519 List.append("################################################################################")
520 String = "\n".join(List)
521 Section += String
522 ItemType = "DYNAMIC"
523 Section += "\n\n[PcdsDynamic]\n " + "\n ".join(SectionDict.get(ItemType, []))
524 Section += "\n\n"
525
526 List = []
527 List.append("################################################################################")
528 List.append("#")
529 List.append("# Pcd Section - list of all EDK II PCD Entries defined by this Platform.")
530 List.append("#")
531 List.append("################################################################################")
532 SectionHeader = "\n".join(List)
533 SectionHeader += "\n"
534 Section = SectionHeader + Section
535 StoreTextFile(DscFile, Section)
536
537 ## Add item to a section
538 #
539 # Add an Item with specific CPU architecture to section dictionary.
540 # The possible duplication is ensured to be removed.
541 #
542 # @param Section Section dictionary indexed by CPU architecture
543 # @param Arch CPU architecture: Ia32, X64, Ipf, Ebc or Common
544 # @param Item The Item to be added to section dictionary
545 #
546 def AddToSection(Section, Arch, Item):
547 SectionArch = Section.get(Arch, [])
548 if Item not in SectionArch:
549 SectionArch.append(Item)
550 Section[Arch] = SectionArch
551
552 ## Get section contents
553 #
554 # Return the content of section named SectionName.
555 # the contents is based on Methods and ObjectLists.
556 #
557 # @param SectionName The name of the section
558 # @param Method A function returning a string item of an object
559 # @param ObjectList The list of object
560 #
561 # @retval Section The string content of a section
562 #
563 def GetSection(SectionName, Method, ObjectList):
564 SupportedArches = ["COMMON", "IA32", "X64", "IPF", "EBC"]
565 SectionDict = {}
566 for Object in ObjectList:
567 if Object.FilePath == "":
568 continue
569 Item = Method(Object)
570 if Item == "":
571 continue
572 Item = " %s" % Item
573 Arches = Object.SupArchList
574 if len(Arches) == 4:
575 AddToSection(SectionDict, "common", Item)
576 else:
577 for Arch in SupportedArches:
578 if Arch.upper() in Arches:
579 AddToSection(SectionDict, Arch, Item)
580
581 Section = ""
582 for Arch in SupportedArches:
583 SectionArch = "\n".join(SectionDict.get(Arch, []))
584 if SectionArch != "":
585 Section += "[%s.%s]\n%s\n" % (SectionName, Arch, SectionArch)
586 Section += "\n"
587 if Section != "":
588 Section += "\n"
589 return Section
590
591 ## Return a Platform Component Item
592 #
593 # Read the input Platform Component object and return one line of Platform Component Item.
594 #
595 # @param Component An input Platform Component class object
596 #
597 # @retval ComponentItem A Platform Component Item
598 #
599 def GetPlatformComponentItem(Component):
600 List = []
601 Section = {}
602
603 List.append("$(WORKSPACE)/" + Component.FilePath)
604
605 LibraryClasses = Component.LibraryClasses
606 if LibraryClasses != []:
607 List = []
608 List.append("$(WORKSPACE)/" + Component.FilePath + " {")
609 List.append("<LibraryClasses>")
610 for LibraryClass in LibraryClasses:
611 if LibraryClass == ["", ""]:
612 continue
613 List.append(" " + LibraryClass[0] + "|$(WORKSPACE)/" + LibraryClass[1])
614
615 PcdBuildDefinitions = Component.PcdBuildDefinitions
616 for PcdData in PcdBuildDefinitions:
617 if PcdData.ItemType == "FEATURE_FLAG":
618 List1 = []
619 List1.append(PcdData.TokenSpaceGuidCName + "." + PcdData.C_NAME)
620 List1.append(PcdData.Value)
621 String = "|".join(List1)
622 ItemType = PcdData.ItemType
623 SectionPcd = Section.get(ItemType, [])
624 if String not in SectionPcd:
625 SectionPcd.append(String)
626 Section[ItemType] = SectionPcd
627 else:
628 List1 = []
629 List1.append(PcdData.TokenSpaceGuidCName + "." + PcdData.C_NAME)
630 List1.append(PcdData.Value)
631 List1.append(PcdData.Token)
632 List1.append(PcdData.DatumType)
633 List1.append(PcdData.MaxDatumSize)
634 String = "|".join(List1)
635 ItemType = PcdData.ItemType
636 if ItemType == "FIXED_AT_BUILD":
637 SectionPcd = Section.get(ItemType, [])
638 if String not in SectionPcd:
639 SectionPcd.append(String)
640 Section[ItemType] = SectionPcd
641 #elif ItemType == "FEATURE_FLAG":
642 #SectionPcd = Section.get(ItemType, [])
643 #if String not in SectionPcd:
644 #SectionPcd.append(String)
645 #Section[ItemType] = SectionPcd
646 elif ItemType == "PATCHABLE_IN_MODULE":
647 SectionPcd = Section.get(ItemType, [])
648 if String not in SectionPcd:
649 SectionPcd.append(String)
650 Section[ItemType] = SectionPcd
651 elif ItemType == "DYNAMIC":
652 SectionPcd = Section.get(ItemType, [])
653 if String not in SectionPcd:
654 SectionPcd.append(String)
655 Section[ItemType] = SectionPcd
656
657 ItemType = "FIXED_AT_BUILD"
658 if Section.get(ItemType, []) != []:
659 List.append("<PcdsFixedAtBuild>")
660 List.append(" " + "\n ".join(Section.get(ItemType,[])))
661 ItemType = "FEATURE_FLAG"
662 if Section.get(ItemType, []) != []:
663 List.append("<PcdsFeatureFlag>")
664 List.append(" " + "\n ".join(Section.get(ItemType,[])))
665 ItemType = "PATCHABLE_IN_MODULE"
666 if Section.get(ItemType, []) != []:
667 List.append("<PcdsPatchableInModule>")
668 List.append(" " + "\n ".join(Section.get(ItemType,[])))
669 ItemType = "DYNAMIC"
670 if Section.get(ItemType, []) != []:
671 List.append("<PcdsDynamic>")
672 List.append(" " + "\n ".join(Section.get(ItemType,[])))
673
674 ListOption = []
675 SectionOption = ""
676 ListBuildOptions = Component.BuildOptions # a list
677 if ListBuildOptions != []:
678 SectionOption += "\n <BuildOptions>\n"
679 for BuildOptions in ListBuildOptions:
680 Options = BuildOptions.Options
681 for Option in Options:
682 for Item in Option.BuildTargetList:
683 ListOption.append(Item)
684 List.append(Option.ToolChainFamily)
685 for Item in Option.SupArchList:
686 ListOption.append(Item)
687 ListOption.append(Option.ToolCode)
688 ListOption.append("FLAGS")
689 #print ListOption
690 SectionOption += " " + "_".join(List) + " = " + Option.Option + "\n"
691 ListOption = []
692 if SectionOption != "":
693 List.append(SectionOption)
694 if List != ["$(WORKSPACE)/" + Component.FilePath]:
695 List.append("}\n")
696
697 return "\n ".join(List)
698
699 ## Store Components section.
700 #
701 # Write [Components] section to the DscFile based on Platform class object.
702 # Different CPU architectures are specified in the subsection if possible.
703 #
704 # @param DscFile The output DSC file to store the Components section
705 # @param Platform An input Platform class object
706 #
707 def StorePlatformComponentsSection(DscFile, Platform):
708 Section = GetSection("Components", GetPlatformComponentItem, Platform.Modules.ModuleList)
709 List = []
710 List.append("################################################################################")
711 List.append("#")
712 List.append("# Components Section - list of all EDK II Modules needed by this Platform.")
713 List.append("#")
714 List.append("################################################################################")
715 SectionHeader = "\n".join(List)
716 SectionHeader += "\n"
717 Section = SectionHeader + Section
718 StoreTextFile(DscFile, Section)
719
720 ## Store User Extensions section.
721 #
722 # Write [UserExtensions] section to the InfFile based on Module class object.
723 # Different CPU architectures are specified in the subsection if possible.
724 #
725 # @param DscFile The output DSC file to store the User Extensions section
726 # @param Platform An input Platform class object
727 #
728 def StorePlatformUserExtensionsSection(DscFile, Platform):
729 Section = "".join(map(GetUserExtensions, Platform.UserExtensions))
730 List = []
731 List.append("################################################################################")
732 List.append("#")
733 List.append("# User Extensions Section - list of all User Extensions specified by user.")
734 List.append("#")
735 List.append("################################################################################")
736 SectionHeader = "\n".join(List)
737 SectionHeader += "\n"
738 Section = SectionHeader + Section
739 StoreTextFile(DscFile, Section)
740
741 ## Store a Platform class object to a new DSC file.
742 #
743 # Read an input Platform class object and save the contents to a new DSC file.
744 #
745 # @param DSCFileName The output DSC file
746 # @param Platform An input Platform class object
747 #
748 def StoreDsc(DscFileName, Platform):
749 DscFile = open(DscFileName, "w+")
750 EdkLogger.info("Save file to %s" % DscFileName)
751
752 StoreHeader(DscFile, Platform.Header)
753 StorePlatformDefinesSection(DscFile, Platform)
754 StorePlatformBuildOptionsSection(DscFile,Platform)
755 StorePlatformSkuIdsSection(DscFile,Platform)
756 StorePlatformLibrariesSection(DscFile,Platform) # new in dsc, Edk I components, list of INF files
757 StorePlatformLibraryClassesSection(DscFile, Platform) # LibraryClasses are from Modules
758 StorePlatformPcdSection(DscFile, Platform)
759 #StorePlatformPcdDynamicSection(DscFile, Platform)
760 StorePlatformComponentsSection(DscFile,Platform)
761 StorePlatformUserExtensionsSection(DscFile,Platform)
762 DscFile.close()
763
764 if __name__ == '__main__':
765 pass