X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FGenDepex.py;h=ed5df2b75440172ac6253a6e5aa18fccbeeb025d;hb=a253d217ee3477fde46cadba0dfe364f9a826694;hp=37ba7bc72cd25bcc1284ab1ac28aae40e17abf51;hpb=b36d134faf4305247830522b8e2bb255e98c5699;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/AutoGen/GenDepex.py b/BaseTools/Source/Python/AutoGen/GenDepex.py index 37ba7bc72c..ed5df2b754 100644 --- a/BaseTools/Source/Python/AutoGen/GenDepex.py +++ b/BaseTools/Source/Python/AutoGen/GenDepex.py @@ -1,7 +1,7 @@ ## @file # This file is used to generate DEPEX file for module's dependency expression # -# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -13,10 +13,10 @@ ## Import Modules # import sys -import os +import Common.LongFilePathOs as os import re import traceback - +from Common.LongFilePathSupport import OpenLongFilePath as open from StringIO import StringIO from struct import pack from Common.BuildToolError import * @@ -24,24 +24,27 @@ from Common.Misc import SaveFileOnChange from Common.Misc import GuidStructureStringToGuidString from Common import EdkLogger as EdkLogger from Common.BuildVersion import gBUILD_VERSION +from Common.DataType import * ## Regular expression for matching "DEPENDENCY_START ... DEPENDENCY_END" gStartClosePattern = re.compile(".*DEPENDENCY_START(.+)DEPENDENCY_END.*", re.S) ## Mapping between module type and EFI phase gType2Phase = { - "BASE" : None, - "SEC" : "PEI", - "PEI_CORE" : "PEI", - "PEIM" : "PEI", - "DXE_CORE" : "DXE", - "DXE_DRIVER" : "DXE", - "DXE_SMM_DRIVER" : "DXE", - "DXE_RUNTIME_DRIVER": "DXE", - "DXE_SAL_DRIVER" : "DXE", - "UEFI_DRIVER" : "DXE", - "UEFI_APPLICATION" : "DXE", - "SMM_CORE" : "DXE", + SUP_MODULE_BASE : None, + SUP_MODULE_SEC : "PEI", + SUP_MODULE_PEI_CORE : "PEI", + SUP_MODULE_PEIM : "PEI", + SUP_MODULE_DXE_CORE : "DXE", + SUP_MODULE_DXE_DRIVER : "DXE", + SUP_MODULE_DXE_SMM_DRIVER : "DXE", + SUP_MODULE_DXE_RUNTIME_DRIVER: "DXE", + SUP_MODULE_DXE_SAL_DRIVER : "DXE", + SUP_MODULE_UEFI_DRIVER : "DXE", + SUP_MODULE_UEFI_APPLICATION : "DXE", + SUP_MODULE_SMM_CORE : "DXE", + SUP_MODULE_MM_STANDALONE : "MM", + SUP_MODULE_MM_CORE_STANDALONE : "MM", } ## Convert dependency expression string into EFI internal representation @@ -51,7 +54,7 @@ gType2Phase = { # class DependencyExpression: - ArchProtocols = set([ + ArchProtocols = { '665e3ff6-46cc-11d4-9a38-0090273fc14d', # 'gEfiBdsArchProtocolGuid' '26baccb1-6f42-11d4-bce7-0080c73c8881', # 'gEfiCpuArchProtocolGuid' '26baccb2-6f42-11d4-bce7-0080c73c8881', # 'gEfiMetronomeArchProtocolGuid' @@ -64,56 +67,65 @@ class DependencyExpression: '6441f818-6362-4e44-b570-7dba31dd2453', # 'gEfiVariableWriteArchProtocolGuid' '1e5668e2-8481-11d4-bcf1-0080c73c8881', # 'gEfiVariableArchProtocolGuid' '665e3ff5-46cc-11d4-9a38-0090273fc14d' # 'gEfiWatchdogTimerArchProtocolGuid' - ] - ) + } OpcodePriority = { - "AND" : 1, - "OR" : 1, - "NOT" : 2, - # "SOR" : 9, - # "BEFORE": 9, - # "AFTER" : 9, + DEPEX_OPCODE_AND : 1, + DEPEX_OPCODE_OR : 1, + DEPEX_OPCODE_NOT : 2, } Opcode = { "PEI" : { - "PUSH" : 0x02, - "AND" : 0x03, - "OR" : 0x04, - "NOT" : 0x05, - "TRUE" : 0x06, - "FALSE" : 0x07, - "END" : 0x08 + DEPEX_OPCODE_PUSH : 0x02, + DEPEX_OPCODE_AND : 0x03, + DEPEX_OPCODE_OR : 0x04, + DEPEX_OPCODE_NOT : 0x05, + DEPEX_OPCODE_TRUE : 0x06, + DEPEX_OPCODE_FALSE : 0x07, + DEPEX_OPCODE_END : 0x08 }, "DXE" : { - "BEFORE": 0x00, - "AFTER" : 0x01, - "PUSH" : 0x02, - "AND" : 0x03, - "OR" : 0x04, - "NOT" : 0x05, - "TRUE" : 0x06, - "FALSE" : 0x07, - "END" : 0x08, - "SOR" : 0x09 + DEPEX_OPCODE_BEFORE: 0x00, + DEPEX_OPCODE_AFTER : 0x01, + DEPEX_OPCODE_PUSH : 0x02, + DEPEX_OPCODE_AND : 0x03, + DEPEX_OPCODE_OR : 0x04, + DEPEX_OPCODE_NOT : 0x05, + DEPEX_OPCODE_TRUE : 0x06, + DEPEX_OPCODE_FALSE : 0x07, + DEPEX_OPCODE_END : 0x08, + DEPEX_OPCODE_SOR : 0x09 + }, + + "MM" : { + DEPEX_OPCODE_BEFORE: 0x00, + DEPEX_OPCODE_AFTER : 0x01, + DEPEX_OPCODE_PUSH : 0x02, + DEPEX_OPCODE_AND : 0x03, + DEPEX_OPCODE_OR : 0x04, + DEPEX_OPCODE_NOT : 0x05, + DEPEX_OPCODE_TRUE : 0x06, + DEPEX_OPCODE_FALSE : 0x07, + DEPEX_OPCODE_END : 0x08, + DEPEX_OPCODE_SOR : 0x09 } } # all supported op codes and operands - SupportedOpcode = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "END", "SOR"] - SupportedOperand = ["TRUE", "FALSE"] + SupportedOpcode = [DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER, DEPEX_OPCODE_PUSH, DEPEX_OPCODE_AND, DEPEX_OPCODE_OR, DEPEX_OPCODE_NOT, DEPEX_OPCODE_END, DEPEX_OPCODE_SOR] + SupportedOperand = [DEPEX_OPCODE_TRUE, DEPEX_OPCODE_FALSE] - OpcodeWithSingleOperand = ['NOT', 'BEFORE', 'AFTER'] - OpcodeWithTwoOperand = ['AND', 'OR'] + OpcodeWithSingleOperand = [DEPEX_OPCODE_NOT, DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER] + OpcodeWithTwoOperand = [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR] # op code that should not be the last one - NonEndingOpcode = ["AND", "OR", "NOT", 'SOR'] + NonEndingOpcode = [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR, DEPEX_OPCODE_NOT, DEPEX_OPCODE_SOR] # op code must not present at the same time - ExclusiveOpcode = ["BEFORE", "AFTER"] + ExclusiveOpcode = [DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER] # op code that should be the first one if it presents - AboveAllOpcode = ["SOR", "BEFORE", "AFTER"] + AboveAllOpcode = [DEPEX_OPCODE_SOR, DEPEX_OPCODE_BEFORE, DEPEX_OPCODE_AFTER] # # open and close brace must be taken as individual tokens @@ -185,7 +197,7 @@ class DependencyExpression: break self.PostfixNotation.append(Stack.pop()) elif Token in self.OpcodePriority: - if Token == "NOT": + if Token == DEPEX_OPCODE_NOT: if LastToken not in self.SupportedOpcode + ['(', '', None]: EdkLogger.error("GenDepex", PARSER_ERROR, "Invalid dependency expression: missing operator before NOT", ExtraData="Near %s" % LastToken) @@ -207,10 +219,10 @@ class DependencyExpression: ExtraData="Near %s" % LastToken) if len(self.OpcodeList) == 0 or self.OpcodeList[-1] not in self.ExclusiveOpcode: if Token not in self.SupportedOperand: - self.PostfixNotation.append("PUSH") + self.PostfixNotation.append(DEPEX_OPCODE_PUSH) # check if OP is valid in this phase elif Token in self.Opcode[self.Phase]: - if Token == "END": + if Token == DEPEX_OPCODE_END: break self.OpcodeList.append(Token) else: @@ -226,8 +238,8 @@ class DependencyExpression: ExtraData=str(self)) while len(Stack) > 0: self.PostfixNotation.append(Stack.pop()) - if self.PostfixNotation[-1] != 'END': - self.PostfixNotation.append("END") + if self.PostfixNotation[-1] != DEPEX_OPCODE_END: + self.PostfixNotation.append(DEPEX_OPCODE_END) ## Validate the dependency expression def ValidateOpcode(self): @@ -247,36 +259,40 @@ class DependencyExpression: if len(self.PostfixNotation) < 3: EdkLogger.error("GenDepex", PARSER_ERROR, "Missing operand for %s" % Op, ExtraData=str(self)) - if self.TokenList[-1] != 'END' and self.TokenList[-1] in self.NonEndingOpcode: + if self.TokenList[-1] != DEPEX_OPCODE_END and self.TokenList[-1] in self.NonEndingOpcode: EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end of the dependency expression" % self.TokenList[-1], ExtraData=str(self)) - if self.TokenList[-1] == 'END' and self.TokenList[-2] in self.NonEndingOpcode: + if self.TokenList[-1] == DEPEX_OPCODE_END and self.TokenList[-2] in self.NonEndingOpcode: EdkLogger.error("GenDepex", PARSER_ERROR, "Extra %s at the end of the dependency expression" % self.TokenList[-2], ExtraData=str(self)) - if "END" in self.TokenList and "END" != self.TokenList[-1]: + if DEPEX_OPCODE_END in self.TokenList and DEPEX_OPCODE_END != self.TokenList[-1]: EdkLogger.error("GenDepex", PARSER_ERROR, "Extra expressions after END", ExtraData=str(self)) ## Simply optimize the dependency expression by removing duplicated operands def Optimize(self): - ValidOpcode = list(set(self.OpcodeList)) - if len(ValidOpcode) != 1 or ValidOpcode[0] not in ['AND', 'OR']: + OpcodeSet = set(self.OpcodeList) + # if there are isn't one in the set, return + if len(OpcodeSet) != 1: + return + Op = OpcodeSet.pop() + #if Op isn't either OR or AND, return + if Op not in [DEPEX_OPCODE_AND, DEPEX_OPCODE_OR]: return - Op = ValidOpcode[0] NewOperand = [] AllOperand = set() for Token in self.PostfixNotation: if Token in self.SupportedOpcode or Token in NewOperand: continue AllOperand.add(Token) - if Token == 'TRUE': - if Op == 'AND': + if Token == DEPEX_OPCODE_TRUE: + if Op == DEPEX_OPCODE_AND: continue else: NewOperand.append(Token) break - elif Token == 'FALSE': - if Op == 'OR': + elif Token == DEPEX_OPCODE_FALSE: + if Op == DEPEX_OPCODE_OR: continue else: NewOperand.append(Token) @@ -284,14 +300,14 @@ class DependencyExpression: NewOperand.append(Token) # don't generate depex if only TRUE operand left - if self.ModuleType == 'PEIM' and len(NewOperand) == 1 and NewOperand[0] == 'TRUE': + if self.ModuleType == SUP_MODULE_PEIM and len(NewOperand) == 1 and NewOperand[0] == DEPEX_OPCODE_TRUE: self.PostfixNotation = [] - return + return # don't generate depex if all operands are architecture protocols - if self.ModuleType in ['UEFI_DRIVER', 'DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'DXE_SMM_DRIVER'] and \ - Op == 'AND' and \ - self.ArchProtocols == set([GuidStructureStringToGuidString(Guid) for Guid in AllOperand]): + if self.ModuleType in [SUP_MODULE_UEFI_DRIVER, SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_MM_STANDALONE] and \ + Op == DEPEX_OPCODE_AND and \ + self.ArchProtocols == set(GuidStructureStringToGuidString(Guid) for Guid in AllOperand): self.PostfixNotation = [] return @@ -345,7 +361,7 @@ class DependencyExpression: FilePath = "" FileChangeFlag = True - if File == None: + if File is None: sys.stdout.write(Buffer.getvalue()) FilePath = "STDOUT" else: @@ -356,7 +372,7 @@ class DependencyExpression: versionNumber = ("0.04" + " " + gBUILD_VERSION) __version__ = "%prog Version " + versionNumber -__copyright__ = "Copyright (c) 2007-2010, Intel Corporation All rights reserved." +__copyright__ = "Copyright (c) 2007-2018, Intel Corporation All rights reserved." __usage__ = "%prog [options] [dependency_expression_file]" ## Parse command line options @@ -399,13 +415,13 @@ def Main(): EdkLogger.SetLevel(EdkLogger.QUIET) elif Option.verbose: EdkLogger.SetLevel(EdkLogger.VERBOSE) - elif Option.debug != None: + elif Option.debug is not None: EdkLogger.SetLevel(Option.debug + 1) else: EdkLogger.SetLevel(EdkLogger.INFO) try: - if Option.ModuleType == None or Option.ModuleType not in gType2Phase: + if Option.ModuleType is None or Option.ModuleType not in gType2Phase: EdkLogger.error("GenDepex", OPTION_MISSING, "Module type is not specified or supported") DxsFile = '' @@ -422,9 +438,9 @@ def Main(): EdkLogger.error("GenDepex", OPTION_MISSING, "No expression string or file given") Dpx = DependencyExpression(DxsString, Option.ModuleType, Option.Optimize) - if Option.OutputFile != None: + if Option.OutputFile is not None: FileChangeFlag = Dpx.Generate(Option.OutputFile) - if not FileChangeFlag and DxsFile: + if not FileChangeFlag and DxsFile: # # Touch the output file if its time stamp is older than the original # DXS file to avoid re-invoke this tool for the dependency check in build rule. @@ -435,7 +451,7 @@ def Main(): Dpx.Generate() except BaseException, X: EdkLogger.quiet("") - if Option != None and Option.debug != None: + if Option is not None and Option.debug is not None: EdkLogger.quiet(traceback.format_exc()) else: EdkLogger.quiet(str(X))