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