diff options
author | Feng, Bob C <bob.c.feng@intel.com> | 2019-07-22 11:09:22 +0800 |
---|---|---|
committer | Feng, Bob C <bob.c.feng@intel.com> | 2019-08-09 23:15:52 +0800 |
commit | e8449e1d8e3b40186eb16ff25242397cffb00a63 (patch) | |
tree | 91e6fd4742f6cc2b351be2f5bfe02ab1a4ea1b38 /BaseTools/Source/Python/AutoGen/DataPipe.py | |
parent | 197ca7febf8668be505ff904f75b97f9e465df82 (diff) | |
download | edk2-e8449e1d8e3b40186eb16ff25242397cffb00a63.tar.gz edk2-e8449e1d8e3b40186eb16ff25242397cffb00a63.tar.bz2 edk2-e8449e1d8e3b40186eb16ff25242397cffb00a63.zip |
BaseTools: Decouple AutoGen Objects
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1875
1. Separate the AutoGen.py into 3 small py files.
One is for AutoGen base class, one is for WorkspaceAutoGen class
and PlatformAutoGen class, and the one for ModuleAutoGen class.
2. Create a new class DataPipe to store the Platform scope settings.
Create a new class PlatformInfo to provide the same interface
as PlatformAutoGen. PlatformInfo class is initialized by
DataPipe instance.
Create a new class WorkspaceInfo to provide the same interface
as WorkspaceAutoGen. WorkspaceInfo class is initialized by
DataPipe instance.
3. Change ModuleAutoGen to depends on DataPipe, PlatformInfo and
WorkspaceInfo. Remove the dependency of ModuleAutoGen to PlatformAutoGen.
Cc: Liming Gao <liming.gao@intel.com>
Cc: Steven Shi <steven.shi@intel.com>
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/AutoGen/DataPipe.py')
-rw-r--r-- | BaseTools/Source/Python/AutoGen/DataPipe.py | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/BaseTools/Source/Python/AutoGen/DataPipe.py b/BaseTools/Source/Python/AutoGen/DataPipe.py new file mode 100644 index 0000000000..5bcc39bd38 --- /dev/null +++ b/BaseTools/Source/Python/AutoGen/DataPipe.py @@ -0,0 +1,147 @@ +## @file
+# Create makefile for MS nmake and GNU make
+#
+# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+from __future__ import absolute_import
+from Workspace.WorkspaceDatabase import BuildDB
+from Workspace.WorkspaceCommon import GetModuleLibInstances
+import Common.GlobalData as GlobalData
+import os
+import pickle
+from pickle import HIGHEST_PROTOCOL
+
+class PCD_DATA():
+ def __init__(self,TokenCName,TokenSpaceGuidCName,Type,DatumType,SkuInfoList,DefaultValue,
+ MaxDatumSize,UserDefinedDefaultStoresFlag,validateranges,
+ validlists,expressions,CustomAttribute,TokenValue):
+ self.TokenCName = TokenCName
+ self.TokenSpaceGuidCName = TokenSpaceGuidCName
+ self.Type = Type
+ self.DatumType = DatumType
+ self.SkuInfoList = SkuInfoList
+ self.DefaultValue = DefaultValue
+ self.MaxDatumSize = MaxDatumSize
+ self.UserDefinedDefaultStoresFlag = UserDefinedDefaultStoresFlag
+ self.validateranges = validateranges
+ self.validlists = validlists
+ self.expressions = expressions
+ self.CustomAttribute = CustomAttribute
+ self.TokenValue = TokenValue
+
+class DataPipe(object):
+ def __init__(self, BuildDir=None):
+ self.data_container = {}
+ self.BuildDir = BuildDir
+
+class MemoryDataPipe(DataPipe):
+
+ def Get(self,key):
+ return self.data_container.get(key)
+
+ def dump(self,file_path):
+ with open(file_path,'wb') as fd:
+ pickle.dump(self.data_container,fd,pickle.HIGHEST_PROTOCOL)
+
+ def load(self,file_path):
+ with open(file_path,'rb') as fd:
+ self.data_container = pickle.load(fd)
+
+ @property
+ def DataContainer(self):
+ return self.data_container
+ @DataContainer.setter
+ def DataContainer(self,data):
+ self.data_container.update(data)
+
+ def FillData(self,PlatformInfo):
+ #Platform Pcds
+ self.DataContainer = {
+ "PLA_PCD" : [PCD_DATA(
+ pcd.TokenCName,pcd.TokenSpaceGuidCName,pcd.Type,
+ pcd.DatumType,pcd.SkuInfoList,pcd.DefaultValue,
+ pcd.MaxDatumSize,pcd.UserDefinedDefaultStoresFlag,pcd.validateranges,
+ pcd.validlists,pcd.expressions,pcd.CustomAttribute,pcd.TokenValue)
+ for pcd in PlatformInfo.Platform.Pcds.values()]
+ }
+
+ #Platform Module Pcds
+ ModulePcds = {}
+ for m in PlatformInfo.Platform.Modules:
+ m_pcds = PlatformInfo.Platform.Modules[m].Pcds
+ if m_pcds:
+ ModulePcds[(m.File,m.Root)] = [PCD_DATA(
+ pcd.TokenCName,pcd.TokenSpaceGuidCName,pcd.Type,
+ pcd.DatumType,pcd.SkuInfoList,pcd.DefaultValue,
+ pcd.MaxDatumSize,pcd.UserDefinedDefaultStoresFlag,pcd.validateranges,
+ pcd.validlists,pcd.expressions,pcd.CustomAttribute,pcd.TokenValue)
+ for pcd in PlatformInfo.Platform.Modules[m].Pcds.values()]
+
+
+ self.DataContainer = {"MOL_PCDS":ModulePcds}
+
+ #Module's Library Instance
+ ModuleLibs = {}
+ for m in PlatformInfo.Platform.Modules:
+ module_obj = BuildDB.BuildObject[m,PlatformInfo.Arch,PlatformInfo.BuildTarget,PlatformInfo.ToolChain]
+ Libs = GetModuleLibInstances(module_obj, PlatformInfo.Platform, BuildDB.BuildObject, PlatformInfo.Arch,PlatformInfo.BuildTarget,PlatformInfo.ToolChain)
+ ModuleLibs[(m.File,m.Root,module_obj.Arch)] = [(l.MetaFile.File,l.MetaFile.Root,l.Arch) for l in Libs]
+ self.DataContainer = {"DEPS":ModuleLibs}
+
+ #Platform BuildOptions
+
+ platform_build_opt = PlatformInfo.EdkIIBuildOption
+
+ ToolDefinition = PlatformInfo.ToolDefinition
+ module_build_opt = {}
+ for m in PlatformInfo.Platform.Modules:
+ ModuleTypeOptions, PlatformModuleOptions = PlatformInfo.GetGlobalBuildOptions(BuildDB.BuildObject[m,PlatformInfo.Arch,PlatformInfo.BuildTarget,PlatformInfo.ToolChain])
+ if ModuleTypeOptions or PlatformModuleOptions:
+ module_build_opt.update({(m.File,m.Root): {"ModuleTypeOptions":ModuleTypeOptions, "PlatformModuleOptions":PlatformModuleOptions}})
+
+ self.DataContainer = {"PLA_BO":platform_build_opt,
+ "TOOLDEF":ToolDefinition,
+ "MOL_BO":module_build_opt
+ }
+
+
+
+ #Platform Info
+ PInfo = {
+ "WorkspaceDir":PlatformInfo.Workspace.WorkspaceDir,
+ "Target":PlatformInfo.BuildTarget,
+ "ToolChain":PlatformInfo.Workspace.ToolChain,
+ "BuildRuleFile":PlatformInfo.BuildRule,
+ "Arch": PlatformInfo.Arch,
+ "ArchList":PlatformInfo.Workspace.ArchList,
+ "ActivePlatform":PlatformInfo.MetaFile
+ }
+ self.DataContainer = {'P_Info':PInfo}
+
+ self.DataContainer = {'M_Name':PlatformInfo.UniqueBaseName}
+
+ self.DataContainer = {"ToolChainFamily": PlatformInfo.ToolChainFamily}
+
+ self.DataContainer = {"BuildRuleFamily": PlatformInfo.BuildRuleFamily}
+
+ self.DataContainer = {"MixedPcd":GlobalData.MixedPcd}
+
+ self.DataContainer = {"BuildOptPcd":GlobalData.BuildOptionPcd}
+
+ self.DataContainer = {"BuildCommand": PlatformInfo.BuildCommand}
+
+ self.DataContainer = {"AsBuildModuleList": PlatformInfo._AsBuildModuleList}
+
+ self.DataContainer = {"G_defines": GlobalData.gGlobalDefines}
+
+ self.DataContainer = {"CL_defines": GlobalData.gCommandLineDefines}
+
+ self.DataContainer = {"Env_Var": {k:v for k, v in os.environ.items()}}
+
+ self.DataContainer = {"PackageList": [(dec.MetaFile,dec.Arch) for dec in PlatformInfo.PackageList]}
+
+ self.DataContainer = {"GuidDict": PlatformInfo.Platform._GuidDict}
+
+ self.DataContainer = {"FdfParser": True if GlobalData.gFdfParser else False}
+
|