]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/DepexSection.py
BaseTools: Replace StandardError with Expression
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DepexSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process depex section generation\r
3#\r
c3dc9d29 4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
30fdf114 5#\r
40d841f6 6# This program and the accompanying materials\r
30fdf114
LG
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
18import Section\r
19from GenFdsGlobalVariable import GenFdsGlobalVariable\r
20import subprocess\r
21from Ffs import Ffs\r
1be2ed90 22import Common.LongFilePathOs as os\r
30fdf114
LG
23from CommonDataClass.FdfClass import DepexSectionClassObject\r
24from AutoGen.GenDepex import DependencyExpression\r
30fdf114
LG
25from Common import EdkLogger\r
26from Common.BuildToolError import *\r
97fa0ee9 27from Common.Misc import PathClass\r
8bb63e37 28from Common.DataType import *\r
30fdf114
LG
29\r
30## generate data section\r
31#\r
32#\r
33class DepexSection (DepexSectionClassObject):\r
34 ## The constructor\r
35 #\r
36 # @param self The object pointer\r
37 #\r
38 def __init__(self):\r
39 DepexSectionClassObject.__init__(self)\r
40\r
41 def __FindGuidValue(self, CName):\r
42 for Arch in GenFdsGlobalVariable.ArchList:\r
97fa0ee9
YL
43 PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,\r
44 Arch,\r
45 GenFdsGlobalVariable.TargetName,\r
46 GenFdsGlobalVariable.ToolChainTag)\r
47 for Inf in GenFdsGlobalVariable.FdfParser.Profile.InfList:\r
48 ModuleFile = PathClass(Inf, GenFdsGlobalVariable.WorkSpaceDir)\r
49 ModuleData = GenFdsGlobalVariable.WorkSpace.BuildObject[\r
50 ModuleFile,\r
51 Arch,\r
52 GenFdsGlobalVariable.TargetName,\r
53 GenFdsGlobalVariable.ToolChainTag\r
54 ]\r
55 for Pkg in ModuleData.Packages:\r
56 if Pkg not in PkgList:\r
57 PkgList.append(Pkg)\r
58 for PkgDb in PkgList:\r
30fdf114
LG
59 if CName in PkgDb.Ppis:\r
60 return PkgDb.Ppis[CName]\r
61 if CName in PkgDb.Protocols:\r
62 return PkgDb.Protocols[CName]\r
63 if CName in PkgDb.Guids:\r
64 return PkgDb.Guids[CName]\r
65 return None\r
66\r
67 ## GenSection() method\r
68 #\r
69 # Generate compressed section\r
70 #\r
71 # @param self The object pointer\r
72 # @param OutputPath Where to place output file\r
73 # @param ModuleName Which module this section belongs to\r
74 # @param SecNum Index of section\r
75 # @param KeyStringList Filter for inputs of section generation\r
76 # @param FfsInf FfsInfStatement object that contains this section data\r
77 # @param Dict dictionary contains macro and its value\r
78 # @retval tuple (Generated file name list, section alignment)\r
79 #\r
c3dc9d29 80 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):\r
52302d4d
LG
81 if self.ExpressionProcessed == False:\r
82 self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")\r
83 ExpList = self.Expression.split()\r
30fdf114 84\r
52302d4d
LG
85 for Exp in ExpList:\r
86 if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):\r
87 GuidStr = self.__FindGuidValue(Exp)\r
4231a819 88 if GuidStr is None:\r
52302d4d
LG
89 EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,\r
90 "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))\r
30fdf114 91\r
c3dc9d29 92 self.Expression = self.Expression.replace(Exp, GuidStr)\r
30fdf114 93\r
52302d4d
LG
94 self.Expression = self.Expression.strip()\r
95 self.ExpressionProcessed = True\r
30fdf114 96\r
b303ea72 97 if self.DepexType == 'PEI_DEPEX_EXP':\r
8bb63e37 98 ModuleType = SUP_MODULE_PEIM\r
91fa33ee 99 SecType = BINARY_FILE_TYPE_PEI_DEPEX\r
b303ea72 100 elif self.DepexType == 'DXE_DEPEX_EXP':\r
8bb63e37 101 ModuleType = SUP_MODULE_DXE_DRIVER\r
91fa33ee 102 SecType = BINARY_FILE_TYPE_DXE_DEPEX\r
b303ea72 103 elif self.DepexType == 'SMM_DEPEX_EXP':\r
8bb63e37 104 ModuleType = SUP_MODULE_DXE_SMM_DRIVER\r
91fa33ee 105 SecType = BINARY_FILE_TYPE_SMM_DEPEX\r
b303ea72
LG
106 else:\r
107 EdkLogger.error("GenFds", FORMAT_INVALID,\r
108 "Depex type %s is not valid for module %s" % (self.DepexType, ModuleName))\r
30fdf114 109\r
8bb63e37 110 InputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.depex')\r
b303ea72
LG
111 InputFile = os.path.normpath(InputFile)\r
112 Depex = DependencyExpression(self.Expression, ModuleType)\r
113 Depex.Generate(InputFile)\r
30fdf114 114\r
8bb63e37 115 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.dpx')\r
30fdf114 116 OutputFile = os.path.normpath(OutputFile)\r
b303ea72 117\r
37de70b7 118 GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType), IsMakefile=IsMakefile)\r
c3dc9d29 119 return [OutputFile], self.Alignment\r