]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # Store a Package class object to a DEC file.\r | |
3 | #\r | |
4 | # Copyright (c) 2007, Intel Corporation\r | |
5 | # All rights reserved. This program and the accompanying materials\r | |
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 | import os\r | |
18 | from Common.MigrationUtilities import *\r | |
19 | from LoadSpd import LoadSpd\r | |
20 | from CommonDataClass.PackageClass import *\r | |
21 | \r | |
22 | \r | |
23 | ## Store Defines section.\r | |
24 | #\r | |
25 | # Write [Defines] section to the DecFile based on Package class object.\r | |
26 | # Different CPU architectures are specified in the subsection if possible.\r | |
27 | #\r | |
28 | # @param DecFile The output DEC file to store the Defines section.\r | |
29 | # @param Package An input Package class object.\r | |
30 | #\r | |
31 | def StorePackageDefinesSection(DecFile, Package):\r | |
32 | DefinesTupleList = []\r | |
33 | DefinesTupleList.append(("DEC_VERSION", Package.Header.DecSpecification))\r | |
34 | DefinesTupleList.append(("PACKAGE_NAME", Package.Header.Name))\r | |
35 | DefinesTupleList.append(("PACKAGE_GUID", Package.Header.Guid))\r | |
36 | \r | |
37 | StoreDefinesSection(DecFile, DefinesTupleList)\r | |
38 | \r | |
39 | \r | |
40 | ## Return a Package Include Class Item.\r | |
41 | #\r | |
42 | # Read the input Include class object and return one Include Class Item.\r | |
43 | #\r | |
44 | # @param Include An input Include class object.\r | |
45 | #\r | |
46 | # @retval IncludeClassItem A Package Include Class Item.\r | |
47 | #\r | |
48 | def GetPackageIncludeClassItem(Include):\r | |
49 | return Include.FilePath\r | |
50 | \r | |
51 | \r | |
52 | ## Store Includes section.\r | |
53 | #\r | |
54 | # Write [Includes] section to the DecFile based on Package class object.\r | |
55 | # Different CPU architectures are specified in the subsection if possible.\r | |
56 | #\r | |
57 | # @param DecFile The output DEC file to store the Includes section.\r | |
58 | # @param Package An input Package class object.\r | |
59 | #\r | |
60 | def StorePackageIncludesSection(DecFile, Package):\r | |
61 | Includes = Package.Includes\r | |
62 | Section = GetSection("Includes", GetPackageIncludeClassItem, Includes)\r | |
63 | StoreTextFile(DecFile, Section)\r | |
64 | \r | |
65 | \r | |
66 | ## Return a Package Library Class Item.\r | |
67 | #\r | |
68 | # Read the input LibraryClass class object and return one Library Class Item.\r | |
69 | #\r | |
70 | # @param LibraryClass An input LibraryClass class object.\r | |
71 | #\r | |
72 | # @retval LibraryClassItem A Package Library Class Item.\r | |
73 | #\r | |
74 | def GetPackageLibraryClassItem(LibraryClass):\r | |
75 | return "|".join((LibraryClass.LibraryClass, LibraryClass.IncludeHeader))\r | |
76 | \r | |
77 | \r | |
78 | ## Store Library Classes section.\r | |
79 | #\r | |
80 | # Write [LibraryClasses] section to the DecFile based on Package class object.\r | |
81 | # Different CPU architectures are specified in the subsection if possible.\r | |
82 | #\r | |
83 | # @param DecFile The output DEC file to store the Library Classes\r | |
84 | # section.\r | |
85 | # @param Package An input Package class object.\r | |
86 | #\r | |
87 | def StorePackageLibraryClassesSection(DecFile, Package):\r | |
88 | LibraryClasses = Package.LibraryClassDeclarations\r | |
89 | Section = GetSection("LibraryClasses", GetPackageLibraryClassItem, LibraryClasses)\r | |
90 | StoreTextFile(DecFile, Section)\r | |
91 | \r | |
92 | \r | |
93 | ## Return a Package Guid Declaration Item.\r | |
94 | #\r | |
95 | # Read the input Guid class object and return one line of Guid Declaration Item.\r | |
96 | #\r | |
97 | # @param Guid An input Guid class object.\r | |
98 | #\r | |
99 | # @retval GuidDeclarationItem A Package Guid Declaration Item.\r | |
100 | #\r | |
101 | def GetPackageGuidDeclarationItem(Guid):\r | |
102 | GuidCName = Guid.CName\r | |
103 | GuidValue = Guid.Guid.replace("-", "")\r | |
104 | GuidValueList = [GuidValue[0:8]]\r | |
105 | GuidValueList += [GuidValue[i : i + 4] for i in range(8, 16, 4)]\r | |
106 | GuidValueList += [GuidValue[i : i + 2] for i in range(16, 32, 2)]\r | |
107 | \r | |
108 | GuidCFormat = "{0x%s" + ", 0x%s" * 2 + ", {0x%s" + ", 0x%s" * 7 + "}}"\r | |
109 | GuidCValue = GuidCFormat % tuple(GuidValueList)\r | |
110 | return "%-30s = %s" % (GuidCName, GuidCValue)\r | |
111 | \r | |
112 | \r | |
113 | ## Store Protocols section.\r | |
114 | #\r | |
115 | # Write [Protocols] section to the DecFile based on Package class object.\r | |
116 | # Different CPU architectures are specified in the subsection if possible.\r | |
117 | #\r | |
118 | # @param DecFile The output DEC file to store the Protocols section.\r | |
119 | # @param Package An input Package class object.\r | |
120 | #\r | |
121 | def StorePackageProtocolsSection(DecFile, Package):\r | |
122 | Protocols = Package.ProtocolDeclarations\r | |
123 | Section = GetSection("Protocols", GetPackageGuidDeclarationItem, Protocols)\r | |
124 | StoreTextFile(DecFile, Section)\r | |
125 | \r | |
126 | \r | |
127 | ## Store Ppis section.\r | |
128 | #\r | |
129 | # Write [Ppis] section to the DecFile based on Package class object.\r | |
130 | # Different CPU architectures are specified in the subsection if possible.\r | |
131 | #\r | |
132 | # @param DecFile The output DEC file to store the Ppis section.\r | |
133 | # @param Package An input Package class object.\r | |
134 | #\r | |
135 | def StorePackagePpisSection(DecFile, Package):\r | |
136 | Ppis = Package.PpiDeclarations\r | |
137 | Section = GetSection("Ppis", GetPackageGuidDeclarationItem, Ppis)\r | |
138 | StoreTextFile(DecFile, Section)\r | |
139 | \r | |
140 | \r | |
141 | ## Store Guids section.\r | |
142 | #\r | |
143 | # Write [Guids] section to the DecFile based on Package class object.\r | |
144 | # Different CPU architectures are specified in the subsection if possible.\r | |
145 | #\r | |
146 | # @param DecFile The output DEC file to store the Guids section.\r | |
147 | # @param Package An input Package class object.\r | |
148 | #\r | |
149 | def StorePackageGuidsSection(DecFile, Package):\r | |
150 | Guids = Package.GuidDeclarations\r | |
151 | Section = GetSection("Guids", GetPackageGuidDeclarationItem, Guids)\r | |
152 | StoreTextFile(DecFile, Section)\r | |
153 | \r | |
154 | \r | |
155 | ## Return a Package Pcd Item.\r | |
156 | #\r | |
157 | # Read the input Pcd class object and return one line of Pcd Item.\r | |
158 | #\r | |
159 | # @param Pcd An input Pcd class object.\r | |
160 | #\r | |
161 | # @retval PcdItem A Package Pcd Item.\r | |
162 | #\r | |
163 | def GetPackagePcdItem(Pcd):\r | |
164 | PcdPair = "%s.%s" % (Pcd.TokenSpaceGuidCName, Pcd.CName)\r | |
165 | DatumType = Pcd.DatumType\r | |
166 | DefaultValue = Pcd.DefaultValue\r | |
167 | Token = Pcd.Token\r | |
168 | PcdList = [PcdPair, DefaultValue, DatumType, Token]\r | |
169 | return "|".join(PcdList)\r | |
170 | \r | |
171 | \r | |
172 | ## DEC Pcd Section Name dictionary indexed by PCD Item Type.\r | |
173 | mDecPcdSectionNameDict = {\r | |
174 | "FEATURE_FLAG" : "PcdsFeatureFlag",\r | |
175 | "FIXED_AT_BUILD" : "PcdsFixedAtBuild",\r | |
176 | "PATCHABLE_IN_MODULE" : "PcdsPatchableInModule",\r | |
177 | "DYNAMIC" : "PcdsDynamic",\r | |
178 | "DYNAMIC_EX" : "PcdsDynamicEx"\r | |
179 | }\r | |
180 | \r | |
181 | ## Store Pcds section.\r | |
182 | #\r | |
183 | # Write [Pcds*] section to the DecFile based on Package class object.\r | |
184 | # Different CPU architectures are specified in the subsection if possible.\r | |
185 | #\r | |
186 | # @param DecFile The output DEC file to store the Pcds section.\r | |
187 | # @param Package An input Package class object.\r | |
188 | #\r | |
189 | def StorePackagePcdsSection(DecFile, Package):\r | |
190 | PcdsDict = {}\r | |
191 | for Pcd in Package.PcdDeclarations:\r | |
192 | for PcdItemType in Pcd.ValidUsage:\r | |
193 | PcdSectionName = mDecPcdSectionNameDict.get(PcdItemType)\r | |
194 | if PcdSectionName:\r | |
195 | PcdsDict.setdefault(PcdSectionName, []).append(Pcd)\r | |
196 | else:\r | |
197 | EdkLogger.info("Unknown Pcd Item Type: %s" % PcdItemType)\r | |
198 | \r | |
199 | Section = ""\r | |
200 | for PcdSectionName in PcdsDict:\r | |
201 | Pcds = PcdsDict[PcdSectionName]\r | |
202 | Section += GetSection(PcdSectionName, GetPackagePcdItem, Pcds)\r | |
203 | \r | |
204 | StoreTextFile(DecFile, Section)\r | |
205 | \r | |
206 | \r | |
207 | ## Store User Extensions section.\r | |
208 | #\r | |
209 | # Write [UserExtensions] section to the DecFile based on Package class object.\r | |
210 | #\r | |
211 | # @param DecFile The output DEC file to store the User Extensions section.\r | |
212 | # @param Package An input Package class object.\r | |
213 | #\r | |
214 | def StorePackageUserExtensionsSection(DecFile, Package):\r | |
215 | Section = "".join(map(GetUserExtensions, Package.UserExtensions))\r | |
216 | StoreTextFile(DecFile, Section)\r | |
217 | \r | |
218 | \r | |
219 | ## Store a Package class object to a new DEC file.\r | |
220 | #\r | |
221 | # Read an input Package class object and ave the contents to a new DEC file.\r | |
222 | #\r | |
223 | # @param DecFileName The output DEC file.\r | |
224 | # @param Package An input Package class object.\r | |
225 | #\r | |
226 | def StoreDec(DecFileName, Package):\r | |
227 | DecFile = open(DecFileName, "w+")\r | |
228 | EdkLogger.info("Save file to %s" % DecFileName)\r | |
229 | \r | |
230 | StoreHeader(DecFile, Package.Header)\r | |
231 | StorePackageDefinesSection(DecFile, Package)\r | |
232 | StorePackageIncludesSection(DecFile, Package)\r | |
233 | StorePackageLibraryClassesSection(DecFile, Package)\r | |
234 | StorePackageProtocolsSection(DecFile, Package)\r | |
235 | StorePackagePpisSection(DecFile, Package)\r | |
236 | StorePackageGuidsSection(DecFile, Package)\r | |
237 | StorePackagePcdsSection(DecFile, Package)\r | |
238 | StorePackageUserExtensionsSection(DecFile, Package)\r | |
239 | \r | |
240 | DecFile.close()\r | |
241 | \r | |
242 | \r | |
243 | # This acts like the main() function for the script, unless it is 'import'ed\r | |
244 | # into another script.\r | |
245 | if __name__ == '__main__':\r | |
246 | pass\r | |
247 |