]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/DepexSection.py
Revert BaseTools: PYTHON3 migration
[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
1ccc4d89 18from __future__ import absolute_import\r
bfa65b61
GL
19from . import Section\r
20from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
30fdf114 21import subprocess\r
bfa65b61 22from .Ffs import Ffs\r
1be2ed90 23import Common.LongFilePathOs as os\r
30fdf114
LG
24from CommonDataClass.FdfClass import DepexSectionClassObject\r
25from AutoGen.GenDepex import DependencyExpression\r
30fdf114
LG
26from Common import EdkLogger\r
27from Common.BuildToolError import *\r
97fa0ee9 28from Common.Misc import PathClass\r
8bb63e37 29from Common.DataType import *\r
30fdf114
LG
30\r
31## generate data section\r
32#\r
33#\r
34class DepexSection (DepexSectionClassObject):\r
35 ## The constructor\r
36 #\r
37 # @param self The object pointer\r
38 #\r
39 def __init__(self):\r
40 DepexSectionClassObject.__init__(self)\r
41\r
42 def __FindGuidValue(self, CName):\r
43 for Arch in GenFdsGlobalVariable.ArchList:\r
97fa0ee9
YL
44 PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,\r
45 Arch,\r
46 GenFdsGlobalVariable.TargetName,\r
47 GenFdsGlobalVariable.ToolChainTag)\r
48 for Inf in GenFdsGlobalVariable.FdfParser.Profile.InfList:\r
49 ModuleFile = PathClass(Inf, GenFdsGlobalVariable.WorkSpaceDir)\r
50 ModuleData = GenFdsGlobalVariable.WorkSpace.BuildObject[\r
51 ModuleFile,\r
52 Arch,\r
53 GenFdsGlobalVariable.TargetName,\r
54 GenFdsGlobalVariable.ToolChainTag\r
55 ]\r
56 for Pkg in ModuleData.Packages:\r
57 if Pkg not in PkgList:\r
58 PkgList.append(Pkg)\r
59 for PkgDb in PkgList:\r
30fdf114
LG
60 if CName in PkgDb.Ppis:\r
61 return PkgDb.Ppis[CName]\r
62 if CName in PkgDb.Protocols:\r
63 return PkgDb.Protocols[CName]\r
64 if CName in PkgDb.Guids:\r
65 return PkgDb.Guids[CName]\r
66 return None\r
67\r
68 ## GenSection() method\r
69 #\r
70 # Generate compressed section\r
71 #\r
72 # @param self The object pointer\r
73 # @param OutputPath Where to place output file\r
74 # @param ModuleName Which module this section belongs to\r
75 # @param SecNum Index of section\r
76 # @param KeyStringList Filter for inputs of section generation\r
77 # @param FfsInf FfsInfStatement object that contains this section data\r
78 # @param Dict dictionary contains macro and its value\r
79 # @retval tuple (Generated file name list, section alignment)\r
80 #\r
c3dc9d29 81 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):\r
52302d4d
LG
82 if self.ExpressionProcessed == False:\r
83 self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")\r
84 ExpList = self.Expression.split()\r
30fdf114 85\r
52302d4d
LG
86 for Exp in ExpList:\r
87 if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):\r
88 GuidStr = self.__FindGuidValue(Exp)\r
4231a819 89 if GuidStr is None:\r
52302d4d
LG
90 EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,\r
91 "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))\r
30fdf114 92\r
c3dc9d29 93 self.Expression = self.Expression.replace(Exp, GuidStr)\r
30fdf114 94\r
52302d4d
LG
95 self.Expression = self.Expression.strip()\r
96 self.ExpressionProcessed = True\r
30fdf114 97\r
b303ea72 98 if self.DepexType == 'PEI_DEPEX_EXP':\r
8bb63e37 99 ModuleType = SUP_MODULE_PEIM\r
91fa33ee 100 SecType = BINARY_FILE_TYPE_PEI_DEPEX\r
b303ea72 101 elif self.DepexType == 'DXE_DEPEX_EXP':\r
8bb63e37 102 ModuleType = SUP_MODULE_DXE_DRIVER\r
91fa33ee 103 SecType = BINARY_FILE_TYPE_DXE_DEPEX\r
b303ea72 104 elif self.DepexType == 'SMM_DEPEX_EXP':\r
8bb63e37 105 ModuleType = SUP_MODULE_DXE_SMM_DRIVER\r
91fa33ee 106 SecType = BINARY_FILE_TYPE_SMM_DEPEX\r
b303ea72
LG
107 else:\r
108 EdkLogger.error("GenFds", FORMAT_INVALID,\r
109 "Depex type %s is not valid for module %s" % (self.DepexType, ModuleName))\r
30fdf114 110\r
8bb63e37 111 InputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.depex')\r
b303ea72
LG
112 InputFile = os.path.normpath(InputFile)\r
113 Depex = DependencyExpression(self.Expression, ModuleType)\r
114 Depex.Generate(InputFile)\r
30fdf114 115\r
8bb63e37 116 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.dpx')\r
30fdf114 117 OutputFile = os.path.normpath(OutputFile)\r
b303ea72 118\r
37de70b7 119 GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType), IsMakefile=IsMakefile)\r
c3dc9d29 120 return [OutputFile], self.Alignment\r