2 # This file is used to define a class object to describe a distribution package
4 # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
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
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.
15 DistributionPackageClass
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
36 ## DistributionPackageHeaderClass
38 # @param IdentificationObject: Identification Object
39 # @param CommonHeaderObject: Common Header Object
41 class DistributionPackageHeaderObject(IdentificationObject
, \
44 IdentificationObject
.__init
__(self
)
45 CommonHeaderObject
.__init
__(self
)
50 self
.Signature
= 'Md5Sum'
51 self
.XmlSpecification
= ''
53 def GetReadOnly(self
):
56 def SetReadOnly(self
, ReadOnly
):
57 self
.ReadOnly
= ReadOnly
59 def GetRePackage(self
):
62 def SetRePackage(self
, RePackage
):
63 self
.RePackage
= RePackage
68 def SetDate(self
, Date
):
74 def SetSignature(self
, Signature
):
75 self
.Signature
= Signature
77 def GetSignature(self
):
80 def SetXmlSpecification(self
, XmlSpecification
):
81 self
.XmlSpecification
= XmlSpecification
83 def GetXmlSpecification(self
):
84 return self
.XmlSpecification
86 ## DistributionPackageClass
88 # @param object: DistributionPackageClass
90 class DistributionPackageClass(object):
92 self
.Header
= DistributionPackageHeaderObject()
94 # {(Guid, Version, Path) : PackageObj}
96 self
.PackageSurfaceArea
= Sdict()
98 # {(Guid, Version, Name, Path) : ModuleObj}
100 self
.ModuleSurfaceArea
= Sdict()
101 self
.Tools
= MiscFileObject()
102 self
.MiscellaneousFiles
= MiscFileObject()
103 self
.UserExtensions
= []
106 ## Get all included packages and modules for a distribution package
108 # @param WorkspaceDir: WorkspaceDir
109 # @param PackageList: A list of all packages
110 # @param ModuleList: A list of all modules
112 def GetDistributionPackage(self
, WorkspaceDir
, PackageList
, ModuleList
):
117 for PackageFile
in PackageList
:
118 PackageFileFullPath
= \
119 os
.path
.normpath(os
.path
.join(WorkspaceDir
, PackageFile
))
120 DecObj
= DecPomAlignment(PackageFileFullPath
, WorkspaceDir
, CheckMulDec
= True)
123 # Parser inf file one bye one
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
:
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
)
138 # Call INF parser to generate Inf Object.
139 # Actually, this call is not directly call, but wrapped by
140 # Inf class in InfPomAlignment.
143 ModuleObj
= InfPomAlignment(Filename
, WorkspaceDir
, \
144 PackageObj
.GetPackagePath())
147 # Add module to package
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
:
158 ST
.WRN_EDK1_INF_FOUND
%Filename
)
162 self
.PackageSurfaceArea\
163 [(PackageObj
.GetGuid(), PackageObj
.GetVersion(), \
164 PackageObj
.GetCombinePath())] = PackageObj
170 for ModuleFile
in ModuleList
:
171 ModuleFileFullPath
= \
172 os
.path
.normpath(os
.path
.join(WorkspaceDir
, ModuleFile
))
174 ModuleObj
= InfPomAlignment(ModuleFileFullPath
,
176 ModuleKey
= (ModuleObj
.GetGuid(),
177 ModuleObj
.GetVersion(),
179 ModuleObj
.GetCombinePath())
180 self
.ModuleSurfaceArea
[ModuleKey
] = ModuleObj
181 except FatalError
, ErrCode
:
182 if ErrCode
.message
== EDK1_INF_ERROR
:
185 ST
.WRN_EDK1_INF_FOUND
%ModuleFileFullPath
,
186 ExtraData
=ST
.ERR_NOT_SUPPORTED_SA_MODULE
)
190 ## Get all files included for a distribution package, except tool/misc of
193 # @retval DistFileList A list of filepath for NonMetaDataFile, relative to workspace
194 # @retval MetaDataFileList A list of filepath for MetaDataFile, relative to workspace
196 def GetDistributionFileList(self
):
197 MetaDataFileList
= []
198 SkipModulesUniList
= []
200 for Guid
, Version
, Path
in self
.PackageSurfaceArea
:
201 Package
= self
.PackageSurfaceArea
[Guid
, Version
, Path
]
202 PackagePath
= Package
.GetPackagePath()
203 FullPath
= Package
.GetFullPath()
204 MetaDataFileList
.append(Path
)
205 IncludePathList
= Package
.GetIncludePathList()
206 for IncludePath
in IncludePathList
:
207 SearchPath
= os
.path
.normpath(os
.path
.join(os
.path
.dirname(FullPath
), IncludePath
))
208 AddPath
= os
.path
.normpath(os
.path
.join(PackagePath
, IncludePath
))
209 self
.FileList
+= GetNonMetaDataFiles(SearchPath
, ['CVS', '.svn'], False, AddPath
)
211 # Add the miscellaneous files on DEC file
213 for MiscFileObj
in Package
.GetMiscFileList():
214 for FileObj
in MiscFileObj
.GetFileList():
215 MiscFileFullPath
= os
.path
.normpath(os
.path
.join(PackagePath
, FileObj
.GetURI()))
216 if MiscFileFullPath
not in self
.FileList
:
217 self
.FileList
.append(MiscFileFullPath
)
220 ModuleDict
= Package
.GetModuleDict()
221 for Guid
, Version
, Name
, Path
in ModuleDict
:
222 Module
= ModuleDict
[Guid
, Version
, Name
, Path
]
223 ModulePath
= Module
.GetModulePath()
224 FullPath
= Module
.GetFullPath()
225 PkgRelPath
= os
.path
.normpath(os
.path
.join(PackagePath
, ModulePath
))
226 MetaDataFileList
.append(Path
)
227 SkipList
= ['CVS', '.svn']
228 NonMetaDataFileList
= []
229 if Module
.UniFileClassObject
:
230 for UniFile
in Module
.UniFileClassObject
.IncFileList
:
231 OriPath
= os
.path
.normpath(os
.path
.dirname(FullPath
))
232 UniFilePath
= os
.path
.normpath(os
.path
.join(PkgRelPath
, UniFile
.Path
[len(OriPath
) + 1:]))
233 if UniFilePath
not in SkipModulesUniList
:
234 SkipModulesUniList
.append(UniFilePath
)
235 for IncludeFile
in Module
.UniFileClassObject
.IncludePathList
:
236 if IncludeFile
not in SkipModulesUniList
:
237 SkipModulesUniList
.append(IncludeFile
)
238 NonMetaDataFileList
= GetNonMetaDataFiles(os
.path
.dirname(FullPath
), SkipList
, False, PkgRelPath
)
239 for NonMetaDataFile
in NonMetaDataFileList
:
240 if NonMetaDataFile
not in self
.FileList
:
241 self
.FileList
.append(NonMetaDataFile
)
242 for Guid
, Version
, Name
, Path
in self
.ModuleSurfaceArea
:
243 Module
= self
.ModuleSurfaceArea
[Guid
, Version
, Name
, Path
]
244 ModulePath
= Module
.GetModulePath()
245 FullPath
= Module
.GetFullPath()
246 MetaDataFileList
.append(Path
)
247 SkipList
= ['CVS', '.svn']
248 NonMetaDataFileList
= []
249 if Module
.UniFileClassObject
:
250 for UniFile
in Module
.UniFileClassObject
.IncFileList
:
251 OriPath
= os
.path
.normpath(os
.path
.dirname(FullPath
))
252 UniFilePath
= os
.path
.normpath(os
.path
.join(ModulePath
, UniFile
.Path
[len(OriPath
) + 1:]))
253 if UniFilePath
not in SkipModulesUniList
:
254 SkipModulesUniList
.append(UniFilePath
)
255 NonMetaDataFileList
= GetNonMetaDataFiles(os
.path
.dirname(FullPath
), SkipList
, False, ModulePath
)
256 for NonMetaDataFile
in NonMetaDataFileList
:
257 if NonMetaDataFile
not in self
.FileList
:
258 self
.FileList
.append(NonMetaDataFile
)
260 for SkipModuleUni
in SkipModulesUniList
:
261 if SkipModuleUni
in self
.FileList
:
262 self
.FileList
.remove(SkipModuleUni
)
264 return self
.FileList
, MetaDataFileList