2 # Store a Package class object to a DEC file.
4 # Copyright (c) 2007, Intel Corporation
5 # All rights reserved. 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.
18 from Common
.MigrationUtilities
import *
19 from LoadSpd
import LoadSpd
20 from CommonDataClass
.PackageClass
import *
23 ## Store Defines section.
25 # Write [Defines] section to the DecFile based on Package class object.
26 # Different CPU architectures are specified in the subsection if possible.
28 # @param DecFile The output DEC file to store the Defines section.
29 # @param Package An input Package class object.
31 def StorePackageDefinesSection(DecFile
, Package
):
33 DefinesTupleList
.append(("DEC_VERSION", Package
.Header
.DecSpecification
))
34 DefinesTupleList
.append(("PACKAGE_NAME", Package
.Header
.Name
))
35 DefinesTupleList
.append(("PACKAGE_GUID", Package
.Header
.Guid
))
37 StoreDefinesSection(DecFile
, DefinesTupleList
)
40 ## Return a Package Include Class Item.
42 # Read the input Include class object and return one Include Class Item.
44 # @param Include An input Include class object.
46 # @retval IncludeClassItem A Package Include Class Item.
48 def GetPackageIncludeClassItem(Include
):
49 return Include
.FilePath
52 ## Store Includes section.
54 # Write [Includes] section to the DecFile based on Package class object.
55 # Different CPU architectures are specified in the subsection if possible.
57 # @param DecFile The output DEC file to store the Includes section.
58 # @param Package An input Package class object.
60 def StorePackageIncludesSection(DecFile
, Package
):
61 Includes
= Package
.Includes
62 Section
= GetSection("Includes", GetPackageIncludeClassItem
, Includes
)
63 StoreTextFile(DecFile
, Section
)
66 ## Return a Package Library Class Item.
68 # Read the input LibraryClass class object and return one Library Class Item.
70 # @param LibraryClass An input LibraryClass class object.
72 # @retval LibraryClassItem A Package Library Class Item.
74 def GetPackageLibraryClassItem(LibraryClass
):
75 return "|".join((LibraryClass
.LibraryClass
, LibraryClass
.IncludeHeader
))
78 ## Store Library Classes section.
80 # Write [LibraryClasses] section to the DecFile based on Package class object.
81 # Different CPU architectures are specified in the subsection if possible.
83 # @param DecFile The output DEC file to store the Library Classes
85 # @param Package An input Package class object.
87 def StorePackageLibraryClassesSection(DecFile
, Package
):
88 LibraryClasses
= Package
.LibraryClassDeclarations
89 Section
= GetSection("LibraryClasses", GetPackageLibraryClassItem
, LibraryClasses
)
90 StoreTextFile(DecFile
, Section
)
93 ## Return a Package Guid Declaration Item.
95 # Read the input Guid class object and return one line of Guid Declaration Item.
97 # @param Guid An input Guid class object.
99 # @retval GuidDeclarationItem A Package Guid Declaration Item.
101 def GetPackageGuidDeclarationItem(Guid
):
102 GuidCName
= Guid
.CName
103 GuidValue
= Guid
.Guid
.replace("-", "")
104 GuidValueList
= [GuidValue
[0:8]]
105 GuidValueList
+= [GuidValue
[i
: i
+ 4] for i
in range(8, 16, 4)]
106 GuidValueList
+= [GuidValue
[i
: i
+ 2] for i
in range(16, 32, 2)]
108 GuidCFormat
= "{0x%s" + ", 0x%s" * 2 + ", {0x%s" + ", 0x%s" * 7 + "}}"
109 GuidCValue
= GuidCFormat
% tuple(GuidValueList
)
110 return "%-30s = %s" % (GuidCName
, GuidCValue
)
113 ## Store Protocols section.
115 # Write [Protocols] section to the DecFile based on Package class object.
116 # Different CPU architectures are specified in the subsection if possible.
118 # @param DecFile The output DEC file to store the Protocols section.
119 # @param Package An input Package class object.
121 def StorePackageProtocolsSection(DecFile
, Package
):
122 Protocols
= Package
.ProtocolDeclarations
123 Section
= GetSection("Protocols", GetPackageGuidDeclarationItem
, Protocols
)
124 StoreTextFile(DecFile
, Section
)
127 ## Store Ppis section.
129 # Write [Ppis] section to the DecFile based on Package class object.
130 # Different CPU architectures are specified in the subsection if possible.
132 # @param DecFile The output DEC file to store the Ppis section.
133 # @param Package An input Package class object.
135 def StorePackagePpisSection(DecFile
, Package
):
136 Ppis
= Package
.PpiDeclarations
137 Section
= GetSection("Ppis", GetPackageGuidDeclarationItem
, Ppis
)
138 StoreTextFile(DecFile
, Section
)
141 ## Store Guids section.
143 # Write [Guids] section to the DecFile based on Package class object.
144 # Different CPU architectures are specified in the subsection if possible.
146 # @param DecFile The output DEC file to store the Guids section.
147 # @param Package An input Package class object.
149 def StorePackageGuidsSection(DecFile
, Package
):
150 Guids
= Package
.GuidDeclarations
151 Section
= GetSection("Guids", GetPackageGuidDeclarationItem
, Guids
)
152 StoreTextFile(DecFile
, Section
)
155 ## Return a Package Pcd Item.
157 # Read the input Pcd class object and return one line of Pcd Item.
159 # @param Pcd An input Pcd class object.
161 # @retval PcdItem A Package Pcd Item.
163 def GetPackagePcdItem(Pcd
):
164 PcdPair
= "%s.%s" % (Pcd
.TokenSpaceGuidCName
, Pcd
.CName
)
165 DatumType
= Pcd
.DatumType
166 DefaultValue
= Pcd
.DefaultValue
168 PcdList
= [PcdPair
, DefaultValue
, DatumType
, Token
]
169 return "|".join(PcdList
)
172 ## DEC Pcd Section Name dictionary indexed by PCD Item Type.
173 mDecPcdSectionNameDict
= {
174 "FEATURE_FLAG" : "PcdsFeatureFlag",
175 "FIXED_AT_BUILD" : "PcdsFixedAtBuild",
176 "PATCHABLE_IN_MODULE" : "PcdsPatchableInModule",
177 "DYNAMIC" : "PcdsDynamic",
178 "DYNAMIC_EX" : "PcdsDynamicEx"
181 ## Store Pcds section.
183 # Write [Pcds*] section to the DecFile based on Package class object.
184 # Different CPU architectures are specified in the subsection if possible.
186 # @param DecFile The output DEC file to store the Pcds section.
187 # @param Package An input Package class object.
189 def StorePackagePcdsSection(DecFile
, Package
):
191 for Pcd
in Package
.PcdDeclarations
:
192 for PcdItemType
in Pcd
.ValidUsage
:
193 PcdSectionName
= mDecPcdSectionNameDict
.get(PcdItemType
)
195 PcdsDict
.setdefault(PcdSectionName
, []).append(Pcd
)
197 EdkLogger
.info("Unknown Pcd Item Type: %s" % PcdItemType
)
200 for PcdSectionName
in PcdsDict
:
201 Pcds
= PcdsDict
[PcdSectionName
]
202 Section
+= GetSection(PcdSectionName
, GetPackagePcdItem
, Pcds
)
204 StoreTextFile(DecFile
, Section
)
207 ## Store User Extensions section.
209 # Write [UserExtensions] section to the DecFile based on Package class object.
211 # @param DecFile The output DEC file to store the User Extensions section.
212 # @param Package An input Package class object.
214 def StorePackageUserExtensionsSection(DecFile
, Package
):
215 Section
= "".join(map(GetUserExtensions
, Package
.UserExtensions
))
216 StoreTextFile(DecFile
, Section
)
219 ## Store a Package class object to a new DEC file.
221 # Read an input Package class object and ave the contents to a new DEC file.
223 # @param DecFileName The output DEC file.
224 # @param Package An input Package class object.
226 def StoreDec(DecFileName
, Package
):
227 DecFile
= open(DecFileName
, "w+")
228 EdkLogger
.info("Save file to %s" % DecFileName
)
230 StoreHeader(DecFile
, Package
.Header
)
231 StorePackageDefinesSection(DecFile
, Package
)
232 StorePackageIncludesSection(DecFile
, Package
)
233 StorePackageLibraryClassesSection(DecFile
, Package
)
234 StorePackageProtocolsSection(DecFile
, Package
)
235 StorePackagePpisSection(DecFile
, Package
)
236 StorePackageGuidsSection(DecFile
, Package
)
237 StorePackagePcdsSection(DecFile
, Package
)
238 StorePackageUserExtensionsSection(DecFile
, Package
)
243 # This acts like the main() function for the script, unless it is 'import'ed
244 # into another script.
245 if __name__
== '__main__':