]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py
03872379518eb26c5b38ad7e9e8259a3703c84f8
[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, 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.GetCombinePath())] = ModuleObj
153 PackageObj.SetModuleDict(ModuleDict)
154 except FatalError, ErrCode:
155 if ErrCode.message == EDK1_INF_ERROR:
156 Logger.Warn("UPT",
157 ST.WRN_EDK1_INF_FOUND%Filename)
158 else:
159 raise
160
161 self.PackageSurfaceArea\
162 [(PackageObj.GetGuid(), PackageObj.GetVersion(), \
163 PackageObj.GetCombinePath())] = PackageObj
164
165 #
166 # Get Modules
167 #
168 if ModuleList:
169 for ModuleFile in ModuleList:
170 ModuleFileFullPath = \
171 os.path.normpath(os.path.join(WorkspaceDir, ModuleFile))
172 try:
173 ModuleObj = InfPomAlignment(ModuleFileFullPath,
174 WorkspaceDir)
175 self.ModuleSurfaceArea[(ModuleObj.GetGuid(), \
176 ModuleObj.GetVersion(), \
177 ModuleObj.GetCombinePath())] = \
178 ModuleObj
179 except FatalError, ErrCode:
180 if ErrCode.message == EDK1_INF_ERROR:
181 Logger.Error("UPT",
182 EDK1_INF_ERROR,
183 ST.WRN_EDK1_INF_FOUND%ModuleFileFullPath,
184 ExtraData=ST.ERR_NOT_SUPPORTED_SA_MODULE)
185 else:
186 raise
187
188 ## Get all files included for a distribution package, except tool/misc of
189 # distribution level
190 #
191 # @retval DistFileList A list of filepath for NonMetaDataFile, relative to workspace
192 # @retval MetaDataFileList A list of filepath for MetaDataFile, relative to workspace
193 #
194 def GetDistributionFileList(self):
195 MetaDataFileList = []
196
197 for Guid, Version, Path in self.PackageSurfaceArea:
198 Package = self.PackageSurfaceArea[Guid, Version, Path]
199 PackagePath = Package.GetPackagePath()
200 FullPath = Package.GetFullPath()
201 MetaDataFileList.append(Path)
202 IncludePathList = Package.GetIncludePathList()
203 for IncludePath in IncludePathList:
204 SearchPath = os.path.normpath(os.path.join(os.path.dirname(FullPath), IncludePath))
205 AddPath = os.path.normpath(os.path.join(PackagePath, IncludePath))
206 self.FileList += GetNonMetaDataFiles(SearchPath, ['CVS', '.svn'], False, AddPath)
207
208 Module = None
209 ModuleDict = Package.GetModuleDict()
210 for Guid, Version, Path in ModuleDict:
211 Module = ModuleDict[Guid, Version, Path]
212 ModulePath = Module.GetModulePath()
213 FullPath = Module.GetFullPath()
214 PkgRelPath = os.path.normpath(os.path.join(PackagePath, ModulePath))
215 MetaDataFileList.append(Path)
216 self.FileList += GetNonMetaDataFiles(os.path.dirname(FullPath), ['CVS', '.svn'], False, PkgRelPath)
217
218 for Guid, Version, Path in self.ModuleSurfaceArea:
219 Module = self.ModuleSurfaceArea[Guid, Version, Path]
220 ModulePath = Module.GetModulePath()
221 FullPath = Module.GetFullPath()
222 MetaDataFileList.append(Path)
223 self.FileList += GetNonMetaDataFiles(os.path.dirname(FullPath), ['CVS', '.svn'], False, ModulePath)
224
225 return self.FileList, MetaDataFileList
226
227
228