X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FDscClassObject.py;h=c2fa1c275a2d99a774e28a432307f602d114df96;hb=5397bd425eba0cd00c5f76c8d35f328ca625db0e;hp=ddccf6507da64170dae0ae4c23df60027d145cfd;hpb=30fdf1140b8d1ce93f3821d986fa165552023440;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/Common/DscClassObject.py b/BaseTools/Source/Python/Common/DscClassObject.py index ddccf6507d..c2fa1c275a 100644 --- a/BaseTools/Source/Python/Common/DscClassObject.py +++ b/BaseTools/Source/Python/Common/DscClassObject.py @@ -1,8 +1,8 @@ ## @file # This file is used to define each component of DSC file # -# Copyright (c) 2007 ~ 2008, Intel Corporation -# All rights reserved. This program and the accompanying materials +# Copyright (c) 2007 - 2016, 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 # http://opensource.org/licenses/bsd-license.php @@ -14,7 +14,7 @@ ## # Import Modules # -import os +import Common.LongFilePathOs as os import EdkLogger as EdkLogger import Database from String import * @@ -28,6 +28,7 @@ from BuildToolError import * from Misc import sdict import GlobalData from Table.TableDsc import TableDsc +from Common.LongFilePathSupport import OpenLongFilePath as open # # Global variable @@ -91,17 +92,16 @@ class DscObject(object): class Dsc(DscObject): _NullClassIndex = 0 - def __init__(self, Filename = None, IsToDatabase = False, IsToPlatform = False, WorkspaceDir = None, Database = None): + def __init__(self, Filename=None, IsToDatabase=False, IsToPlatform=False, WorkspaceDir=None, Database=None): self.Identification = Identification() self.Platform = PlatformClass() self.UserExtensions = '' self.WorkspaceDir = WorkspaceDir self.IsToDatabase = IsToDatabase - - self.Cur = Database.Cur - self.TblFile = Database.TblFile - self.TblDsc = Database.TblDsc - + if Database: + self.Cur = Database.Cur + self.TblFile = Database.TblFile + self.TblDsc = Database.TblDsc self.KeyList = [ TAB_SKUIDS, TAB_LIBRARIES, TAB_LIBRARY_CLASSES, TAB_BUILD_OPTIONS, TAB_PCDS_FIXED_AT_BUILD_NULL, \ @@ -251,6 +251,12 @@ class Dsc(DscObject): Fdf = PlatformFlashDefinitionFileClass() Fdf.FilePath = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_DEFINES_FLASH_DEFINITION, Arch, self.FileID)[0]) self.Platform.FlashDefinitionFile = Fdf + Prebuild = BuildScriptClass() + Prebuild.FilePath = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_PREBUILD, Arch, self.FileID)[0]) + self.Platform.Prebuild = Prebuild + Postbuild = BuildScriptClass() + Postbuild.FilePath = NormPath(QueryDefinesItem(self.TblDsc, TAB_DSC_POSTBUILD, Arch, self.FileID)[0]) + self.Platform.Postbuild = Postbuild ## GenBuildOptions # @@ -385,10 +391,11 @@ class Dsc(DscObject): for IncludeFile in IncludeFiles: if IncludeFile[1] == Arch or IncludeFile[1] == TAB_ARCH_COMMON.upper(): Filename = CheckFileExist(self.WorkspaceDir, IncludeFile[0], ContainerFile, TAB_LIBRARIES, '', IncludeFile[2]) - for NewItem in open(Filename, 'r').readlines(): - if CleanString(NewItem) == '': - continue - MergeArches(Libraries, NewItem, Arch) + if os.path.exists(Filename): + for NewItem in open(Filename, 'r').readlines(): + if CleanString(NewItem) == '': + continue + MergeArches(Libraries, NewItem, Arch) for Record in RecordSet: if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper(): @@ -459,7 +466,7 @@ class Dsc(DscObject): # @param Type: The type of Pcd # @param ContainerFile: The file which describes the pcd, used for error report # - def GenPcds(self, Type = '', ContainerFile = ''): + def GenPcds(self, Type='', ContainerFile=''): Pcds = {} if Type == DataType.TAB_PCDS_PATCHABLE_IN_MODULE: Model = MODEL_PCD_PATCHABLE_IN_MODULE @@ -511,7 +518,7 @@ class Dsc(DscObject): # @param Type: The type of Pcd # @param ContainerFile: The file which describes the pcd, used for error report # - def GenFeatureFlagPcds(self, Type = '', ContainerFile = ''): + def GenFeatureFlagPcds(self, Type='', ContainerFile=''): Pcds = {} if Type == DataType.TAB_PCDS_FEATURE_FLAG: Model = MODEL_PCD_FEATURE_FLAG @@ -561,7 +568,7 @@ class Dsc(DscObject): # @param Type: The type of Pcd # @param ContainerFile: The file which describes the pcd, used for error report # - def GenDynamicDefaultPcds(self, Type = '', ContainerFile = ''): + def GenDynamicDefaultPcds(self, Type='', ContainerFile=''): Pcds = {} SkuInfoList = {} if Type == DataType.TAB_PCDS_DYNAMIC_DEFAULT: @@ -593,20 +600,20 @@ class Dsc(DscObject): if CleanString(NewItem) == '': continue (K1, K2, K3, K4, K5, K6) = GetDynamicDefaultPcd(NewItem, Type, Filename, -1) - MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, IncludeFile[4]), Arch) + MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, IncludeFile[4]), Arch) self.PcdToken[Record[3]] = (K2, K1) for Record in RecordSet: if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper(): (K1, K2, K3, K4, K5, K6) = GetDynamicDefaultPcd(Record[0], Type, ContainerFile, Record[2]) - MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, Record[4]), Arch) + MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, Record[4]), Arch) self.PcdToken[Record[3]] = (K2, K1) for Key in Pcds: (Status, SkuInfoList) = self.GenSkuInfoList(Key[6], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', '', Key[2]) if Status == False: ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type) - EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError = EdkLogger.IsRaiseError) + EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError=EdkLogger.IsRaiseError) Pcd = PcdClass(Key[0], '', Key[1], Key[3], Key[4], Key[2], Key[5], [], SkuInfoList, []) Pcd.SupArchList = Pcds[Key] self.Platform.DynamicPcdBuildDefinitions.append(Pcd) @@ -618,7 +625,7 @@ class Dsc(DscObject): # @param Type: The type of Pcd # @param ContainerFile: The file which describes the pcd, used for error report # - def GenDynamicHiiPcds(self, Type = '', ContainerFile = ''): + def GenDynamicHiiPcds(self, Type='', ContainerFile=''): Pcds = {} SkuInfoList = {} if Type == DataType.TAB_PCDS_DYNAMIC_HII: @@ -650,20 +657,20 @@ class Dsc(DscObject): if CleanString(NewItem) == '': continue (K1, K2, K3, K4, K5, K6, K7, K8) = GetDynamicHiiPcd(NewItem, Type, Filename, -1) - MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, K7, K8, IncludeFile[4]), Arch) + MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, K7, K8, IncludeFile[4]), Arch) self.PcdToken[Record[3]] = (K2, K1) for Record in RecordSet: if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper(): (K1, K2, K3, K4, K5, K6, K7, K8) = GetDynamicHiiPcd(Record[0], Type, ContainerFile, Record[2]) - MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, K7, K8, Record[4]), Arch) + MergeArches(Pcds, (K1, K2, K3, K4, K5, K6, K7, K8, Record[4]), Arch) self.PcdToken[Record[3]] = (K2, K1) for Key in Pcds: (Status, SkuInfoList) = self.GenSkuInfoList(Key[8], self.Platform.SkuInfos.SkuInfoList, Key[2], Key[3], Key[4], Key[5], '', '') if Status == False: ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type) - EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError = EdkLogger.IsRaiseError) + EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError=EdkLogger.IsRaiseError) Pcd = PcdClass(Key[0], '', Key[1], '', Key[6], Key[5], Key[7], [], SkuInfoList, []) Pcd.SupArchList = Pcds[Key] self.Platform.DynamicPcdBuildDefinitions.append(Pcd) @@ -675,7 +682,7 @@ class Dsc(DscObject): # @param Type: The type of Pcd # @param ContainerFile: The file which describes the pcd, used for error report # - def GenDynamicVpdPcds(self, Type = '', ContainerFile = ''): + def GenDynamicVpdPcds(self, Type='', ContainerFile=''): Pcds = {} SkuInfoList = {} if Type == DataType.TAB_PCDS_DYNAMIC_VPD: @@ -707,20 +714,20 @@ class Dsc(DscObject): if CleanString(NewItem) == '': continue (K1, K2, K3, K4, K5) = GetDynamicVpdPcd(NewItem, Type, Filename, -1) - MergeArches(Pcds, (K1, K2, K3, K4, K5, IncludeFile[4]), Arch) + MergeArches(Pcds, (K1, K2, K3, K4, K5, IncludeFile[4]), Arch) self.PcdToken[Record[3]] = (K2, K1) for Record in RecordSet: if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON.upper(): (K1, K2, K3, K4, K5) = GetDynamicVpdPcd(Record[0], Type, ContainerFile, Record[2]) - MergeArches(Pcds, (K1, K2, K3, K4, K5, Record[4]), Arch) + MergeArches(Pcds, (K1, K2, K3, K4, K5, Record[4]), Arch) self.PcdToken[Record[3]] = (K2, K1) for Key in Pcds: (Status, SkuInfoList) = self.GenSkuInfoList(Key[5], self.Platform.SkuInfos.SkuInfoList, '', '', '', '', Key[2], '') if Status == False: ErrorMsg = "The SKUID '%s' used in section '%s' is not defined in section [SkuIds]" % (SkuInfoList, Type) - EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError = EdkLogger.IsRaiseError) + EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, ContainerFile, RaiseError=EdkLogger.IsRaiseError) Pcd = PcdClass(Key[0], '', Key[1], '', Key[3], '', Key[4], [], SkuInfoList, []) Pcd.SupArchList = Pcds[Key] self.Platform.DynamicPcdBuildDefinitions.append(Pcd) @@ -768,7 +775,7 @@ class Dsc(DscObject): SubLibSet = QueryDscItem(self.TblDsc, MODEL_EFI_LIBRARY_CLASS, Record[3], self.FileID) for SubLib in SubLibSet: - Lib.append(TAB_VALUE_SPLIT.join([SubLib[0],SubLib[4]])) + Lib.append(TAB_VALUE_SPLIT.join([SubLib[0], SubLib[4]])) SubBoSet = QueryDscItem(self.TblDsc, MODEL_META_DATA_BUILD_OPTION, Record[3], self.FileID) for SubBo in SubBoSet: @@ -805,7 +812,7 @@ class Dsc(DscObject): # # @retval PlatformModuleClass() A instance for PlatformModuleClass # - def GenComponent(self, Item, ContainerFile, LineNo = -1): + def GenComponent(self, Item, ContainerFile, LineNo= -1): (InfFilename, ExecFilename) = GetExec(Item[0]) LibraryClasses = Item[1] BuildOptions = Item[2] @@ -893,7 +900,7 @@ class Dsc(DscObject): # @retval (False, SkuName) Not found in section SkuId Dsc file # @retval (True, SkuInfoList) Found in section SkuId of Dsc file # - def GenSkuInfoList(self, SkuNameList, SkuInfo, VariableName = '', VariableGuid = '', VariableOffset = '', HiiDefaultValue = '', VpdOffset = '', DefaultValue = ''): + def GenSkuInfoList(self, SkuNameList, SkuInfo, VariableName='', VariableGuid='', VariableOffset='', HiiDefaultValue='', VpdOffset='', DefaultValue=''): SkuNameList = GetSplitValueList(SkuNameList) if SkuNameList == None or SkuNameList == [] or SkuNameList == ['']: SkuNameList = ['DEFAULT'] @@ -963,7 +970,7 @@ class Dsc(DscObject): (Value1, Value2, Value3, Model, StartColumn, EndColumn, Enabled) = ('', '', '', -1, -1, -1, 0) if IfDefList == []: ErrorMsg = 'Not suited conditional statement in file %s' % Filename - EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, Filename, RaiseError = EdkLogger.IsRaiseError) + EdkLogger.error("DSC File Parser", PARSER_ERROR, ErrorMsg, Filename, RaiseError=EdkLogger.IsRaiseError) else: # # Get New Dsc item ID @@ -988,10 +995,14 @@ class Dsc(DscObject): # elif PreviousIf[2] in (MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, Model): List = PreviousIf[0].split(' ') - Value1 = List[0] - Value2 = List[1] - Value3 = List[2] - Value3 = SplitString(Value3) + Value1, Value2, Value3 = '', '==', '0' + if len(List) == 3: + Value1 = List[0] + Value2 = List[1] + Value3 = List[2] + Value3 = SplitString(Value3) + if len(List) == 1: + Value1 = List[0] Model = PreviousIf[2] self.TblDsc.Insert(Model, Value1, Value2, Value3, ArchList, BelongsToItem, self.FileID, PreviousIf[1], StartColumn, EndLine, EndColumn, Enabled) # @@ -1040,11 +1051,11 @@ class Dsc(DscObject): # # Remove comment block # - if Line.find(TAB_COMMENT_R8_START) > -1: - ReservedLine = GetSplitValueList(Line, TAB_COMMENT_R8_START, 1)[0] + if Line.find(TAB_COMMENT_EDK_START) > -1: + ReservedLine = GetSplitList(Line, TAB_COMMENT_EDK_START, 1)[0] IsFindBlockComment = True - if Line.find(TAB_COMMENT_R8_END) > -1: - Line = ReservedLine + GetSplitValueList(Line, TAB_COMMENT_R8_END, 1)[1] + if Line.find(TAB_COMMENT_EDK_END) > -1: + Line = ReservedLine + GetSplitList(Line, TAB_COMMENT_EDK_END, 1)[1] ReservedLine = '' IsFindBlockComment = False if IsFindBlockComment: @@ -1082,7 +1093,7 @@ class Dsc(DscObject): CurrentSection = ItemList[0] else: if CurrentSection != ItemList[0]: - EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError) + EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError) if CurrentSection.upper() not in self.KeyList: RaiseParserError(Line, CurrentSection, Filename, '', LineNo) CurrentSection = TAB_UNKNOWN @@ -1093,7 +1104,7 @@ class Dsc(DscObject): RaiseParserError(Line, CurrentSection, Filename, '', LineNo) else: if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL: - EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError) + EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError) ArchList.append(ItemList[1].upper()) ThirdList.append(ItemList[2]) @@ -1104,7 +1115,7 @@ class Dsc(DscObject): # if CurrentSection == TAB_UNKNOWN: ErrorMsg = "%s is not in any defined section" % Line - EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError) + EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError) # # Add a section item @@ -1156,7 +1167,7 @@ class Dsc(DscObject): MODEL_META_DATA_DEFINE) RecordSet = self.TblDsc.Exec(SqlCommand) for Record in RecordSet: - SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" %(self.TblDsc.Table, Record[0], Record[1]) + SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self.TblDsc.Table, Record[0], Record[1]) self.TblDsc.Exec(SqlCommand) # @@ -1180,8 +1191,8 @@ class Dsc(DscObject): MODEL_META_DATA_DEFINE) RecordSet = self.TblDsc.Exec(SqlCommand) for Record in RecordSet: - SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" %(self.TblDsc.Table, Record[0], Record[1]) - EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand) + SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self.TblDsc.Table, Record[0], Record[1]) + EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) # @@ -1205,13 +1216,13 @@ class Dsc(DscObject): for Record in RecordSet: if Record[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_IF: if not self.Compare(Record[6], Record[2], Record[3]): - SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" %(self.TblDsc.Table, Record[4], Record[5]) + SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self.TblDsc.Table, Record[4], Record[5]) self.TblDsc.Exec(SqlCommand) else: DisabledList.append(Record[1]) continue if Record[0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE and Record[1] in DisabledList: - SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" %(self.TblDsc.Table, Record[4], Record[5]) + SqlCommand = """Update %s set Enabled = -1 where StartLine >= %s and EndLine <= %s""" % (self.TblDsc.Table, Record[4], Record[5]) self.TblDsc.Exec(SqlCommand) ## Compare @@ -1222,7 +1233,7 @@ class Dsc(DscObject): # @param Value2: # def Compare(self, Value1, CompareType, Value2): - Command = """Value1 %s Value2""" %CompareType + Command = """Value1 %s Value2""" % CompareType return eval(Command) ## First time to insert records to database @@ -1254,7 +1265,7 @@ class Dsc(DscObject): LineValue, StartLine, EndLine = SectionItem[0], SectionItem[1], SectionItem[1] - EdkLogger.debug(4, "Parsing %s ..." %LineValue) + EdkLogger.debug(4, "Parsing %s ..." % LineValue) # # Parse '!ifdef' # @@ -1332,10 +1343,10 @@ class Dsc(DscObject): Components = [] GetComponent(SectionItemList, Components) for Component in Components: - EdkLogger.debug(4, "Parsing component %s ..." %Component) + EdkLogger.debug(4, "Parsing component %s ..." % Component) DscItmeID = self.TblDsc.Insert(MODEL_META_DATA_COMPONENT, Component[0], '', '', Arch, -1, FileID, StartLine, -1, StartLine, -1, 0) for Item in Component[1]: - List = GetSplitValueList(Item, MaxSplit = 2) + List = GetSplitValueList(Item, MaxSplit=2) LibName, LibIns = '', '' if len(List) == 2: LibName = List[0]