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