1## @file 2# Create makefile for MS nmake and GNU make 3# 4# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> 5# SPDX-License-Identifier: BSD-2-Clause-Patent 6# 7from __future__ import absolute_import 8from Workspace.WorkspaceDatabase import BuildDB 9from Workspace.WorkspaceCommon import GetModuleLibInstances 10import Common.GlobalData as GlobalData 11import os 12import pickle 13from pickle import HIGHEST_PROTOCOL 14from Common import EdkLogger 15 16class PCD_DATA(): 17 def __init__(self,TokenCName,TokenSpaceGuidCName,Type,DatumType,SkuInfoList,DefaultValue, 18 MaxDatumSize,UserDefinedDefaultStoresFlag,validateranges, 19 validlists,expressions,CustomAttribute,TokenValue): 20 self.TokenCName = TokenCName 21 self.TokenSpaceGuidCName = TokenSpaceGuidCName 22 self.Type = Type 23 self.DatumType = DatumType 24 self.SkuInfoList = SkuInfoList 25 self.DefaultValue = DefaultValue 26 self.MaxDatumSize = MaxDatumSize 27 self.UserDefinedDefaultStoresFlag = UserDefinedDefaultStoresFlag 28 self.validateranges = validateranges 29 self.validlists = validlists 30 self.expressions = expressions 31 self.CustomAttribute = CustomAttribute 32 self.TokenValue = TokenValue 33 34class DataPipe(object): 35 def __init__(self, BuildDir=None): 36 self.data_container = {} 37 self.BuildDir = BuildDir 38 self.dump_file = "" 39 40class MemoryDataPipe(DataPipe): 41 42 def Get(self,key): 43 return self.data_container.get(key) 44 45 def dump(self,file_path): 46 self.dump_file = file_path 47 with open(file_path,'wb') as fd: 48 pickle.dump(self.data_container,fd,pickle.HIGHEST_PROTOCOL) 49 50 def load(self,file_path): 51 with open(file_path,'rb') as fd: 52 self.data_container = pickle.load(fd) 53 54 @property 55 def DataContainer(self): 56 return self.data_container 57 @DataContainer.setter 58 def DataContainer(self,data): 59 self.data_container.update(data) 60 61 def FillData(self,PlatformInfo): 62 #Platform Pcds 63 self.DataContainer = { 64 "PLA_PCD" : [PCD_DATA( 65 pcd.TokenCName,pcd.TokenSpaceGuidCName,pcd.Type, 66 pcd.DatumType,pcd.SkuInfoList,pcd.DefaultValue, 67 pcd.MaxDatumSize,pcd.UserDefinedDefaultStoresFlag,pcd.validateranges, 68 pcd.validlists,pcd.expressions,pcd.CustomAttribute,pcd.TokenValue) 69 for pcd in PlatformInfo.Platform.Pcds.values()] 70 } 71 72 #Platform Module Pcds 73 ModulePcds = {} 74 for m in PlatformInfo.Platform.Modules: 75 m_pcds = PlatformInfo.Platform.Modules[m].Pcds 76 if m_pcds: 77 ModulePcds[(m.File,m.Root,m.Arch)] = [PCD_DATA( 78 pcd.TokenCName,pcd.TokenSpaceGuidCName,pcd.Type, 79 pcd.DatumType,pcd.SkuInfoList,pcd.DefaultValue, 80 pcd.MaxDatumSize,pcd.UserDefinedDefaultStoresFlag,pcd.validateranges, 81 pcd.validlists,pcd.expressions,pcd.CustomAttribute,pcd.TokenValue) 82 for pcd in PlatformInfo.Platform.Modules[m].Pcds.values()] 83 84 85 self.DataContainer = {"MOL_PCDS":ModulePcds} 86 87 #Module's Library Instance 88 ModuleLibs = {} 89 libModules = {} 90 for m in PlatformInfo.Platform.Modules: 91 module_obj = BuildDB.BuildObject[m,PlatformInfo.Arch,PlatformInfo.BuildTarget,PlatformInfo.ToolChain] 92 Libs = GetModuleLibInstances(module_obj, PlatformInfo.Platform, BuildDB.BuildObject, PlatformInfo.Arch,PlatformInfo.BuildTarget,PlatformInfo.ToolChain,PlatformInfo.MetaFile,EdkLogger) 93 for lib in Libs: 94 try: 95 libModules[(lib.MetaFile.File,lib.MetaFile.Root,lib.Arch,lib.MetaFile.Path)].append((m.File,m.Root,module_obj.Arch,m.Path)) 96 except: 97 libModules[(lib.MetaFile.File,lib.MetaFile.Root,lib.Arch,lib.MetaFile.Path)] = [(m.File,m.Root,module_obj.Arch,m.Path)] 98 ModuleLibs[(m.File,m.Root,module_obj.Arch,m.Path)] = [(l.MetaFile.File,l.MetaFile.Root,l.Arch,l.MetaFile.Path) for l in Libs] 99 self.DataContainer = {"DEPS":ModuleLibs} 100 self.DataContainer = {"REFS":libModules} 101 102 #Platform BuildOptions 103 104 platform_build_opt = PlatformInfo.EdkIIBuildOption 105 106 ToolDefinition = PlatformInfo.ToolDefinition 107 module_build_opt = {} 108 for m in PlatformInfo.Platform.Modules: 109 ModuleTypeOptions, PlatformModuleOptions = PlatformInfo.GetGlobalBuildOptions(BuildDB.BuildObject[m,PlatformInfo.Arch,PlatformInfo.BuildTarget,PlatformInfo.ToolChain]) 110 if ModuleTypeOptions or PlatformModuleOptions: 111 module_build_opt.update({(m.File,m.Root): {"ModuleTypeOptions":ModuleTypeOptions, "PlatformModuleOptions":PlatformModuleOptions}}) 112 113 self.DataContainer = {"PLA_BO":platform_build_opt, 114 "TOOLDEF":ToolDefinition, 115 "MOL_BO":module_build_opt 116 } 117 118 119 120 #Platform Info 121 PInfo = { 122 "WorkspaceDir":PlatformInfo.Workspace.WorkspaceDir, 123 "Target":PlatformInfo.BuildTarget, 124 "ToolChain":PlatformInfo.Workspace.ToolChain, 125 "BuildRuleFile":PlatformInfo.BuildRule, 126 "Arch": PlatformInfo.Arch, 127 "ArchList":PlatformInfo.Workspace.ArchList, 128 "ActivePlatform":PlatformInfo.MetaFile 129 } 130 self.DataContainer = {'P_Info':PInfo} 131 132 self.DataContainer = {'M_Name':PlatformInfo.UniqueBaseName} 133 134 self.DataContainer = {"ToolChainFamily": PlatformInfo.ToolChainFamily} 135 136 self.DataContainer = {"BuildRuleFamily": PlatformInfo.BuildRuleFamily} 137 138 self.DataContainer = {"MixedPcd":GlobalData.MixedPcd} 139 140 self.DataContainer = {"BuildOptPcd":GlobalData.BuildOptionPcd} 141 142 self.DataContainer = {"BuildCommand": PlatformInfo.BuildCommand} 143 144 self.DataContainer = {"AsBuildModuleList": PlatformInfo._AsBuildModuleList} 145 146 self.DataContainer = {"G_defines": GlobalData.gGlobalDefines} 147 148 self.DataContainer = {"CL_defines": GlobalData.gCommandLineDefines} 149 150 self.DataContainer = {"Env_Var": {k:v for k, v in os.environ.items()}} 151 152 self.DataContainer = {"PackageList": [(dec.MetaFile,dec.Arch) for dec in PlatformInfo.PackageList]} 153 154 self.DataContainer = {"GuidDict": PlatformInfo.Platform._GuidDict} 155 156 self.DataContainer = {"DatabasePath":GlobalData.gDatabasePath} 157 158 self.DataContainer = {"FdfParser": True if GlobalData.gFdfParser else False} 159 160 self.DataContainer = {"LogLevel": EdkLogger.GetLevel()} 161 162 self.DataContainer = {"UseHashCache":GlobalData.gUseHashCache} 163 164 self.DataContainer = {"BinCacheSource":GlobalData.gBinCacheSource} 165 166 self.DataContainer = {"BinCacheDest":GlobalData.gBinCacheDest} 167 168 self.DataContainer = {"EnableGenfdsMultiThread":GlobalData.gEnableGenfdsMultiThread} 169