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