# This class just implements the cache mechanism of AutoGen objects.\r
#\r
class AutoGen(object):\r
- # database to maintain the objects of xxxAutoGen\r
- _CACHE_ = {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}\r
+ # database to maintain the objects in each child class\r
+ __ObjectCache = {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object\r
\r
## Factory method\r
#\r
# @param *args The specific class related parameters\r
# @param **kwargs The specific class related dict parameters\r
#\r
- def __new__(Class, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
+ def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
# check if the object has been created\r
- Key = (Target, Toolchain)\r
- if Key not in Class._CACHE_ or Arch not in Class._CACHE_[Key] \\r
- or MetaFile not in Class._CACHE_[Key][Arch]:\r
- AutoGenObject = super(AutoGen, Class).__new__(Class)\r
- # call real constructor\r
- if not AutoGenObject._Init(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
- return None\r
- if Key not in Class._CACHE_:\r
- Class._CACHE_[Key] = {}\r
- if Arch not in Class._CACHE_[Key]:\r
- Class._CACHE_[Key][Arch] = {}\r
- Class._CACHE_[Key][Arch][MetaFile] = AutoGenObject\r
- else:\r
- AutoGenObject = Class._CACHE_[Key][Arch][MetaFile]\r
+ Key = (Target, Toolchain, Arch, MetaFile)\r
+ try:\r
+ # if it exists, just return it directly\r
+ return cls.__ObjectCache[Key]\r
+ except:\r
+ # it didnt exist. create it, cache it, then return it\r
+ cls.__ObjectCache[Key] = super(AutoGen, cls).__new__(cls)\r
+ return cls.__ObjectCache[Key]\r
\r
- return AutoGenObject\r
+ def __init__ (self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
+ super(AutoGen, self).__init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
\r
## hash() operator\r
#\r
# architecture. This class will generate top level makefile.\r
#\r
class WorkspaceAutoGen(AutoGen):\r
- ## Real constructor of WorkspaceAutoGen\r
- #\r
- # This method behaves the same as __init__ except that it needs explicit invoke\r
- # (in super class's __new__ method)\r
+ # call super().__init__ then call the worker function with different parameter count\r
+ def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
+ try:\r
+ self._Init\r
+ except:\r
+ super(WorkspaceAutoGen, self).__init__(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
+ self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
+ self._Init = True\r
+ \r
+ ## Initialize WorkspaceAutoGen\r
#\r
# @param WorkspaceDir Root directory of workspace\r
# @param ActivePlatform Meta-file of active platform\r
# @param Caps Capsule list to be generated\r
# @param SkuId SKU id from command line\r
#\r
- def _Init(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
+ def _InitWorker(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,\r
Progress=None, BuildModule=None):\r
if Fds is None:\r
# file in order to generate makefile for platform.\r
#\r
class PlatformAutoGen(AutoGen):\r
+ # call super().__init__ then call the worker function with different parameter count\r
+ def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
+ try:\r
+ self._Init\r
+ except:\r
+ super(PlatformAutoGen, self).__init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
+ self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch)\r
+ self._Init = True\r
#\r
# Used to store all PCDs for both PEI and DXE phase, in order to generate \r
# correct PCD database\r
"0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE\r
"0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)\r
\r
- ## The real constructor of PlatformAutoGen\r
+ ## Initialize PlatformAutoGen\r
#\r
- # This method is not supposed to be called by users of PlatformAutoGen. It's\r
- # only used by factory method __new__() to do real initialization work for an\r
- # object of PlatformAutoGen\r
#\r
# @param Workspace WorkspaceAutoGen object\r
# @param PlatformFile Platform file (DSC file)\r
# @param Toolchain Name of tool chain\r
# @param Arch arch of the platform supports\r
#\r
- def _Init(self, Workspace, PlatformFile, Target, Toolchain, Arch):\r
+ def _InitWorker(self, Workspace, PlatformFile, Target, Toolchain, Arch):\r
EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))\r
GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)\r
\r
# This interface should be invoked explicitly when platform action is created.\r
#\r
def CollectPlatformDynamicPcds(self):\r
- # Override the platform Pcd's value by build option\r
- if GlobalData.BuildOptionPcd:\r
- for PcdItem in GlobalData.BuildOptionPcd:\r
- PlatformPcd = self.Platform.Pcds.get((PcdItem[1],PcdItem[0]))\r
- if PlatformPcd:\r
- if PlatformPcd.DatumType in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64,'BOOLEAN']:\r
- for sku in PlatformPcd.SkuInfoList:\r
- PlatformPcd.SkuInfoList[sku].DefaultValue = PcdItem[2]\r
- else:\r
- PcdDefaultValue = StringToArray(PcdItem[2])\r
- for sku in PlatformPcd.SkuInfoList:\r
- skuinfo = PlatformPcd.SkuInfoList[sku]\r
- if skuinfo.VariableGuid:\r
- skuinfo.HiiDefaultValue = PcdDefaultValue\r
- else:\r
- skuinfo.DefaultValue = PcdDefaultValue\r
- PlatformPcd.DefaultValue = PcdDefaultValue\r
- if PlatformPcd.MaxDatumSize:\r
- PlatformPcd.MaxDatumSize = str(max([int(PlatformPcd.MaxDatumSize),len(PcdDefaultValue.split(","))]))\r
- else:\r
- PlatformPcd.MaxDatumSize = str(len(PcdDefaultValue.split(",")))\r
\r
for key in self.Platform.Pcds:\r
for SinglePcd in GlobalData.MixedPcd:\r
TokenCName = PcdItem[0]\r
break\r
if FromPcd != None:\r
- if GlobalData.BuildOptionPcd:\r
- for pcd in GlobalData.BuildOptionPcd:\r
- if (FromPcd.TokenSpaceGuidCName, FromPcd.TokenCName) == (pcd[0], pcd[1]):\r
- FromPcd.DefaultValue = pcd[2]\r
- break\r
if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
ToPcd.Type = FromPcd.Type\r
elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
ToPcd.validlists = FromPcd.validlists\r
ToPcd.expressions = FromPcd.expressions\r
\r
- if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
+ if FromPcd != None and ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
% (ToPcd.TokenSpaceGuidCName, TokenCName))\r
Value = ToPcd.DefaultValue\r
break\r
if Flag:\r
self._OverridePcd(ToPcd, PlatformModule.Pcds[Key], Module)\r
+ # use PCD value to calculate the MaxDatumSize when it is not specified\r
+ for Name, Guid in Pcds:\r
+ Pcd = Pcds[Name, Guid]\r
+ if Pcd.DatumType == "VOID*" and Pcd.MaxDatumSize in ['', None]:\r
+ Value = Pcd.DefaultValue\r
+ if Value in [None, '']:\r
+ Pcd.MaxDatumSize = '1'\r
+ elif Value[0] == 'L':\r
+ Pcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
+ elif Value[0] == '{':\r
+ Pcd.MaxDatumSize = str(len(Value.split(',')))\r
+ else:\r
+ Pcd.MaxDatumSize = str(len(Value) - 1)\r
return Pcds.values()\r
\r
## Resolve library names to library modules\r
# to the [depex] section in module's inf file.\r
#\r
class ModuleAutoGen(AutoGen):\r
+ # call super().__init__ then call the worker function with different parameter count\r
+ def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
+ try:\r
+ self._Init\r
+ except:\r
+ super(ModuleAutoGen, self).__init__(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
+ self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args)\r
+ self._Init = True\r
+\r
## Cache the timestamps of metafiles of every module in a class variable\r
#\r
TimeDict = {}\r
\r
- ## The real constructor of ModuleAutoGen\r
- #\r
- # This method is not supposed to be called by users of ModuleAutoGen. It's\r
- # only used by factory method __new__() to do real initialization work for an\r
- # object of ModuleAutoGen\r
+ def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
+ obj = super(ModuleAutoGen, cls).__new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
+ # check if this module is employed by active platform\r
+ if not PlatformAutoGen(Workspace, args[0], Target, Toolchain, Arch).ValidModule(MetaFile):\r
+ EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
+ % (MetaFile, Arch))\r
+ return None\r
+ return obj\r
+ \r
+ ## Initialize ModuleAutoGen\r
#\r
# @param Workspace EdkIIWorkspaceBuild object\r
# @param ModuleFile The path of module file\r
# @param Arch The arch the module supports\r
# @param PlatformFile Platform meta-file\r
#\r
- def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
+ def _InitWorker(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
\r
\r
self.MetaFile = ModuleFile\r
self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
- # check if this module is employed by active platform\r
- if not self.PlatformInfo.ValidModule(self.MetaFile):\r
- EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
- % (self.MetaFile, Arch))\r
- return False\r
\r
self.SourceDir = self.MetaFile.SubDir\r
self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r
OutputDir = self.OutputDir.replace('\\', '/').strip('/')\r
DebugDir = self.DebugDir.replace('\\', '/').strip('/')\r
for Item in self.CodaTargetList:\r
- File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').strip('/')\r
+ File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')\r
if File not in self.OutputFile:\r
self.OutputFile.append(File)\r
if os.path.isabs(File):\r