1## @file 2# process depex section generation 3# 4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR> 5# 6# SPDX-License-Identifier: BSD-2-Clause-Patent 7# 8 9## 10# Import Modules 11# 12from __future__ import absolute_import 13from . import Section 14from .GenFdsGlobalVariable import GenFdsGlobalVariable 15import Common.LongFilePathOs as os 16from CommonDataClass.FdfClass import DepexSectionClassObject 17from AutoGen.GenDepex import DependencyExpression 18from Common import EdkLogger 19from Common.BuildToolError import * 20from Common.Misc import PathClass 21from Common.DataType import * 22 23## generate data section 24# 25# 26class DepexSection (DepexSectionClassObject): 27 ## The constructor 28 # 29 # @param self The object pointer 30 # 31 def __init__(self): 32 DepexSectionClassObject.__init__(self) 33 34 def __FindGuidValue(self, CName): 35 for Arch in GenFdsGlobalVariable.ArchList: 36 PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform, 37 Arch, 38 GenFdsGlobalVariable.TargetName, 39 GenFdsGlobalVariable.ToolChainTag) 40 for Inf in GenFdsGlobalVariable.FdfParser.Profile.InfList: 41 ModuleData = GenFdsGlobalVariable.WorkSpace.BuildObject[ 42 PathClass(Inf, GenFdsGlobalVariable.WorkSpaceDir), 43 Arch, 44 GenFdsGlobalVariable.TargetName, 45 GenFdsGlobalVariable.ToolChainTag 46 ] 47 for Pkg in ModuleData.Packages: 48 if Pkg not in PkgList: 49 PkgList.append(Pkg) 50 for PkgDb in PkgList: 51 if CName in PkgDb.Ppis: 52 return PkgDb.Ppis[CName] 53 if CName in PkgDb.Protocols: 54 return PkgDb.Protocols[CName] 55 if CName in PkgDb.Guids: 56 return PkgDb.Guids[CName] 57 return None 58 59 ## GenSection() method 60 # 61 # Generate compressed section 62 # 63 # @param self The object pointer 64 # @param OutputPath Where to place output file 65 # @param ModuleName Which module this section belongs to 66 # @param SecNum Index of section 67 # @param KeyStringList Filter for inputs of section generation 68 # @param FfsInf FfsInfStatement object that contains this section data 69 # @param Dict dictionary contains macro and its value 70 # @retval tuple (Generated file name list, section alignment) 71 # 72 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False): 73 if self.ExpressionProcessed == False: 74 self.Expression = self.Expression.replace("\n", " ").replace("\r", " ") 75 ExpList = self.Expression.split() 76 77 for Exp in ExpList: 78 if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'): 79 GuidStr = self.__FindGuidValue(Exp) 80 if GuidStr is None: 81 EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE, 82 "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName)) 83 84 self.Expression = self.Expression.replace(Exp, GuidStr) 85 86 self.Expression = self.Expression.strip() 87 self.ExpressionProcessed = True 88 89 if self.DepexType == 'PEI_DEPEX_EXP': 90 ModuleType = SUP_MODULE_PEIM 91 SecType = BINARY_FILE_TYPE_PEI_DEPEX 92 elif self.DepexType == 'DXE_DEPEX_EXP': 93 ModuleType = SUP_MODULE_DXE_DRIVER 94 SecType = BINARY_FILE_TYPE_DXE_DEPEX 95 elif self.DepexType == 'SMM_DEPEX_EXP': 96 ModuleType = SUP_MODULE_DXE_SMM_DRIVER 97 SecType = BINARY_FILE_TYPE_SMM_DEPEX 98 else: 99 EdkLogger.error("GenFds", FORMAT_INVALID, 100 "Depex type %s is not valid for module %s" % (self.DepexType, ModuleName)) 101 102 InputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.depex') 103 InputFile = os.path.normpath(InputFile) 104 Depex = DependencyExpression(self.Expression, ModuleType) 105 Depex.Generate(InputFile) 106 107 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.dpx') 108 OutputFile = os.path.normpath(OutputFile) 109 110 GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType), IsMakefile=IsMakefile) 111 return [OutputFile], self.Alignment 112