]>
Commit | Line | Data |
---|---|---|
4234283c LG |
1 | ## @file\r |
2 | # This file is used to define a class object to describe a distribution package\r | |
3 | #\r | |
421ccda3 | 4 | # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r |
4234283c LG |
5 | #\r |
6 | # This program and the accompanying materials are licensed and made available \r | |
7 | # under the terms and conditions of the BSD License which accompanies this \r | |
8 | # distribution. The full text of the license may be found at \r | |
9 | # http://opensource.org/licenses/bsd-license.php\r | |
10 | #\r | |
11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | '''\r | |
15 | DistributionPackageClass\r | |
16 | '''\r | |
17 | \r | |
18 | ##\r | |
19 | # Import Modules\r | |
20 | #\r | |
21 | import os.path\r | |
22 | \r | |
23 | from Library.Misc import Sdict\r | |
24 | from Library.Misc import GetNonMetaDataFiles\r | |
25 | from PomAdapter.InfPomAlignment import InfPomAlignment\r | |
26 | from PomAdapter.DecPomAlignment import DecPomAlignment\r | |
27 | import Logger.Log as Logger\r | |
28 | from Logger import StringTable as ST\r | |
29 | from Logger.ToolError import OPTION_VALUE_INVALID\r | |
30 | from Logger.ToolError import FatalError\r | |
31 | from Logger.ToolError import EDK1_INF_ERROR\r | |
32 | from Object.POM.CommonObject import IdentificationObject\r | |
33 | from Object.POM.CommonObject import CommonHeaderObject\r | |
34 | from Object.POM.CommonObject import MiscFileObject\r | |
35 | \r | |
36 | ## DistributionPackageHeaderClass\r | |
37 | #\r | |
38 | # @param IdentificationObject: Identification Object\r | |
39 | # @param CommonHeaderObject: Common Header Object\r | |
40 | #\r | |
41 | class DistributionPackageHeaderObject(IdentificationObject, \\r | |
42 | CommonHeaderObject):\r | |
43 | def __init__(self):\r | |
44 | IdentificationObject.__init__(self)\r | |
45 | CommonHeaderObject.__init__(self)\r | |
46 | self.ReadOnly = ''\r | |
47 | self.RePackage = ''\r | |
48 | self.Vendor = ''\r | |
49 | self.Date = ''\r | |
50 | self.Signature = 'Md5Sum'\r | |
51 | self.XmlSpecification = ''\r | |
52 | \r | |
53 | def GetReadOnly(self):\r | |
54 | return self.ReadOnly\r | |
55 | \r | |
56 | def SetReadOnly(self, ReadOnly):\r | |
57 | self.ReadOnly = ReadOnly\r | |
58 | \r | |
59 | def GetRePackage(self):\r | |
60 | return self.RePackage\r | |
61 | \r | |
62 | def SetRePackage(self, RePackage):\r | |
63 | self.RePackage = RePackage\r | |
64 | \r | |
65 | def GetVendor(self):\r | |
66 | return self.Vendor\r | |
67 | \r | |
68 | def SetDate(self, Date):\r | |
69 | self.Date = Date\r | |
70 | \r | |
71 | def GetDate(self):\r | |
72 | return self.Date\r | |
73 | \r | |
74 | def SetSignature(self, Signature):\r | |
75 | self.Signature = Signature\r | |
76 | \r | |
77 | def GetSignature(self):\r | |
78 | return self.Signature\r | |
79 | \r | |
80 | def SetXmlSpecification(self, XmlSpecification):\r | |
81 | self.XmlSpecification = XmlSpecification\r | |
82 | \r | |
83 | def GetXmlSpecification(self):\r | |
84 | return self.XmlSpecification\r | |
85 | \r | |
86 | ## DistributionPackageClass\r | |
87 | #\r | |
88 | # @param object: DistributionPackageClass\r | |
89 | # \r | |
90 | class DistributionPackageClass(object):\r | |
91 | def __init__(self):\r | |
92 | self.Header = DistributionPackageHeaderObject()\r | |
93 | #\r | |
94 | # {(Guid, Version, Path) : PackageObj}\r | |
95 | #\r | |
96 | self.PackageSurfaceArea = Sdict() \r | |
97 | #\r | |
d0acc87a | 98 | # {(Guid, Version, Name, Path) : ModuleObj}\r |
4234283c LG |
99 | #\r |
100 | self.ModuleSurfaceArea = Sdict() \r | |
101 | self.Tools = MiscFileObject()\r | |
102 | self.MiscellaneousFiles = MiscFileObject()\r | |
103 | self.UserExtensions = []\r | |
104 | self.FileList = []\r | |
105 | \r | |
106 | ## Get all included packages and modules for a distribution package\r | |
107 | # \r | |
108 | # @param WorkspaceDir: WorkspaceDir\r | |
109 | # @param PackageList: A list of all packages\r | |
110 | # @param ModuleList: A list of all modules\r | |
111 | #\r | |
112 | def GetDistributionPackage(self, WorkspaceDir, PackageList, ModuleList):\r | |
113 | #\r | |
114 | # Get Packages\r | |
115 | #\r | |
116 | if PackageList:\r | |
117 | for PackageFile in PackageList:\r | |
118 | PackageFileFullPath = \\r | |
119 | os.path.normpath(os.path.join(WorkspaceDir, PackageFile))\r | |
120 | DecObj = DecPomAlignment(PackageFileFullPath, WorkspaceDir, CheckMulDec = True)\r | |
121 | PackageObj = DecObj\r | |
122 | #\r | |
123 | # Parser inf file one bye one\r | |
124 | #\r | |
125 | ModuleInfFileList = PackageObj.GetModuleFileList()\r | |
126 | for File in ModuleInfFileList:\r | |
127 | WsRelPath = os.path.join(PackageObj.GetPackagePath(), File)\r | |
128 | WsRelPath = os.path.normpath(WsRelPath)\r | |
129 | if ModuleList and WsRelPath in ModuleList:\r | |
130 | Logger.Error("UPT",\r | |
131 | OPTION_VALUE_INVALID, \r | |
132 | ST.ERR_NOT_STANDALONE_MODULE_ERROR%\\r | |
133 | (WsRelPath, PackageFile))\r | |
134 | Filename = os.path.normpath\\r | |
135 | (os.path.join(PackageObj.GetRelaPath(), File))\r | |
136 | os.path.splitext(Filename)\r | |
137 | #\r | |
138 | # Call INF parser to generate Inf Object.\r | |
139 | # Actually, this call is not directly call, but wrapped by \r | |
140 | # Inf class in InfPomAlignment.\r | |
141 | #\r | |
142 | try:\r | |
143 | ModuleObj = InfPomAlignment(Filename, WorkspaceDir, \\r | |
144 | PackageObj.GetPackagePath())\r | |
145 | \r | |
146 | #\r | |
147 | # Add module to package\r | |
148 | #\r | |
149 | ModuleDict = PackageObj.GetModuleDict()\r | |
150 | ModuleDict[(ModuleObj.GetGuid(), \\r | |
151 | ModuleObj.GetVersion(), \\r | |
d0acc87a | 152 | ModuleObj.GetName(), \\r |
4234283c LG |
153 | ModuleObj.GetCombinePath())] = ModuleObj\r |
154 | PackageObj.SetModuleDict(ModuleDict)\r | |
155 | except FatalError, ErrCode:\r | |
156 | if ErrCode.message == EDK1_INF_ERROR:\r | |
157 | Logger.Warn("UPT",\r | |
158 | ST.WRN_EDK1_INF_FOUND%Filename)\r | |
159 | else:\r | |
160 | raise\r | |
161 | \r | |
162 | self.PackageSurfaceArea\\r | |
163 | [(PackageObj.GetGuid(), PackageObj.GetVersion(), \\r | |
164 | PackageObj.GetCombinePath())] = PackageObj\r | |
165 | \r | |
166 | #\r | |
167 | # Get Modules\r | |
168 | #\r | |
169 | if ModuleList:\r | |
170 | for ModuleFile in ModuleList:\r | |
171 | ModuleFileFullPath = \\r | |
172 | os.path.normpath(os.path.join(WorkspaceDir, ModuleFile))\r | |
173 | try:\r | |
174 | ModuleObj = InfPomAlignment(ModuleFileFullPath, \r | |
175 | WorkspaceDir)\r | |
d0acc87a LG |
176 | ModuleKey = (ModuleObj.GetGuid(), \r |
177 | ModuleObj.GetVersion(), \r | |
178 | ModuleObj.GetName(), \r | |
179 | ModuleObj.GetCombinePath())\r | |
180 | self.ModuleSurfaceArea[ModuleKey] = ModuleObj\r | |
4234283c LG |
181 | except FatalError, ErrCode:\r |
182 | if ErrCode.message == EDK1_INF_ERROR:\r | |
183 | Logger.Error("UPT",\r | |
184 | EDK1_INF_ERROR,\r | |
185 | ST.WRN_EDK1_INF_FOUND%ModuleFileFullPath, \r | |
186 | ExtraData=ST.ERR_NOT_SUPPORTED_SA_MODULE)\r | |
187 | else:\r | |
188 | raise \r | |
189 | \r | |
190 | ## Get all files included for a distribution package, except tool/misc of \r | |
191 | # distribution level\r | |
192 | # \r | |
193 | # @retval DistFileList A list of filepath for NonMetaDataFile, relative to workspace\r | |
194 | # @retval MetaDataFileList A list of filepath for MetaDataFile, relative to workspace\r | |
195 | #\r | |
196 | def GetDistributionFileList(self):\r | |
197 | MetaDataFileList = []\r | |
421ccda3 | 198 | SkipModulesUniList = []\r |
4234283c LG |
199 | \r |
200 | for Guid, Version, Path in self.PackageSurfaceArea:\r | |
201 | Package = self.PackageSurfaceArea[Guid, Version, Path]\r | |
202 | PackagePath = Package.GetPackagePath()\r | |
203 | FullPath = Package.GetFullPath()\r | |
204 | MetaDataFileList.append(Path)\r | |
205 | IncludePathList = Package.GetIncludePathList()\r | |
206 | for IncludePath in IncludePathList:\r | |
207 | SearchPath = os.path.normpath(os.path.join(os.path.dirname(FullPath), IncludePath))\r | |
208 | AddPath = os.path.normpath(os.path.join(PackagePath, IncludePath))\r | |
209 | self.FileList += GetNonMetaDataFiles(SearchPath, ['CVS', '.svn'], False, AddPath)\r | |
421ccda3 HC |
210 | #\r |
211 | # Add the miscellaneous files on DEC file\r | |
212 | #\r | |
213 | for MiscFileObj in Package.GetMiscFileList():\r | |
214 | for FileObj in MiscFileObj.GetFileList():\r | |
215 | MiscFileFullPath = os.path.normpath(os.path.join(os.path.dirname(FullPath), FileObj.GetURI()))\r | |
216 | if MiscFileFullPath not in self.FileList:\r | |
217 | self.FileList.append(MiscFileFullPath)\r | |
218 | \r | |
4234283c LG |
219 | Module = None\r |
220 | ModuleDict = Package.GetModuleDict()\r | |
d0acc87a LG |
221 | for Guid, Version, Name, Path in ModuleDict:\r |
222 | Module = ModuleDict[Guid, Version, Name, Path]\r | |
4234283c LG |
223 | ModulePath = Module.GetModulePath()\r |
224 | FullPath = Module.GetFullPath()\r | |
225 | PkgRelPath = os.path.normpath(os.path.join(PackagePath, ModulePath))\r | |
226 | MetaDataFileList.append(Path)\r | |
421ccda3 HC |
227 | SkipList = ['CVS', '.svn']\r |
228 | NonMetaDataFileList = []\r | |
229 | if Module.UniFileClassObject:\r | |
230 | for UniFile in Module.UniFileClassObject.IncFileList:\r | |
231 | OriPath = os.path.normpath(os.path.dirname(FullPath))\r | |
232 | UniFilePath = os.path.normpath(os.path.join(PkgRelPath, UniFile.Path[len(OriPath) + 1:]))\r | |
233 | if UniFilePath not in SkipModulesUniList:\r | |
234 | SkipModulesUniList.append(UniFilePath)\r | |
235 | for IncludeFile in Module.UniFileClassObject.IncludePathList:\r | |
236 | if IncludeFile not in SkipModulesUniList:\r | |
237 | SkipModulesUniList.append(IncludeFile)\r | |
238 | NonMetaDataFileList = GetNonMetaDataFiles(os.path.dirname(FullPath), SkipList, False, PkgRelPath)\r | |
239 | for NonMetaDataFile in NonMetaDataFileList:\r | |
240 | if NonMetaDataFile not in self.FileList:\r | |
241 | self.FileList.append(NonMetaDataFile)\r | |
d0acc87a LG |
242 | for Guid, Version, Name, Path in self.ModuleSurfaceArea:\r |
243 | Module = self.ModuleSurfaceArea[Guid, Version, Name, Path]\r | |
4234283c LG |
244 | ModulePath = Module.GetModulePath()\r |
245 | FullPath = Module.GetFullPath()\r | |
246 | MetaDataFileList.append(Path)\r | |
421ccda3 HC |
247 | SkipList = ['CVS', '.svn']\r |
248 | NonMetaDataFileList = []\r | |
249 | if Module.UniFileClassObject:\r | |
250 | for UniFile in Module.UniFileClassObject.IncFileList:\r | |
251 | OriPath = os.path.normpath(os.path.dirname(FullPath))\r | |
252 | UniFilePath = os.path.normpath(os.path.join(ModulePath, UniFile.Path[len(OriPath) + 1:]))\r | |
253 | if UniFilePath not in SkipModulesUniList:\r | |
254 | SkipModulesUniList.append(UniFilePath)\r | |
255 | NonMetaDataFileList = GetNonMetaDataFiles(os.path.dirname(FullPath), SkipList, False, ModulePath)\r | |
256 | for NonMetaDataFile in NonMetaDataFileList:\r | |
257 | if NonMetaDataFile not in self.FileList:\r | |
258 | self.FileList.append(NonMetaDataFile)\r | |
259 | \r | |
260 | for SkipModuleUni in SkipModulesUniList:\r | |
261 | if SkipModuleUni in self.FileList:\r | |
262 | self.FileList.remove(SkipModuleUni)\r | |
263 | \r | |
4234283c LG |
264 | return self.FileList, MetaDataFileList\r |
265 | \r | |
266 | \r | |
267 | \r |