2 # Store a Platform class object to an INF file.
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
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.
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 *
24 ## Store Defines section
26 # Write [Defines] section to the DscFile based on Platform class object.
27 # Different CPU architectures are specified in the subsection if possible.
29 # @param DscFile The output DSC file to store the Defines section
30 # @param Platform An input Platform class object
32 def StorePlatformDefinesSection(DscFile
, Platform
):
33 PlatformHeader
= Platform
.Header
37 if PlatformHeader
.Name
!= "":
38 DefinesTupleList
.append(("PLATFORM_NAME", PlatformHeader
.Name
))
40 if PlatformHeader
.Guid
!= "":
41 DefinesTupleList
.append(("PLATFORM_GUID", PlatformHeader
.Guid
))
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
))
49 if PlatformHeader
.OutputDirectory
!= "":
50 DefinesTupleList
.append(("OUTPUT_DIRECTORY", PlatformHeader
.OutputDirectory
))
52 if PlatformHeader
.SupArchList
!= "":
53 String
= "|".join(PlatformHeader
.SupArchList
)
54 DefinesTupleList
.append(("SUPPORTED_ARCHITECTURES", String
))
56 if PlatformHeader
.BuildTargets
!= "":
57 String
= "|".join(PlatformHeader
.BuildTargets
)
58 DefinesTupleList
.append(("BUILD_TARGETS", String
))
60 if PlatformHeader
.SkuIdName
!= "":
61 #DefinesTupleList.append(("SKUID_IDENTIFIER", PlatformHeader.SkuIdName))
62 String
= "|".join(PlatformHeader
.SkuIdName
)
64 DefinesTupleList
.append(("SKUID_IDENTIFIER", String
))
66 String
= Platform
.FlashDefinitionFile
.FilePath
68 DefinesTupleList
.append(("FLASH_DEFINITION", String
))
71 List
.append("################################################################################")
73 List
.append("# Defines Section - statements that will be processed to create a Makefile.")
75 List
.append("################################################################################")
76 Section
= "\n".join(List
)
78 StoreTextFile(DscFile
, Section
)
80 StoreDefinesSection(DscFile
, DefinesTupleList
)
82 ## Store SkuIds section
84 # Write [SkuIds] section to the DscFile based on Platform class object.
85 # Different CPU architectures are specified in the subsection if possible.
87 # @param DscFile The output DSC file to store the Library Classes section
88 # @param Platform An input Platform class object
90 def StorePlatformSkuIdsSection(DscFile
, Platform
):
92 List
.append("################################################################################")
94 List
.append("# SKU Identification section - list of all SKU IDs supported by this Platform.")
96 List
.append("################################################################################")
97 Section
= "\n".join(List
)
100 Section
+= "[SkuIds]" + '\n'
102 List
= Platform
.SkuInfos
.SkuInfoList
104 Section
= Section
+ "%s" % Item
[0] + '|' + "%s" % Item
[1] + '\n'
105 Section
= Section
+ '\n'
107 StoreTextFile(DscFile
, Section
)
109 ## Store Build Options section
111 # Write [BuildOptions] section to the DscFile based on Platform class object.
112 # Different CPU architectures are specified in the subsection if possible.
114 # @param DscFile The output DSC file to store the Build Options section
115 # @param Platform An input Platform class object
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
130 Dict1
= ToolDef
.ToolsDefTxtDictionary
# we care the info in this Dict
132 # We only support *(DEBUG/RELEASE) and *(All Arch: IA32, X64, IPF and EBC) for now
136 SectionVS2005EXP
= ''
137 SectionVS2005STD
= ''
138 SectionVS2005PRO
= ''
139 SectionVS2005TEAMSUITE
= ''
141 SectionCYGWINGCC
= ''
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"
173 # First need to check which arch
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
180 #print "need to search debug/release string"
184 SectionName
= "[BuildOptions.Common]\n"
188 SectionName
= "[BuildOptions.IA32]\n"
190 SectionName
= "[BuildOptions.X64]\n"
192 SectionName
= "[BuildOptions.IPF]\n"
194 SectionName
= "[BuildOptions.EBC]\n"
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
226 SectionICC
= "*_ICC_" + Arch
+ "_CC_FLAGS" + SectionICC
227 Section
+= SectionICC
228 if SectionMYTOOLS
!= "":
229 SectionMYTOOLS
= "*_MYTOOLS_" + Arch
+ "_CC_FLAGS" + SectionMYTOOLS
230 Section
+= SectionMYTOOLS
233 List
.append("################################################################################")
235 List
.append("# Build Options section - list of all Build Options supported by this Platform.")
237 List
.append("################################################################################")
238 SectionHeader
= "\n".join(List
)
239 SectionHeader
+= "\n"
241 Section
= SectionHeader
+ SectionName
+ Section
243 StoreTextFile(DscFile
, Section
)
245 ## Store Libraries section
247 # Write [Libraries] section to the DscFile based on Platform class object.
248 # Different CPU architectures are specified in the subsection if possible.
250 # @param DscFile The output DSC file to store the Library Classes section
251 # @param Platform An input Platform class object
253 def StorePlatformLibrariesSection(DscFile
,Platform
):
255 List
.append("################################################################################")
257 List
.append("# Libraries section - list of all Libraries needed by this Platform.")
259 List
.append("################################################################################")
260 SectionHeader
= "\n".join(List
)
261 SectionHeader
+= "\n"
263 Section
= SectionHeader
+ '[Libraries]\n\n'
264 StoreTextFile(DscFile
, Section
)
266 ## Return a Platform Library Class Item
268 # Read the input LibraryClass class object and return one line of Library Class Item.
270 # @param LibraryClass An input LibraryClass class object
272 # @retval LibraryClassItem A Module Library Class Item
274 def GetPlatformLibraryClassItem(LibraryClass
):
275 LibraryClassList
= []
276 LibraryClassList
.append(LibraryClass
.Name
)
277 LibraryClassList
.append(LibraryClass
.FilePath
)
279 return "|$(WORKSPACE)/".join(LibraryClassList
).rstrip("|")
281 ## Add item to a LibraryClass section
283 # Add an Item with specific Module Type to section dictionary.
284 # The possible duplication is ensured to be removed.
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
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
297 ## Get Library Classes section contents
299 # Return the content of section named SectionName.
300 # the contents is based on Methods and ObjectLists.
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
306 # @retval Section The string content of a section
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
= {}
316 #ObjectList = list(set(ObjectList)) # delete the same element in the list
317 for Object
in ObjectList
:
320 Item
= Method(Object
)
324 Arches
= Object
.SupArchList
326 ModuleType
= Object
.ModuleType
327 # [LibraryClasses.Common.ModuleType]
328 if ModuleType
== "BASE":
329 SupModuleList
= ["BASE"]
330 AddToLibraryClassSection(SectionCommonDict
, SupModuleList
, Item
)
333 SupModuleList
= Object
.SupModuleList
334 #AddToSection(SectionDict, "|".join(SupModuleList), Item)
335 AddToLibraryClassSection(SectionCommonDict
, SupModuleList
, Item
)
338 for Arch
in SupportedArches
:
339 if Arch
.upper() in Arches
:
341 # [LibraryClasses.IA32.ModuleType]
342 ModuleType
= Object
.ModuleType
343 if ModuleType
== "BASE":
344 SupModuleList
= ["BASE"]
345 AddToLibraryClassSection(SectionIA32Dict
, SupModuleList
, Item
)
347 SupModuleList
= Object
.SupModuleList
348 AddToLibraryClassSection(SectionIA32Dict
, SupModuleList
, Item
)
350 # [LibraryClasses.X64.ModuleType]
351 ModuleType
= Object
.ModuleType
352 if ModuleType
== "BASE":
353 SupModuleList
= ["BASE"]
354 AddToLibraryClassSection(SectionX64Dict
, SupModuleList
, Item
)
356 SupModuleList
= Object
.SupModuleList
357 AddToLibraryClassSection(SectionX64Dict
, SupModuleList
, Item
)
359 # [LibraryClasses.IPF.ModuleType]
360 ModuleType
= Object
.ModuleType
361 if ModuleType
== "BASE":
362 SupModuleList
= ["BASE"]
363 AddToLibraryClassSection(SectionIPFDict
, SupModuleList
, Item
)
365 SupModuleList
= Object
.SupModuleList
366 AddToLibraryClassSection(SectionIPFDict
, SupModuleList
, Item
)
368 # [LibraryClasses.EBC.ModuleType]
369 ModuleType
= Object
.ModuleType
370 if ModuleType
== "BASE":
371 SupModuleList
= ["BASE"]
372 AddToLibraryClassSection(SectionEBCDict
, SupModuleList
, Item
)
374 SupModuleList
= Object
.SupModuleList
375 AddToLibraryClassSection(SectionEBCDict
, SupModuleList
, Item
)
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
)
383 for ModuleType
in ModuleTypes
:
384 ListIA32
= SectionIA32Dict
.get(ModuleType
, [])
386 SectionIA32Module
= "\n".join(SectionIA32Dict
.get(ModuleType
, []))
387 if SectionIA32Module
!= "":
388 Section
+= "[%s.IA32.%s]\n%s\n" % (SectionName
, ModuleType
, SectionIA32Module
)
390 ListX64
= SectionX64Dict
.get(ModuleType
, [])
392 SectionX64Module
= "\n".join(SectionX64Dict
.get(ModuleType
, []))
393 if SectionX64Module
!= "":
394 Section
+= "[%s.X64.%s]\n%s\n" % (SectionName
, ModuleType
, SectionX64Module
)
396 ListIPF
= SectionIPFDict
.get(ModuleType
, [])
398 SectionIPFModule
= "\n".join(SectionIPFDict
.get(ModuleType
, []))
399 if SectionIPFModule
!= "":
400 Section
+= "[%s.IPF.%s]\n%s\n" % (SectionName
, ModuleType
, SectionIPFModule
)
402 ListEBC
= SectionEBCDict
.get(ModuleType
, [])
404 SectionEBCModule
= "\n".join(SectionEBCDict
.get(ModuleType
, []))
405 if SectionEBCModule
!= "":
406 Section
+= "[%s.EBC.%s]\n%s\n" % (SectionName
, ModuleType
, SectionEBCModule
)
413 ## Store Library Classes section
415 # Write [LibraryClasses] section to the DscFile based on Platform class object.
416 # Different CPU architectures are specified in the subsection if possible.
418 # @param DscFile The output DSC file to store the Library Classes section
419 # @param Platform An input Platform class object
421 def StorePlatformLibraryClassesSection(DscFile
, Platform
):
422 Section
= GetLibraryClassesSection("LibraryClasses", GetPlatformLibraryClassItem
, Platform
.LibraryClasses
.LibraryList
)
424 List
.append("################################################################################")
426 List
.append("# Library Class section - list of all Library Classes needed by this Platform.")
428 List
.append("################################################################################")
429 SectionHeader
= "\n".join(List
)
430 SectionHeader
+= "\n"
431 Section
= SectionHeader
+ Section
432 StoreTextFile(DscFile
, Section
)
436 # Write [Pcd] section to the DscFile based on Platform class object.
437 # Different CPU architectures are specified in the subsection if possible.
439 # @param DscFile The output DSC file to store the Build Options section
440 # @param Platform An input Platform class object
442 def StorePlatformPcdSection(DscFile
, Platform
):
443 # {PcdsFixedAtBuild:String1, PcdsFixedAtBuild:String2, PcdsPatchableInModule:String3}
446 # [PcdsFixedAtBuild], [PcdsPatchableInModule] and [PcdsFeatureFlag] are from platform.modules
447 # [PcdsDynamic] is from platform.DynamicPcdBuildDefinitions
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":
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
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
493 DynamicPcdBuildDefinitions
= Platform
.DynamicPcdBuildDefinitions
# It's a list
494 for PcdBuildData
in DynamicPcdBuildDefinitions
:
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
, []))
515 List
.append("################################################################################")
517 List
.append("# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform.")
519 List
.append("################################################################################")
520 String
= "\n".join(List
)
523 Section
+= "\n\n[PcdsDynamic]\n " + "\n ".join(SectionDict
.get(ItemType
, []))
527 List
.append("################################################################################")
529 List
.append("# Pcd Section - list of all EDK II PCD Entries defined by this Platform.")
531 List
.append("################################################################################")
532 SectionHeader
= "\n".join(List
)
533 SectionHeader
+= "\n"
534 Section
= SectionHeader
+ Section
535 StoreTextFile(DscFile
, Section
)
537 ## Add item to a section
539 # Add an Item with specific CPU architecture to section dictionary.
540 # The possible duplication is ensured to be removed.
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
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
552 ## Get section contents
554 # Return the content of section named SectionName.
555 # the contents is based on Methods and ObjectLists.
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
561 # @retval Section The string content of a section
563 def GetSection(SectionName
, Method
, ObjectList
):
564 SupportedArches
= ["COMMON", "IA32", "X64", "IPF", "EBC"]
566 for Object
in ObjectList
:
567 if Object
.FilePath
== "":
569 Item
= Method(Object
)
573 Arches
= Object
.SupArchList
575 AddToSection(SectionDict
, "common", Item
)
577 for Arch
in SupportedArches
:
578 if Arch
.upper() in Arches
:
579 AddToSection(SectionDict
, Arch
, Item
)
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
)
591 ## Return a Platform Component Item
593 # Read the input Platform Component object and return one line of Platform Component Item.
595 # @param Component An input Platform Component class object
597 # @retval ComponentItem A Platform Component Item
599 def GetPlatformComponentItem(Component
):
603 List
.append("$(WORKSPACE)/" + Component
.FilePath
)
605 LibraryClasses
= Component
.LibraryClasses
606 if LibraryClasses
!= []:
608 List
.append("$(WORKSPACE)/" + Component
.FilePath
+ " {")
609 List
.append("<LibraryClasses>")
610 for LibraryClass
in LibraryClasses
:
611 if LibraryClass
== ["", ""]:
613 List
.append(" " + LibraryClass
[0] + "|$(WORKSPACE)/" + LibraryClass
[1])
615 PcdBuildDefinitions
= Component
.PcdBuildDefinitions
616 for PcdData
in PcdBuildDefinitions
:
617 if PcdData
.ItemType
== "FEATURE_FLAG":
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
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
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
,[])))
670 if Section
.get(ItemType
, []) != []:
671 List
.append("<PcdsDynamic>")
672 List
.append(" " + "\n ".join(Section
.get(ItemType
,[])))
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")
690 SectionOption
+= " " + "_".join(List
) + " = " + Option
.Option
+ "\n"
692 if SectionOption
!= "":
693 List
.append(SectionOption
)
694 if List
!= ["$(WORKSPACE)/" + Component
.FilePath
]:
697 return "\n ".join(List
)
699 ## Store Components section.
701 # Write [Components] section to the DscFile based on Platform class object.
702 # Different CPU architectures are specified in the subsection if possible.
704 # @param DscFile The output DSC file to store the Components section
705 # @param Platform An input Platform class object
707 def StorePlatformComponentsSection(DscFile
, Platform
):
708 Section
= GetSection("Components", GetPlatformComponentItem
, Platform
.Modules
.ModuleList
)
710 List
.append("################################################################################")
712 List
.append("# Components Section - list of all EDK II Modules needed by this Platform.")
714 List
.append("################################################################################")
715 SectionHeader
= "\n".join(List
)
716 SectionHeader
+= "\n"
717 Section
= SectionHeader
+ Section
718 StoreTextFile(DscFile
, Section
)
720 ## Store User Extensions section.
722 # Write [UserExtensions] section to the InfFile based on Module class object.
723 # Different CPU architectures are specified in the subsection if possible.
725 # @param DscFile The output DSC file to store the User Extensions section
726 # @param Platform An input Platform class object
728 def StorePlatformUserExtensionsSection(DscFile
, Platform
):
729 Section
= "".join(map(GetUserExtensions
, Platform
.UserExtensions
))
731 List
.append("################################################################################")
733 List
.append("# User Extensions Section - list of all User Extensions specified by user.")
735 List
.append("################################################################################")
736 SectionHeader
= "\n".join(List
)
737 SectionHeader
+= "\n"
738 Section
= SectionHeader
+ Section
739 StoreTextFile(DscFile
, Section
)
741 ## Store a Platform class object to a new DSC file.
743 # Read an input Platform class object and save the contents to a new DSC file.
745 # @param DSCFileName The output DSC file
746 # @param Platform An input Platform class object
748 def StoreDsc(DscFileName
, Platform
):
749 DscFile
= open(DscFileName
, "w+")
750 EdkLogger
.info("Save file to %s" % DscFileName
)
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
)
764 if __name__
== '__main__':